0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / BinMDF / BinMDF_ADriverTable.cxx
CommitLineData
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
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>
ec357c5c 21#include <Standard_Type.hxx>
7fd59977 22
23//=======================================================================
24//function : BinMDF_ADriverTable
25//purpose : Constructor
26//=======================================================================
27
28BinMDF_ADriverTable::BinMDF_ADriverTable ()
29{
30}
31
32//=======================================================================
33//function : AddDriver
34//purpose : Adds a translation driver <theDriver>.
35//=======================================================================
36
37void 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
51void BinMDF_ADriverTable::AssignIds
52 (const TColStd_IndexedMapOfTransient& theTypes)
53{
54 myMapId.Clear();
55 Standard_Integer i;
56 for (i=1; i <= theTypes.Extent(); i++) {
c5f3a425 57 Handle(Standard_Type) aType (Handle(Standard_Type)::DownCast (theTypes(i)));
7fd59977 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
76void 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}