home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / chlist.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-14  |  5.1 KB  |  161 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- //
  5. // C++ Header File Name: chlist.h 
  6. // C++ Compiler Used: Microsoft Visual C/C++ 4.2  
  7. // Produced By: Doug Gaer
  8. // File Creation Date: 12/29/1996
  9. // Date Last Modified: 03/15/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ---------- Include File Description and Details  ---------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. A character string doubly linked list class derived from the
  32. DNodeBase class and the DLListBase class.
  33. */
  34. // ----------------------------------------------------------- //   
  35. #ifndef __CHLIST_HPP
  36. #define __CHLIST_HPP
  37.  
  38. #include "dllistb.h"
  39.  
  40. // General definition of the concrete data type used
  41. typedef char * DLTYPE;
  42.  
  43. // (C)haracter (B)ased (D)oubly Linked List (N)ode class 
  44. class ChNode : public DNodeBase
  45. {
  46. public:
  47.   ChNode() { } // Implicitly call default constructor for Data
  48.   ChNode(const DLTYPE &X) : Data(X) { } // Call copy constructor
  49.  
  50. public:
  51.   ChNode *GetPrior() { return (ChNode *)Prior; }
  52.   const ChNode *GetPrior() const { return (ChNode *)Prior; }
  53.   ChNode *GetNext() { return (ChNode *)Next; }
  54.   const ChNode *GetNext() const { return (ChNode *)Next; }
  55.  
  56. public:
  57.   DLTYPE Data;
  58. };
  59.  
  60. // (C)haracter (B)ased (D)oubly (L)inked (L)ist class 
  61. class ChList : public DLListBase
  62. {
  63. public:
  64.   ChList() { }
  65.   virtual ~ChList();
  66.   ChList(const ChList &X) { Copy(X); }
  67.   void operator=(const ChList &X) { Copy(X); }
  68.  
  69. public:
  70.   int Copy(const ChList &List);
  71.   int Cat(const ChList &X) { return DLListBase::Cat(X); }
  72.   const ChNode  *Find(const DLTYPE &X, const ChNode  *ptr=0) const;
  73.   ChNode *Find(const DLTYPE &X, ChNode  *ptr=0);
  74.   int Delete(ChNode  *Node, DLTYPE *X = 0);
  75.   int DeleteFront(DLTYPE *X = 0);
  76.   int DeleteBack(DLTYPE *X = 0);
  77.   ChNode *Store(const DLTYPE &X);
  78.   ChNode *AddToFront(const DLTYPE &X);
  79.   ChNode *AddToBack(const DLTYPE &X);
  80.   ChNode *AddBefore(const DLTYPE &X, ChNode *Node);
  81.   ChNode *AddAfter(const DLTYPE &X, ChNode *Node);
  82.   ChNode *GetHeader() { return(ChNode *) this; }
  83.   const ChNode *GetHeader() const { return(ChNode *) this; }
  84.   ChNode *GetFront() { return(ChNode *)DLListBase::GetFront(); }
  85.   ChNode *GetBack() { return (ChNode *)DLListBase::GetBack(); }
  86.   
  87.   const ChNode *GetFront() const { // Read only version
  88.     return(ChNode *)DLListBase::GetFront();
  89.   }
  90.  
  91.   const ChNode *GetBack() const { // Read only version
  92.     return (ChNode *)DLListBase::GetBack();
  93.   }
  94.  
  95.   int IsHeader(const ChNode *Node) const {
  96.     return DLListBase::IsHeader(Node);
  97.   }
  98.   DLTYPE *GetFrontNode() {
  99.     ChNode *ptr = (ChNode *)DLListBase::GetFront();
  100.     return IsHeader(ptr) ? 0 : &(ptr->Data);
  101.   }
  102.  
  103.   const DLTYPE *GetFrontNode() const {
  104.     ChNode *ptr = (ChNode *)DLListBase::GetFront();
  105.     return IsHeader(ptr) ? 0 : &(ptr->Data);
  106.   }
  107.  
  108.   DLTYPE *GetBackNode() {
  109.     ChNode *ptr = (ChNode *)DLListBase::GetBack();
  110.     return IsHeader(ptr) ? 0 : &(ptr->Data);
  111.   }
  112.  
  113.   const DLTYPE *GetBackNode() const {
  114.     ChNode *ptr = (ChNode *)DLListBase::GetBack();
  115.     return IsHeader(ptr) ? 0 : &(ptr->Data);
  116.   }
  117.  
  118. public:
  119.   void InsertBefore(ChNode *A, ChNode *B) {
  120.     DLListBase::InsertBefore(A, B);
  121.   }
  122.  
  123.   void InsertAfter(ChNode *A, ChNode *B) {
  124.     DLListBase::InsertAfter(A, B);
  125.   }
  126.  
  127.   void AttachToFront(ChNode *Node) {
  128.     DLListBase::AttachToFront(Node);
  129.   }
  130.  
  131.   void AttachToBack(ChNode *Node) {
  132.     DLListBase::AttachToBack(Node);
  133.   }
  134.  
  135.   ChNode *RmvFront() {
  136.     return(ChNode *)(DLListBase::RmvFront());
  137.   }
  138.  
  139.   ChNode *Rmv(ChNode  *Node) {
  140.     return(ChNode *)(DLListBase::Rmv(Node));
  141.   }
  142.  
  143.   ChNode *RmvBack() {
  144.     return(ChNode *)(DLListBase::RmvBack());
  145.   }
  146.  
  147. protected:
  148.   virtual ChNode *AllocNode(const DLTYPE &X);
  149.   virtual DNodeBase *DupNode(const DNodeBase *Node);
  150.   virtual void FreeNode(DNodeBase *Node);
  151.  
  152. public: // Overloaded operators
  153.   int operator+=(const ChList &X) { return Cat(X); }
  154. };
  155.  
  156. #endif  // __CHLIST_HPP //
  157. // ----------------------------------------------------------- // 
  158. // ------------------------------- //
  159. // --------- End of File --------- //
  160. // ------------------------------- //
  161.