home *** CD-ROM | disk | FTP | other *** search
- #ifndef APP_PriorityList_H
- #define APP_PriorityList_H
- /******************************************************************************
- **
- ** C++ Class Library for the Amiga© system software.
- **
- ** Copyright (C) 1994 by Armin Vogt ** EMail: armin@uni-paderborn.de
- ** All Rights Reserved.
- **
- ** $VER: apphome:APlusPlus/exec/PriorityList.h 1.04 (04.05.94) $
- **
- ******************************************************************************/
-
-
- #include <APlusPlus/exec/List.h>
-
-
- /**********************************************************************************************
- » PriorityNode class «
- is derived from NodeC but hides direct priority setting to prevent from messing up the
- integrity of the PriorityList.
- **********************************************************************************************/
- class PriorityList;
-
- class PriorityNode : private NodeC
- {
- friend class PriorityList;
-
- protected:
- NodeC::name_ref;
-
- public:
- PriorityNode(const UBYTE* name = 0,UBYTE type = NT_USER) : NodeC(name,type) { };
- // virtual ~PriorityNode();
-
- PriorityNode *succ() { return (PriorityNode*)NodeC::succ(); }
- PriorityNode *pred() { return (PriorityNode*)NodeC::pred(); }
- // make selected private NodeC::functions public again
- NodeC::name;
- NodeC::setName;
- NodeC::type;
- NodeC::setType;
- NodeC::type_ref;
- NodeC::priority;
- NodeC::applyNodeC;
- NodeC::remove;
- NodeC::isLonelyNode;
- };
-
- /**********************************************************************************************
- » PriorityList class «
- hides the ListC methods which could mess up the sorting
- **********************************************************************************************/
- class PriorityList : private ListC
- {
- friend PriorityNode;
- private:
- BYTE internalEnqueue(PriorityNode *node,BYTE pri);
- BYTE internalChangePri(PriorityNode *node,BYTE pri);
- public:
- PriorityList(UBYTE type = 0) : ListC(type) { }
-
- PriorityNode *head() { return (PriorityNode*)ListC::head(); }
- PriorityNode *tail() { return (PriorityNode*)ListC::tail(); }
-
- PriorityNode *remHead() { return (PriorityNode*)ListC::remHead(); }
- PriorityNode *remTail() { return (PriorityNode*)ListC::remTail(); }
- PriorityNode *remove(PriorityNode *node) { return (PriorityNode*)ListC::remove(node); }
-
- ListC::apply;
- ListC::empty;
- ListC::isEmpty;
-
- BOOL member(PriorityNode *node) { return ListC::member((NodeC*)node); }
-
- //void enqueue(PriorityNode *node,BYTE pri=0); //!!! (..,BYTE pri = 0) crashes with gcc!!!!!!!!
- void enqueue(PriorityNode *node,BYTE pri);
-
- PriorityNode *findName(const UBYTE* name) { return (PriorityNode*)ListC::findName(name); }
- BYTE changePri(PriorityNode *node,BYTE pri) // change node priority and eventual place
- { if (member(node)) return internalChangePri(node,pri); else return 0; }
- };
-
-
- inline void PriorityList::enqueue(PriorityNode *node,BYTE pri)
- {
- if (member(node)) // must not enqueue already enqueued node
- internalChangePri(node,pri); // dequeue member, then enqueue again
- else
- internalEnqueue(node,pri);
- }
-
- #endif /* APP_PriorityList_H */