Salome HOME
Merge branch 'abn/fix_intersec' into V7_main
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingRefCountObject.i
1 // Copyright (C) 2007-2014  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 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 namespace ParaMEDMEM
40 {
41   class TimeLabel
42   {
43   public:
44     void declareAsNew() const;
45     virtual void updateTime() const;
46     unsigned int getTimeOfThis() const;
47   protected:
48     ~TimeLabel();
49   };
50 }
51
52 namespace ParaMEDMEM
53 {
54   typedef enum
55     {
56       C_DEALLOC = 2,
57       CPP_DEALLOC = 3
58     } DeallocType;
59
60   const char *MEDCouplingVersionStr();
61   int MEDCouplingVersion();
62   int MEDCouplingSizeOfVoidStar();
63   bool MEDCouplingByteOrder();
64   const char *MEDCouplingByteOrderStr();
65
66   class BigMemoryObject
67   {
68   public:
69     std::size_t getHeapMemorySize() const throw(INTERP_KERNEL::Exception);
70     std::string getHeapMemorySizeStr() const throw(INTERP_KERNEL::Exception);
71     virtual std::size_t getHeapMemorySizeWithoutChildren() const throw(INTERP_KERNEL::Exception);
72     virtual ~BigMemoryObject();
73     %extend
74     {
75       virtual PyObject *getDirectChildren() const throw(INTERP_KERNEL::Exception)
76       {
77         std::vector<const BigMemoryObject *> c(self->getDirectChildren());
78         PyObject *ret(PyList_New(c.size()));
79         for(std::size_t i=0;i<c.size();i++)
80           PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(c[i]),SWIGTYPE_p_ParaMEDMEM__BigMemoryObject, 0 | 0 ));
81         return ret;
82       }
83
84       static std::size_t GetHeapMemorySizeOfObjs(PyObject *objs) throw(INTERP_KERNEL::Exception)
85       {
86         std::vector<const BigMemoryObject *> cppObjs;
87         convertFromPyObjVectorOfObj<const ParaMEDMEM::BigMemoryObject *>(objs,SWIGTYPE_p_ParaMEDMEM__BigMemoryObject,"BigMemoryObject",cppObjs);
88         return BigMemoryObject::GetHeapMemorySizeOfObjs(cppObjs);
89       }
90     }
91   };
92   
93   class RefCountObjectOnly
94   {
95   public:
96     bool decrRef() const;
97     void incrRef() const;
98     int getRCValue() const;
99   protected:
100     ~RefCountObjectOnly();
101   };
102
103   class RefCountObject : public RefCountObjectOnly, public BigMemoryObject
104   {
105   protected:
106     ~RefCountObject();
107   };
108 }
109
110 %inline
111 {
112   PyObject *MEDCouplingVersionMajMinRel()
113   {
114     int tmp0=0,tmp1=0,tmp2=0;
115     MEDCouplingVersionMajMinRel(tmp0,tmp1,tmp2);
116     PyObject *res = PyList_New(3);
117     PyList_SetItem(res,0,SWIG_From_int(tmp0));
118     PyList_SetItem(res,1,SWIG_From_int(tmp1));
119     PyList_SetItem(res,2,SWIG_From_int(tmp2));
120     return res;
121   }
122
123   bool MEDCouplingHasNumPyBindings()
124   {
125 #ifdef WITH_NUMPY
126     return true;
127 #else
128     return false;
129 #endif
130   }
131
132   bool MEDCouplingHasSciPyBindings()
133   {
134 #ifdef WITH_SCIPY
135     return true;
136 #else
137     return false;
138 #endif
139   }
140
141   std::string MEDCouplingCompletionScript() throw(INTERP_KERNEL::Exception)
142   {
143     static const char script[]="import rlcompleter,readline\nreadline.parse_and_bind('tab:complete')";
144     std::ostringstream oss; oss << "MEDCouplingCompletionScript : error when trying to activate completion ! readline not present ?\nScript is :\n" << script;
145     if(PyRun_SimpleString(script)!=0)
146       throw INTERP_KERNEL::Exception(oss.str().c_str());
147     return std::string(script);
148   }
149 }