home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / classes.lha / Classes / Exec / Lists.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-31  |  3.8 KB  |  153 lines

  1. #ifndef CPP_EXEC_LISTS_H
  2. #define CPP_EXEC_LISTS_H
  3.  
  4. // Die Exec Listenklassen
  5. //
  6. // Es stehen beide Varianten der Exec Listen zur Verfügung: die kleine Liste
  7. // mit den beiden Verkettungszeigern und die erweiterte Liste mit zusätzlich
  8. // einem Namens-, Typs- und Prioritätseintrag pro Knoten.
  9. //
  10. // Autor: Jochen Becher
  11. //
  12. // Historie:
  13. // Version 1.0 am 25. Juni 94
  14.  
  15. #ifndef EXEC_NODES_H
  16. #include <exec/nodes.h>
  17. #endif
  18.  
  19. #ifndef EXEC_LISTS_H
  20. #include <exec/lists.h>
  21. #endif
  22.  
  23. class NodeC : private MinNode {
  24. friend class ListC;
  25. public:
  26.     NodeC();
  27.     NodeC(const NodeC &);
  28.     ~NodeC();
  29.     NodeC &operator= (const NodeC &);
  30.     VOID remove();
  31.     BOOL isInList() const
  32.         { return (mln_Succ != NULL) && (mln_Pred != NULL); };
  33.     ULONG index() const;
  34.     NodeC *succ() const { return (NodeC *) mln_Succ; };
  35.     NodeC *pred() const { return (NodeC *) mln_Pred; };
  36.     NodeC *next() const;
  37.     NodeC *prev() const;
  38. };
  39.  
  40. class ListC : private MinList {
  41. friend class ListCursorC;
  42. public:
  43.     ListC();
  44.     ListC(const ListC &);
  45.     ~ListC();
  46.     ListC &operator= (const ListC &);
  47.     // die 'after' Node muss in der Liste sein
  48.     VOID insert(NodeC &node, NodeC *after);
  49.     VOID addHead(NodeC &node);
  50.     VOID addTail(NodeC &node);
  51.     NodeC *remHead();
  52.     NodeC *remTail();
  53.     BOOL isEmpty() const { return IsListEmpty((struct List *) this); };
  54.     ULONG indexOf(const NodeC &node) const;
  55.     ULONG length() const;
  56.     NodeC *find(ULONG index) const;
  57.     NodeC *head() const { return (NodeC *) mlh_Head; };
  58.     NodeC *tail() const { return (NodeC *) mlh_TailPred; };
  59.     NodeC *first() const;
  60.     NodeC *last() const;
  61. private:
  62.     VOID newList()
  63.         { mlh_Head = (struct MinNode *) &mlh_Tail;
  64.           mlh_Tail = NULL;
  65.           mlh_TailPred = (struct MinNode *) &mlh_Head; };
  66. };
  67.  
  68. // Ein typische Schleife sieht etwa so aus:
  69. //    ListC l();
  70. //    ListCursor lc(l);
  71. //    while (!lc.isDone()) {
  72. //       /* hier irgendwas mit lc.item() anstellen */
  73. //       lc.next();
  74. //    };
  75. //
  76. class ListCursorC {
  77. public:
  78.     ListCursorC(const ListC &);
  79.     ListCursorC(const ListCursorC &);
  80.     ListCursorC &operator= (const ListCursorC &);
  81.     VOID first();
  82.     VOID last();
  83.     VOID next();
  84.     VOID prev();
  85.     NodeC *item() const;
  86.     BOOL isDone() const;
  87. private:
  88.     ListC *list;
  89.     NodeC *pos;
  90. };
  91.  
  92. // *************************************************************
  93.  
  94. class ENodeC : public NodeC {
  95. friend class EListC;
  96. private:
  97.     UBYTE ln_Type;
  98.     BYTE ln_Pri;
  99.     STRPTR ln_Name;
  100. public:
  101.     ENodeC(STRPTR name = NULL, UBYTE type = NT_USER, BYTE pri = 0);
  102.     ENodeC(const ENodeC &);
  103.     ~ENodeC();
  104.     ENodeC &operator= (const ENodeC &);
  105.     VOID setName(STRPTR name) { ln_Name = name; };
  106.     STRPTR name() const { return ln_Name; };
  107.     VOID setType(UBYTE type) { ln_Type = type; };
  108.     UBYTE type() const { return ln_Type; };
  109.     VOID setPri(UBYTE pri) { ln_Pri = pri; };
  110.     BYTE pri() const { return ln_Pri; };
  111.     ENodeC *find(STRPTR name) const;
  112. };
  113.  
  114. class EListC : public ListC {
  115. friend class EListCursorC;
  116. private:
  117.     UBYTE lh_Type;
  118.     UBYTE lh_pad;
  119. public:
  120.     EListC(UBYTE type = NT_USER);
  121.     EListC(const EListC &);
  122.     ~EListC();
  123.     EListC &operator= (const EListC &);
  124.     VOID setType(UBYTE type) { lh_Type = type; };
  125.     UBYTE type() const { return lh_Type; };
  126.     VOID insert(ENodeC &node, ENodeC *after)
  127.         { ListC::insert(node,after); };
  128.     VOID addHead(ENodeC &node)
  129.         { ListC::addHead(node) };
  130.     VOID addTail(ENodeC &node)
  131.         { ListC::addTail(node) };
  132.     ENodeC *remHead()
  133.         { return (ENodeC *) ListC::remHead(); };
  134.     ENodeC *remTail()
  135.         { return (ENodeC *) ListC::remTail(); };
  136.     ULONG indexOf(const ENodeC &node) const
  137.         { return ListC::indexOf(node); };
  138.     VOID enqueue(ENodeC &node);
  139.     ENodeC *find(STRPTR name) const;
  140.     ENodeC *find(ULONG index) const
  141.         { return (ENodeC *) ListC::find(index); };
  142. };
  143.  
  144. class EListCursorC : public ListCursorC {
  145. public:
  146.     EListCursorC(const EListC &l) : ListCursorC(l) { };
  147.     EListCursorC(const EListCursorC &lc) : ListCursorC((ListCursorC &) lc) { };
  148.     EListCursorC &operator= (const EListCursorC &);
  149.     ENodeC *item() const { return (ENodeC *) ListCursorC::item(); };
  150. };
  151.  
  152. #endif
  153.