b311480e |
1 | // Created on: 2002-10-29 |
2 | // Created by: Michael SAZONOV |
973c2be1 |
3 | // Copyright (c) 2002-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
17 | #include <BinMDF_ADriver.hxx> |
18 | #include <BinMDF_ADriverTable.hxx> |
7fd59977 |
19 | #include <BinMDF_DataMapIteratorOfTypeADriverMap.hxx> |
42cf5bc1 |
20 | #include <BinMDF_StringIdMap.hxx> |
21 | #include <Standard_NoSuchObject.hxx> |
ec357c5c |
22 | #include <Standard_Type.hxx> |
42cf5bc1 |
23 | #include <TCollection_HAsciiString.hxx> |
7fd59977 |
24 | |
25e59720 |
25 | IMPLEMENT_STANDARD_RTTIEXT(BinMDF_ADriverTable,Standard_Transient) |
92efcf78 |
26 | |
7fd59977 |
27 | //======================================================================= |
28 | //function : BinMDF_ADriverTable |
29 | //purpose : Constructor |
30 | //======================================================================= |
7fd59977 |
31 | BinMDF_ADriverTable::BinMDF_ADriverTable () |
32 | { |
33 | } |
34 | |
35 | //======================================================================= |
36 | //function : AddDriver |
37 | //purpose : Adds a translation driver <theDriver>. |
38 | //======================================================================= |
39 | |
40 | void BinMDF_ADriverTable::AddDriver |
41 | (const Handle(BinMDF_ADriver)& theDriver) |
42 | { |
43 | const Handle(Standard_Type)& aType = theDriver->SourceType(); |
44 | myMap.Bind (aType, theDriver); |
45 | } |
46 | |
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 | //======================================================================= |
53 | |
54 | void BinMDF_ADriverTable::AssignIds |
55 | (const TColStd_IndexedMapOfTransient& theTypes) |
56 | { |
57 | myMapId.Clear(); |
58 | Standard_Integer i; |
59 | for (i=1; i <= theTypes.Extent(); i++) { |
c5f3a425 |
60 | Handle(Standard_Type) aType (Handle(Standard_Type)::DownCast (theTypes(i))); |
7fd59977 |
61 | if (myMap.IsBound (aType)) { |
62 | myMapId.Bind (aType, i); |
63 | } |
64 | else { |
9775fa61 |
65 | throw Standard_NoSuchObject((TCollection_AsciiString("BinMDF_ADriverTable::AssignIds : ") + |
7fd59977 |
66 | "the type " + aType->Name() + " has not been registered").ToCString()); |
67 | } |
68 | } |
69 | } |
70 | |
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 | //======================================================================= |
77 | |
78 | void BinMDF_ADriverTable::AssignIds |
79 | (const TColStd_SequenceOfAsciiString& theTypeNames) |
80 | { |
81 | myMapId.Clear(); |
82 | // first prepare the data map (TypeName => TypeID) for input types |
83 | BinMDF_StringIdMap aStringIdMap; |
84 | Standard_Integer i; |
85 | for (i=1; i <= theTypeNames.Length(); i++) { |
86 | const TCollection_AsciiString& aTypeName = theTypeNames(i); |
87 | aStringIdMap.Bind (aTypeName, i); |
88 | } |
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); |
98 | } |
99 | } |
100 | } |