b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
42cf5bc1 |
15 | |
42cf5bc1 |
16 | #include <Standard_Persistent.hxx> |
7ed7467d |
17 | #include <Standard_ErrorHandler.hxx> |
18 | #include <Standard_NoSuchObject.hxx> |
42cf5bc1 |
19 | #include <Storage_RootData.hxx> |
7ed7467d |
20 | #include <Storage_Root.hxx> |
21 | #include <Storage_BaseDriver.hxx> |
22 | #include <Storage_StreamTypeMismatchError.hxx> |
23 | #include <Storage_DataMapIteratorOfMapOfPers.hxx> |
42cf5bc1 |
24 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
25 | |
25e59720 |
26 | IMPLEMENT_STANDARD_RTTIEXT(Storage_RootData,Standard_Transient) |
92efcf78 |
27 | |
7fd59977 |
28 | Storage_RootData::Storage_RootData() : myErrorStatus(Storage_VSOk) |
29 | { |
30 | } |
31 | |
39c8dc70 |
32 | Standard_Boolean Storage_RootData::Read (const Handle(Storage_BaseDriver)& theDriver) |
7ed7467d |
33 | { |
34 | // Check driver open mode |
39c8dc70 |
35 | if (theDriver->OpenMode() != Storage_VSRead |
36 | && theDriver->OpenMode() != Storage_VSReadWrite) |
7ed7467d |
37 | { |
38 | myErrorStatus = Storage_VSModeError; |
39 | myErrorStatusExt = "OpenMode"; |
40 | return Standard_False; |
41 | } |
42 | |
43 | // Read root section |
39c8dc70 |
44 | myErrorStatus = theDriver->BeginReadRootSection(); |
7ed7467d |
45 | if (myErrorStatus != Storage_VSOk) |
46 | { |
47 | myErrorStatusExt = "BeginReadRootSection"; |
48 | return Standard_False; |
49 | } |
50 | |
51 | TCollection_AsciiString aRootName, aTypeName; |
52 | Standard_Integer aRef; |
53 | |
39c8dc70 |
54 | Standard_Integer len = theDriver->RootSectionSize(); |
7ed7467d |
55 | for (Standard_Integer i = 1; i <= len; i++) |
56 | { |
57 | try |
58 | { |
59 | OCC_CATCH_SIGNALS |
39c8dc70 |
60 | theDriver->ReadRoot (aRootName, aRef, aTypeName); |
7ed7467d |
61 | } |
a738b534 |
62 | catch (Storage_StreamTypeMismatchError const&) |
7ed7467d |
63 | { |
64 | myErrorStatus = Storage_VSTypeMismatch; |
65 | myErrorStatusExt = "ReadRoot"; |
66 | return Standard_False; |
67 | } |
68 | |
69 | Handle(Storage_Root) aRoot = new Storage_Root (aRootName, aRef, aTypeName); |
70 | myObjects.Bind (aRootName, aRoot); |
71 | } |
72 | |
39c8dc70 |
73 | myErrorStatus = theDriver->EndReadRootSection(); |
7ed7467d |
74 | if (myErrorStatus != Storage_VSOk) |
75 | { |
76 | myErrorStatusExt = "EndReadRootSection"; |
77 | return Standard_False; |
78 | } |
79 | |
80 | return Standard_True; |
81 | } |
82 | |
7fd59977 |
83 | Standard_Integer Storage_RootData::NumberOfRoots() const |
84 | { |
85 | return myObjects.Extent(); |
86 | } |
87 | |
88 | void Storage_RootData::AddRoot(const Handle(Storage_Root)& aRoot) |
89 | { |
90 | myObjects.Bind(aRoot->Name(),aRoot); |
91 | } |
92 | |
93 | Handle(Storage_HSeqOfRoot) Storage_RootData::Roots() const |
94 | { |
95 | Handle(Storage_HSeqOfRoot) anObjectsSeq = new Storage_HSeqOfRoot; |
96 | Storage_DataMapIteratorOfMapOfPers it(myObjects); |
97 | |
98 | for(;it.More(); it.Next()) { |
99 | anObjectsSeq->Append(it.Value()); |
100 | } |
101 | |
102 | return anObjectsSeq; |
103 | } |
104 | |
105 | Handle(Storage_Root) Storage_RootData::Find(const TCollection_AsciiString& aName) const |
106 | { |
107 | Handle(Storage_Root) p; |
108 | |
109 | if (myObjects.IsBound(aName)) { |
110 | p = myObjects.Find(aName); |
111 | } |
112 | |
113 | return p; |
114 | } |
115 | |
116 | Standard_Boolean Storage_RootData::IsRoot(const TCollection_AsciiString& aName) const |
117 | { |
118 | return myObjects.IsBound(aName); |
119 | } |
120 | |
121 | void Storage_RootData::RemoveRoot(const TCollection_AsciiString& aName) |
122 | { |
123 | if (myObjects.IsBound(aName)) { |
124 | myObjects.UnBind(aName); |
125 | } |
126 | } |
127 | |
128 | void Storage_RootData::UpdateRoot(const TCollection_AsciiString& aName,const Handle(Standard_Persistent)& aPers) |
129 | { |
130 | if (myObjects.IsBound(aName)) { |
131 | myObjects.ChangeFind(aName)->SetObject(aPers); |
132 | } |
133 | else { |
9775fa61 |
134 | throw Standard_NoSuchObject(); |
7fd59977 |
135 | } |
136 | } |
137 | |
138 | Storage_Error Storage_RootData::ErrorStatus() const |
139 | { |
140 | return myErrorStatus; |
141 | } |
142 | |
143 | void Storage_RootData::SetErrorStatus(const Storage_Error anError) |
144 | { |
145 | myErrorStatus = anError; |
146 | } |
147 | |
148 | void Storage_RootData::ClearErrorStatus() |
149 | { |
150 | myErrorStatus = Storage_VSOk; |
151 | myErrorStatusExt.Clear(); |
152 | } |
153 | |
154 | TCollection_AsciiString Storage_RootData::ErrorStatusExtension() const |
155 | { |
156 | return myErrorStatusExt; |
157 | } |
158 | |
159 | void Storage_RootData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt) |
160 | { |
161 | myErrorStatusExt = anErrorExt; |
162 | } |