b311480e |
1 | // Created on: 2002-10-29 |
2 | // Created by: Michael SAZONOV |
3 | // Copyright (c) 2002-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | #include <BinMDF_ADriverTable.ixx> |
22 | #include <Standard_NoSuchObject.hxx> |
23 | #include <BinMDF_StringIdMap.hxx> |
24 | #include <TCollection_HAsciiString.hxx> |
25 | #include <BinMDF_DataMapIteratorOfTypeADriverMap.hxx> |
26 | |
27 | //======================================================================= |
28 | //function : BinMDF_ADriverTable |
29 | //purpose : Constructor |
30 | //======================================================================= |
31 | |
32 | BinMDF_ADriverTable::BinMDF_ADriverTable () |
33 | { |
34 | } |
35 | |
36 | //======================================================================= |
37 | //function : AddDriver |
38 | //purpose : Adds a translation driver <theDriver>. |
39 | //======================================================================= |
40 | |
41 | void BinMDF_ADriverTable::AddDriver |
42 | (const Handle(BinMDF_ADriver)& theDriver) |
43 | { |
44 | const Handle(Standard_Type)& aType = theDriver->SourceType(); |
45 | myMap.Bind (aType, theDriver); |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : AssignIds |
50 | //purpose : Assigns the IDs to the drivers of the given Types. |
51 | // It uses indices in the map as IDs. |
52 | // Useful in storage procedure. |
53 | //======================================================================= |
54 | |
55 | void BinMDF_ADriverTable::AssignIds |
56 | (const TColStd_IndexedMapOfTransient& theTypes) |
57 | { |
58 | myMapId.Clear(); |
59 | Standard_Integer i; |
60 | for (i=1; i <= theTypes.Extent(); i++) { |
61 | const Handle(Standard_Type)& aType = |
62 | Handle(Standard_Type)::DownCast (theTypes(i)); |
63 | if (myMap.IsBound (aType)) { |
64 | myMapId.Bind (aType, i); |
65 | } |
66 | else { |
67 | Standard_NoSuchObject::Raise |
68 | ((TCollection_AsciiString("BinMDF_ADriverTable::AssignIds : ") + |
69 | "the type " + aType->Name() + " has not been registered").ToCString()); |
70 | } |
71 | } |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : AssignIds |
76 | //purpose : Assigns the IDs to the drivers of the given Type Names; |
77 | // It uses indices in the sequence as IDs. |
78 | // Useful in retrieval procedure. |
79 | //======================================================================= |
80 | |
81 | void BinMDF_ADriverTable::AssignIds |
82 | (const TColStd_SequenceOfAsciiString& theTypeNames) |
83 | { |
84 | myMapId.Clear(); |
85 | // first prepare the data map (TypeName => TypeID) for input types |
86 | BinMDF_StringIdMap aStringIdMap; |
87 | Standard_Integer i; |
88 | for (i=1; i <= theTypeNames.Length(); i++) { |
89 | const TCollection_AsciiString& aTypeName = theTypeNames(i); |
90 | aStringIdMap.Bind (aTypeName, i); |
91 | } |
92 | // and now associate the names with the registered types |
93 | BinMDF_DataMapIteratorOfTypeADriverMap it (myMap); |
94 | for (; it.More(); it.Next()) { |
95 | const Handle(Standard_Type)& aType = it.Key(); |
96 | const Handle(BinMDF_ADriver)& aDriver = it.Value(); |
97 | const TCollection_AsciiString& aTypeName = aDriver->TypeName(); |
98 | if (aStringIdMap.IsBound(aTypeName)) { |
99 | i = aStringIdMap(aTypeName); |
100 | myMapId.Bind (aType, i); |
101 | } |
102 | } |
103 | } |