Salome HOME
7f9f493f699e17bb262483694325c10affc72de7
[modules/med.git] / src / MEDCoupling / MEDCouplingRefCountObject.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingRefCountObject.hxx"
22 #include "MED_version.h"
23
24 using namespace ParaMEDMEM;
25
26 const char *ParaMEDMEM::MEDCouplingVersionStr()
27 {
28   return SALOMEMED_VERSION_STR;
29 }
30
31 int ParaMEDMEM::MEDCouplingVersion()
32 {
33   return SALOMEMED_VERSION;
34 }
35
36 void ParaMEDMEM::MEDCouplingVersionMajMinRel(int& maj, int& minor, int& releas)
37 {
38   int ver=SALOMEMED_VERSION;
39   maj=(ver & 0xFF0000) >> 16;
40   minor=(ver & 0xFF00) >> 8;
41   releas=(ver & 0xFF);
42 }
43
44 int ParaMEDMEM::MEDCouplingSizeOfVoidStar()
45 {
46   return 8*sizeof(std::size_t);
47 }
48
49 /*!
50  * If true is returned it is a LittleEndian machine.
51  * If false it is a BigEndian machine.
52  * \return the coding mode of integers of the machine.
53  */
54 bool ParaMEDMEM::MEDCouplingByteOrder()
55 {
56   unsigned int x(1);
57   unsigned char *xc(reinterpret_cast<unsigned char *>(&x));
58   return xc[0]==1;
59 }
60
61 const char *ParaMEDMEM::MEDCouplingByteOrderStr()
62 {
63   static const char LITTLEENDIAN_STR[]="LittleEndian";
64   static const char BIGENDIAN_STR[]="BigEndian";
65   if(MEDCouplingByteOrder())
66     return LITTLEENDIAN_STR;
67   else
68     return BIGENDIAN_STR;
69 }
70
71 RefCountObject::RefCountObject():_cnt(1)
72 {
73 }
74
75 RefCountObject::RefCountObject(const RefCountObject& other):_cnt(1)
76 {
77 }
78
79 /*!
80  * Do nothing here ! It is not a bug ( I hope :) ) because all subclasses that
81  * copies using operator= should not copy the ref counter of \a other !
82  */
83 RefCountObject& RefCountObject::operator=(const RefCountObject& other)
84 {
85   return *this;
86 }
87
88 bool RefCountObject::decrRef() const
89 {
90   bool ret=((--_cnt)==0);
91   if(ret)
92     delete this;
93   return ret;
94 }
95
96 void RefCountObject::incrRef() const
97 {
98   _cnt++;
99 }
100
101 int RefCountObject::getRCValue() const
102 {
103   return _cnt;
104 }
105
106 RefCountObject::~RefCountObject()
107 {
108 }