Salome HOME
5473a9a0467df7fabeaa9aa483bc20171f2ffbbf
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingRefCountObject.hxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 #ifndef __PARAMEDMEM_MEDCOUPLINGREFCOUNTOBJECT_HXX__
22 #define __PARAMEDMEM_MEDCOUPLINGREFCOUNTOBJECT_HXX__
23
24 #include "MEDCoupling.hxx"
25
26 #include <set>
27 #include <map>
28 #include <vector>
29 #include <string>
30 #include <cstddef>
31
32 namespace MEDCoupling
33 {
34   enum class DeallocType
35   {
36     C_DEALLOC = 2,
37     CPP_DEALLOC = 3,
38     C_DEALLOC_WITH_OFFSET = 4
39   };
40
41   //! The various spatial discretization of a field
42   typedef enum
43   {
44     ON_CELLS = 0,
45     ON_NODES = 1,
46     ON_GAUSS_PT = 2,
47     ON_GAUSS_NE = 3,
48     ON_NODES_KR = 4
49   } TypeOfField;
50
51   //! The various temporal discretization of a field
52   typedef enum
53   {
54     NO_TIME = 4,
55     ONE_TIME = 5,
56     LINEAR_TIME = 6,
57     CONST_ON_TIME_INTERVAL = 7
58   } TypeOfTimeDiscretization;
59
60   typedef bool (*FunctionToEvaluate)(const double *pos, double *res);
61
62   MEDCOUPLING_EXPORT const char *MEDCouplingVersionStr();
63   MEDCOUPLING_EXPORT int MEDCouplingVersion();
64   MEDCOUPLING_EXPORT void MEDCouplingVersionMajMinRel(int& maj, int& minor, int& releas);
65   MEDCOUPLING_EXPORT int MEDCouplingSizeOfVoidStar();
66   MEDCOUPLING_EXPORT bool MEDCouplingByteOrder();
67   MEDCOUPLING_EXPORT const char *MEDCouplingByteOrderStr();
68   MEDCOUPLING_EXPORT bool IsCXX11Compiled();
69   
70   class BigMemoryObject
71   {
72   public:
73     MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const;
74     MEDCOUPLING_EXPORT std::string getHeapMemorySizeStr() const;
75     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
76     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getAllTheProgeny() const;
77     MEDCOUPLING_EXPORT bool isObjectInTheProgeny(const BigMemoryObject *obj) const;
78     MEDCOUPLING_EXPORT static std::size_t GetHeapMemorySizeOfObjs(const std::vector<const BigMemoryObject *>& objs);
79     MEDCOUPLING_EXPORT virtual std::size_t getHeapMemorySizeWithoutChildren() const = 0;
80     MEDCOUPLING_EXPORT virtual std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const = 0;
81     MEDCOUPLING_EXPORT virtual ~BigMemoryObject();
82   private:
83     static std::size_t GetHeapMemoryOfSet(std::set<const BigMemoryObject *>& s1, std::set<const BigMemoryObject *>& s2);
84   };
85
86   class RefCountObjectOnly
87   {
88   protected:
89     MEDCOUPLING_EXPORT RefCountObjectOnly();
90     MEDCOUPLING_EXPORT RefCountObjectOnly(const RefCountObjectOnly& other);
91   public:
92     MEDCOUPLING_EXPORT bool decrRef() const;
93     MEDCOUPLING_EXPORT void incrRef() const;
94     MEDCOUPLING_EXPORT int getRCValue() const;
95     MEDCOUPLING_EXPORT RefCountObjectOnly& operator=(const RefCountObjectOnly& other);
96   protected:
97     virtual ~RefCountObjectOnly();
98   private:
99     mutable int _cnt;
100   };
101
102   class RefCountObject : public RefCountObjectOnly, public BigMemoryObject
103   {
104   protected:
105     MEDCOUPLING_EXPORT RefCountObject();
106     MEDCOUPLING_EXPORT RefCountObject(const RefCountObject& other);
107     MEDCOUPLING_EXPORT virtual ~RefCountObject();
108   };
109
110   class GlobalDict
111   {
112   public:
113     MEDCOUPLING_EXPORT static GlobalDict *GetInstance();
114     MEDCOUPLING_EXPORT bool hasKey(const std::string& key) const;
115     MEDCOUPLING_EXPORT std::string value(const std::string& key) const;
116     MEDCOUPLING_EXPORT std::vector<std::string> keys() const;
117     MEDCOUPLING_EXPORT void erase(const std::string& key);
118     MEDCOUPLING_EXPORT void clear();
119     MEDCOUPLING_EXPORT void setKeyValue(const std::string& key, const std::string& val);
120     MEDCOUPLING_EXPORT void setKeyValueForce(const std::string& key, const std::string& val);
121     MEDCOUPLING_EXPORT std::string printSelf() const;
122   private:
123     GlobalDict() { }
124   private:
125     static GlobalDict *UNIQUE_INSTANCE;
126   private:
127     std::map<std::string, std::string> _my_map;
128   };
129 }
130
131 #endif