Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Aspect / Aspect_GenId.cxx
1
2 // File         Aspect_GenId.cxx
3 // Created      Mai 1992
4 // Author       NW,JPB,CAL
5
6 //-Copyright    MatraDatavision 1991,1992
7
8 //-Version      
9
10 //-Design       Declaration des variables specifiques aux identificateurs
11
12 //-Warning      Un identificateur est un entier.
13
14 //-References   
15
16 //-Language     C++ 2.0
17
18 //-Declarations
19
20 // for the class
21 #include <Aspect_GenId.ixx>
22
23 //-Aliases
24
25 //-Global data definitions
26
27 //-Constructors
28
29 //-Destructors
30
31 //-Methods, in order
32
33 Aspect_GenId::Aspect_GenId ():
34
35         MyCount (INT_MAX/2 + 1),
36         MyLength (INT_MAX/2 + 1),
37         MyLowerBound (0),
38         MyUpperBound (INT_MAX/2),
39         MyFreeIds () {
40
41 }
42
43 Aspect_GenId::Aspect_GenId (const Standard_Integer Low, const Standard_Integer Up):MyFreeIds () {
44
45         if (Low <= Up) {
46                 MyLowerBound    = Low;
47                 MyUpperBound    = Up;
48                 MyLength        = MyUpperBound - MyLowerBound + 1;
49                 MyCount         = MyLength;
50         }
51         else
52                 Aspect_IdentDefinitionError::Raise
53                         ("GenId Create Error: Low > Up");
54
55 }
56
57 Standard_Integer Aspect_GenId::Available () const {
58
59         return (MyCount);
60
61 }
62
63 void Aspect_GenId::Free () {
64
65         MyCount = MyLength;
66         MyFreeIds.Clear ();
67
68 }
69
70 void Aspect_GenId::Free (const Standard_Integer Id) {
71
72         if ( (Id >= MyLowerBound) && (Id <= MyUpperBound) )
73                 MyFreeIds.Prepend (Id);
74
75 }
76
77 Standard_Integer Aspect_GenId::Lower () const {
78
79         return (MyLowerBound);
80
81 }
82
83 Standard_Integer Aspect_GenId::Next () {
84
85         if (MyCount == 0)
86                 Aspect_IdentDefinitionError::Raise
87                         ("GenId Next Error: Available == 0");
88
89 Standard_Integer Id;
90
91         if (! MyFreeIds.IsEmpty ()) {
92                 Id      = MyFreeIds.First ();
93                 MyFreeIds.RemoveFirst ();
94         }
95         else {
96                 MyCount --;
97                 Id      = MyLowerBound + MyLength - MyCount - 1;
98         }
99
100         return Id;
101
102 }
103
104 Standard_Integer Aspect_GenId::Upper () const {
105
106         return (MyUpperBound);
107
108 }
109
110 //void Aspect_GenId::Assign (const Aspect_GenId& Other) {
111 //
112 //      MyLowerBound    = Other.Lower ();
113 //      MyUpperBound    = Other.Upper ();
114 //
115 //}