home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / srcos2 / vthislst.cpp < prev    next >
C/C++ Source or Header  |  1999-02-15  |  3KB  |  108 lines

  1. //===============================================================
  2. // vThislst.cpp - vThisList class functions - Windows
  3. //
  4. // Copyright (C) 1995,1996,1997,1998  Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11.  
  12. #include <v/vos2.h>        // for OS/2 stuff
  13. #include <v/vthislst.h>
  14.  
  15. //======================>>> vThisList::vThisList <<<=======================
  16.   vThisList::vThisList()
  17.   {
  18.     // This will keep a list of this pointers accessed by some id
  19.     _cur = 0;        // empty list
  20.     _list = 0;
  21.  
  22.   }
  23.  
  24. //======================>>> vThisList::~vThisList <<<=======================
  25.   vThisList::~vThisList()
  26.   {
  27.     // This will keep a list of this pointers accessed by some id
  28.     thisList* next;
  29.     for (thisList* tl = _list ; tl != 0 ; tl = next)
  30.     {
  31.       next = tl->next;    // get next one
  32.       delete tl;
  33.     }
  34.   }
  35.  
  36. //======================>>> vThisList::Add <<<=======================
  37.   void vThisList::Add(ThisId id, void* This)
  38.   {
  39.     // Add to list
  40.     thisList* newList = new thisList;
  41.  
  42.     newList->id = id;
  43.     newList->thisPtr = This;
  44.     newList->next = _list;
  45.     _cur = _list = newList;
  46.   }
  47.  
  48. //======================>>> vThisList::Delete <<<=======================
  49.   void vThisList::Delete(ThisId id)
  50.   {
  51.     // delete from the list
  52.     thisList* next, *prev;
  53.  
  54.     prev = 0;
  55.     for (thisList* tl = _list ; tl != 0 ; tl = next)
  56.     {
  57.       next = tl->next;
  58.       if (tl->id == id)
  59.       {
  60.         if (prev == 0)
  61.           _list = next;
  62.         else
  63.       prev->next = next;
  64.     delete tl;
  65.     _cur = _list;        // keep _cur valid
  66.     return;
  67.       }
  68.       prev = tl;
  69.     }
  70.   }
  71.  
  72. //======================>>> vThisList::GetThis <<<=======================
  73.   void* vThisList::GetThis(ThisId id) VCONST
  74.   {
  75.     for (thisList* tl = _list ; tl != 0 ; tl = tl->next)
  76.     {
  77.       if (tl->id == id)
  78.       {
  79.         _cur = tl;        // keep cur valid
  80.     return tl->thisPtr;
  81.       }
  82.     }
  83.     return 0;
  84.   }
  85.  
  86. //======================>>> vThisList::GetFirstThis <<<=======================
  87.   void* vThisList::GetFirstThis() VCONST
  88.   {
  89.     _cur = _list;        // start at front
  90.     if (_cur)
  91.       return _cur->thisPtr;
  92.     else
  93.       return 0;
  94.   }
  95.  
  96. //======================>>> vThisList::GetNextThis <<<======================
  97.   void* vThisList::GetNextThis() VCONST
  98.   {
  99.     if (_cur)
  100.     {
  101.       _cur = _cur->next;    // point to next entry
  102.       if (_cur)
  103.         return _cur->thisPtr;
  104.     }
  105.     return 0;
  106.   }
  107.  
  108.