home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / Basic Classes / Z Headers / ZArray.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-09  |  2.9 KB  |  119 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp        -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZArray.h            -- the basic container class object
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21.  
  22. #pragma once
  23.  
  24. #ifndef __ZARRAY__
  25. #define    __ZARRAY__
  26.  
  27. #ifndef __ZCOMRADE__
  28. #include    "ZComrade.h"
  29. #endif
  30.  
  31. // form of the basic grovelling function you can pass to DoForEach(). Read note below.
  32.  
  33. typedef void (*IteratorProcPtr)( void* item, const long ref );
  34.  
  35. // Form of the sort comparison function you can pass to Sort(). This function should return
  36. // -1 if a < b, +1 if a > b, and 0 if they are equal. The sort function uses a very fast
  37. // shellsort algorithm. <itema> and <itemb> are POINTERS to the data held in the array, whatever
  38. // it is. If the array contains object pointers, this is therefore a POINTER to a POINTER to the
  39. // object, not the object pointer itself. This is an important point if you use Sort() with the
  40. // ZObjectArray<> class. This is also true of the grovelling function above.
  41.  
  42. typedef short (*SortCmpProcPtr)( void* itema, void* itemb, const long ref );
  43.  
  44. // class definition
  45.  
  46. class ZArray : public ZComrade
  47. {
  48. protected:
  49.     Handle        a;
  50.     long        blkSize;
  51.     long        numElements;
  52.     
  53. public:
  54.     
  55.     ZArray( short elementSize = sizeof(Ptr));
  56.     virtual ~ZArray();
  57.  
  58. // putting stuff in the array
  59.     
  60.     virtual void    InsertItem( void* item, const long index );
  61.     virtual void    AppendItem( void* item );
  62.     virtual void    SetArrayItem( void* item, const long index );
  63.  
  64. // getting stuff out
  65.  
  66.     virtual void    GetArrayItem( void* item, const long index );
  67.     virtual long    CountItems();
  68.     virtual long    FindIndex( void* item );
  69.  
  70. // deleting items
  71.  
  72.     virtual void    DeleteItem( const long index );
  73.     
  74. // moving items
  75.  
  76.     virtual void    MoveItem( const long curIndex, const long newIndex );
  77.     virtual void    Swap( const long itema, const long itemb );
  78.     
  79. // grovelling over the items
  80.  
  81.     virtual void    DoForEach( IteratorProcPtr aProc, const long ref );
  82.     
  83. // sorting the items
  84.  
  85.     virtual void    Sort( SortCmpProcPtr compareProc, const long ref );
  86.     virtual void    Sort();
  87.     virtual short    Compare( void* itema, void* itemb, const long ref );
  88.     
  89. // inserting items in a sorted list
  90.  
  91.     virtual long    InsertSortedItem( void* item, SortCmpProcPtr compareProc, const long ref = 0 );
  92.     virtual long    InsertSortedItem( void* item, const long ref = 0 );
  93.     
  94. // finding items in a sorted list
  95.     virtual long    BFindIndex( void* item, SortCmpProcPtr compareProc, const long ref );
  96.  
  97. protected:    
  98.     
  99.     virtual void    InsertElement( const long index );        
  100.     virtual void    DeleteElement( const long index );
  101. };
  102.  
  103. Boolean        EqualMem( void* a, void* b, const unsigned long length );
  104.  
  105. #define        kIndexOutOfRangeErr        230
  106.  
  107. // message "transmitted" when array is manipulated
  108.  
  109. enum
  110. {
  111.     msgArrayItemAdded = 'arr1',
  112.     msgArrayItemDeleted,
  113.     msgArrayItemMoved,
  114.     msgArrayItemChanged,
  115.     msgArrayItemInserted
  116. };
  117.  
  118.  
  119. #endif