// file: $isip/class/dstr/DoubleLinkedList/DoubleLinkedNode.h // version: $Id: DoubleLinkedNode.h 5923 2000-12-16 21:50:09Z picone $ // // make sure definitions are only made once // #ifndef ISIP_DOUBLE_LINKED_NODE #define ISIP_DOUBLE_LINKED_NODE // isip include files // #ifndef ISIP_NODE #include #endif #ifndef ISIP_STRING #include #endif #ifndef ISIP_CHAR #include #endif #ifndef ISIP_CONSOLE #include #endif // forward class definitions // template class DoubleLinkedNodeDiagnose; // DoubleLinkedNode: a generic node template class which has a forward and a // backward link to an object of the same type. this class inherits the // Node template class and adds a pointer to the "next" and "previous" // DoubleLinkedNode // template class DoubleLinkedNode : public Node { //--------------------------------------------------------------------------- // // 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 = 40200; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // define pointers to the next and previous nodes: // the item pointer and the debug level are inherited from the Node // template class // DoubleLinkedNode* next_d; DoubleLinkedNode* prev_d; // define the memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // static methods: // diagnose method is moved outside the class header file and // defined in the DoubleLinkedNodeDiagnose.h in order to avoid issues // related to preprocessing of the diagnose code. // static const String& name(); // debug methods // boolean debug(const unichar* message) const; // method: destructor // ~DoubleLinkedNode() { clear(Integral::RESET); } // method: default constructor // DoubleLinkedNode(TObject* item = (TObject*)NULL) { item_d = item; next_d = (DoubleLinkedNode*)NULL; prev_d = (DoubleLinkedNode*)NULL; } // method: copy constructor // DoubleLinkedNode(const DoubleLinkedNode& arg) { next_d = (DoubleLinkedNode*)NULL; prev_d = (DoubleLinkedNode*)NULL; assign(arg); } // assign methods // boolean assign(const DoubleLinkedNode& arg); // method: operator= // DoubleLinkedNode& operator=(const DoubleLinkedNode& arg) { assign(arg); return *this; } // i/o methods: // unlike other classes, we have two read and write methods in dstr // classes. the interface is still the same as that in other // classes. the reason behind this is that we can not use // "CLASS_NAME" as default argument in the read and write methods // here because the data structures build the class name on the fly // // 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: // the sofSize, readData and writeData are inherited from the Node class // boolean read(Sof& sof, long tag, const String& name); boolean write(Sof& sof, long tag, const String& name) const; // equality methods: // the eq method is inherited from the Node template class // // 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); } //--------------------------------------------------------------------------- // // class-specific public methods // get methods // //--------------------------------------------------------------------------- // method: getNext // DoubleLinkedNode* getNext() const { return next_d; } // method: getPrev // DoubleLinkedNode* getPrev() const { return prev_d; } //--------------------------------------------------------------------------- // // class-specific public methods // set methods // //--------------------------------------------------------------------------- // method: setNext // boolean setNext(DoubleLinkedNode* next_node) { next_d = next_node; return true; } // method: setPrev // boolean setPrev(DoubleLinkedNode* prev_node) { prev_d = prev_node; return true; } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // friend class // template friend class DoubleLinkedNodeDiagnose; }; //----------------------------------------------------------------------------- // // 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 const String DoubleLinkedNode::CLASS_NAME(L"DoubleLinkedNode"); template const String DoubleLinkedNode::DEF_PARAM(L"item"); // static instantiations: memory manager // template MemoryManager DoubleLinkedNode::mgr_d(sizeof(DoubleLinkedNode), CLASS_NAME); // below are all the methods for the DoubleLinkedNode template class // //---------------------------------------------------------------------- // // required static methods // //---------------------------------------------------------------------- // method: name // // arguments: none // // return: a static String& containing the class name // template const String& DoubleLinkedNode::name() { // create the static name string for this class and return it // static String cname(CLASS_NAME); cname.clear(); cname.concat(CLASS_NAME); cname.concat(L"<"); cname.concat(TObject::name()); cname.concat(L">"); // return the name // return cname; } //---------------------------------------------------------------------- // // required debug methods // //---------------------------------------------------------------------- // method: debug // // arguments: // const unichar* message: (input) information message // // return: a boolean value indicating status // // this method dumps the contents of an object to the console // template boolean DoubleLinkedNode::debug(const unichar* message_a) const { // call the parent debug method since we add no new data // Node::debug(message_a); // exit gracefully // return true; } //------------------------------------------------------------------------ // // required assign methods // //------------------------------------------------------------------------- // method: assign // // arguments: // const DoubleLinkedNode& arg: (input) the node to copy // // return: a boolean value indicating status // // this method copies the contents of the input to this node // template boolean DoubleLinkedNode::assign(const DoubleLinkedNode& arg_a) { // copy the previous and next pointers // prev_d = arg_a.prev_d; next_d = arg_a.next_d; // call the assign in the base class which is responsible for // assigning the item pointer. // return Node::assign(arg_a); } //------------------------------------------------------------------------ // // required i/o methods // //------------------------------------------------------------------------ // method: read // // arguments: // Sof& sof: (input) sof file object // long tag: (input) sof object instance tag // const String& name: (input) sof object instance name // // return: a boolean value indicating status // // this method has the object read itself from an Sof file // template boolean DoubleLinkedNode::read(Sof& sof_a, long tag_a, const String& name_a) { // get the instance of the object from the Sof file // if (!sof_a.find(name_a, tag_a)) { return false; } // read the actual data from the sof file // if (!readData(sof_a)) { return false; } // exit gracefully // return true; } // method: write // // arguments: // Sof& sof: (input) sof file object // long tag: (input) sof object instance tag // const String& name: (input) sof object instance name // // return: a boolean value indicating status // // this method has the object write itself to an Sof file // template boolean DoubleLinkedNode::write(Sof& sof_a, long tag_a, const String& name_a) const { // declare a temporary size variable // long obj_size = 0; // switch on ascii or binary mode // if (sof_a.isText()) { // set the size to be dynamic // obj_size = Sof::ANY_SIZE; } else { // the size of the binary data to write // obj_size = sofSize(); } // put the object into the sof file's index // if (!sof_a.put(name_a, tag_a, obj_size)) { return false; } // exit gracefully // return writeData(sof_a); } // end of include file // #endif