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_ErrorHandler.hxx>
17 #include <Standard_NoSuchObject.hxx>
18 #include <Storage_TypeData.hxx>
19 #include <Storage_BaseDriver.hxx>
20 #include <Storage_StreamTypeMismatchError.hxx>
21 #include <TCollection_AsciiString.hxx>
23 IMPLEMENT_STANDARD_RTTIEXT(Storage_TypeData,Standard_Transient)
25 Storage_TypeData::Storage_TypeData() : myErrorStatus(Storage_VSOk)
29 Standard_Boolean Storage_TypeData::Read (const Handle(Storage_BaseDriver)& theDriver)
31 // Check driver open mode
32 if (theDriver->OpenMode() != Storage_VSRead
33 && theDriver->OpenMode() != Storage_VSReadWrite)
35 myErrorStatus = Storage_VSModeError;
36 myErrorStatusExt = "OpenMode";
37 return Standard_False;
41 myErrorStatus = theDriver->BeginReadTypeSection();
42 if (myErrorStatus != Storage_VSOk)
44 myErrorStatusExt = "BeginReadTypeSection";
45 return Standard_False;
48 Standard_Integer aTypeNum;
49 TCollection_AsciiString aTypeName;
51 Standard_Integer len = theDriver->TypeSectionSize();
52 for (Standard_Integer i = 1; i <= len; i++)
57 theDriver->ReadTypeInformations (aTypeNum, aTypeName);
59 catch (const Storage_StreamTypeMismatchError&)
61 myErrorStatus = Storage_VSTypeMismatch;
62 myErrorStatusExt = "ReadTypeInformations";
63 return Standard_False;
66 myPt.Add (aTypeName, aTypeNum);
69 myErrorStatus = theDriver->EndReadTypeSection();
70 if (myErrorStatus != Storage_VSOk)
72 myErrorStatusExt = "EndReadTypeSection";
73 return Standard_False;
79 Standard_Integer Storage_TypeData::NumberOfTypes() const
84 Standard_Boolean Storage_TypeData::IsType(const TCollection_AsciiString& aName) const
86 return myPt.Contains(aName);
89 Handle(TColStd_HSequenceOfAsciiString) Storage_TypeData::Types() const
91 Handle(TColStd_HSequenceOfAsciiString) r = new TColStd_HSequenceOfAsciiString;
94 for (i = 1; i <= myPt.Extent(); i++) {
95 r->Append(myPt.FindKey(i));
101 void Storage_TypeData::AddType(const TCollection_AsciiString& aName,const Standard_Integer aTypeNum)
103 myPt.Add(aName,aTypeNum);
106 TCollection_AsciiString Storage_TypeData::Type(const Standard_Integer aTypeNum) const
108 TCollection_AsciiString r;
110 if (aTypeNum <= myPt.Extent() && aTypeNum > 0) {
111 r = myPt.FindKey(aTypeNum);
114 throw Standard_NoSuchObject("Storage_TypeData::Type - aTypeNum not in range");
120 Standard_Integer Storage_TypeData::Type(const TCollection_AsciiString& aTypeName) const
122 Standard_Integer r = 0;
124 if (myPt.Contains(aTypeName)) {
125 r = myPt.FindFromKey(aTypeName);
128 throw Standard_NoSuchObject("Storage_TypeData::Type - aTypeName not found");
134 void Storage_TypeData::Clear()
139 Storage_Error Storage_TypeData::ErrorStatus() const
141 return myErrorStatus;
144 void Storage_TypeData::SetErrorStatus(const Storage_Error anError)
146 myErrorStatus = anError;
149 void Storage_TypeData::ClearErrorStatus()
151 myErrorStatus = Storage_VSOk;
152 myErrorStatusExt.Clear();
155 TCollection_AsciiString Storage_TypeData::ErrorStatusExtension() const
157 return myErrorStatusExt;
160 void Storage_TypeData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
162 myErrorStatusExt = anErrorExt;