home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / LANCELOT / LITEMS.HPP < prev    next >
C/C++ Source or Header  |  1995-04-01  |  5KB  |  158 lines

  1. /*******************************************************************************
  2. * FILE NAME: litems.hpp                                                        *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *                                                                              *
  6. * Class                                                                        *
  7. *   Item                                                                       *
  8. *                                                                              *
  9. * COPYRIGHT:                                                                   *
  10. *   Licensed Materials - Property of IBM                                       *
  11. *   (C) Copyright IBM Corporation 1992, 1995                                   *
  12. *   All Rights Reserved                                                        *
  13. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  14. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  15. *                                                                              *
  16. * CHANGE HISTORY:                                                              *
  17. *******************************************************************************/
  18. #ifndef _LITEMS_
  19. #define _LITEMS_
  20.  
  21. #include <iostream.h>
  22.  
  23. #include <istring.hpp>
  24. #include <ikeybag.h>
  25. #include <ibag.h>
  26.  
  27. // forward declaration
  28. class Itemb;
  29. class Item;
  30. class Entry;
  31.  
  32. typedef IBag<IString> ItemsBag;
  33. typedef IKeyBag<Item, Entry> Items;
  34.  
  35.  
  36. #include <istring.hpp>
  37. #include <iglobals.h>
  38.  
  39.                              // Class lentry:
  40. #include "lentry.hpp"
  41.  
  42.  
  43. //----------------------------------------------------------------------------
  44. // class Item
  45. //----------------------------------------------------------------------------
  46. class Item : public IBase {
  47.  
  48. public: // ---------------------- PUBLIC -------------------------------------
  49.  
  50. enum Rule {
  51.            na,
  52.            file,
  53.            add,
  54.            replace,
  55.            remove
  56.            };
  57.  
  58. //----------------------- Contructor/Destructor ------------------------------
  59. // Class Item:: Item()
  60. //----------------------------------------------------------------------------
  61.   Item(char *a
  62.      , char *b=(char *)""
  63.      , char *c=(char *)""
  64.      , char *d=(char *)""
  65.      , char *e=(char *)""
  66.   ) : i1(a), i2(b), i3(c), i4(d), i5(e), stat(na)  {};
  67.  
  68.   Item(Rule s,
  69.        char *a
  70.        , char *b
  71.        , char *c=(char *)""
  72.        , char *d=(char *)""
  73.        , char *e=(char *)""
  74.   ) : stat(s),
  75.       i1(a), i2(b), i3(c), i4(d), i5(e) {};
  76.  
  77.   // For copy constructor we use the compiler generated default.
  78.  
  79.   // For assignment we use the compiler generated default.
  80.  
  81. inline Boolean operator==(Item const& p) const  {
  82.        return  (
  83.                 ((i1 == p.i1) &&
  84.                  (i2 == p.i2) &&
  85.                  (i3 == p.i3) &&
  86.                  (i4 == p.i4) &&
  87.                  (i5 == p.i5)) );
  88.        };
  89.  
  90. inline Entry const& item1() const { return i1; };
  91.  
  92. inline Entry const& item2() const { return i2; };
  93.  
  94. inline  Entry const& item3() const { return i3; };
  95.  
  96. inline  Entry const& item4() const { return i4; };
  97.  
  98. inline  Entry const& item5() const { return i5; };
  99.  
  100. inline  Rule  rule() const { return stat; };
  101.  
  102. inline  IString  sRule() const {
  103.  
  104.      switch (stat) {
  105.         case  (na):
  106.            return (IString("na"));
  107.         case (file):
  108.            return (IString("file"));
  109.         case (add):
  110.            return (IString("add"));
  111.         case (replace):
  112.            return (IString("replace"));
  113.         case (remove):
  114.            return (IString("remove"));
  115.      }
  116.      return (IString("ERROR"));
  117.    };
  118.  
  119. friend ostream& operator<<(ostream& os, Item const& p)  {
  120.      return os << "> Item1 <" << p.item1().text()
  121.                << "> Item2 <" << p.item2().text()
  122.                << "> Item3 <" << p.item3().text()
  123.                << "> Item4 <" << p.item4().text()
  124.                << "> Item5 <" << p.item5().text()
  125.                << " rule = " << p.sRule() << "> \n";
  126.  
  127. };
  128.  
  129. private: //----------------------- Private --------------------------------------------
  130.  
  131. // replace with IStrings..
  132.  
  133. Entry
  134.   i1,
  135.   i2,
  136.   i3,
  137.   i4,
  138.   i5;
  139.  
  140. Rule
  141.   stat;
  142.  
  143. };
  144.  
  145. // Key access:
  146. inline Entry const& key(Item const& p)  {
  147.   return p.item1();
  148. }
  149.  
  150. // We need a hash function for the key type as well.
  151. // Let's just use the default provided for char*.
  152.  
  153. inline unsigned long hash(Entry const& ts, unsigned long n) {
  154.   return hash(ts.text(), n);
  155. }
  156.  
  157. #endif
  158.