// // Basic Summary: // // Include file for circular buffer definition // // Copyright: // // Copyright 1993 Ron Burback // Copyright 1993 Objects Plus // All rights reserved // // Description: // // This header file defines the class circular buffer. // circular buffer includes a fixed size (CHUNK_SIZE) storage array of void pointers // circular buffer includes two location indicators of top and bottom. // circular buffer includes the current number of elements // Top is the location of the first element of the array // Bottom is the location of the next available slot in the array // As you get and set locations, Top and Bottom chase each other around the array // The algorithm uses CHUNK_SIZE locations of the array at any one time. // // Methods: // // The methods are // circular_buffer(); - standard constructor // ~circular_buffer(); - standard disctructor // void * get(natural n); - get and remove the nth element // void * peak(natural n); - get and keep the nth element // Boolean full () ; - is the array full ? // Boolean empty () ; - is the array empty ? // Boolean bounds(natural n) ; - is n in the bounds of the array // void set(natural n,void * e) ; - insert at the nth location, move all elements down // void replace(natural n,void * e) ; - replace element at the nth location with e // natural length() ; - the current length of the array in use // natural location(natural n) ; - the location of a particular elemtent // void shrink(natural n); - reduce the size of the used elements by one // void expand(natural n); - increase the size of the used elements by one // // static Boolean test(); = quality assurance test // #ifndef _OP_FIXEDCHUNK #define _OP_FIXEDCHUNK // Macro definitions: // // storage size // #define CHUNK_SIZE 10 // // arithmetic in a circular fashion // #define PLUS(n,m) ((n+m) % CHUNK_SIZE) #define MINUS(n,m) ((n-m+CHUNK_SIZE) % CHUNK_SIZE) // // include files: // #include #include "standard.h" #include "pool.h" // // Class definition: // // fixed chunk // class circular_buffer { friend class dynamic_array ; friend class linked_chunk ; private: void * storage[CHUNK_SIZE] ; natural top ; natural bottom ; natural size ; public: static pool ThePool ; static char * version ; circular_buffer(); ~circular_buffer(); void * get(natural n); void * peak(natural n); Boolean full () ; Boolean empty () ; Boolean bounds(natural n) ; void set(natural n,void * e) ; void replace(natural n,void * e) ; natural length() ; natural location(natural n) ; void shrink(natural n); void expand(natural n); void * operator new(size_t) { return ThePool.alloc(); }; void operator delete(void * p) { ThePool.free(p); }; static Boolean test(); }; #endif