1 // Created on: 2002-10-29
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BinMDF_ADriver.hxx>
18 #include <BinMDF_ADriverTable.hxx>
19 #include <BinMDF_DataMapIteratorOfTypeADriverMap.hxx>
20 #include <BinMDF_StringIdMap.hxx>
21 #include <Standard_NoSuchObject.hxx>
22 #include <Standard_Type.hxx>
23 #include <TCollection_HAsciiString.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(BinMDF_ADriverTable,Standard_Transient)
27 //=======================================================================
28 //function : BinMDF_ADriverTable
29 //purpose : Constructor
30 //=======================================================================
31 BinMDF_ADriverTable::BinMDF_ADriverTable ()
35 //=======================================================================
36 //function : AddDriver
37 //purpose : Adds a translation driver <theDriver>.
38 //=======================================================================
40 void BinMDF_ADriverTable::AddDriver
41 (const Handle(BinMDF_ADriver)& theDriver)
43 const Handle(Standard_Type)& aType = theDriver->SourceType();
44 myMap.Bind (aType, theDriver);
47 //=======================================================================
48 //function : AssignIds
49 //purpose : Assigns the IDs to the drivers of the given Types.
50 // It uses indices in the map as IDs.
51 // Useful in storage procedure.
52 //=======================================================================
54 void BinMDF_ADriverTable::AssignIds
55 (const TColStd_IndexedMapOfTransient& theTypes)
59 for (i=1; i <= theTypes.Extent(); i++) {
60 Handle(Standard_Type) aType (Handle(Standard_Type)::DownCast (theTypes(i)));
61 if (myMap.IsBound (aType)) {
62 myMapId.Bind (aType, i);
65 throw Standard_NoSuchObject((TCollection_AsciiString("BinMDF_ADriverTable::AssignIds : ") +
66 "the type " + aType->Name() + " has not been registered").ToCString());
71 //=======================================================================
72 //function : AssignIds
73 //purpose : Assigns the IDs to the drivers of the given Type Names;
74 // It uses indices in the sequence as IDs.
75 // Useful in retrieval procedure.
76 //=======================================================================
78 void BinMDF_ADriverTable::AssignIds
79 (const TColStd_SequenceOfAsciiString& theTypeNames)
82 // first prepare the data map (TypeName => TypeID) for input types
83 BinMDF_StringIdMap aStringIdMap;
85 for (i=1; i <= theTypeNames.Length(); i++) {
86 const TCollection_AsciiString& aTypeName = theTypeNames(i);
87 aStringIdMap.Bind (aTypeName, i);
89 // and now associate the names with the registered types
90 BinMDF_DataMapIteratorOfTypeADriverMap it (myMap);
91 for (; it.More(); it.Next()) {
92 const Handle(Standard_Type)& aType = it.Key();
93 const Handle(BinMDF_ADriver)& aDriver = it.Value();
94 const TCollection_AsciiString& aTypeName = aDriver->TypeName();
95 if (aStringIdMap.IsBound(aTypeName)) {
96 i = aStringIdMap(aTypeName);
97 myMapId.Bind (aType, i);