blob: ba954de670fa21ef1bfa9d3e5395862528815d00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// File: MDF_DriverTable.gxx
// -------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 May 6 1997 Creation
#include TheHDriver_hxx
#include MDF_DataMapIteratorOfTypeDriverListMap_hxx
#include MDF_DriverList_hxx
//=======================================================================
//function : MDF_DriverTable
//purpose :
//=======================================================================
MDF_DriverTable::MDF_DriverTable() :
myVersion(-1)
{}
//=======================================================================
//function : SetDriver
//purpose : Sets a driver in its List,
// in decreasing version number order
//=======================================================================
void MDF_DriverTable::SetDriver
(const Handle(TheHDriver)& anHDriver)
{
const Handle(Standard_Type)& type = anHDriver->SourceType();
if (myMapOfLst.IsBound(type)) {
MDF_DriverList& lst = myMapOfLst.ChangeFind(type);
if (lst.IsEmpty()) {
lst.Append(anHDriver);
}
else {
Standard_Integer driverVersion = anHDriver->VersionNumber();
Standard_Integer currentVersion;
for (MDF_ListIteratorOfDriverList itr(lst); itr.More(); itr.Next()) {
const Handle(TheHDriver)& driver = itr.Value();
currentVersion = driver->VersionNumber();
if (driverVersion == currentVersion) {
lst.Remove(itr);
if (lst.IsEmpty()) lst.Append(anHDriver);
else lst.InsertBefore(anHDriver,itr);
break;
}
else if (driverVersion > currentVersion) {
lst.InsertAfter(anHDriver,itr);
break;
}
}
}
}
else {
MDF_DriverList lst;
lst.Append(anHDriver);
myMapOfLst.Bind(type,lst);
}
myMap.Clear();
}
//=======================================================================
//function : SetDrivers
//purpose :
//=======================================================================
void MDF_DriverTable::SetDrivers
(const Handle(TheDriverHSeq)& aDriverHSeq)
{
const Standard_Integer upper = aDriverHSeq->Length();
for (Standard_Integer i = 1; i <= upper; ++i)
SetDriver(aDriverHSeq->Value(i));
}
//=======================================================================
//function : GetDrivers
//purpose :
//=======================================================================
const TheTypeDriverMap& MDF_DriverTable::GetDrivers
(const Standard_Integer aVersion)
{
if ((myMap.IsEmpty()) || (myVersion != aVersion)) {
// Rebuild the map.
Handle(TheHDriver) driver;
MDF_DataMapIteratorOfTypeDriverListMap itr(myMapOfLst);
for ( ; itr.More(); itr.Next()) {
const Handle(Standard_Type)& type = itr.Key();
if (MDF_DriverTable::GetDriver(type, driver, aVersion))
myMap.Bind(type, driver);
}
myVersion = aVersion;
}
return myMap;
}
//=======================================================================
//function : GetDriver
//purpose :
//=======================================================================
Standard_Boolean MDF_DriverTable::GetDriver
(const Handle(Standard_Type)& aType,
Handle(TheHDriver)& anHDriver,
const Standard_Integer aVersion) const
{
Standard_Boolean found = Standard_False;
if (myMapOfLst.IsBound(aType)) {
const MDF_DriverList& lst = myMapOfLst.Find(aType);
if ( (aVersion == 0) && !lst.IsEmpty() ) {
found = Standard_True;
anHDriver = lst.First();
}
else {
for (MDF_ListIteratorOfDriverList itr(lst); itr.More(); itr.Next()) {
const Handle(TheHDriver)& driver = itr.Value();
if (driver->VersionNumber() >= aVersion) {
found = Standard_True;
anHDriver = driver;
break;
}
}
}
}
return found;
}
|