home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / Iterators / Source / ITTest.cpp next >
C/C++ Source or Header  |  1996-08-12  |  2KB  |  96 lines

  1. // ITTest.cpp
  2.  
  3. // $Header: W:/Projects/OCL/Samples/Iterators/Source/rcs/ITTest.cpp 1.50 1996/08/11 23:48:27 B.STEIN Release $
  4.  
  5. #define __OCL_RESOLVE_TEMPLATES__
  6.  
  7. #define OINCL_BASE
  8. #include <ocl.hpp>
  9.  
  10. #include <lOString.hpp>
  11. #include <OConstIterator.hpp>
  12. #include <OIterator.hpp>
  13.  
  14. #if defined(__EMX__)
  15.   template class OConstIterator<OString>;
  16.   template class OIterator<OString>;
  17. #endif
  18.  
  19.  
  20. class printableList 
  21.   : public lOString
  22. {
  23.  private:
  24.  
  25.    class _printer
  26.      : public OConstIterator<OString>   
  27.    {
  28.     public:
  29.       void applyToElement(const OString* elem) const;
  30.    }; 
  31.  
  32.    class _editor
  33.      : public OIterator<OString>   
  34.    {
  35.     public:
  36.       void applyToElement(OString* elem);
  37.    }; 
  38.  
  39.    _printer            printTool;
  40.    _editor             editTool;
  41.  
  42.  public:
  43.        printableList   () {}
  44.  
  45.    virtual
  46.       ~printableList   () {}
  47.  
  48.    inline void
  49.       print            () { allElementsDo(printTool); }
  50.  
  51.    inline void
  52.       edit             () { allElementsDo(editTool); }
  53. };
  54.  
  55.  
  56.  
  57. void main(void)
  58. {
  59.  OString       a("A"),
  60.                b("B"),
  61.                c("C"),
  62.                d("D"),
  63.                e("E");
  64.  
  65.  printableList list;
  66.  
  67.  list << a;
  68.  list << b;
  69.  list << c;
  70.  list << d;
  71.  list << e;
  72.  
  73.  list.print();
  74.  list.edit();
  75.  list.print();
  76.  
  77.  _exit(0);
  78.  
  79.  
  80.  
  81. void printableList::_printer::applyToElement(const OString* elem) const
  82. {
  83.  if (elem)
  84.    cout << elem->getText() << endl;
  85. }
  86.  
  87. void printableList::_editor::applyToElement(OString* elem)
  88. {
  89.  if (elem)
  90.    *elem + *elem;
  91. }
  92.  
  93.  
  94. // end of source
  95.