1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
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>
23 #include <Standard_Persistent.hxx>
25 // taille a partir de laquelle la tableau cre son propre container
27 #define DBC_TAILLE_PLAFOND_CREATION_SEGMENT 10000
29 #include <StandardOBJS_PersistentMacro.hxx>
30 #include <StandardOBJS_PrimitiveTypes.hxx>
32 // just use for internal generic identifiaction of Item
34 static PStandard_ArrayNode DBC_tmpItem;
39 #include <StandardDB_O2Handle.hxx>
42 // --------------------------------------------------------------------
43 // BaseArray implementation : Temporary arrays known as variable-size arrays.
44 // BaseArray of BaseArray is not supported in this version.
46 // Last Revision : Feb,10 1992 J.P Tirault
47 // . Implementation of Lock/Unlock methods :
48 // . Implementation of ShallowCopy,ShallowDump,IsSameState.
50 // Last Revision : April,4 1992 J.P Tirault, R Barreto
51 // . Implementation for Object store.
52 // . Implementation for Memory.
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 :
67 // For no Handle Storing
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
82 // --------------------------------------------------------------------
84 // --------------------------------------------------------------------
85 DBC_BaseArray::DBC_BaseArray (const Standard_Integer Size)
87 //==== Call the father's constructor.
88 : myData((unsigned int) Size)
92 : myData((unsigned int) Size)
95 Standard_NegativeValue_Raise_if((Size < 0), "Attempt to create aBaseArray with a bad size");
97 // Standard_Integer i;
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();
105 myData = Standard_PersistentAllocation(DBC_tmpItem, Size);
106 Storage_CurrentContainer() = seg;
108 INTERNAL_MODE_OODB_END;
116 DBC_BaseArray::DBC_BaseArray ()
119 //==== Call the father's constructor.
124 : myData((unsigned int) 0)
135 // --------------------------------------------------------------------
138 // --------------------------------------------------------------------
139 DBC_BaseArray::DBC_BaseArray (const DBC_BaseArray& Other)
141 //==== Call the father's constructor.
142 : myData(Other.myData)
145 // utilisable pour d_array mais pas o2_list
147 //==== Call the father's constructor.
148 : myData(Other.myData)
152 mySize = Other.mySize;
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];
160 INTERNAL_MODE_OODB_END;
166 DBC_BaseArray::~DBC_BaseArray()
171 // --------------------------------------------------------------------
174 // - Call the oodb method update which
175 // --------------------------------------------------------------------
176 Standard_Address DBC_BaseArray::Lock () const
179 return (Standard_Address) &(myData.elem(0));
183 return (Standard_Address) &(Value(0));
187 Standard_Address adr;
188 INTERNAL_MODE_OODB_START {
189 adr = (Standard_Address) &myData;
191 INTERNAL_MODE_OODB_END;
196 return (Standard_Address) myData;
201 // --------------------------------------------------------------------
203 // --------------------------------------------------------------------
204 void DBC_BaseArray::Unlock() const
210 // Liste de fonctionnalire permettent de manipuler StandardDB_O2Handle et
211 // les types primitifs de maniere tranparente
213 inline Item &O2Handle_getValue(const StandardDB_O2Handle &val) {
215 //Item *hd = (Item *) val.getHandle();
217 return * ((Item *) val.getHandle());
219 // polymorphisme avec type primitif
221 inline Standard_Boolean &O2Handle_getValue(const Standard_Boolean &val) {
222 return (Standard_Boolean) val;
224 inline Standard_Integer &O2Handle_getValue(const Standard_Integer &val){
225 return (Standard_Integer) val;
227 inline Standard_Real &O2Handle_getValue(const Standard_Real &val){
228 return (Standard_Real) val;
230 inline Standard_Character &O2Handle_getValue(const Standard_Character &val){
231 return (Standard_Character) val;
233 inline Standard_ExtCharacter &O2Handle_getValue(const Standard_ExtCharacter &val){
234 return (Standard_ExtCharacter) val;
236 inline Standard_CString &O2Handle_getValue(const Standard_CString &val){
237 return (Standard_CString) val;
239 inline Standard_ExtString &O2Handle_getValue(const Standard_ExtString &val){
240 return (Standard_ExtString) val;
242 inline Standard_Address &O2Handle_getValue(const Standard_Address &val){
243 return (Standard_Address ) val;
245 inline Standard_ShortReal &O2Handle_getValue(const Standard_ShortReal &val){
246 return (Standard_ShortReal) val;