Salome HOME
fix: replace unordered_set/map with set/map
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingRefCountObject.i
1 // Copyright (C) 2007-2024  CEA, EDF
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 namespace INTERP_KERNEL
22 {
23   class Exception
24   {
25   public:
26     Exception(const char* what);
27     ~Exception() throw ();
28     const char *what() const throw ();
29     %extend
30     {
31       std::string __str__() const
32       {
33         return std::string(self->what());
34       }
35     }
36   };
37 }
38
39 /*
40  * ABN: Install default exception handler: this catches all INTERP_KERNEL::Exception (even when no
41  * except declaration was added to the function declaration) and propagates it to the Python level.
42  */
43 %exception {
44   try {
45     $action
46   }
47   catch (INTERP_KERNEL::Exception& _e) {
48     // Reraise with SWIG_Python_Raise
49     SWIG_Python_Raise(SWIG_NewPointerObj((new INTERP_KERNEL::Exception(static_cast< const INTERP_KERNEL::Exception& >(_e))),SWIGTYPE_p_INTERP_KERNEL__Exception,SWIG_POINTER_OWN), "INTERP_KERNEL::Exception", SWIGTYPE_p_INTERP_KERNEL__Exception);
50 #ifdef MEDCOUPLING_SWIG4_COMPAT
51     return nullptr;
52 #else
53     SWIG_fail;
54 #endif
55   }
56 }
57
58 namespace MEDCoupling
59 {
60   class TimeLabel
61   {
62   public:
63     void declareAsNew() const;
64     virtual void updateTime() const;
65     unsigned int getTimeOfThis() const;
66   protected:
67     ~TimeLabel();
68   };
69 }
70
71 namespace MEDCoupling
72 {
73   enum class DeallocType
74     {
75       C_DEALLOC = 2,
76       CPP_DEALLOC = 3
77     };
78
79   const char *MEDCouplingVersionStr();
80   int MEDCouplingVersion();
81   int MEDCouplingSizeOfVoidStar();
82   int MEDCouplingSizeOfIDs();
83   bool MEDCouplingByteOrder();
84   const char *MEDCouplingByteOrderStr();
85   bool IsCXX11Compiled();
86   
87   class BigMemoryObject
88   {
89   public:
90     std::size_t getHeapMemorySize() const;
91     std::string getHeapMemorySizeStr() const;
92     bool isObjectInTheProgeny(const BigMemoryObject *obj) const;
93     std::size_t getHeapMemorySizeWithoutChildren() const;
94     std::string debugHeapMemorySize() const;
95     std::string getClassName() const;
96     virtual ~BigMemoryObject();
97     %extend
98     {
99       virtual PyObject *getDirectChildren() const
100       {
101         std::vector<const BigMemoryObject *> c(self->getDirectChildren());
102         PyObject *ret(PyList_New(c.size()));
103         for(std::size_t i=0;i<c.size();i++)
104           PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(c[i]),SWIGTYPE_p_MEDCoupling__BigMemoryObject, 0 | 0 ));
105         return ret;
106       }
107
108       PyObject *getAllTheProgeny() const
109       {
110         std::vector<const BigMemoryObject *> c(self->getAllTheProgeny());
111         PyObject *ret(PyList_New(c.size()));
112         for(std::size_t i=0;i<c.size();i++)
113           PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(c[i]),SWIGTYPE_p_MEDCoupling__BigMemoryObject, 0 | 0 ));
114         return ret;
115       }
116
117       static std::size_t GetHeapMemorySizeOfObjs(PyObject *objs)
118       {
119         std::vector<const BigMemoryObject *> cppObjs;
120         convertFromPyObjVectorOfObj<const MEDCoupling::BigMemoryObject *>(objs,SWIGTYPE_p_MEDCoupling__BigMemoryObject,"BigMemoryObject",cppObjs);
121         return BigMemoryObject::GetHeapMemorySizeOfObjs(cppObjs);
122       }
123     }
124   };
125   
126   class RefCountObjectOnly
127   {
128   public:
129     bool decrRef() const;
130     void incrRef() const;
131     int getRCValue() const;
132   protected:
133     ~RefCountObjectOnly();
134   };
135
136   class RefCountObject : public RefCountObjectOnly, public BigMemoryObject
137   {
138   protected:
139     ~RefCountObject();
140   };
141
142   class GlobalDict
143   {
144   public:
145     static GlobalDict *GetInstance();
146     bool hasKey(const std::string& key) const;
147     std::string value(const std::string& key) const;
148     std::vector<std::string> keys() const;
149     void erase(const std::string& key);
150     void clear();
151     void setKeyValue(const std::string& key, const std::string& value);
152     void setKeyValueForce(const std::string& key, const std::string& value);
153   private:
154     GlobalDict();
155   public:
156     %extend
157     {
158       std::string __str__() const
159       {
160         return self->printSelf();
161       }
162     }
163   };
164 }
165
166 %inline
167 {
168   PyObject *MEDCouplingVersionMajMinRel()
169   {
170     int tmp0=0,tmp1=0,tmp2=0;
171     MEDCouplingVersionMajMinRel(tmp0,tmp1,tmp2);
172     PyObject *res = PyList_New(3);
173     PyList_SetItem(res,0,SWIG_From_int(tmp0));
174     PyList_SetItem(res,1,SWIG_From_int(tmp1));
175     PyList_SetItem(res,2,SWIG_From_int(tmp2));
176     return res;
177   }
178
179   bool MEDCouplingHasNumPyBindings()
180   {
181 #ifdef WITH_NUMPY
182     return true;
183 #else
184     return false;
185 #endif
186   }
187
188   bool MEDCouplingHasSciPyBindings()
189   {
190 #ifdef WITH_SCIPY
191     return true;
192 #else
193     return false;
194 #endif
195   }
196   
197   bool MEDCouplingUse64BitIDs()
198   {
199 #ifndef MEDCOUPLING_USE_64BIT_IDS
200     return false;
201 #else
202     return true;
203 #endif
204   }
205
206   std::string MEDCouplingCompletionScript()
207   {
208     static const char script[]="import rlcompleter,readline\nreadline.parse_and_bind('tab:complete')";
209     std::ostringstream oss; oss << "MEDCouplingCompletionScript : error when trying to activate completion ! readline not present ?\nScript is :\n" << script;
210     if(PyRun_SimpleString(script)!=0)
211       throw INTERP_KERNEL::Exception(oss.str().c_str());
212     return std::string(script);
213   }
214 }
215
216 %pythoncode %{
217 def INTERPKERNELExceptionReduceFunct(a,b):
218     ret=InterpKernelException.__new__(a)
219     ret.__init__(*b)
220     return ret
221 def INTERPKERNELExceptionReduce(self):
222     return INTERPKERNELExceptionReduceFunct,(InterpKernelException,(self.what(),))
223 %}