0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / Aspect / Aspect_GenId.cxx
CommitLineData
b311480e 1// Created on: 1992-05-14
2// Created by: NW,JPB,CAL
3// Copyright (c) 1992-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <Aspect_GenId.hxx>
19#include <Aspect_IdentDefinitionError.hxx>
7fd59977 20
a9568545 21// =======================================================================
22// function : Aspect_GenId
23// purpose :
24// =======================================================================
25Aspect_GenId::Aspect_GenId()
26: myFreeCount (INT_MAX / 2 + 1),
27 myLength (INT_MAX / 2 + 1),
28 myLowerBound (0),
29 myUpperBound (INT_MAX / 2)
30{
31 //
7fd59977 32}
33
a9568545 34// =======================================================================
35// function : Aspect_GenId
36// purpose :
37// =======================================================================
38Aspect_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)
44{
45 if (theLow > theUpper)
46 {
47 Aspect_IdentDefinitionError::Raise ("GenId Create Error: wrong interval");
48 }
7fd59977 49}
50
a9568545 51// =======================================================================
52// function : HasFree
53// purpose :
54// =======================================================================
55Standard_Boolean Aspect_GenId::HasFree() const
56{
57 return myFreeCount > 0
58 || myFreeIds.Extent() > 0;
7fd59977 59}
60
a9568545 61// =======================================================================
62// function : Available
63// purpose :
64// =======================================================================
65Standard_Integer Aspect_GenId::Available() const
66{
67 return myFreeCount + myFreeIds.Extent();
7fd59977 68}
69
a9568545 70// =======================================================================
71// function : Free
72// purpose :
73// =======================================================================
74void Aspect_GenId::Free()
75{
76 myFreeCount = myLength;
77 myFreeIds.Clear();
7fd59977 78}
79
a9568545 80// =======================================================================
81// function : Free
82// purpose :
83// =======================================================================
84void Aspect_GenId::Free (const Standard_Integer theId)
85{
86 if (theId >= myLowerBound
87 && theId <= myUpperBound)
88 {
89 if (myFreeCount + myFreeIds.Extent() + 1 == myLength)
90 {
91 myFreeCount = myLength;
92 myFreeIds.Clear();
93 }
94 else
95 {
96 myFreeIds.Prepend (theId);
97 }
98 }
7fd59977 99}
100
a9568545 101// =======================================================================
102// function : Lower
103// purpose :
104// =======================================================================
105Standard_Integer Aspect_GenId::Lower() const
106{
107 return myLowerBound;
7fd59977 108}
109
a9568545 110// =======================================================================
111// function : Next
112// purpose :
113// =======================================================================
114Standard_Integer Aspect_GenId::Next()
115{
116 if (!myFreeIds.IsEmpty())
117 {
118 const Standard_Integer anId = myFreeIds.First();
119 myFreeIds.RemoveFirst();
120 return anId;
121 }
122 else if (myFreeCount < 1)
123 {
124 Aspect_IdentDefinitionError::Raise ("GenId Next Error: Available == 0");
125 }
126
127 --myFreeCount;
128 const Standard_Integer anId = myLowerBound + myLength - myFreeCount - 1;
129 return anId;
7fd59977 130}
131
a9568545 132// =======================================================================
133// function : Upper
134// purpose :
135// =======================================================================
136Standard_Integer Aspect_GenId::Upper() const
137{
138 return myUpperBound;
139}