b7ba39b331a930faf49d24f9fe44321dfd518f6b
[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
22 //=======================================================================
23 //function : BinMDF_ADriverTable
24 //purpose  : Constructor
25 //=======================================================================
26
27 BinMDF_ADriverTable::BinMDF_ADriverTable ()
28 {
29 }
30
31 //=======================================================================
32 //function : AddDriver
33 //purpose  : Adds a translation driver <theDriver>.
34 //=======================================================================
35
36 void BinMDF_ADriverTable::AddDriver
37                 (const Handle(BinMDF_ADriver)& theDriver)
38 {
39   const Handle(Standard_Type)& aType = theDriver->SourceType();
40   myMap.Bind (aType, theDriver);
41 }
42
43 //=======================================================================
44 //function : AssignIds
45 //purpose  : Assigns the IDs to the drivers of the given Types.
46 //           It uses indices in the map as IDs.
47 //           Useful in storage procedure.
48 //=======================================================================
49
50 void BinMDF_ADriverTable::AssignIds
51                 (const TColStd_IndexedMapOfTransient& theTypes)
52 {
53   myMapId.Clear();
54   Standard_Integer i;
55   for (i=1; i <= theTypes.Extent(); i++) {
56     const Handle(Standard_Type)& aType =
57       Handle(Standard_Type)::DownCast (theTypes(i));
58     if (myMap.IsBound (aType)) {
59       myMapId.Bind (aType, i);
60     }
61     else {
62       Standard_NoSuchObject::Raise
63         ((TCollection_AsciiString("BinMDF_ADriverTable::AssignIds : ") +
64           "the type " + aType->Name() + " has not been registered").ToCString());
65     }
66   }
67 }
68
69 //=======================================================================
70 //function : AssignIds
71 //purpose  : Assigns the IDs to the drivers of the given Type Names;
72 //           It uses indices in the sequence as IDs.
73 //           Useful in retrieval procedure.
74 //=======================================================================
75
76 void BinMDF_ADriverTable::AssignIds
77                 (const TColStd_SequenceOfAsciiString& theTypeNames)
78 {
79   myMapId.Clear();
80   // first prepare the data map (TypeName => TypeID) for input types
81   BinMDF_StringIdMap aStringIdMap;
82   Standard_Integer i;
83   for (i=1; i <= theTypeNames.Length(); i++) {
84     const TCollection_AsciiString& aTypeName = theTypeNames(i);
85     aStringIdMap.Bind (aTypeName, i);
86   }
87   // and now associate the names with the registered types
88   BinMDF_DataMapIteratorOfTypeADriverMap it (myMap);
89   for (; it.More(); it.Next()) {
90     const Handle(Standard_Type)& aType = it.Key();
91     const Handle(BinMDF_ADriver)& aDriver = it.Value();
92     const TCollection_AsciiString& aTypeName = aDriver->TypeName();
93     if (aStringIdMap.IsBound(aTypeName)) {
94       i = aStringIdMap(aTypeName);
95       myMapId.Bind (aType, i);
96     }
97   }
98 }