📄 queue.h
字号:
// file: $isip/class/dstr/Queue/Queue.h// version: $Id: Queue.h,v 1.50 2000/12/28 22:31:08 duncan Exp $//// make sure definitions are made only once//#ifndef ISIP_QUEUE#define ISIP_QUEUE// isip include files//#ifndef ISIP_DSTR_BASE#include <DstrBase.h>#endif#ifndef ISIP_DOUBLE_LINKED_LIST#include <DoubleLinkedList.h>#endif#ifndef ISIP_STRING#include <String.h>#endif#ifndef ISIP_CHAR#include <Char.h>#endif#ifndef ISIP_CONSOLE#include <Console.h>#endif// forward class definitions//template<class TObject> class DoubleLinkedList;// Queue: this class implements a standard queue (first-in, first-out)// using a double linked list. this class uses the double linked list// class in USER mode since this list is used to store either// the actual data or a pointer to it.//template<class TObject>class Queue : public DstrBase { //--------------------------------------------------------------------------- // // public constants // //---------------------------------------------------------------------------public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; //---------------------------------------- // // default values and arguments // //---------------------------------------- // default values // static const long REMOVE_ALL = -1; static const long REMOVE_TO_MARK = -2; // default arguments to methods // //---------------------------------------- // // error codes // //---------------------------------------- static const long ERR = 40600; static const long ERR_EMPTY = 40601; //--------------------------------------------------------------------------- // // protected data // //---------------------------------------------------------------------------protected: // the internal structure of the queue is a DoubleLinkedList // DoubleLinkedList<TObject> queue_d; // the allocation mode // ALLOCATION alloc_d; // debugging parameters // static Integral::DEBUG debug_level_d; // define the memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // static methods: // the diagnose method is moved outside the class header file and // defined in the QueueDiagnose.h in order to avoid issues // with preprocessing of the diagnose code. // static const String& name(); // method: setDebug // static boolean setDebug(Integral::DEBUG debug_level) { debug_level_d = debug_level; return true; } // other debug methods // boolean debug(const unichar* message) const; // method: destructor // ~Queue() { clear(Integral::RESET); } // default constructor // Queue(ALLOCATION alloc = DEF_ALLOCATION); // method: copy constructor // Queue(const Queue<TObject>& copy_queue) { alloc_d = copy_queue.alloc_d; queue_d.setAllocationMode(USER); assign(copy_queue); } // assign method // boolean assign(const Queue<TObject>& copy_stack); // method: operator= // Queue<TObject>& operator=(const Queue<TObject>& arg) { assign(arg); return *this; } // method: eq // boolean eq(const Queue<TObject>& arg) const { return queue_d.eq(arg.queue_d); } // method: sofSize // long sofSize() const { return queue_d.sofSize(); } // method: read // boolean read(Sof& sof, long tag) { return read(sof, tag, name()); } // method: write // boolean write(Sof& sof, long tag) const { return write(sof, tag, name()); } // method: read // boolean read(Sof& sof, long tag, const String& name) { return queue_d.read(sof, tag, name); } // method: write // boolean write(Sof& sof, long tag, const String& name) const { return queue_d.write(sof, tag, name); } // method: readData // boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false) { return queue_d.readData(sof, pname, size, param, nested); } // method: writeData // boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const { return queue_d.writeData(sof, pname); } // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static boolean setGrowSize(long grow_size) { return mgr_d.setGrow(grow_size); } // method: clear // boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE) { queue_d.setAllocationMode(alloc_d); boolean ret = queue_d.clear(cmode); queue_d.setAllocationMode(USER); return ret; } //--------------------------------------------------------------------------- // // class-specific public methods: // extensions to required methods // //--------------------------------------------------------------------------- // method: ne // boolean ne(const Queue<TObject>& compare_queue) const { return (!eq(compare_queue)); } //--------------------------------------------------------------------------- // // class-specific public methods: // queue add and remove methods // //--------------------------------------------------------------------------- // add methods: // the add methods add items to the front of the queue // boolean add(TObject* item); boolean add(Queue<TObject>& item_queue); boolean add(TObject** items, long num_items); // other queue manipulation methods // const TObject* peek() const; TObject* peek(); TObject* remove(TObject* item = (TObject*)NULL); long remove(Queue<TObject>& items, long num_items); // method: removeAll // boolean removeAll(Queue<TObject>& item_queue) { if (remove(item_queue, REMOVE_ALL) <= 0) { return false; } return true; } // method: removeToMark // boolean removeToMark(Queue<TObject>& item_queue) { if (remove(item_queue, REMOVE_TO_MARK) <= 0) { return false; } return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // queue marker positioning methods // //--------------------------------------------------------------------------- // method: setMark // sets the end of the queue to be the marked position // boolean setMark() { queue_d.gotoLast(); return queue_d.setMark(); } // method: clearMark // unmarks the marked queue position // boolean clearMark() { return queue_d.clearMark(); } // method: markIsSet // boolean markIsSet() const { return queue_d.markIsSet(); } // method: getMark // const TObject* getMark() const { return queue_d.getMark(); } // method: getMark // TObject* getMark() { return queue_d.getMark(); } // method: isMarkedElement // indicates if the marked element is on top of the queue // boolean isMarkedElement() const { return (queue_d.getFirst() == queue_d.getMark()); } //--------------------------------------------------------------------------- // // class-specific public methods: // queue property methods // //--------------------------------------------------------------------------- // method: isEmpty // boolean isEmpty() const { return queue_d.isEmpty(); } // method: length // long length() const { return queue_d.length(); } // method: find // boolean find(TObject* item) { // since the position of the queue must be at the end of the // queue, we set the mark to the element if it is found // return (queue_d.find(item) && queue_d.setMark() && queue_d.gotoLast()); } // method: contains // boolean contains(TObject* item) const { return queue_d.contains(item); } //--------------------------------------------------------------------------- // // class-specific public methods: // queue computation methods // //--------------------------------------------------------------------------- // method: apply // applies the input method to each element in the queue // boolean apply(boolean (TObject::*method)()) { return (queue_d.apply(method) && queue_d.gotoLast()); } // method: apply // applies the input method to each element in the input queue // and assigns the input queue to this queue // boolean apply(boolean (TObject::*method)(), Queue<TObject>& arg) { assign(arg); queue_d.gotoFirst(); return apply(method); } //--------------------------------------------------------------------------- // // class-specific public methods: // queue element ordering methods // //--------------------------------------------------------------------------- // method: sort // sorts the elements in the queue according to the given order with // ascending order, the item at the bottom of the queue will be the // greatest in value. // boolean sort(Integral::ORDER sort_order = Integral::ASCENDING, SORT_ALGO sort_algo = DEF_SORT_ALGO) { return (queue_d.sort(sort_order, sort_algo) && queue_d.gotoLast()); } // method: reverse // reverses the order of elements in the queue // boolean reverse() { return (queue_d.reverse() && queue_d.gotoLast()); } // method: getAllocationMode // ALLOCATION getAllocationMode() const { return alloc_d; } // method: setAllocationMode // boolean setAllocationMode(ALLOCATION alloc) { alloc_d = alloc; return true; } //--------------------------------------------------------------------------- // // private methods // //---------------------------------------------------------------------------private:};//-----------------------------------------------------------------------------//// we define non-integral constants at the end of class definition for// templates (for non-templates these are defined in the default constructor)// //-----------------------------------------------------------------------------// constants: required constants such as the class name//template <class TObject>const String Queue<TObject>::CLASS_NAME(L"Queue");template <class TObject>const String Queue<TObject>::DEF_PARAM(L"values");// static instantiations: debug level//template <class TObject>Integral::DEBUG Queue<TObject>::debug_level_d = Integral::NONE;// static instantiations: the memory manager
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -