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 | |
a5162275 |
21 | #include <Standard_Dump.hxx> |
22 | |
a9568545 |
23 | // ======================================================================= |
24 | // function : Aspect_GenId |
25 | // purpose : |
26 | // ======================================================================= |
27 | Aspect_GenId::Aspect_GenId() |
28 | : myFreeCount (INT_MAX / 2 + 1), |
29 | myLength (INT_MAX / 2 + 1), |
30 | myLowerBound (0), |
31 | myUpperBound (INT_MAX / 2) |
32 | { |
33 | // |
7fd59977 |
34 | } |
35 | |
a9568545 |
36 | // ======================================================================= |
37 | // function : Aspect_GenId |
38 | // purpose : |
39 | // ======================================================================= |
40 | Aspect_GenId::Aspect_GenId (const Standard_Integer theLow, |
41 | const Standard_Integer theUpper) |
42 | : myFreeCount (theUpper - theLow + 1), |
43 | myLength (theUpper - theLow + 1), |
44 | myLowerBound (theLow), |
45 | myUpperBound (theUpper) |
46 | { |
47 | if (theLow > theUpper) |
48 | { |
9775fa61 |
49 | throw Aspect_IdentDefinitionError("GenId Create Error: wrong interval"); |
a9568545 |
50 | } |
7fd59977 |
51 | } |
52 | |
a9568545 |
53 | // ======================================================================= |
54 | // function : Free |
55 | // purpose : |
56 | // ======================================================================= |
57 | void Aspect_GenId::Free() |
58 | { |
59 | myFreeCount = myLength; |
60 | myFreeIds.Clear(); |
7fd59977 |
61 | } |
62 | |
a9568545 |
63 | // ======================================================================= |
64 | // function : Free |
65 | // purpose : |
66 | // ======================================================================= |
67 | void Aspect_GenId::Free (const Standard_Integer theId) |
68 | { |
69 | if (theId >= myLowerBound |
70 | && theId <= myUpperBound) |
71 | { |
72 | if (myFreeCount + myFreeIds.Extent() + 1 == myLength) |
73 | { |
74 | myFreeCount = myLength; |
75 | myFreeIds.Clear(); |
76 | } |
77 | else |
78 | { |
79 | myFreeIds.Prepend (theId); |
80 | } |
81 | } |
7fd59977 |
82 | } |
83 | |
a9568545 |
84 | // ======================================================================= |
1c728f2d |
85 | // function : Next |
a9568545 |
86 | // purpose : |
87 | // ======================================================================= |
1c728f2d |
88 | Standard_Integer Aspect_GenId::Next() |
a9568545 |
89 | { |
1c728f2d |
90 | Standard_Integer aNewId = 0; |
91 | if (!Next (aNewId)) |
92 | { |
93 | throw Aspect_IdentDefinitionError("Aspect_GenId::Next(), Error: Available == 0"); |
94 | } |
95 | return aNewId; |
7fd59977 |
96 | } |
97 | |
a9568545 |
98 | // ======================================================================= |
99 | // function : Next |
100 | // purpose : |
101 | // ======================================================================= |
1c728f2d |
102 | Standard_Boolean Aspect_GenId::Next (Standard_Integer& theId) |
a9568545 |
103 | { |
104 | if (!myFreeIds.IsEmpty()) |
105 | { |
1c728f2d |
106 | theId = myFreeIds.First(); |
a9568545 |
107 | myFreeIds.RemoveFirst(); |
1c728f2d |
108 | return Standard_True; |
a9568545 |
109 | } |
110 | else if (myFreeCount < 1) |
111 | { |
1c728f2d |
112 | return Standard_False; |
a9568545 |
113 | } |
114 | |
115 | --myFreeCount; |
1c728f2d |
116 | theId = myLowerBound + myLength - myFreeCount - 1; |
117 | return Standard_True; |
a9568545 |
118 | } |
a5162275 |
119 | |
120 | // ======================================================================= |
121 | // function : DumpJson |
122 | // purpose : |
123 | // ======================================================================= |
124 | void Aspect_GenId::DumpJson (Standard_OStream& theOStream, Standard_Integer) const |
125 | { |
126 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myFreeCount) |
127 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myLength) |
128 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myLowerBound) |
129 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUpperBound) |
130 | |
131 | for (TColStd_ListOfInteger::Iterator anIter (myFreeIds); anIter.More(); anIter.Next()) |
132 | { |
133 | Standard_Integer aFreeId = anIter.Value(); |
134 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aFreeId) |
135 | } |
136 | } |