home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oclsrc15.zip / OCL / Include / OCollection.hpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  4KB  |  124 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OCollection.hpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30.  
  31. // $Header: W:/Projects/OCL/INCLUDE/rcs/OCollection.hpp 1.1 1996/08/12 00:01:12 B.STEIN Release $
  32.  
  33. #ifndef OCOLLECTION_INCLUDED
  34.   #define OCOLLECTION_INCLUDED
  35.  
  36.  
  37. #if (defined ( __IBMCPP__ ) && !defined ( OCL_HPP_INCLUDED ))  // in case of template generation
  38.   #define INCL_DOS
  39.   #define INCL_WIN
  40.   #define INCL_PM
  41.   #include <ocl.hpp>
  42. #endif
  43.  
  44.  
  45. template <class T>
  46. class OListItem
  47. {
  48.  public:
  49.    OListItem<T>        *next;  // next OListItem
  50.    OListItem<T>        *prev;  // previous OListItem
  51.    T                   *item;  // Data
  52.    inline OListItem    () : next(NULL), prev(NULL), item(NULL)
  53.                        {}
  54.    inline ~OListItem   ()
  55.                        {}
  56. };
  57.  
  58. typedef OListItem<VOID> PVITEM;
  59. typedef PVITEM *PPVITEM;
  60.  
  61. class __CPP_EXPORT__ OCollection
  62.   : public OCLObject
  63. {
  64.  protected:
  65.     BOOL                   copyFlag; // are elements copied to the collection?
  66.     ULONG                  items;    // number of elements in list
  67.     PPVITEM                actual;   // last accessed element
  68.     PPVITEM                first;    // first element
  69.     PPVITEM                last;     // last element
  70.  
  71.     virtual
  72.        void freeItem       (PVOID elem) = 0;
  73.  
  74.     virtual PVOID
  75.        _getFirst           (),
  76.        _getLast            (),
  77.        _getNext            (),       
  78.        _getNext            (PVOID elem),
  79.        _getPrev            (),
  80.        _getPrev            (PVOID elem),
  81.        _getItem            (ULONG itemNum);
  82.  
  83.     virtual PPVITEM
  84.         _getNextListItem   (PVOID elem),
  85.         _getPrevListItem   (PVOID elem);
  86.  
  87.  
  88.  public:
  89.  
  90.     OCollection            (BOOL copyElements);
  91.           
  92.     virtual
  93.        ~OCollection        (); 
  94.  
  95.     virtual
  96.        PSZ isOfType        () const;
  97.  
  98.     BOOL
  99.        isCopyCollection    () const,
  100.        isEmpty             () const;
  101.  
  102.     ULONG numberOfElements () const;
  103.  
  104.     void
  105.        rewind              (),
  106.        init                ();
  107.  
  108.     virtual void 
  109.        reset               (),
  110.        addFirst            (PVOID elem),
  111.        addLast             (PVOID elem),
  112.        addAfter            (PVOID   previous, PVOID elem),
  113.        addAfter            (PPVITEM previous, PVOID elem),
  114.        remove              (PVOID elem),
  115.        del                 (PVOID elem);
  116. };
  117.  
  118.  
  119. #endif // OCOLLECTION_INCLUDED
  120.  
  121.  
  122.  
  123. // end of source
  124.