// file: $isip/class/dstr/SingleLinkedList/SingleLinkedNode.h // version: $Id: SingleLinkedNode.h 5923 2000-12-16 21:50:09Z picone $ // // make sure definitions are only made once // #ifndef ISIP_SINGLE_LINKED_NODE #define ISIP_SINGLE_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 SingleLinkedNodeDiagnose; // SingleLinkedNode: a generic node template class which has a forward link // to an object of the same type. this class inherits the Node template class // and adds a pointer to a "next" SingleLinkedNode // template class SingleLinkedNode : 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 = 40100; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // define a pointer to the next node: // the item pointer, the allocation flag and the debug level are // inherited from the Node template class // SingleLinkedNode* next_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 SingleLinkedNodeDiagnose.h in order to avoid issues // related to preprocessing of the diagnose code. // static const String& name(); // setdebug methods: // this method is inherited from the Node template class // // method: debug // boolean debug(const unichar* message) const { Node::debug(message); return true; } // method: destructor // ~SingleLinkedNode() { clear(Integral::RESET); } // method: default constructor // SingleLinkedNode(TObject* item = (TObject*)NULL) { item_d = item; next_d = (SingleLinkedNode*)NULL; } // method: copy constructor // SingleLinkedNode(const SingleLinkedNode& arg) { next_d = (SingleLinkedNode*)NULL; assign(arg); } // assign methods // boolean assign(const SingleLinkedNode& arg); // method: operator= // SingleLinkedNode& operator=(const SingleLinkedNode& 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 method is 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 // SingleLinkedNode* getNext() const { return next_d; } //--------------------------------------------------------------------------- // // class-specific public methods: // set methods // //--------------------------------------------------------------------------- // method: setNext // boolean setNext(SingleLinkedNode* next_node) { next_d = next_node; return true; } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // friend class // template friend class SingleLinkedNodeDiagnose; }; //----------------------------------------------------------------------------- // // 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 SingleLinkedNode::CLASS_NAME(L"SingleLinkedNode"); // constants: required constants for i/o methods // template const String SingleLinkedNode::DEF_PARAM(L"item"); // static instantiations: the memory manager // template MemoryManager SingleLinkedNode::mgr_d(sizeof(SingleLinkedNode), CLASS_NAME); // below are all the methods for the SingleLinkedNode template class // //---------------------------------------------------------------------- // // required static methods // //---------------------------------------------------------------------- // method: name // // arguments: none // // return: a static String& containing the class name // // this method returns the class name // template const String& SingleLinkedNode::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 assign methods // //------------------------------------------------------------------------- // method: assign // // arguments: // const SingleLinkedNode& 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 SingleLinkedNode::assign(const SingleLinkedNode& arg_a) { // copy the previous and next pointers // 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 SingleLinkedNode::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 SingleLinkedNode::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