From 8f564ea8ce5d148285823fcbe1e9f345a3571586 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 18 Mar 2003 02:27:51 +0000 Subject: [PATCH] dos2unix --- panda/src/putil/test_uniqueIdAllocator.cxx | 92 +++--- panda/src/putil/uniqueIdAllocator.cxx | 328 ++++++++++----------- panda/src/putil/uniqueIdAllocator.h | 102 +++---- 3 files changed, 261 insertions(+), 261 deletions(-) diff --git a/panda/src/putil/test_uniqueIdAllocator.cxx b/panda/src/putil/test_uniqueIdAllocator.cxx index 73f3d33751..4a05f6c4af 100644 --- a/panda/src/putil/test_uniqueIdAllocator.cxx +++ b/panda/src/putil/test_uniqueIdAllocator.cxx @@ -1,46 +1,46 @@ - -#include "stdafx.h" - -#include -#include -#include -using namespace std; - -#include "uniqueIdAllocator.h" - - -int _tmain(int argc, _TCHAR* argv[]) { - cout <<"UniqueIdAllocator Test"< +#include +#include +using namespace std; + +#include "uniqueIdAllocator.h" + + +int _tmain(int argc, _TCHAR* argv[]) { + cout <<"UniqueIdAllocator Test"<debug() << msg << endl; \ - } else {} - - #define uniqueIdAllocator_info(msg) \ - uniqueIdAllocator_cat->info() << msg << endl - - #define uniqueIdAllocator_warning(msg) \ - uniqueIdAllocator_cat->warning() << msg << endl -#else //][ - // Release build: - #define uniqueIdAllocator_debug(msg) ((void)0) - #define uniqueIdAllocator_info(msg) ((void)0) - #define uniqueIdAllocator_warning(msg) ((void)0) -#endif //] - -#define audio_error(msg) \ - audio_cat->error() << msg << endl - -//////////////////////////////////////////////////////////////////// -// Function: -// Access: -// Description: Create a free id pool in the range [min:max]. -//////////////////////////////////////////////////////////////////// -UniqueIdAllocator:: -UniqueIdAllocator(U32 min, U32 max) - : _min(min), _max(max) { - uniqueIdAllocator_debug("UniqueIdAllocator("< 0. - _table=new U32[_size]; - nassertv(_table); // This should be redundant if new throws an exception. - for (U32 i=0; i<_size; ++i) { - _table[i]=i+1; - } - _table[_size-1]=-1; - _next_free=0; - _last_free=_size-1; - _free=_size; -} - -//////////////////////////////////////////////////////////////////// -// Function: -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -UniqueIdAllocator:: -~UniqueIdAllocator() { - uniqueIdAllocator_debug("~UniqueIdAllocator()"); - delete [] _table; -} - - -//////////////////////////////////////////////////////////////////// -// Function: -// Access: -// Description: Receive an id between _min and _max (that were passed -// to the constructor). -// -1 is returned if no ids are available. -//////////////////////////////////////////////////////////////////// -U32 UniqueIdAllocator:: -allocate() { - if (_next_free==-1) { - // ...all ids allocated. - uniqueIdAllocator_warning("allocate Error: no more free ids."); - return -1; - } - U32 id=_min+_next_free; - _next_free=_table[_next_free]; - nassertr(_table[id-_min]=-2, -1); // this assignment is debug only. - --_free; - uniqueIdAllocator_debug("allocate() returning "<=_min); // Attempt to free out-of-range id. - nassertv(index<=_max); // Attempt to free out-of-range id. - index=index-_min; // Convert to _table index. - nassertv(_table[index]==-2); // Attempt to free non-allocated id. - _table[index]=-1; // Mark this element as the end of the list. - _table[_last_free]=index; - if (_next_free==-1) { - // ...the free list was empty. - _next_free=index; - } - _last_free=index; - ++_free; -} - - -//////////////////////////////////////////////////////////////////// -// Function: -// Access: -// Description: return what percentage of the pool is used. The -// range is 0 to 1.0, so 75% would be 0.75, for example. -//////////////////////////////////////////////////////////////////// -float UniqueIdAllocator:: -percent_used() const { - return float(_size-_free)/_size; -} - - -//////////////////////////////////////////////////////////////////// -// Function: -// Access: -// Description: ...intended for debugging only. -//////////////////////////////////////////////////////////////////// -void UniqueIdAllocator:: -output(ostream& os, bool verbose) const { - os <<"[_next_free: "<debug() << msg << endl; \ + } else {} + + #define uniqueIdAllocator_info(msg) \ + uniqueIdAllocator_cat->info() << msg << endl + + #define uniqueIdAllocator_warning(msg) \ + uniqueIdAllocator_cat->warning() << msg << endl +#else //][ + // Release build: + #define uniqueIdAllocator_debug(msg) ((void)0) + #define uniqueIdAllocator_info(msg) ((void)0) + #define uniqueIdAllocator_warning(msg) ((void)0) +#endif //] + +#define audio_error(msg) \ + audio_cat->error() << msg << endl + +//////////////////////////////////////////////////////////////////// +// Function: +// Access: +// Description: Create a free id pool in the range [min:max]. +//////////////////////////////////////////////////////////////////// +UniqueIdAllocator:: +UniqueIdAllocator(U32 min, U32 max) + : _min(min), _max(max) { + uniqueIdAllocator_debug("UniqueIdAllocator("< 0. + _table=new U32[_size]; + nassertv(_table); // This should be redundant if new throws an exception. + for (U32 i=0; i<_size; ++i) { + _table[i]=i+1; + } + _table[_size-1]=-1; + _next_free=0; + _last_free=_size-1; + _free=_size; +} + +//////////////////////////////////////////////////////////////////// +// Function: +// Access: +// Description: +//////////////////////////////////////////////////////////////////// +UniqueIdAllocator:: +~UniqueIdAllocator() { + uniqueIdAllocator_debug("~UniqueIdAllocator()"); + delete [] _table; +} + + +//////////////////////////////////////////////////////////////////// +// Function: +// Access: +// Description: Receive an id between _min and _max (that were passed +// to the constructor). +// -1 is returned if no ids are available. +//////////////////////////////////////////////////////////////////// +U32 UniqueIdAllocator:: +allocate() { + if (_next_free==-1) { + // ...all ids allocated. + uniqueIdAllocator_warning("allocate Error: no more free ids."); + return -1; + } + U32 id=_min+_next_free; + _next_free=_table[_next_free]; + nassertr(_table[id-_min]=-2, -1); // this assignment is debug only. + --_free; + uniqueIdAllocator_debug("allocate() returning "<=_min); // Attempt to free out-of-range id. + nassertv(index<=_max); // Attempt to free out-of-range id. + index=index-_min; // Convert to _table index. + nassertv(_table[index]==-2); // Attempt to free non-allocated id. + _table[index]=-1; // Mark this element as the end of the list. + _table[_last_free]=index; + if (_next_free==-1) { + // ...the free list was empty. + _next_free=index; + } + _last_free=index; + ++_free; +} + + +//////////////////////////////////////////////////////////////////// +// Function: +// Access: +// Description: return what percentage of the pool is used. The +// range is 0 to 1.0, so 75% would be 0.75, for example. +//////////////////////////////////////////////////////////////////// +float UniqueIdAllocator:: +percent_used() const { + return float(_size-_free)/_size; +} + + +//////////////////////////////////////////////////////////////////// +// Function: +// Access: +// Description: ...intended for debugging only. +//////////////////////////////////////////////////////////////////// +void UniqueIdAllocator:: +output(ostream& os, bool verbose) const { + os <<"[_next_free: "<