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 void Aspect_GenId::Free()
57 myFreeCount = myLength;
61 // =======================================================================
64 // =======================================================================
65 void Aspect_GenId::Free (const Standard_Integer theId)
67 if (theId >= myLowerBound
68 && theId <= myUpperBound)
70 if (myFreeCount + myFreeIds.Extent() + 1 == myLength)
72 myFreeCount = myLength;
77 myFreeIds.Prepend (theId);
82 // =======================================================================
85 // =======================================================================
86 Standard_Integer Aspect_GenId::Next()
88 Standard_Integer aNewId = 0;
91 throw Aspect_IdentDefinitionError("Aspect_GenId::Next(), Error: Available == 0");
96 // =======================================================================
99 // =======================================================================
100 Standard_Boolean Aspect_GenId::Next (Standard_Integer& theId)
102 if (!myFreeIds.IsEmpty())
104 theId = myFreeIds.First();
105 myFreeIds.RemoveFirst();
106 return Standard_True;
108 else if (myFreeCount < 1)
110 return Standard_False;
114 theId = myLowerBound + myLength - myFreeCount - 1;
115 return Standard_True;