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.
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>
26 IMPLEMENT_STANDARD_RTTIEXT(Storage_RootData,Standard_Transient)
28 Storage_RootData::Storage_RootData() : myErrorStatus(Storage_VSOk)
32 Standard_Boolean Storage_RootData::Read (Storage_BaseDriver& theDriver)
34 // Check driver open mode
35 if (theDriver.OpenMode() != Storage_VSRead
36 && theDriver.OpenMode() != Storage_VSReadWrite)
38 myErrorStatus = Storage_VSModeError;
39 myErrorStatusExt = "OpenMode";
40 return Standard_False;
44 myErrorStatus = theDriver.BeginReadRootSection();
45 if (myErrorStatus != Storage_VSOk)
47 myErrorStatusExt = "BeginReadRootSection";
48 return Standard_False;
51 TCollection_AsciiString aRootName, aTypeName;
52 Standard_Integer aRef;
54 Standard_Integer len = theDriver.RootSectionSize();
55 for (Standard_Integer i = 1; i <= len; i++)
60 theDriver.ReadRoot (aRootName, aRef, aTypeName);
62 catch (Storage_StreamTypeMismatchError const&)
64 myErrorStatus = Storage_VSTypeMismatch;
65 myErrorStatusExt = "ReadRoot";
66 return Standard_False;
69 Handle(Storage_Root) aRoot = new Storage_Root (aRootName, aRef, aTypeName);
70 myObjects.Bind (aRootName, aRoot);
73 myErrorStatus = theDriver.EndReadRootSection();
74 if (myErrorStatus != Storage_VSOk)
76 myErrorStatusExt = "EndReadRootSection";
77 return Standard_False;
83 Standard_Integer Storage_RootData::NumberOfRoots() const
85 return myObjects.Extent();
88 void Storage_RootData::AddRoot(const Handle(Storage_Root)& aRoot)
90 myObjects.Bind(aRoot->Name(),aRoot);
93 Handle(Storage_HSeqOfRoot) Storage_RootData::Roots() const
95 Handle(Storage_HSeqOfRoot) anObjectsSeq = new Storage_HSeqOfRoot;
96 Storage_DataMapIteratorOfMapOfPers it(myObjects);
98 for(;it.More(); it.Next()) {
99 anObjectsSeq->Append(it.Value());
105 Handle(Storage_Root) Storage_RootData::Find(const TCollection_AsciiString& aName) const
107 Handle(Storage_Root) p;
109 if (myObjects.IsBound(aName)) {
110 p = myObjects.Find(aName);
116 Standard_Boolean Storage_RootData::IsRoot(const TCollection_AsciiString& aName) const
118 return myObjects.IsBound(aName);
121 void Storage_RootData::RemoveRoot(const TCollection_AsciiString& aName)
123 if (myObjects.IsBound(aName)) {
124 myObjects.UnBind(aName);
128 void Storage_RootData::UpdateRoot(const TCollection_AsciiString& aName,const Handle(Standard_Persistent)& aPers)
130 if (myObjects.IsBound(aName)) {
131 myObjects.ChangeFind(aName)->SetObject(aPers);
134 throw Standard_NoSuchObject();
138 Storage_Error Storage_RootData::ErrorStatus() const
140 return myErrorStatus;
143 void Storage_RootData::SetErrorStatus(const Storage_Error anError)
145 myErrorStatus = anError;
148 void Storage_RootData::ClearErrorStatus()
150 myErrorStatus = Storage_VSOk;
151 myErrorStatusExt.Clear();
154 TCollection_AsciiString Storage_RootData::ErrorStatusExtension() const
156 return myErrorStatusExt;
159 void Storage_RootData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
161 myErrorStatusExt = anErrorExt;