0023024: Update headers of OCCT files
[occt.git] / src / Aspect / Aspect_GenId.cxx
1 // Created on: 1992-05-14
2 // Created by: NW,JPB,CAL
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23
24 //-Version      
25
26 //-Design       Declaration des variables specifiques aux identificateurs
27
28 //-Warning      Un identificateur est un entier.
29
30 //-References   
31
32 //-Language     C++ 2.0
33
34 //-Declarations
35
36 // for the class
37 #include <Aspect_GenId.ixx>
38
39 //-Aliases
40
41 //-Global data definitions
42
43 //-Constructors
44
45 //-Destructors
46
47 //-Methods, in order
48
49 Aspect_GenId::Aspect_GenId ():
50
51         MyCount (INT_MAX/2 + 1),
52         MyLength (INT_MAX/2 + 1),
53         MyLowerBound (0),
54         MyUpperBound (INT_MAX/2),
55         MyFreeIds () {
56
57 }
58
59 Aspect_GenId::Aspect_GenId (const Standard_Integer Low, const Standard_Integer Up):MyFreeIds () {
60
61         if (Low <= Up) {
62                 MyLowerBound    = Low;
63                 MyUpperBound    = Up;
64                 MyLength        = MyUpperBound - MyLowerBound + 1;
65                 MyCount         = MyLength;
66         }
67         else
68                 Aspect_IdentDefinitionError::Raise
69                         ("GenId Create Error: Low > Up");
70
71 }
72
73 Standard_Integer Aspect_GenId::Available () const {
74
75         return (MyCount);
76
77 }
78
79 void Aspect_GenId::Free () {
80
81         MyCount = MyLength;
82         MyFreeIds.Clear ();
83
84 }
85
86 void Aspect_GenId::Free (const Standard_Integer Id) {
87
88         if ( (Id >= MyLowerBound) && (Id <= MyUpperBound) )
89                 MyFreeIds.Prepend (Id);
90
91 }
92
93 Standard_Integer Aspect_GenId::Lower () const {
94
95         return (MyLowerBound);
96
97 }
98
99 Standard_Integer Aspect_GenId::Next () {
100
101         if (MyCount == 0)
102                 Aspect_IdentDefinitionError::Raise
103                         ("GenId Next Error: Available == 0");
104
105 Standard_Integer Id;
106
107         if (! MyFreeIds.IsEmpty ()) {
108                 Id      = MyFreeIds.First ();
109                 MyFreeIds.RemoveFirst ();
110         }
111         else {
112                 MyCount --;
113                 Id      = MyLowerBound + MyLength - MyCount - 1;
114         }
115
116         return Id;
117
118 }
119
120 Standard_Integer Aspect_GenId::Upper () const {
121
122         return (MyUpperBound);
123
124 }
125
126 //void Aspect_GenId::Assign (const Aspect_GenId& Other) {
127 //
128 //      MyLowerBound    = Other.Lower ();
129 //      MyUpperBound    = Other.Upper ();
130 //
131 //}