//===========================================================================// // File: plug.hpp // // Project: MUNGA Brick: Connection Library // // Contents: Interface specifications for plugs and their iterators // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- -----------------------------------------------------------// // 10/19/94 ECH Initial coding. // // 10/20/94 JMA Fixed style stuff, merged PLGITR.HPP, added Remove() to // // PlugIterator // // 10/23/94 ECH Added greater deletion safety // // 10/28/94 JMA Made compatible with SGI CC // // 11/02/94 ECH Restored base ReceivePlugCommand // // 11/03/94 ECH Made compatible with BC4.0 // // 11/08/94 JMA Made compatible with GNU C++ // // 11/29/94 JMA Changed ClassIdentity to ClassID // // 11/30/94 JMA Adapted to style changes // // 12/06/94 JMA Made virtual data publicly visible // // 12/12/94 ECH Removed release handler // // 02/16/95 ECH Removed plug commands, added node command // //---------------------------------------------------------------------------// // Copyright (C) 1994-1995, Virtual World Entertainment, Inc. // // All Rights reserved worldwide // // This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL // //===========================================================================// #if !defined(PLUG_HPP) # define PLUG_HPP # if !defined(VDATA_HPP) # include # endif # if !defined(ITERATOR_HPP) # include # endif # if !defined(LINK_HPP) # include # endif class PlugStream; // //-------------------------------------------------------------------- // Node Commands - start at zero, inherited commands start with // Node::NextCommand //-------------------------------------------------------------------- // typedef Enumeration NodeCommandID; enum { NodeNullCommandID = 0, NodeNextCommandID }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Plug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class PlugIterator; class Plug : public RegisteredClass { friend class Link; friend class PlugIterator; public: // //-------------------------------------------------------------------- // Destructor and instance testing //-------------------------------------------------------------------- // ~Plug(); Logical TestInstance() const; protected: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Protected interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Plug(ClassID class_id = TrivialPlugClassID); Plug(PlugStream *stream); private: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Private data //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Link *linkHead; }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PlugOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template class PlugOf: public Plug { public: // //-------------------------------------------------------------------- // Constructor, Destructor //-------------------------------------------------------------------- // PlugOf(const T &item); ~PlugOf(); // //-------------------------------------------------------------------- // Can cast to the type //-------------------------------------------------------------------- // operator T() const {return item;} // //-------------------------------------------------------------------- // Accessors //-------------------------------------------------------------------- // T GetItem() const {return item;} T* GetPointer() {return &item;} private: // //-------------------------------------------------------------------- // Private data //-------------------------------------------------------------------- // T item; }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PlugOf templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template PlugOf::PlugOf(const T &the_item) { item = the_item; } template PlugOf::~PlugOf() { } //~~~~~~~~~~~~~~~~~~~~~~~~~~~ PlugIterator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class PlugIterator: public Iterator { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // // //-------------------------------------------------------------------- // Constructor, Destructor & testing //-------------------------------------------------------------------- // PlugIterator( const Plug *plug, RegisteredClass::ClassID class_to_iterate=RegisteredClass::NullClassID ); PlugIterator(const PlugIterator &iterator); ~PlugIterator(); Logical TestInstance() const; // //-------------------------------------------------------------------- // Iterator methods (see Iterator for full listing) //-------------------------------------------------------------------- // void First(); void Last(); void Next(); void Previous(); CollectionSize GetSize(); void Remove(); // //-------------------------------------------------------------------- // SendNodeCommand - Send a command and related info to all nodes, // returns when all nodes receive command or until // receive method returns non-zero. If the receive // returns non-zero, then the iterator will remain // at that plug. //-------------------------------------------------------------------- // int SendNodeCommand( NodeCommandID node_command, void *info = NULL ); // //-------------------------------------------------------------------- // RemoveSocket - Removes this plug from the specified socket. //-------------------------------------------------------------------- // void RemoveSocket(Socket *socket); protected: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Protected interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // void* ReadAndNextImplementation(); void* ReadAndPreviousImplementation(); void* GetCurrentImplementation(); void* GetNthImplementation(CollectionSize index); protected: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Protected data //-------------------------------------------------------------------- //-------------------------------------------------------------------- // const Plug *plug; Link *currentLink; private: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Private //-------------------------------------------------------------------- //-------------------------------------------------------------------- // RegisteredClass::ClassID classToIterate; void NextNode(); void PreviousNode(); }; //~~~~~~~~~~~~~~~~~~~~~~~~~~ PlugIteratorOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template class PlugIteratorOf: public PlugIterator { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // // //-------------------------------------------------------------------- // Constructor, Destructors //-------------------------------------------------------------------- // PlugIteratorOf( const Plug *plug, RegisteredClass::ClassID class_to_iterate=RegisteredClass::NullClassID ); PlugIteratorOf( const Plug &plug, RegisteredClass::ClassID class_to_iterate=RegisteredClass::NullClassID ); PlugIteratorOf(const PlugIteratorOf &iterator); ~PlugIteratorOf(); // //-------------------------------------------------------------------- // 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);} #if 0 // //--------------------------------------------------- // Operators useful when it is known that the iterator // is a PlugIteratorOf<> Iterator //--------------------------------------------------- // Logical operator!() {return currentLink == NULL;} operator T() {return GetCurrent();} T operator->() {return GetCurrent();} PlugIteratorOf& operator++() {Next(); return *this;} PlugIteratorOf& operator--() {Previous(); return *this;} T operator++(int) {return ReadAndNext();} T operator--(int) {return ReadAndPrevious();} #endif }; //~~~~~~~~~~~~~~~~~~~~~~~~~~ PlugIteratorOf templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template PlugIteratorOf::PlugIteratorOf( const Plug *plug, RegisteredClass::ClassID class_to_iterate ): PlugIterator(plug, class_to_iterate) { } template PlugIteratorOf::PlugIteratorOf( const Plug &plug, RegisteredClass::ClassID class_to_iterate ): PlugIterator(&plug, class_to_iterate) { } template PlugIteratorOf::PlugIteratorOf(const PlugIteratorOf &iterator): PlugIterator(iterator) { } template PlugIteratorOf::~PlugIteratorOf() { } #endif