home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / ObjectList.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  2.9 KB  |  98 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ObjectList.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __OBJECTLIST__
  15. #define __OBJECTLIST__
  16.  
  17. #ifndef    __TYPES__
  18. #include "Types.h"
  19. #endif
  20.  
  21. #ifndef    __DIRECTOBJECT__
  22. #include "DirectObject.h"
  23. #endif
  24.  
  25. #pragma push
  26. #pragma segment ObjectList
  27.  
  28. class ostream;
  29.  
  30. /***********************************|****************************************/
  31.  
  32. class TObjectList : public TDirectObject
  33. {
  34. public:
  35.     virtual ~TObjectList ();
  36.  
  37.             void*                     operator [] ( unsigned long ) const;
  38.             void*                    Get ( unsigned long ) const;
  39.  
  40.             void                     Append ( void* );                    // throws on memFullErr
  41.             void                     Insert ( unsigned long, void* );    // throws on memFullErr
  42.  
  43.             Boolean                 Remove ( const void* );        // true if obj was found
  44.             void*                     Remove ( unsigned long );    // returns obj
  45.             void                    RemoveAll ();
  46.  
  47.             Boolean                 Delete ( unsigned long );    // true if obj was found
  48.             Boolean                 Delete ( void* );        // true if obj was found
  49.             void                    DeleteAll ();
  50.  
  51.             unsigned long            Count () const;
  52.             unsigned long             Find ( const void* ) const;
  53.             Boolean                 IsValidIndex ( unsigned long ) const;
  54.  
  55.             void                    SetOwnsObjects ( Boolean = true );
  56.             Boolean                    GetOwnsObjects () const;
  57.  
  58.     virtual    ostream&                operator >> ( ostream& ) const;
  59.  
  60. protected:    TObjectList ( Boolean ownsObjects = true );
  61.             void                    SetSize ( unsigned long objects );
  62.     virtual    void                    DeleteObject ( void* ) const;
  63.  
  64. private:    TObjectList ( const TObjectList& );
  65.             TObjectList&            operator = ( const TObjectList& );
  66.  
  67.             void***                    fList;
  68.             unsigned long             fCount;
  69.             Boolean                    fOwnsObjects;
  70. };
  71.  
  72. /***********************************|****************************************/
  73.  
  74. inline void TObjectList::Append(void* item){Insert(fCount+1,item);}
  75. inline unsigned long TObjectList::Count()const{return fCount;}
  76. inline Boolean TObjectList::IsValidIndex(unsigned long i)const{return i>=1 && i<=fCount;}
  77. inline ostream& operator<<(ostream& s,const TObjectList& l) {return l>>s;}
  78.  
  79. #define    DeclareList(OBJECT,LIST)\
  80.     class LIST:public TObjectList{public:LIST();virtual ~LIST();\
  81.     Boolean Remove(const OBJECT* o){return TObjectList::Remove((void*) o);};\
  82.     OBJECT* Remove(unsigned long i){return (OBJECT*)TObjectList::Remove(i);};\
  83.     OBJECT* operator[](unsigned long i)const{return (OBJECT*)TObjectList::operator[](i);};\
  84.     OBJECT* Get(unsigned long i)const{return (OBJECT*)TObjectList::Get(i);};\
  85.     virtual    ostream& operator>>(ostream&) const;\
  86.     protected: virtual void DeleteObject(void* o) const;}
  87.  
  88. #define    ImplementList(OBJECT,LIST,OWNS)\
  89.     LIST::LIST():TObjectList(OWNS){}LIST::~LIST(){if(GetOwnsObjects())DeleteAll();}\
  90.     void LIST::DeleteObject(void* o)const{delete(OBJECT*)o;}\
  91.     ostream& LIST::operator>>(ostream& s)const{s<<#LIST;return TObjectList::operator>>(s);}
  92.  
  93. /***********************************|****************************************/
  94.  
  95. #pragma pop
  96.  
  97. #endif    // __OBJECTLIST__
  98.