0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / BinMDF / BinMDF_ADriverTable.cxx
1 // Created on: 2002-10-29
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BinMDF_ADriverTable.ixx>
17 #include <Standard_NoSuchObject.hxx>
18 #include <BinMDF_StringIdMap.hxx>
19 #include <TCollection_HAsciiString.hxx>
20 #include <BinMDF_DataMapIteratorOfTypeADriverMap.hxx>
21 #include <Standard_Type.hxx>
22
23 //=======================================================================
24 //function : BinMDF_ADriverTable
25 //purpose  : Constructor
26 //=======================================================================
27
28 BinMDF_ADriverTable::BinMDF_ADriverTable ()
29 {
30 }
31
32 //=======================================================================
33 //function : AddDriver
34 //purpose  : Adds a translation driver <theDriver>.
35 //=======================================================================
36
37 void BinMDF_ADriverTable::AddDriver
38                 (const Handle(BinMDF_ADriver)& theDriver)
39 {
40   const Handle(Standard_Type)& aType = theDriver->SourceType();
41   myMap.Bind (aType, theDriver);
42 }
43
44 //=======================================================================
45 //function : AssignIds
46 //purpose  : Assigns the IDs to the drivers of the given Types.
47 //           It uses indices in the map as IDs.
48 //           Useful in storage procedure.
49 //=======================================================================
50
51 void BinMDF_ADriverTable::AssignIds
52                 (const TColStd_IndexedMapOfTransient& theTypes)
53 {
54   myMapId.Clear();
55   Standard_Integer i;
56   for (i=1; i <= theTypes.Extent(); i++) {
57     const Handle(Standard_Type)& aType =
58       Handle(Standard_Type)::DownCast (theTypes(i));
59     if (myMap.IsBound (aType)) {
60       myMapId.Bind (aType, i);
61     }
62     else {
63       Standard_NoSuchObject::Raise
64         ((TCollection_AsciiString("BinMDF_ADriverTable::AssignIds : ") +
65           "the type " + aType->Name() + " has not been registered").ToCString());
66     }
67   }
68 }
69
70 //=======================================================================
71 //function : AssignIds
72 //purpose  : Assigns the IDs to the drivers of the given Type Names;
73 //           It uses indices in the sequence as IDs.
74 //           Useful in retrieval procedure.
75 //=======================================================================
76
77 void BinMDF_ADriverTable::AssignIds
78                 (const TColStd_SequenceOfAsciiString& theTypeNames)
79 {
80   myMapId.Clear();
81   // first prepare the data map (TypeName => TypeID) for input types
82   BinMDF_StringIdMap aStringIdMap;
83   Standard_Integer i;
84   for (i=1; i <= theTypeNames.Length(); i++) {
85     const TCollection_AsciiString& aTypeName = theTypeNames(i);
86     aStringIdMap.Bind (aTypeName, i);
87   }
88   // and now associate the names with the registered types
89   BinMDF_DataMapIteratorOfTypeADriverMap it (myMap);
90   for (; it.More(); it.Next()) {
91     const Handle(Standard_Type)& aType = it.Key();
92     const Handle(BinMDF_ADriver)& aDriver = it.Value();
93     const TCollection_AsciiString& aTypeName = aDriver->TypeName();
94     if (aStringIdMap.IsBound(aTypeName)) {
95       i = aStringIdMap(aTypeName);
96       myMapId.Bind (aType, i);
97     }
98   }
99 }