Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/paravis.git] / src / Plugins / MedReader / IO / vtkMedSetGet.h
1 // Copyright (C) 2010-2012  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
20 #ifndef _vtkMedSetGet_h_
21 #define _vtkMedSetGet_h_
22
23 //BTX
24 template <class T> class vtkObjectVector;
25 template <class T> class vtkList;
26 template <class T> class vtkMedComputeStepMap;
27
28 #define vtkGetObjectVectorMacro(name, type)\
29   virtual type* Get##name (int index);\
30   virtual vtkIdType GetNumberOf##name ();
31
32 #define vtkSetObjectVectorMacro(name, type)\
33   virtual void  AllocateNumberOf##name (vtkIdType size);\
34   virtual void  Set##name (vtkIdType index, type* obj);\
35   virtual void  Append##name (type* obj);\
36   virtual void  Remove##name (type* obj);
37
38 #define vtkSetAbstractObjectVectorMacro(name, type)\
39   virtual void SetNumberOf##name (vtkIdType size);\
40   virtual void Set##name (vtkIdType index, type* obj);\
41   virtual void Append##name (type* obj);
42
43 #define vtkCxxGetObjectVectorMacro(class, name, type)\
44   type* class::Get##name (int index)\
45   {\
46     if(index < 0 || index >= this->name->size())\
47       return NULL;\
48     return this->name->at(index);\
49   }\
50   vtkIdType class::GetNumberOf##name ()\
51   {\
52     return this->name->size();\
53   }
54
55 #define vtkCxxSetObjectVectorMacro(class, name, type)\
56   void  class::AllocateNumberOf##name (vtkIdType size)\
57   {\
58     if(this->name->size() == size)\
59       return;\
60     if(size <= 0 )\
61       this->name->clear();\
62     else\
63       this->name->resize(size);\
64     for(vtkIdType _ii=0; _ii<this->name->size(); _ii++)\
65       {\
66         this->name->at(_ii) = vtkSmartPointer< type > ::New();\
67       }\
68     this->Modified();\
69   }\
70   void class::Set##name (vtkIdType index, type* obj)\
71   {\
72     if(index < 0 || index >= this->name->size())\
73     {\
74       vtkWarningMacro("has not been allocated before setting value" );\
75       return;\
76     }\
77     if( this->name->at(index) == obj)\
78       return;\
79     this->name->at(index) = obj; \
80     this->Modified();\
81   }\
82   void  class::Append##name (type* obj)\
83   {\
84     this->name->resize(this->name->size()+1);\
85     this->name->at(this->name->size()-1) = obj;\
86     this->Modified();\
87   }\
88   void  class::Remove##name (type* obj)\
89   {\
90     vtkIdType index=0;\
91     for(index=0; index < this->name->size(); index++)\
92      {\
93        if(this->name->at(index) == obj) break;\
94      }\
95     if(index == this->name->size()) return;\
96     for(vtkIdType id=index; id < this->name->size()-1; id++)\
97       {\
98         this->name->at(id) = this->name->at(id+1);\
99       }\
100     this->name->resize(this->name->size()-1);\
101     this->Modified();\
102   }
103
104 #define vtkCxxSetAbstractObjectVectorMacro(class, name, type)\
105   void  class::SetNumberOf##name (vtkIdType size)\
106   {\
107     if(this->name->size() == size)\
108       return;\
109     if(size <= 0 )\
110       this->name->clear();\
111     else\
112       this->name->resize(size);\
113     this->Modified();\
114   }\
115   void class::Set##name (vtkIdType index, type* obj)\
116   {\
117     if(index < 0 || index >= this->name->size())\
118     {\
119       vtkWarningMacro("has not been allocated before setting value" );\
120       return;\
121     }\
122     if( this->name->at(index) == obj)\
123       return;\
124     this->name->at(index) = obj; \
125     this->Modified();\
126   }\
127   void  class::Append##name (type* obj)\
128   {\
129     this->name->resize(this->name->size()+1);\
130     this->name->at(this->name->size()-1) = obj;\
131     this->Modified();\
132   }
133
134 //ETX
135
136 #endif