6588486cd130a77fad4263c9e51ed18d289a15a6
[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_NoSuchObject.hxx>
17 #include <Standard_Persistent.hxx>
18 #include <Standard_Type.hxx>
19 #include <Storage_DataMapIteratorOfMapOfPers.hxx>
20 #include <Storage_Root.hxx>
21 #include <Storage_RootData.hxx>
22 #include <Storage_Schema.hxx>
23 #include <TCollection_AsciiString.hxx>
24
25 IMPLEMENT_STANDARD_RTTIEXT(Storage_RootData,MMgt_TShared)
26
27 Storage_RootData::Storage_RootData() : myErrorStatus(Storage_VSOk)
28 {
29 }
30
31 Standard_Integer Storage_RootData::NumberOfRoots() const
32 {
33   return myObjects.Extent();
34 }
35
36 void Storage_RootData::AddRoot(const Handle(Storage_Root)& aRoot) 
37 {
38   myObjects.Bind(aRoot->Name(),aRoot);
39 }
40
41 Handle(Storage_HSeqOfRoot) Storage_RootData::Roots() const
42 {
43   Handle(Storage_HSeqOfRoot)   anObjectsSeq = new Storage_HSeqOfRoot;
44   Storage_DataMapIteratorOfMapOfPers it(myObjects);
45   
46   for(;it.More(); it.Next()) {
47     anObjectsSeq->Append(it.Value());
48   }
49
50   return anObjectsSeq;
51 }
52
53 Handle(Storage_Root) Storage_RootData::Find(const TCollection_AsciiString& aName) const
54 {
55   Handle(Storage_Root) p;
56
57   if (myObjects.IsBound(aName)) {
58     p = myObjects.Find(aName);
59   }
60
61   return p;
62 }
63
64 Standard_Boolean Storage_RootData::IsRoot(const TCollection_AsciiString& aName) const
65 {
66   return myObjects.IsBound(aName);
67 }
68
69 void Storage_RootData::RemoveRoot(const TCollection_AsciiString& aName) 
70 {
71   if (myObjects.IsBound(aName)) {
72     myObjects.UnBind(aName);    
73   }
74 }
75
76 void Storage_RootData::UpdateRoot(const TCollection_AsciiString& aName,const Handle(Standard_Persistent)& aPers) 
77 {
78   if (myObjects.IsBound(aName)) {
79     myObjects.ChangeFind(aName)->SetObject(aPers);
80   }
81   else {
82     Standard_NoSuchObject::Raise();
83   }
84 }
85
86 Storage_Error  Storage_RootData::ErrorStatus() const
87 {
88   return myErrorStatus;
89 }
90
91 void Storage_RootData::SetErrorStatus(const Storage_Error anError)
92 {
93   myErrorStatus = anError;
94 }
95
96 void Storage_RootData::ClearErrorStatus()
97 {
98   myErrorStatus = Storage_VSOk;
99   myErrorStatusExt.Clear();
100 }
101
102 TCollection_AsciiString Storage_RootData::ErrorStatusExtension() const
103 {
104   return myErrorStatusExt;
105 }
106
107 void Storage_RootData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
108 {
109   myErrorStatusExt = anErrorExt;
110 }