home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mandlcpp.zip / chain.h < prev    next >
C/C++ Source or Header  |  1993-06-26  |  3KB  |  90 lines

  1. #ifndef CHAIN_H
  2. #define CHAIN_H
  3.  
  4.  
  5. #include "object.h"
  6.  
  7.  
  8. // There is a foreach() method which calls toBeCalledForeachElement()
  9. // for each element which is contained in an object of class chain.
  10. // There will be passed a message and a pointer.
  11. // If you make a derived class and you define some messages,
  12. // you should use idForeachChainElementLast + 1 as the first id
  13. // See toBeCalledForeachElement of derived classes.
  14. // If the message passed to toBeCalledForeachElement()
  15. // is not defined in this class, the base class method will be called.
  16. #define idForeachChainElementDestruct 0
  17. #define idForeachChainElementMove 1
  18. #define idForeachChainElementLast 1
  19.  
  20.  
  21. class chainElement;
  22.  
  23.  
  24. class chain : virtual public mtxObject        // container class
  25. {    public:
  26.     chainElement *pFirst, *pLast;
  27.     unsigned int iNumberOfElements;
  28.     chain(void);
  29.     virtual ~chain(void);
  30.     int foreach(unsigned int iMsg, void *pDummy);    // calls for each chainElement
  31.     // Makes a bubblesort of the elements
  32.     virtual void bubbleSort(unsigned int iMsg);
  33.     // classes derived fro class chainElement can access to
  34.     // their parent by the member pParent.
  35.     // Caused of that pParent is of type (chain*)
  36.     // you cannot access to members of derived classes from chain
  37.     // but you can use this function
  38.     // See derived classes
  39.     // DO NOT CAST OBJECTS!!!
  40.     // If a message is not defined in a class the base class function will
  41.     // be called
  42.     virtual void *getChainMember(unsigned int iMsg)
  43.     {    (void)iMsg;
  44.         abort();
  45.         return (void*)"DO NOT TRY THIS AT HOME!!!";
  46.     }
  47. };
  48.  
  49.  
  50. class chainElement : virtual public mtxObject    // double linked list
  51. {    public:
  52.     chain *pParent;            // container
  53.     chainElement *pPrev, *pSucc;
  54.     chainElement(chain *pParentNew);
  55.     chainElement(void);
  56.     // See above comment for getChainMember()
  57.     // Sometime you want to access a member of a derived class via
  58.     // chain.pFirst or chainElement.pSucc
  59.     // use this method
  60.     virtual void *getChainElementMember(unsigned int iMsg)
  61.     {    (void)iMsg;
  62.         abort();
  63.         return (void*)"DO NOT TRY THIS AT HOME!!!";
  64.     }
  65.     virtual ~chainElement(void);
  66.     // Will be called from chain.foreach()
  67.     virtual int toBeCalledForeachElement(unsigned int iMsg, void *pDummy);
  68.     // inserts a chainElement() which is not bound to a chain into
  69.     // the passed chain
  70.     virtual void insertSorted(chain *pParentNew, unsigned int iMsg);
  71.     // Used for sorting.
  72.     // The message identifies kind of sorting.
  73.     // Base class method should be called if the message is not defined
  74.     virtual Boolean laterThenThis(chainElement *pElement,
  75.         unsigned int iMsg);
  76.     // Exchanges this with pElement
  77.     virtual void exchange(chainElement *pElement);
  78.     // Moves this from one chain into the passed new one
  79.     virtual void move(chain *pChain);
  80.     // See mtxObject
  81.     virtual void getMutualExclusiveAccess(void);
  82.     virtual void freeMutualExclusiveAccess(void);
  83. #ifdef DEBUG
  84.     void checkConsistence(void);
  85. #endif /* DEBUG */
  86. };
  87.  
  88.  
  89. #endif /* !CHAIN_H */
  90.