⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/dstr/Stack/Stack.h// version: $Id: Stack.h,v 1.63 2002/09/03 19:32:31 alphonso Exp $//// make sure definitions are made only once//#ifndef ISIP_STACK#define ISIP_STACK// 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 declaration//template<class TObject> class DoubleLinkedList;// Stack: this class implements a standard stack (last-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 Stack : 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 POP_ALL = -1;  static const long POP_TO_MARK = -2;    // default arguments to methods  //    //----------------------------------------  //  // error codes  //  //----------------------------------------      static const long ERR = 40500;  static const long ERR_EMPTY = 40501;    //---------------------------------------------------------------------------  //  // protected data  //  //---------------------------------------------------------------------------protected:    // the internal structure of the stack is a DoubleLinkedList  //  DoubleLinkedList<TObject> stack_d;  // the allocation mode  //  ALLOCATION alloc_d;  // define the memory manager  //  static MemoryManager mgr_d;    // debugging parameters  //  static Integral::DEBUG debug_level_d;    //---------------------------------------------------------------------------  //  // required public methods  //  //---------------------------------------------------------------------------public:  // static methods:  //  the diagnose method is moved outside the class header file and  //  defined in the StackDiagnose.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  //  ~Stack() {    clear(Integral::RESET);  }    // default constructor  //  Stack(ALLOCATION alloc = DEF_ALLOCATION);    // method: copy constructor  //  Stack(const Stack<TObject>& copy_stack) {    alloc_d = copy_stack.alloc_d;    stack_d.setAllocationMode(USER);    assign(copy_stack);  }    // assign method  //  boolean assign(const Stack<TObject>& copy_stack);  // method: operator=  //  Stack<TObject>& operator=(const Stack<TObject>& arg) {    assign(arg);    return *this;  }  // method: eq  //  boolean eq(const Stack<TObject>& compare_stack) const {    return stack_d.eq(compare_stack.stack_d);  }    // method: sofSize  //  long sofSize() const {    return stack_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 stack_d.read(sof, tag, name);  }    // method: write  //  boolean write(Sof& sof, long tag, const String& name) const {    return stack_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 stack_d.readData(sof, pname, size, param, nested);  }  // method: writeData  //  boolean writeData(Sof& sof, const String& pname =  DEF_PARAM) const {    return stack_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) {    stack_d.setAllocationMode(alloc_d);    boolean ret = stack_d.clear(cmode);    stack_d.setAllocationMode(USER);    return ret;  }  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  extensions to required methods  //  //---------------------------------------------------------------------------  // method: ne  //  boolean ne(const Stack<TObject>& compare_stack) const {    return (!eq(compare_stack));  }    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  stack push and pop methods  //  //---------------------------------------------------------------------------    // push methods:  //  the push methods add items to the top of the stack  //  boolean push(TObject* item);  boolean push(Stack<TObject>& item_stack);  boolean push(TObject** items, long num_items);    // other stack manipulation methods  //  const TObject* peek() const;    TObject* peek();    TObject* pop(TObject* item = (TObject*)NULL);  long pop(Stack<TObject>& items, long num_items);  // method: popAll  //  boolean popAll(Stack<TObject>& item_stack) {    if (pop(item_stack, POP_ALL) <= 0) {      return false;    }    return true;  }  // method: popToMark  //  boolean popToMark(Stack<TObject>& item_stack) {    if (pop(item_stack, POP_TO_MARK) <= 0) {      return false;    }    return true;  }  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  stack marker positioning methods  //  //---------------------------------------------------------------------------    // method: setMark  //  sets the top of the stack to be the marked position  //  boolean setMark() {    return stack_d.setMark();  }  // method: clearMark  //  unmarks the marked stack position  //  boolean clearMark() {    return stack_d.clearMark();  }  // method: markIsSet  //  boolean markIsSet() const {    return stack_d.markIsSet();  }  // method: getMark  //  const TObject* getMark() const {    return stack_d.getMark();  }  // method: getMark  //  TObject* getMark() {    return stack_d.getMark();  }  // method: isMarkedElement  //  indicates if the marked element is on top of the stack  //  boolean isMarkedElement() const {    return stack_d.isMarkedElement();  }  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  stack property methods  //  //---------------------------------------------------------------------------    // method: isEmpty  //  boolean isEmpty() const {    return (stack_d.isEmpty());  }  // method: length  //  long length() const {    return stack_d.length();  }  // method: find  //  boolean find(TObject* item) {    // since the position of the stack must be at the top of the    // stack, we set the mark to the element if it is found    //    return (stack_d.find(item) && stack_d.setMark() &&	    stack_d.gotoFirst());  }  // method: contains  //  boolean contains(TObject* item) const {    return stack_d.contains(item);  }  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  stack computation methods  //  //---------------------------------------------------------------------------      // method: apply  //  apply an external function to each element in the list  //  boolean apply(boolean (TObject::*method)()) {    return (stack_d.apply(method));  }  // method: apply  //  applies the input method to each element in the input stack  //  and assigns the input stack to this stack  //  boolean apply(boolean (TObject::*method)(), Stack<TObject>& arg) {    assign(arg);    stack_d.gotoFirst();    return apply(method);  }  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  stack element ordering methods  //  //---------------------------------------------------------------------------    // method: sort  //  sorts the elements in the stack according to the given order with  //  ascending order, the item at the bottom of the stack will be the  //  greatest in value.  //  boolean sort(Integral::ORDER sort_order = Integral::ASCENDING,               DstrBase::SORT_ALGO sort_algo =  DstrBase::DEF_SORT_ALGO) {    return stack_d.sort(sort_order, sort_algo);  }  // method: reverse  //  reverses the order of elements in the stack  //  boolean reverse() {    return stack_d.reverse();  }        // method: getAllocationMode  //  ALLOCATION getAllocationMode() const {    return alloc_d;  }  // method: setAllocationMode  //  boolean setAllocationMode(ALLOCATION alloc) {    alloc_d = alloc;    return true;  }  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  stack container access methods  //  //---------------------------------------------------------------------------  // method: gotoFirst  //  boolean gotoFirst() {    return stack_d.gotoFirst();  }  // method: gotoNext  //    boolean gotoNext() {    return stack_d.gotoNext();      }  // method: gotoPrev  //      boolean gotoPrev() {    return stack_d.gotoPrev();  }  // method: gotoMark  //      boolean gotoMark() {    return stack_d.gotoMark();  }    // method: getFirst  //  TObject* getFirst() {    return stack_d.getFirst();  }  // method: getNext  //    TObject* getNext() {    return stack_d.getNext();      }  // method: getPrev  //      TObject* getPrev() {    return stack_d.getPrev();  }  // method: getCurr  //      TObject* getCurr() {    return stack_d.getCurr();  }    // method: gotoPosition  //        boolean gotoPosition() {    return stack_d.gotoPosition();  }  // method: getPosition  //          long getPosition() {    return stack_d.getPosition();  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -