1 // Created on: 1992-05-14
2 // Created by: NW,JPB,CAL
3 // Copyright (c) 1992-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 <Aspect_GenId.hxx>
19 #include <Aspect_IdentDefinitionError.hxx>
21 // =======================================================================
22 // function : Aspect_GenId
24 // =======================================================================
25 Aspect_GenId::Aspect_GenId()
26 : myFreeCount (INT_MAX / 2 + 1),
27 myLength (INT_MAX / 2 + 1),
29 myUpperBound (INT_MAX / 2)
34 // =======================================================================
35 // function : Aspect_GenId
37 // =======================================================================
38 Aspect_GenId::Aspect_GenId (const Standard_Integer theLow,
39 const Standard_Integer theUpper)
40 : myFreeCount (theUpper - theLow + 1),
41 myLength (theUpper - theLow + 1),
42 myLowerBound (theLow),
43 myUpperBound (theUpper)
45 if (theLow > theUpper)
47 throw Aspect_IdentDefinitionError("GenId Create Error: wrong interval");
51 // =======================================================================
54 // =======================================================================
55 Standard_Boolean Aspect_GenId::HasFree() const
57 return myFreeCount > 0
58 || myFreeIds.Extent() > 0;
61 // =======================================================================
62 // function : Available
64 // =======================================================================
65 Standard_Integer Aspect_GenId::Available() const
67 return myFreeCount + myFreeIds.Extent();
70 // =======================================================================
73 // =======================================================================
74 void Aspect_GenId::Free()
76 myFreeCount = myLength;
80 // =======================================================================
83 // =======================================================================
84 void Aspect_GenId::Free (const Standard_Integer theId)
86 if (theId >= myLowerBound
87 && theId <= myUpperBound)
89 if (myFreeCount + myFreeIds.Extent() + 1 == myLength)
91 myFreeCount = myLength;
96 myFreeIds.Prepend (theId);
101 // =======================================================================
104 // =======================================================================
105 Standard_Integer Aspect_GenId::Lower() const
110 // =======================================================================
113 // =======================================================================
114 Standard_Integer Aspect_GenId::Next()
116 if (!myFreeIds.IsEmpty())
118 const Standard_Integer anId = myFreeIds.First();
119 myFreeIds.RemoveFirst();
122 else if (myFreeCount < 1)
124 throw Aspect_IdentDefinitionError("GenId Next Error: Available == 0");
128 const Standard_Integer anId = myLowerBound + myLength - myFreeCount - 1;
132 // =======================================================================
135 // =======================================================================
136 Standard_Integer Aspect_GenId::Upper() const