home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / lancelot / litems.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  5.1 KB  |  164 lines

  1. /******************************************************************************
  2. * .FILE:         litems.hpp                                                   *
  3. *                                                                             *
  4. * .DESCRIPTION:  Lancelot Sample Program:              Class Definition       *
  5. *                                                                             *
  6. * .CLASSES:      Item                                                         *
  7. *                                                                             *
  8. * .COPYRIGHT:                                                                 *
  9. *    Licensed Material - Program-Property of IBM                              *
  10. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  11. *                                                                             *
  12. * .DISCLAIMER:                                                                *
  13. *   The following [enclosed] code is sample code created by IBM               *
  14. *   Corporation.  This sample code is not part of any standard IBM product    *
  15. *   and is provided to you solely for the purpose of assisting you in the     *
  16. *   development of your applications.  The code is provided 'AS IS',          *
  17. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  18. *   arising out of your use of the sample code, even if they have been        *
  19. *   advised of the possibility of such damages.                               *
  20. *                                                                             *
  21. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  22. *                                                                             *
  23. ******************************************************************************/
  24. #ifndef _LITEMS_
  25. #define _LITEMS_
  26.  
  27. #include <iostream.h>
  28.  
  29. #include <istring.hpp>
  30. #include <ikeybag.h>
  31. #include <ibag.h>
  32.  
  33. // forward declaration
  34. class Itemb;
  35. class Item;
  36. class Entry;
  37.  
  38. typedef IBag<IString> ItemsBag;
  39. typedef IKeyBag<Item, Entry> Items;
  40.  
  41.  
  42. #include <istring.hpp>
  43. #include <iglobals.h>
  44.  
  45.                              // Class lentry:
  46. #include "lentry.hpp"
  47.  
  48.  
  49. //----------------------------------------------------------------------------
  50. // class Item
  51. //----------------------------------------------------------------------------
  52. class Item : public IBase {
  53.  
  54. public: // ---------------------- PUBLIC -------------------------------------
  55.  
  56. enum Rule {
  57.            na,
  58.            file,
  59.            add,
  60.            replace,
  61.            remove
  62.            };
  63.  
  64. //----------------------- Contructor/Destructor ------------------------------
  65. // Class Item:: Item()
  66. //----------------------------------------------------------------------------
  67.   Item(char *a
  68.      , char *b=(char *)""
  69.      , char *c=(char *)""
  70.      , char *d=(char *)""
  71.      , char *e=(char *)""
  72.   ) : i1(a), i2(b), i3(c), i4(d), i5(e), stat(na)  {};
  73.  
  74.   Item(Rule s,
  75.        char *a
  76.        , char *b
  77.        , char *c=(char *)""
  78.        , char *d=(char *)""
  79.        , char *e=(char *)""
  80.   ) : stat(s),
  81.       i1(a), i2(b), i3(c), i4(d), i5(e) {};
  82.  
  83.   // For copy constructor we use the compiler generated default.
  84.  
  85.   // For assignment we use the compiler generated default.
  86.  
  87. inline Boolean operator==(Item const& p) const  {
  88.        return  (
  89.                 ((i1 == p.i1) &&
  90.                  (i2 == p.i2) &&
  91.                  (i3 == p.i3) &&
  92.                  (i4 == p.i4) &&
  93.                  (i5 == p.i5)) );
  94.        };
  95.  
  96. inline Entry const& item1() const { return i1; };
  97.  
  98. inline Entry const& item2() const { return i2; };
  99.  
  100. inline  Entry const& item3() const { return i3; };
  101.  
  102. inline  Entry const& item4() const { return i4; };
  103.  
  104. inline  Entry const& item5() const { return i5; };
  105.  
  106. inline  Rule  rule() const { return stat; };
  107.  
  108. inline  IString  sRule() const {
  109.  
  110.      switch (stat) {
  111.         case  (na):
  112.            return (IString("na"));
  113.         case (file):
  114.            return (IString("file"));
  115.         case (add):
  116.            return (IString("add"));
  117.         case (replace):
  118.            return (IString("replace"));
  119.         case (remove):
  120.            return (IString("remove"));
  121.      }
  122.      return (IString("ERROR"));
  123.    };
  124.  
  125. friend ostream& operator<<(ostream& os, Item const& p)  {
  126.      return os << "> Item1 <" << p.item1().text()
  127.                << "> Item2 <" << p.item2().text()
  128.                << "> Item3 <" << p.item3().text()
  129.                << "> Item4 <" << p.item4().text()
  130.                << "> Item5 <" << p.item5().text()
  131.                << " rule = " << p.sRule() << "> \n";
  132.  
  133. };
  134.  
  135. private: //----------------------- Private --------------------------------------------
  136.  
  137. // replace with IStrings..
  138.  
  139. Entry
  140.   i1,
  141.   i2,
  142.   i3,
  143.   i4,
  144.   i5;
  145.  
  146. Rule
  147.   stat;
  148.  
  149. };
  150.  
  151. // Key access:
  152. inline Entry const& key(Item const& p)  {
  153.   return p.item1();
  154. }
  155.  
  156. // We need a hash function for the key type as well.
  157. // Let's just use the default provided for char*.
  158.  
  159. inline unsigned long hash(Entry const& ts, unsigned long n) {
  160.   return hash(ts.text(), n);
  161. }
  162.  
  163. #endif
  164.