1 // Created on: 1999-06-11
2 // Created by: Vladislav ROMASHKO
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Standard_GUID.hxx>
19 #include <Standard_Type.hxx>
20 #include <TCollection_ExtendedString.hxx>
22 #include <TFunction_DataMapIteratorOfDataMapOfGUIDDriver.hxx>
23 #include <TFunction_DataMapOfGUIDDriver.hxx>
24 #include <TFunction_Driver.hxx>
25 #include <TFunction_DriverTable.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(TFunction_DriverTable,Standard_Transient)
29 static Handle(TFunction_DriverTable) DT;
31 //=======================================================================
34 //=======================================================================
36 Handle(TFunction_DriverTable) TFunction_DriverTable::Get()
38 if (DT.IsNull()) DT = new TFunction_DriverTable;
42 //=======================================================================
43 //function : TFunction_DriverTable
44 //purpose : Constructor
45 //=======================================================================
47 TFunction_DriverTable::TFunction_DriverTable()
50 //=======================================================================
51 //function : AddDriver
52 //purpose : Adds a driver to the DriverTable
53 //=======================================================================
55 Standard_Boolean TFunction_DriverTable::AddDriver(const Standard_GUID& guid,
56 const Handle(TFunction_Driver)& driver,
57 const Standard_Integer thread)
60 return myDrivers.Bind(guid,driver);
63 if (myThreadDrivers.IsNull())
65 // Create a new table for thread-drivers.
66 myThreadDrivers = new TFunction_HArray1OfDataMapOfGUIDDriver(1, thread);
68 else if (myThreadDrivers->Upper() < thread)
70 // Create a bigger table for thread-drivers.
71 Handle(TFunction_HArray1OfDataMapOfGUIDDriver) new_dt = new TFunction_HArray1OfDataMapOfGUIDDriver(1, thread);
72 // Copy old table to the expanded (new) one.
73 Standard_Integer i = 1, old_upper = myThreadDrivers->Upper();
74 for (; i <= old_upper; i++)
76 const TFunction_DataMapOfGUIDDriver& t = myThreadDrivers->Value(i);
77 TFunction_DataMapIteratorOfDataMapOfGUIDDriver itrt(t);
78 for (; itrt.More(); itrt.Next())
80 new_dt->ChangeValue(i).Bind(itrt.Key(), itrt.Value());
83 myThreadDrivers = new_dt;
85 return myThreadDrivers->ChangeValue(thread).Bind(guid, driver);
87 return Standard_False;
90 //=======================================================================
91 //function : HasDriver
93 //=======================================================================
95 Standard_Boolean TFunction_DriverTable::HasDriver(const Standard_GUID& guid,
96 const Standard_Integer thread) const
99 return myDrivers.IsBound(guid);
100 else if (thread > 0 && !myThreadDrivers.IsNull() && myThreadDrivers->Upper() >= thread)
101 return myThreadDrivers->Value(thread).IsBound(guid);
102 return Standard_False;
105 //=======================================================================
106 //function : FindDriver
107 //purpose : Returns the driver if find
108 //=======================================================================
110 Standard_Boolean TFunction_DriverTable::FindDriver(const Standard_GUID& guid,
111 Handle(TFunction_Driver)& driver,
112 const Standard_Integer thread) const
116 if (myDrivers.IsBound(guid))
118 driver = myDrivers.Find(guid);
119 return Standard_True;
122 else if (thread > 0 && !myThreadDrivers.IsNull() && myThreadDrivers->Upper() >= thread)
124 if (myThreadDrivers->Value(thread).IsBound(guid))
126 driver = myThreadDrivers->Value(thread).Find(guid);
127 return Standard_True;
130 return Standard_False;
133 //=======================================================================
136 //=======================================================================
138 Standard_OStream& TFunction_DriverTable::Dump(Standard_OStream& anOS) const
140 TFunction_DataMapIteratorOfDataMapOfGUIDDriver itr(myDrivers);
141 for (; itr.More(); itr.Next())
143 itr.Key().ShallowDump(anOS);
145 TCollection_ExtendedString es;
146 TDF::ProgIDFromGUID(itr.Key(), es);
152 //=======================================================================
153 //function : RemoveDriver
154 //purpose : Removes a driver from the DriverTable
155 //=======================================================================
157 Standard_Boolean TFunction_DriverTable::RemoveDriver(const Standard_GUID& guid,
158 const Standard_Integer thread)
161 return myDrivers.UnBind(guid);
162 else if (thread > 0 && !myThreadDrivers.IsNull() && myThreadDrivers->Upper() >= thread)
163 myThreadDrivers->ChangeValue(thread).UnBind(guid);
164 return Standard_False;
167 //=======================================================================
169 //purpose : Removes all drivers
170 //=======================================================================
172 void TFunction_DriverTable::Clear()
175 if (!myThreadDrivers.IsNull())
176 myThreadDrivers.Nullify();