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 | |
7ed7467d |
16 | #include <Standard_ErrorHandler.hxx> |
42cf5bc1 |
17 | #include <Standard_NoSuchObject.hxx> |
42cf5bc1 |
18 | #include <Storage_TypeData.hxx> |
7ed7467d |
19 | #include <Storage_BaseDriver.hxx> |
20 | #include <Storage_StreamTypeMismatchError.hxx> |
42cf5bc1 |
21 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
22 | |
92efcf78 |
23 | IMPLEMENT_STANDARD_RTTIEXT(Storage_TypeData,MMgt_TShared) |
24 | |
7fd59977 |
25 | Storage_TypeData::Storage_TypeData() : myErrorStatus(Storage_VSOk) |
26 | { |
27 | } |
28 | |
7ed7467d |
29 | Standard_Boolean Storage_TypeData::Read (Storage_BaseDriver& theDriver) |
30 | { |
31 | // Check driver open mode |
32 | if (theDriver.OpenMode() != Storage_VSRead |
33 | && theDriver.OpenMode() != Storage_VSReadWrite) |
34 | { |
35 | myErrorStatus = Storage_VSModeError; |
36 | myErrorStatusExt = "OpenMode"; |
37 | return Standard_False; |
38 | } |
39 | |
40 | // Read type section |
41 | myErrorStatus = theDriver.BeginReadTypeSection(); |
42 | if (myErrorStatus != Storage_VSOk) |
43 | { |
44 | myErrorStatusExt = "BeginReadTypeSection"; |
45 | return Standard_False; |
46 | } |
47 | |
48 | Standard_Integer aTypeNum; |
49 | TCollection_AsciiString aTypeName; |
50 | |
51 | Standard_Integer len = theDriver.TypeSectionSize(); |
52 | for (Standard_Integer i = 1; i <= len; i++) |
53 | { |
54 | try |
55 | { |
56 | OCC_CATCH_SIGNALS |
57 | theDriver.ReadTypeInformations (aTypeNum, aTypeName); |
58 | } |
59 | catch (Storage_StreamTypeMismatchError) |
60 | { |
61 | myErrorStatus = Storage_VSTypeMismatch; |
62 | myErrorStatusExt = "ReadTypeInformations"; |
63 | return Standard_False; |
64 | } |
65 | |
66 | myPt.Add (aTypeName, aTypeNum); |
67 | } |
68 | |
69 | myErrorStatus = theDriver.EndReadTypeSection(); |
70 | if (myErrorStatus != Storage_VSOk) |
71 | { |
72 | myErrorStatusExt = "EndReadTypeSection"; |
73 | return Standard_False; |
74 | } |
75 | |
76 | return Standard_True; |
77 | } |
78 | |
7fd59977 |
79 | Standard_Integer Storage_TypeData::NumberOfTypes() const |
80 | { |
81 | return myPt.Extent(); |
82 | } |
83 | |
84 | Standard_Boolean Storage_TypeData::IsType(const TCollection_AsciiString& aName) const |
85 | { |
86 | return myPt.Contains(aName); |
87 | } |
88 | |
89 | Handle(TColStd_HSequenceOfAsciiString) Storage_TypeData::Types() const |
90 | { |
91 | Handle(TColStd_HSequenceOfAsciiString) r = new TColStd_HSequenceOfAsciiString; |
92 | Standard_Integer i; |
93 | |
94 | for (i = 1; i <= myPt.Extent(); i++) { |
95 | r->Append(myPt.FindKey(i)); |
96 | } |
97 | |
98 | return r; |
99 | } |
100 | |
101 | void Storage_TypeData::AddType(const TCollection_AsciiString& aName,const Standard_Integer aTypeNum) |
102 | { |
103 | myPt.Add(aName,aTypeNum); |
104 | } |
105 | |
106 | TCollection_AsciiString Storage_TypeData::Type(const Standard_Integer aTypeNum) const |
107 | { |
108 | TCollection_AsciiString r; |
109 | |
110 | if (aTypeNum <= myPt.Extent() && aTypeNum > 0) { |
111 | r = myPt.FindKey(aTypeNum); |
112 | } |
113 | else { |
9775fa61 |
114 | throw Standard_NoSuchObject("Storage_TypeData::Type - aTypeNum not in range"); |
7fd59977 |
115 | } |
116 | |
117 | return r; |
118 | } |
119 | |
120 | Standard_Integer Storage_TypeData::Type(const TCollection_AsciiString& aTypeName) const |
121 | { |
122 | Standard_Integer r = 0; |
123 | |
124 | if (myPt.Contains(aTypeName)) { |
125 | r = myPt.FindFromKey(aTypeName); |
126 | } |
127 | else { |
9775fa61 |
128 | throw Standard_NoSuchObject("Storage_TypeData::Type - aTypeName not found"); |
7fd59977 |
129 | } |
130 | |
131 | return r; |
132 | } |
133 | |
134 | void Storage_TypeData::Clear() |
135 | { |
136 | myPt.Clear(); |
137 | } |
138 | |
139 | Storage_Error Storage_TypeData::ErrorStatus() const |
140 | { |
141 | return myErrorStatus; |
142 | } |
143 | |
144 | void Storage_TypeData::SetErrorStatus(const Storage_Error anError) |
145 | { |
146 | myErrorStatus = anError; |
147 | } |
148 | |
149 | void Storage_TypeData::ClearErrorStatus() |
150 | { |
151 | myErrorStatus = Storage_VSOk; |
152 | myErrorStatusExt.Clear(); |
153 | } |
154 | |
155 | TCollection_AsciiString Storage_TypeData::ErrorStatusExtension() const |
156 | { |
157 | return myErrorStatusExt; |
158 | } |
159 | |
160 | void Storage_TypeData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt) |
161 | { |
162 | myErrorStatusExt = anErrorExt; |
163 | } |