📄 node.h
字号:
// file: $isip/class/dstr/Node/Node.h// version: $Id: Node.h,v 1.84 2001/03/20 21:21:07 duncan Exp $//// make sure definitions are only made once//#ifndef ISIP_NODE#define ISIP_NODE// isip include files//#ifndef ISIP_STRING#include <String.h>#endif#ifndef ISIP_DSTR_BASE#include <DstrBase.h>#endif#ifndef ISIP_CHAR#include <Char.h>#endif#ifndef ISIP_CONSOLE #include <Console.h>#endif// forward class definitions//template<class TObject> class NodeDiagnose;// Node: a generic node template class. this is simply a container// class for use by other classes. most likely, data structures such// as linked-lists, queues, graphs, etc. will create their own node// type which inherits this Node object.//template<class TObject>class Node : 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 // // default arguments to methods // //---------------------------------------- // // error codes // //---------------------------------------- static const long ERR = 40000; static const long ERR_NOITEM = 40001; //--------------------------------------------------------------------------- // // protected data // //---------------------------------------------------------------------------protected: // a pointer to the item stored in this node: // a NULL item is not valid and operations on a node containing a NULL // item will typically result in an error // TObject* item_d; // debugging parameters and static memory manager // static Integral::DEBUG debug_level_d; static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // static methods: // diagnose method is moved outside the class header file and // defined in the NodeDiagnose.h in order to avoid issues // related to 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 // ~Node() { } // method: default constructor // Node() { item_d = (TObject*)NULL; } // method: copy constructor // Node(const Node<TObject>& arg) { item_d = arg.item_d; } // method: assign // boolean assign(const Node<TObject>& arg) { item_d = arg.item_d; return true; } // method: operator= // Node<TObject>& operator=(const Node<TObject>& arg) { assign(arg); return *this; } // equality methods: // determines if the contents of the node are equivalent. // this method calls the eq(TObject&) method for the items // contained in the respective nodes to determine equivalence. // only classes with an eq() method are available for use with // this Node object // boolean eq(const Node<TObject>& arg) const; // 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()); } // other i/o methods: // sofSize determines the amount of disk storage needed to store this object // the read and write methods are for full object i/o. the readData and // writeData methods handle i/o when this object is a component of another // object // long sofSize() const; boolean read(Sof& sof, long tag, const String& name); boolean write(Sof& sof, long tag, const String& name) const; boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false); boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const; // 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); } // other memory-management methods // boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods: // extensions to required methods // //--------------------------------------------------------------------------- // method: constructor // Node(TObject* item) { item_d = item; } // method: assign // boolean assign(TObject* item) { item_d = item; return true; } // method: ne // boolean ne(const Node<TObject>& arg) const { return (!eq(arg)); } // method: lt // boolean lt(const Node<TObject>& arg) const { return item_d->lt(*(arg.item_d)); } // method: gt // boolean gt(const Node<TObject>& arg) const { return item_d->gt(*(arg.item_d)); } //--------------------------------------------------------------------------- // // class-specific public methods: // item manipulation methods // //--------------------------------------------------------------------------- // method: getItem // const TObject* getItem() const { return item_d; } // method: getItem // TObject* getItem() { return item_d; } // method: setItem // boolean setItem(TObject* item) { return ((item_d = item) != (TObject*)NULL); } // method: accessByMode // TObject* accessByMode(TObject* ptr, ALLOCATION mode) const { if (!((mode == SYSTEM) ^ (ptr == (TObject*)NULL))) { Error::handle(name(), L"accessByMode", ERR, __FILE__, __LINE__); } else if (mode == USER) { return item_d; } else if ((mode == SYSTEM) && (item_d == (TObject*)NULL)) { ptr->clear(); return (TObject*)NULL; } ptr->assign(*item_d); return ptr; } // method: assignByMode // boolean assignByMode(TObject* ptr, ALLOCATION mode) { if (ptr == (TObject*)NULL) { return Error::handle(name(), L"assignByMode", ERR, __FILE__, __LINE__); } if (mode == SYSTEM) { item_d = new TObject(*ptr); } else { item_d = ptr; } return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // hashing function // //--------------------------------------------------------------------------- // method: hash // // note that this will hash the pointer, not the value of the object // long hash(long capacity) const { // interpret the pointer as a ulong* // return Integral::hash((ulong)item_d, capacity); } //--------------------------------------------------------------------------- // // private methods // //---------------------------------------------------------------------------private: // friend class // template <class TObject_diagnose> friend class NodeDiagnose; }; //-----------------------------------------------------------------------------//// we define non-integral constants at the end of class definition for// templates (for non-templates these are defined in the default constructor)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -