-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathStdStorage_RootData.cxx
More file actions
215 lines (185 loc) · 5.72 KB
/
StdStorage_RootData.cxx
File metadata and controls
215 lines (185 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdObjMgt_Persistent.hxx>
#include <Standard_ErrorHandler.hxx>
#include <StdStorage_RootData.hxx>
#include <StdStorage_Root.hxx>
#include <Storage_BaseDriver.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
#include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(StdStorage_RootData, Standard_Transient)
StdStorage_RootData::StdStorage_RootData()
: myErrorStatus(Storage_VSOk)
{
}
bool StdStorage_RootData::Read(const occ::handle<Storage_BaseDriver>& theDriver)
{
// Check driver open mode
if (theDriver->OpenMode() != Storage_VSRead && theDriver->OpenMode() != Storage_VSReadWrite)
{
myErrorStatus = Storage_VSModeError;
myErrorStatusExt = "OpenMode";
return false;
}
// Read root section
myErrorStatus = theDriver->BeginReadRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginReadRootSection";
return false;
}
TCollection_AsciiString aRootName, aTypeName;
int aRef;
int len = theDriver->RootSectionSize();
for (int i = 1; i <= len; i++)
{
try
{
OCC_CATCH_SIGNALS
theDriver->ReadRoot(aRootName, aRef, aTypeName);
}
catch (Storage_StreamTypeMismatchError const&)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "ReadRoot";
return false;
}
occ::handle<StdStorage_Root> aRoot = new StdStorage_Root(aRootName, aRef, aTypeName);
myObjects.Add(aRootName, aRoot);
}
myErrorStatus = theDriver->EndReadRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndReadRootSection";
return false;
}
return true;
}
bool StdStorage_RootData::Write(const occ::handle<Storage_BaseDriver>& theDriver)
{
// Check driver open mode
if (theDriver->OpenMode() != Storage_VSWrite && theDriver->OpenMode() != Storage_VSReadWrite)
{
myErrorStatus = Storage_VSModeError;
myErrorStatusExt = "OpenMode";
return false;
}
// Write root section
myErrorStatus = theDriver->BeginWriteRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "BeginWriteRootSection";
return false;
}
theDriver->SetRootSectionSize(NumberOfRoots());
for (NCollection_IndexedDataMap<TCollection_AsciiString, occ::handle<StdStorage_Root>>::Iterator
anIt(myObjects);
anIt.More();
anIt.Next())
{
const occ::handle<StdStorage_Root>& aRoot = anIt.Value();
try
{
OCC_CATCH_SIGNALS
theDriver->WriteRoot(aRoot->Name(), aRoot->Reference(), aRoot->Type());
}
catch (Storage_StreamTypeMismatchError const&)
{
myErrorStatus = Storage_VSTypeMismatch;
myErrorStatusExt = "ReadRoot";
return false;
}
}
myErrorStatus = theDriver->EndWriteRootSection();
if (myErrorStatus != Storage_VSOk)
{
myErrorStatusExt = "EndWriteRootSection";
return false;
}
return true;
}
int StdStorage_RootData::NumberOfRoots() const
{
return myObjects.Extent();
}
void StdStorage_RootData::AddRoot(const occ::handle<StdStorage_Root>& aRoot)
{
myObjects.Add(aRoot->Name(), aRoot);
aRoot->myRef = myObjects.Size();
}
occ::handle<NCollection_HSequence<occ::handle<StdStorage_Root>>> StdStorage_RootData::Roots() const
{
occ::handle<NCollection_HSequence<occ::handle<StdStorage_Root>>> anObjectsSeq =
new NCollection_HSequence<occ::handle<StdStorage_Root>>;
NCollection_IndexedDataMap<TCollection_AsciiString, occ::handle<StdStorage_Root>>::Iterator it(
myObjects);
for (; it.More(); it.Next())
{
anObjectsSeq->Append(it.Value());
}
return anObjectsSeq;
}
occ::handle<StdStorage_Root> StdStorage_RootData::Find(const TCollection_AsciiString& aName) const
{
const occ::handle<StdStorage_Root>* pRoot = myObjects.Seek(aName);
return pRoot ? *pRoot : occ::handle<StdStorage_Root>();
}
bool StdStorage_RootData::IsRoot(const TCollection_AsciiString& aName) const
{
return myObjects.Contains(aName);
}
void StdStorage_RootData::RemoveRoot(const TCollection_AsciiString& aName)
{
occ::handle<StdStorage_Root>* pRoot = myObjects.ChangeSeek(aName);
if (pRoot)
{
(*pRoot)->myRef = 0;
myObjects.RemoveKey(aName);
int aRef = 1;
for (NCollection_IndexedDataMap<TCollection_AsciiString, occ::handle<StdStorage_Root>>::Iterator
anIt(myObjects);
anIt.More();
anIt.Next(), ++aRef)
anIt.ChangeValue()->myRef = aRef;
}
}
void StdStorage_RootData::Clear()
{
for (NCollection_IndexedDataMap<TCollection_AsciiString, occ::handle<StdStorage_Root>>::Iterator
anIt(myObjects);
anIt.More();
anIt.Next())
anIt.ChangeValue()->myRef = 0;
myObjects.Clear();
}
Storage_Error StdStorage_RootData::ErrorStatus() const
{
return myErrorStatus;
}
void StdStorage_RootData::SetErrorStatus(const Storage_Error anError)
{
myErrorStatus = anError;
}
void StdStorage_RootData::ClearErrorStatus()
{
myErrorStatus = Storage_VSOk;
myErrorStatusExt.Clear();
}
TCollection_AsciiString StdStorage_RootData::ErrorStatusExtension() const
{
return myErrorStatusExt;
}
void StdStorage_RootData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
{
myErrorStatusExt = anErrorExt;
}