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 #include <Standard_Dump.hxx>
23 // =======================================================================
24 // function : Aspect_GenId
26 // =======================================================================
27 Aspect_GenId::Aspect_GenId()
28 : myFreeCount (INT_MAX / 2 + 1),
29 myLength (INT_MAX / 2 + 1),
31 myUpperBound (INT_MAX / 2)
36 // =======================================================================
37 // function : Aspect_GenId
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)
47 if (theLow > theUpper)
49 throw Aspect_IdentDefinitionError("GenId Create Error: wrong interval");
53 // =======================================================================
56 // =======================================================================
57 void Aspect_GenId::Free()
59 myFreeCount = myLength;
63 // =======================================================================
66 // =======================================================================
67 void Aspect_GenId::Free (const Standard_Integer theId)
69 if (theId >= myLowerBound
70 && theId <= myUpperBound)
72 if (myFreeCount + myFreeIds.Extent() + 1 == myLength)
74 myFreeCount = myLength;
79 myFreeIds.Prepend (theId);
84 // =======================================================================
87 // =======================================================================
88 Standard_Integer Aspect_GenId::Next()
90 Standard_Integer aNewId = 0;
93 throw Aspect_IdentDefinitionError("Aspect_GenId::Next(), Error: Available == 0");
98 // =======================================================================
101 // =======================================================================
102 Standard_Boolean Aspect_GenId::Next (Standard_Integer& theId)
104 if (!myFreeIds.IsEmpty())
106 theId = myFreeIds.First();
107 myFreeIds.RemoveFirst();
108 return Standard_True;
110 else if (myFreeCount < 1)
112 return Standard_False;
116 theId = myLowerBound + myLength - myFreeCount - 1;
117 return Standard_True;
120 // =======================================================================
121 // function : DumpJson
123 // =======================================================================
124 void Aspect_GenId::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
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)
131 for (TColStd_ListOfInteger::Iterator anIter (myFreeIds); anIter.More(); anIter.Next())
133 Standard_Integer aFreeId = anIter.Value();
134 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aFreeId)