0025622: CAST analysis: Avoid invocation of virtual Methods of the declared Class...
[occt.git] / src / DBC / DBC_BaseArray.cxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <Standard_OutOfRange.hxx> 
16 #include <Standard_NegativeValue.hxx>
17 #include <Standard_NullObject.hxx>
18 #include <Standard_NotImplemented.hxx>
19 //#include <DBC_DBVArray.hxx>
20 #include <DBC_BaseArray.ixx>
21
22 #ifdef OBJS
23 #include <Standard_Persistent.hxx>
24
25 // taille a partir de laquelle la tableau cre son propre container
26 //
27 #define DBC_TAILLE_PLAFOND_CREATION_SEGMENT 10000 
28
29 #include <StandardOBJS_PersistentMacro.hxx>
30 #include <StandardOBJS_PrimitiveTypes.hxx>
31
32 // just use for internal generic identifiaction of Item
33 //
34 static PStandard_ArrayNode DBC_tmpItem;
35
36 #endif
37
38 #ifdef OO2
39 #include <StandardDB_O2Handle.hxx>
40 #endif
41
42 // --------------------------------------------------------------------
43 // BaseArray implementation  : Temporary arrays known as variable-size arrays.
44 //                          BaseArray of BaseArray is not supported in this version.
45 // 
46 // Last Revision : Feb,10 1992 J.P Tirault
47 //                 . Implementation of Lock/Unlock methods :
48 //                 . Implementation of ShallowCopy,ShallowDump,IsSameState.
49 //                               
50 // Last Revision : April,4 1992 J.P Tirault, R Barreto
51 //                 . Implementation for Object store.
52 //                 . Implementation for Memory.
53 //                               
54 // Last Revision : September,17 1992 J.P Tirault
55 //                 . Free old area in Resize method. 
56 // Last revision : January,18 1995 N. Massip
57 //                   . Implementation for ObjectStore 
58 //                   with an c++ persistent array
59 //   This version store all the information for the Item
60 // in case of non primitive type, the handle, the Standard oid,
61 // and the object itself are stored
62 // if the oid_standard disapear, it may become interresting to
63 // store only the object itself. So a special version who store
64 // only the Object is join in comment with each function who
65 // may be different, the Haeder of this ccomment is like this :
66 //
67 //   For no Handle Storing
68      /*
69         <code>
70      */
71 //   Last revision : April 19 1992 N. Massip
72 //                     . Implementation for o2 technology
73 //                     with an o2_array for 4.5
74 //                     should be d_Varray for 4.6
75 //                Use an Collection of StandardDB_O2Handle
76 //                for none primitive type to avoid to import
77 //                Handle(Standard_Persistent).
78 // --------------------------------------------------------------------
79 //   Last revision : January 1996 JMS/CLE
80 //                   portage OBJY 3.8
81
82 // --------------------------------------------------------------------
83 //                                  Constructor
84 // --------------------------------------------------------------------
85 DBC_BaseArray::DBC_BaseArray (const Standard_Integer Size) 
86 #ifdef OBJY
87      //==== Call the father's constructor.
88      : myData((unsigned int) Size)
89 #endif
90
91 #ifdef OO2
92      : myData((unsigned int) Size)
93 #endif
94 {
95   Standard_NegativeValue_Raise_if((Size < 0), "Attempt to create aBaseArray with a bad size");
96   mySize = Size;
97 // Standard_Integer i;
98 #ifdef OBJSold
99   INTERNAL_MODE_OODB_START {
100     os_segment *seg = Storage_CurrentContainer(); 
101     if ( Size > DBC_TAILLE_PLAFOND_CREATION_SEGMENT ) { 
102       os_database *db = seg->database_of();
103       Storage_CurrentContainer() = db->create_segment();
104     }        
105     myData = Standard_PersistentAllocation(DBC_tmpItem, Size);
106     Storage_CurrentContainer() = seg;
107   }
108   INTERNAL_MODE_OODB_END;
109   
110 #endif
111
112
113 }
114
115
116 DBC_BaseArray::DBC_BaseArray () 
117
118 #ifdef OBJY
119    //==== Call the father's constructor.
120    : myData(0)
121 #endif
122
123 #ifdef OO2
124      : myData((unsigned int) 0)
125 #endif
126 {
127   mySize = 0;
128
129 #ifdef OBJS
130   myData = NULL;
131 #endif
132 }
133
134
135 // --------------------------------------------------------------------
136 //                                  Constructor
137
138 // --------------------------------------------------------------------
139 DBC_BaseArray::DBC_BaseArray (const DBC_BaseArray& Other) 
140 #ifdef OBJY
141      //==== Call the father's constructor.
142      : myData(Other.myData)
143 #endif
144
145 // utilisable pour d_array mais pas o2_list
146 #ifdef OO2
147      //==== Call the father's constructor.
148      : myData(Other.myData)
149 #endif
150 {
151
152   mySize = Other.mySize;
153
154 #ifdef OBJSold
155   INTERNAL_MODE_OODB_START {    
156     myData = Standard_PersistentAllocation(DBC_tmpItem, mySize);
157     for(Standard_Integer i=0; i<mySize; i++)
158       myData[i] = Other.myData[i];
159   }
160   INTERNAL_MODE_OODB_END;   
161 #endif
162
163
164 }
165
166 DBC_BaseArray::~DBC_BaseArray()
167 {
168 }
169
170
171 // --------------------------------------------------------------------
172 //                                  Lock
173 //
174 //   - Call the oodb method update which 
175 // --------------------------------------------------------------------
176 Standard_Address DBC_BaseArray::Lock () const
177 {
178 #ifdef OBJY
179   return (Standard_Address) &(myData.elem(0));
180 #endif
181
182 #ifdef OO2
183   return (Standard_Address) &(Value(0));
184 #endif
185
186 #ifdef OBJS
187   Standard_Address adr;
188   INTERNAL_MODE_OODB_START {
189     adr = (Standard_Address) &myData;
190   }
191   INTERNAL_MODE_OODB_END;
192   return adr;
193 #endif
194
195 #ifdef CSFDB
196   return (Standard_Address) myData;
197 #endif
198 }
199
200
201 // --------------------------------------------------------------------
202 //                                  Unlock
203 // --------------------------------------------------------------------
204 void DBC_BaseArray::Unlock() const
205 {
206 }
207
208
209 #ifdef OO2
210 // Liste de fonctionnalire permettent de manipuler StandardDB_O2Handle et
211 // les types primitifs de maniere tranparente
212 //
213 inline Item &O2Handle_getValue(const StandardDB_O2Handle &val) {
214
215   //Item *hd = (Item *) val.getHandle();
216   //return *hd; 
217   return * ((Item *) val.getHandle());
218 }
219 // polymorphisme avec type primitif
220
221 inline Standard_Boolean      &O2Handle_getValue(const Standard_Boolean &val) {
222   return (Standard_Boolean) val;
223 };
224 inline Standard_Integer      &O2Handle_getValue(const Standard_Integer &val){
225   return (Standard_Integer) val;
226 };
227 inline Standard_Real         &O2Handle_getValue(const Standard_Real &val){
228   return (Standard_Real) val;
229 };
230 inline Standard_Character    &O2Handle_getValue(const Standard_Character &val){
231   return (Standard_Character) val;
232 };
233 inline Standard_ExtCharacter &O2Handle_getValue(const Standard_ExtCharacter &val){
234   return (Standard_ExtCharacter) val;
235 };
236 inline Standard_CString      &O2Handle_getValue(const Standard_CString &val){
237   return (Standard_CString) val;
238 };
239 inline Standard_ExtString    &O2Handle_getValue(const Standard_ExtString &val){
240   return (Standard_ExtString) val;
241 };
242 inline Standard_Address      &O2Handle_getValue(const Standard_Address &val){
243   return (Standard_Address ) val;
244 };
245 inline Standard_ShortReal    &O2Handle_getValue(const Standard_ShortReal &val){
246   return (Standard_ShortReal) val;
247 };
248 #endif
249  
250
251