//===========================================================================// // File: schain.hh // // Project: MUGNA Brick: Connection engine // // Contents: Interface definition for safe chains // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 09/29/94 ECH Initial coding. // // 11/01/94 JMA Made compatible with SGI CC, merged with iterator // // 11/03/94 ECH Made compatible with BC4.0 // // 11/05/94 JMA Made compatible with GNU C++ // // 12/12/94 ECH Changed release mechanism // //---------------------------------------------------------------------------// // Copyright (C) 1994-1995, Virtual World Entertainment, Inc. // // PROPRIETARY AND CONFIDENTIAL // //===========================================================================// #if !defined(SCHAIN_HPP) # define SCHAIN_HPP # if !defined(SFESKT_HPP) # include # endif # if !defined(MEMBLOCK_HPP) # include # endif //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SChainLink ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #define SCHAINLINK_MEMORYBLOCK_ALLOCATION (100) class SChainLink: public Link { friend class SChain; friend class SChainIterator; public: ~SChainLink(); Logical TestInstance() const; private: SChainLink( SChain *chain, Plug *plug, SChainLink *nextSChainLink, SChainLink *prevSChainLink ); SChainLink *nextSChainLink; SChainLink *prevSChainLink; private: static MemoryBlock AllocatedMemory; void* operator new(size_t) {return AllocatedMemory.New();} void operator delete(void *where) {AllocatedMemory.Delete(where);} }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SChain ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class SChain: public SafeSocket { friend class SChainLink; friend class SChainIterator; public: // //----------------------------------------------------------------------- //----------------------------------------------------------------------- // Public interface //----------------------------------------------------------------------- //----------------------------------------------------------------------- // SChain(Node *node); ~SChain(); Logical TestInstance() const; static void TestClass(); static void ProfileClass(); protected: // //----------------------------------------------------------------------- //----------------------------------------------------------------------- // Protected interface //----------------------------------------------------------------------- //----------------------------------------------------------------------- // void AddImplementation(Plug *plug); private: // //----------------------------------------------------------------------- // Private utilities //----------------------------------------------------------------------- // SChainLink* InsertSChainLink( Plug *plug, SChainLink *link ); // //----------------------------------------------------------------------- // Private data //----------------------------------------------------------------------- // SChainLink *head; SChainLink *tail; }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SChainOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template class SChainOf: public SChain { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // SChainOf(Node *node); ~SChainOf(); // //-------------------------------------------------------------------- // Socket methods (see Socket for full listing) //-------------------------------------------------------------------- // void Add(T plug) {AddImplementation(Cast_Object(Plug*,plug));} }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~ SChainOf templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~ template SChainOf::SChainOf(Node *node): SChain(node) { } template SChainOf::~SChainOf() { } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SChainIterator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class SChainIterator: public SafeIterator { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // // //-------------------------------------------------------------------- // Constructors, Destructor and testing //-------------------------------------------------------------------- // SChainIterator(SChain *chain); SChainIterator(const SChainIterator &iterator); ~SChainIterator(); Logical TestInstance() const; // //-------------------------------------------------------------------- // Iterator methods (see Iterator for full listing) //-------------------------------------------------------------------- // void First(); void Last(); void Next(); void Previous(); CollectionSize GetSize(); void Remove(); protected: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Protected interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // void* ReadAndNextImplementation(); void* ReadAndPreviousImplementation(); void* GetCurrentImplementation(); void* GetNthImplementation( CollectionSize index ); void InsertImplementation(Plug *plug); private: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Private interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // void ReceiveMemo( IteratorMemo memo, void *content ); // //-------------------------------------------------------------------- // Private data //-------------------------------------------------------------------- // SChainLink *currentLink; }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SChainIteratorOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template class SChainIteratorOf: public SChainIterator { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // // //-------------------------------------------------------------------- // Constructors and Destructor //-------------------------------------------------------------------- // SChainIteratorOf(SChainOf *chain); SChainIteratorOf(SChainOf &chain); SChainIteratorOf(const SChainIteratorOf &iterator); ~SChainIteratorOf(); // //-------------------------------------------------------------------- // Iterator methods (see Iterator for full listing) //-------------------------------------------------------------------- // T ReadAndNext() {return (T)ReadAndNextImplementation();} T ReadAndPrevious() {return (T)ReadAndPreviousImplementation();} T GetCurrent() {return (T)GetCurrentImplementation();} T GetNth(CollectionSize index) {return (T)GetNthImplementation(index);} void Insert(T plug) {InsertImplementation(Cast_Object(Plug*,plug));} }; //~~~~~~~~~~~~~~~~~~~~~~~ SChainIteratorOf templates ~~~~~~~~~~~~~~~~~~~~~~~ template SChainIteratorOf::SChainIteratorOf(SChainOf *chain): SChainIterator(chain) { } template SChainIteratorOf::SChainIteratorOf(SChainOf &chain): SChainIterator(&chain) { } template SChainIteratorOf::SChainIteratorOf(const SChainIteratorOf &iterator): SChainIterator(iterator) { } template SChainIteratorOf::~SChainIteratorOf() { } #endif