home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ObjectList.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __OBJECTLIST__
- #define __OBJECTLIST__
-
- #ifndef __TYPES__
- #include "Types.h"
- #endif
-
- #ifndef __DIRECTOBJECT__
- #include "DirectObject.h"
- #endif
-
- #pragma push
- #pragma segment ObjectList
-
- class ostream;
-
- /***********************************|****************************************/
-
- class TObjectList : public TDirectObject
- {
- public:
- virtual ~TObjectList ();
-
- void* operator [] ( unsigned long ) const;
- void* Get ( unsigned long ) const;
-
- void Append ( void* ); // throws on memFullErr
- void Insert ( unsigned long, void* ); // throws on memFullErr
-
- Boolean Remove ( const void* ); // true if obj was found
- void* Remove ( unsigned long ); // returns obj
- void RemoveAll ();
-
- Boolean Delete ( unsigned long ); // true if obj was found
- Boolean Delete ( void* ); // true if obj was found
- void DeleteAll ();
-
- unsigned long Count () const;
- unsigned long Find ( const void* ) const;
- Boolean IsValidIndex ( unsigned long ) const;
-
- void SetOwnsObjects ( Boolean = true );
- Boolean GetOwnsObjects () const;
-
- virtual ostream& operator >> ( ostream& ) const;
-
- protected: TObjectList ( Boolean ownsObjects = true );
- void SetSize ( unsigned long objects );
- virtual void DeleteObject ( void* ) const;
-
- private: TObjectList ( const TObjectList& );
- TObjectList& operator = ( const TObjectList& );
-
- void*** fList;
- unsigned long fCount;
- Boolean fOwnsObjects;
- };
-
- /***********************************|****************************************/
-
- inline void TObjectList::Append(void* item){Insert(fCount+1,item);}
- inline unsigned long TObjectList::Count()const{return fCount;}
- inline Boolean TObjectList::IsValidIndex(unsigned long i)const{return i>=1 && i<=fCount;}
- inline ostream& operator<<(ostream& s,const TObjectList& l) {return l>>s;}
-
- #define DeclareList(OBJECT,LIST)\
- class LIST:public TObjectList{public:LIST();virtual ~LIST();\
- Boolean Remove(const OBJECT* o){return TObjectList::Remove((void*) o);};\
- OBJECT* Remove(unsigned long i){return (OBJECT*)TObjectList::Remove(i);};\
- OBJECT* operator[](unsigned long i)const{return (OBJECT*)TObjectList::operator[](i);};\
- OBJECT* Get(unsigned long i)const{return (OBJECT*)TObjectList::Get(i);};\
- virtual ostream& operator>>(ostream&) const;\
- protected: virtual void DeleteObject(void* o) const;}
-
- #define ImplementList(OBJECT,LIST,OWNS)\
- LIST::LIST():TObjectList(OWNS){}LIST::~LIST(){if(GetOwnsObjects())DeleteAll();}\
- void LIST::DeleteObject(void* o)const{delete(OBJECT*)o;}\
- ostream& LIST::operator>>(ostream& s)const{s<<#LIST;return TObjectList::operator>>(s);}
-
- /***********************************|****************************************/
-
- #pragma pop
-
- #endif // __OBJECTLIST__
-