home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Array Classes / OTList.cp next >
Encoding:
Text File  |  1998-06-20  |  885 b   |  69 lines  |  [TEXT/CWIE]

  1. #include "OTList.h"
  2.  
  3. void* OTLinkNextObject(void* obj, int linkOffset)
  4. {
  5.     if (obj != nil)
  6.     {
  7.         OTLink* link = reinterpret_cast<OTLink*>(reinterpret_cast<char*>(obj) + linkOffset)->fNext;
  8.         
  9.         obj = link ? (reinterpret_cast<char*>(link) - linkOffset) : nil;
  10.     }
  11.     
  12.     return obj;
  13. }
  14.  
  15. void* OTLinkIndexObject(void* obj, int count, int linkOffset)
  16. {
  17.     if (obj != nil)
  18.     {
  19.         OTLink* link = (OTLink*) ((char*) obj + linkOffset);
  20.  
  21.         do
  22.         {
  23.             if (count == 0)
  24.             {
  25.                 return ((char*) link - linkOffset);
  26.             }
  27.             else if (count < 0)
  28.             {
  29.                 break;
  30.             }
  31.             else
  32.             {
  33.                 link   = link->fNext;
  34.                 count -= 1;
  35.             }
  36.         }
  37.         while (link != nil);
  38.     }
  39.     
  40.     return nil;
  41. }
  42.  
  43. /*
  44.  
  45. class Foo
  46. {
  47. public:
  48.     long            xxx;
  49.     OTLink            fNextFoo;
  50. };
  51.  
  52. typedef EmbeddedLinkPtr(Foo, fNextFoo) FooLinkPtr;
  53.  
  54.  
  55.  
  56. static void test(void)
  57. {
  58.     Foo anObject;
  59.  
  60.     FooLinkPtr link(&anObject);
  61.     
  62.     while (link)
  63.     {
  64.     
  65.         link = link.Next();
  66.     }
  67. };
  68.  
  69. */