// ============================================================ // // base.h // // Copyright 2002, Dennis Meilicke and Rene Peralta // // ============================================================ // // Description: // // Definition of the number implementation class. This is the // array of digits; the thing that gets ref-counted. // // ============================================================ #ifndef __base_h__ #define __base_h__ #include #include #include #ifndef LN3_DIGIT_ARRAY_SIZE #define LN3_DIGIT_ARRAY_SIZE 1000 #endif typedef enum sign_t { positive, negative }; template sign_t sign( T x ) { return ( (x < 0) ? negative : positive ); } typedef enum compare_t { lessThan = -1, equalTo = 0, greaterThan = 1 }; struct Base { typedef SubHeapAllocator alloc_t; static alloc_t *alloc; Base() { count = 1; sign = positive; size = 0; digit[ 0 ] = 0; } Base(const Base& source) { count = 1; sign = source.sign; size = source.size; memcpy( digit, source.digit, size * sizeof( digit_t ) ); } static void InitAllocator( void ) { if( alloc == 0 ) alloc = new alloc_t; } void *operator new( size_t size ) { if( size != sizeof( Base ) ) return ::operator new( size ); //if( alloc == 0 ) //alloc = new alloc_t; return alloc->allocate( ); } void operator delete( void *mem, size_t size ) { if( mem == 0 ) return; if( size != sizeof( Base ) ) { ::operator delete( mem ); return; } alloc->deallocate( (struct Base *)mem ); return; } size_t count; sign_t sign; size_t size; digit_t digit[ LN3_DIGIT_ARRAY_SIZE ]; }; #endif