0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / Storage / Storage_RootData.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
16 #include <Standard_Persistent.hxx>
17 #include <Standard_ErrorHandler.hxx>
18 #include <Standard_NoSuchObject.hxx>
19 #include <Storage_RootData.hxx>
20 #include <Storage_Root.hxx>
21 #include <Storage_BaseDriver.hxx>
22 #include <Storage_StreamTypeMismatchError.hxx>
23 #include <Storage_DataMapIteratorOfMapOfPers.hxx>
24 #include <TCollection_AsciiString.hxx>
25
26 IMPLEMENT_STANDARD_RTTIEXT(Storage_RootData,MMgt_TShared)
27
28 Storage_RootData::Storage_RootData() : myErrorStatus(Storage_VSOk)
29 {
30 }
31
32 Standard_Boolean Storage_RootData::Read (Storage_BaseDriver& theDriver)
33 {
34   // Check driver open mode
35   if (theDriver.OpenMode() != Storage_VSRead
36    && theDriver.OpenMode() != Storage_VSReadWrite)
37   {
38     myErrorStatus = Storage_VSModeError;
39     myErrorStatusExt = "OpenMode";
40     return Standard_False;
41   }
42
43   // Read root section
44   myErrorStatus = theDriver.BeginReadRootSection();
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
54   Standard_Integer len = theDriver.RootSectionSize();
55   for (Standard_Integer i = 1; i <= len; i++)
56   {
57     try
58     {
59       OCC_CATCH_SIGNALS
60       theDriver.ReadRoot (aRootName, aRef, aTypeName);
61     }
62     catch (Storage_StreamTypeMismatchError)
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
73   myErrorStatus = theDriver.EndReadRootSection();
74   if (myErrorStatus != Storage_VSOk)
75   {
76     myErrorStatusExt = "EndReadRootSection";
77     return Standard_False;
78   }
79
80   return Standard_True;
81 }
82
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 {
134     throw Standard_NoSuchObject();
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 }