home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Apple Shared Library Manager / ASLM Developer Tools / Interfaces / CIncludes / LibraryManagerClasses.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  87.1 KB  |  3,254 lines  |  [TEXT/MPS ]

  1. /*    File:        LibraryManagerClasses.h
  2.  
  3.     Contains:    Declarations for ASLM classes
  4.  
  5.     Copyright:    © 1991-1995 by Apple Computer, Inc., all rights reserved.
  6.  
  7.  
  8. */
  9.  
  10. #ifndef __LIBRARYMANAGERCLASSES__
  11. #define __LIBRARYMANAGERCLASSES__
  12.  
  13. #ifndef __LIBRARYMANAGER__
  14. #include <LibraryManager.h>
  15. #endif
  16.  
  17. /*******************************************************************************
  18. ** Forward class declarations
  19. ********************************************************************************/
  20.  
  21. #ifdef __cplusplus
  22. class TOperation;
  23. class TStandardPool;
  24. class TTraceLog;
  25. class TTaskScheduler;
  26. class TArbitrator;
  27. class TTime;
  28. class TPoolNotifier;
  29. class TRequestToken;
  30. class TToken;
  31. #else
  32. typedef void TOperation;
  33. typedef void TTraceLog;
  34. typedef void TArbitrator;
  35. typedef void TTaskScheduler;
  36. #endif
  37.  
  38. /*******************************************************************************
  39. ** Some typedefs and enums
  40. ********************************************************************************/
  41.  
  42. //
  43. //    PointerType is mainly used for the TCollection::DeleteAll method so the collection
  44. //    knows what type of objects are in the collection so it can do the proper cast
  45. //    and call the destructor (if it really is an object).
  46. //
  47. typedef int                PointerType;
  48.  
  49. #define kVoidPointer        ((PointerType)0)    /* a non-object pointer */
  50. #define kTDynamicPointer    ((PointerType)1)    /* SingleObject with vtable first */
  51. #define kTSCDynamicPointer    ((PointerType)1)    /* subclass of TSCDynamic */
  52. #define kTSCPointer            ((PointerType)2)    /* A Symantec C++ Object */
  53. #define kTStdDynamicPointer    ((PointerType)3)    /* non-SingleObject with vtable first */
  54.  
  55. typedef unsigned long    EventCode;
  56.  
  57. #define kTokenNotification        ((EventCode)0x40000001)
  58. #define kLowPoolMemoryEvent        ((EventCode)0x40000002)
  59. #define kHighPoolMemoryEvent    ((EventCode)0x40000003)
  60. #define kDownsizePoolEvent        ((EventCode)0x40000004)
  61. #define kDeathEvent                ((EventCode)0x40000005)
  62.  
  63. typedef void            (* _CDECL ProcessProcPtr)(TOperation*);
  64.  
  65. typedef unsigned long    (* _CDECL HashProcPtr)(const void*);
  66. typedef Boolean            (* _CDECL IsEqualProcPtr)(const void* ref, const void* toComp);
  67. typedef int                (* _CDECL CompareProcPtr)(const void* ref, const void* toComp);
  68.  
  69. // Below is a typedef for a pointer to a notify method for an object. Ignore the
  70. // fact the the typedef claims that it needs to be a TDynamic method. It can be
  71. // any kind of class. The only caveat is that if the NotifyMethod is a virtual
  72. // function, the vtable for the object must be the first field of the object.
  73. // You can force the vtable to be first by creating a base class that has atleast
  74. // one virtual function and no data members, like TDynamic does.
  75. #ifdef __cplusplus
  76. typedef void        (TDynamic::* _CDECL NotifyMethodPtr)(EventCode, OSErrParm, void* notifyData);
  77. typedef NotifyMethodPtr    NotifyMethod;
  78. #endif
  79. typedef void        (* _CDECL NotifyProcPtr)(void* refPtr, EventCode, OSErrParm, void* notifyData);
  80.  
  81. //
  82. // These are for compatibility with ASLM 1.1
  83. //
  84. typedef ProcessProcPtr    ProcessProc;
  85. typedef HashProcPtr        HashProc;
  86. typedef IsEqualProcPtr    IsEqualProc;
  87. typedef CompareProcPtr    CompareProc;
  88. typedef NotifyProcPtr    NotifyProc;
  89.  
  90. /*******************************************************************************
  91. ** Some "C" Global routines
  92. ********************************************************************************/
  93.  
  94. #ifdef __cplusplus
  95. extern "C"
  96. {
  97. #endif
  98.     TTraceLog*        GetGlobalTraceLog();
  99.     void            SetGlobalTraceLog(TTraceLog*);
  100.     void            Trace(const char *formatStr, ...);
  101.  
  102.     TArbitrator*    GetGlobalArbitrator();
  103.     TTaskScheduler*    GetGlobalTaskScheduler();
  104.     void            DestroyPointer(void*, PointerType);
  105.     
  106.     #if GENERATING68K
  107.     TLibraryManager*    GetClientFromWorld(GlobalWorld);    /* get client which owns the specified global world */
  108.     #endif
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112.  
  113. #ifdef __cplusplus
  114.  
  115. /*******************************************************************************
  116. ** TMacSemaphore class
  117. **
  118. ** Since threads don't really exist on the Macintosh, these semaphores are
  119. ** done by shutting interrupts off to guarantee exclusivity.  Therefore,
  120. ** the rule is - never hold one very long, since on the Macintosh
  121. ** it will degrade performance if you do.
  122. ********************************************************************************/
  123.     
  124. #define kTMacSemaphoreID "!$sema,1.2"
  125.  
  126. class TMacSemaphore : public TDynamic
  127. {
  128.     public:
  129.                             _CDECL TMacSemaphore();
  130.         virtual                ~_CDECL TMacSemaphore();
  131.     
  132.         virtual void        _CDECL Grab();
  133.         virtual void        _CDECL Release();
  134.         virtual Boolean        _CDECL GrabNoWait();
  135.  
  136.     private:
  137.                             TMacSemaphore(const TMacSemaphore&);
  138.                 void        operator=(const TMacSemaphore&);
  139.  
  140.         short    fSaveLevel;
  141.         short    fCount;
  142. };
  143.  
  144. /*******************************************************************************
  145. ** CLASS TMatchObject
  146. **
  147. ** This object is the base class for any object which "knows" how
  148. ** to hash a specific object, as well as how to compare a
  149. ** 2nd object to the specific object.
  150. ********************************************************************************/
  151.  
  152. #define kTMatchObjectID "!$mobj,1.2"
  153.  
  154. class TMatchObject : public TDynamic
  155. {
  156.     public:
  157.         virtual                    ~_CDECL TMatchObject();
  158.         
  159.             // Default implementation is to return 0
  160.         virtual unsigned long    _CDECL Hash() const;
  161.             // Default implementation is to compare
  162.             // address of "this" with address of the object
  163.         virtual short            _CDECL Compare(const void*) const;
  164.             // Default implementation is to call Compare
  165.         virtual Boolean            _CDECL IsEqual(const void*) const;
  166.  
  167.     protected:
  168.                                 _CDECL TMatchObject();
  169. };
  170.  
  171. /*******************************************************************************
  172. ** CLASS TProcMatchObject
  173. **
  174. ** This is a TMatchObject which takes a reference pointer and pointers to "C"
  175. ** functions to do the matching/hashing job.
  176. ********************************************************************************/
  177.  
  178. #define kTProcMatchObjectID "!$pmob,1.2"
  179.  
  180. class TProcMatchObject : public TMatchObject
  181. {
  182.     public:
  183.                                 _CDECL TProcMatchObject(const void* ref, HashProcPtr = 0,
  184.                                                       CompareProcPtr = 0, IsEqualProcPtr = 0);
  185.         virtual                    ~_CDECL TProcMatchObject();
  186.         
  187.         virtual unsigned long    _CDECL Hash() const;
  188.         virtual short            _CDECL Compare(const void*) const;
  189.         virtual Boolean            _CDECL IsEqual(const void*) const;
  190.  
  191.                 void            SetReferencePointer(const void*);
  192.                 void            SetHashProc(HashProcPtr);
  193.                 void            SetCompareProc(CompareProcPtr);
  194.                 void            SetIsEqualProc(IsEqualProcPtr);
  195.                 
  196.                 const void*        GetReferencePointer() const;
  197.                 HashProcPtr        GetHashProc() const;
  198.                 CompareProcPtr    GetCompareProc() const;
  199.                 IsEqualProcPtr    GetIsEqualProc() const;
  200.                 
  201.     private:
  202.             const void*        fRef;
  203.             HashProcPtr        fHashProc;
  204.             CompareProcPtr    fCompareProc;
  205.             IsEqualProcPtr    fIsEqualProc;
  206. };
  207.  
  208.  
  209. /*    -------------------------------------------------------------------------
  210.     Inline methods for TProcMatchObject
  211.     ------------------------------------------------------------------------- */
  212.  
  213.     inline void TProcMatchObject::SetReferencePointer(const void* ref)
  214.     {
  215.         fRef = ref;
  216.     }
  217.  
  218.     inline void TProcMatchObject::SetHashProc(HashProcPtr proc)
  219.     {
  220.         fHashProc = proc;
  221.     }
  222.  
  223.     inline void TProcMatchObject::SetCompareProc(CompareProcPtr proc)
  224.     {
  225.         fCompareProc = proc;
  226.     }
  227.  
  228.     inline void TProcMatchObject::SetIsEqualProc(IsEqualProcPtr proc)
  229.     {
  230.         fIsEqualProc = proc;
  231.     }
  232.  
  233.     inline const void* TProcMatchObject::GetReferencePointer() const
  234.     {
  235.         return fRef;
  236.     }
  237.  
  238.     inline HashProcPtr TProcMatchObject::GetHashProc() const
  239.     {
  240.         return fHashProc;
  241.     }
  242.  
  243.     inline CompareProcPtr TProcMatchObject::GetCompareProc() const
  244.     {
  245.         return fCompareProc;
  246.     }
  247.  
  248.     inline IsEqualProcPtr TProcMatchObject::GetIsEqualProc() const
  249.     {
  250.         return fIsEqualProc;
  251.     }
  252.  
  253. /*******************************************************************************
  254. ** CLASS THashObject
  255. **
  256. ** This object is the base class for any object which "knows" how
  257. ** to hash another object.
  258. ********************************************************************************/
  259.  
  260. #define kTHashObjectID "!$hobj,1.2"
  261.  
  262. class THashObject : public TDynamic
  263. {
  264.     public:
  265.         virtual                    ~_CDECL THashObject();
  266.         
  267.         virtual    unsigned long    _CDECL Hash(const void*) const    = 0;
  268.  
  269.     protected:
  270.                                 _CDECL THashObject();
  271. };
  272.  
  273. /*******************************************************************************
  274. ** CLASS TProcHashObject
  275. **
  276. ** This is a THashObject which uses a "C" Procedure to hash objects. 
  277. ********************************************************************************/
  278.  
  279. #define kTProcHashObjectID "!$phob,1.2"
  280.  
  281. class TProcHashObject : public THashObject
  282. {
  283.     public:
  284.                                 _CDECL TProcHashObject(HashProcPtr);
  285.         virtual                    ~_CDECL TProcHashObject();
  286.         
  287.         virtual    unsigned long    _CDECL Hash(const void*) const;
  288.  
  289.                 void            SetHashProc(HashProcPtr);
  290.                 HashProcPtr        GetHashProc() const;
  291.                 
  292.     private:
  293.         HashProcPtr    fHashProc;
  294. };
  295.  
  296. /*    -------------------------------------------------------------------------
  297.     Inline methods for TProcHashObject
  298.     ------------------------------------------------------------------------- */
  299.  
  300.     inline void TProcHashObject::SetHashProc(HashProcPtr proc)
  301.     {
  302.         fHashProc = proc;
  303.     }
  304.     
  305.     inline HashProcPtr TProcHashObject::GetHashProc() const
  306.     {
  307.         return fHashProc;
  308.     }
  309.     
  310. /*******************************************************************************
  311. ** CLASS TIterator
  312. **
  313. ** This class Iterates through a collection of objects.  Since
  314. ** collections are "thread-safe", when the Next() method returns
  315. ** NULL, call IterationComplete().  If it returns true, then you were
  316. ** returned NULL because the iterator was done.  Otherwise, you were
  317. ** returned NULL because the underlying collection changed.  
  318. ** RemoveCurrentObject will return false if the collection changed
  319. ** before the remove could be done.
  320. ********************************************************************************/
  321.  
  322. #define kTIteratorID "!$iter,1.2"
  323.  
  324. class TIterator : public TDynamic
  325. {
  326.     public:
  327.         virtual                    ~_CDECL TIterator();
  328.         
  329.         virtual    void            _CDECL Reset()                    = 0;
  330.         virtual void*            _CDECL Next()                        = 0;
  331.         
  332.         virtual Boolean            _CDECL IterationComplete() const    = 0;
  333.         virtual Boolean            _CDECL RemoveCurrentObject()        = 0;
  334.         
  335.                 void             SetMatchObject(TMatchObject*);
  336.                 TMatchObject*     GetMatchObject() const;
  337.  
  338.     protected:
  339.                                 _CDECL TIterator();
  340.                                 
  341.     private:
  342.         TMatchObject*        fMatcher;
  343. };
  344.  
  345. /*    -------------------------------------------------------------------------
  346.     Inline methods for TIterator
  347.     ------------------------------------------------------------------------- */
  348.     
  349.     inline void TIterator::SetMatchObject(TMatchObject* theMatcher)
  350.     {
  351.         fMatcher = theMatcher;
  352.     }
  353.     
  354.     inline TMatchObject* TIterator::GetMatchObject() const
  355.     {
  356.         return fMatcher;
  357.     }
  358.  
  359. /*******************************************************************************
  360. ** CLASS TCollection
  361. **
  362. ** This class defines the framework for all collections.
  363. ********************************************************************************/
  364.  
  365. #define kTCollectionID "!$coll,1.2"
  366.  
  367. class TCollection : public TDynamic
  368. {
  369.     public:
  370.         virtual                ~_CDECL TCollection();
  371.         
  372.                 size_t        Count() const;
  373.                 Boolean        IsEmpty() const;
  374.         virtual TIterator*    _CDECL CreateIterator(TStandardPool*)             = 0;
  375.         
  376.         virtual OSErr        _CDECL Add(void*);
  377.         virtual OSErr        _CDECL AddUnique(void*, const TMatchObject&);
  378.         virtual OSErr        _CDECL AddUnique(void*);
  379.                 
  380.         virtual void        _CDECL RemoveAll();
  381.         virtual void        _CDECL DeleteAll(PointerType = kTDynamicPointer);    
  382.         virtual void*        _CDECL Remove(const TMatchObject&)                = 0;
  383.         virtual Boolean        _CDECL Remove(void*)                            = 0;
  384.         virtual void*        _CDECL Member(const TMatchObject&)                = 0;
  385.         virtual Boolean        _CDECL Member(const void*)                        = 0;
  386.         
  387.         virtual void*        _CDECL GetIndexedObject(size_t) const;
  388.                 void*        operator[](size_t);
  389.  
  390.                 long        GetSeed() const;
  391.                 void        Grab();
  392.                 void        Release();
  393.     
  394.     protected:
  395.                             _CDECL TCollection();
  396.         virtual OSErr        _CDECL PrivateAdd(void*, long)                    = 0;
  397.         virtual void        _CDECL KillAll(BooleanParm ifDel, PointerType)    = 0;
  398.  
  399.         long            fSeed;
  400.         size_t            fCount;
  401.         TMacSemaphore    fSemaphore;
  402. };
  403.  
  404. /*    -----------------------------------------------------------------
  405.     Inline Methods for TCollection
  406.     ----------------------------------------------------------------- */
  407.  
  408.     inline size_t TCollection::Count() const
  409.     {
  410.         return fCount;
  411.     }
  412.  
  413.     inline Boolean TCollection::IsEmpty() const
  414.     {
  415.         return fCount == 0;
  416.     }
  417.  
  418.     inline void* TCollection::operator[](size_t idx)
  419.     {
  420.         return GetIndexedObject(idx);
  421.     }
  422.  
  423.     inline long TCollection::GetSeed() const
  424.     {
  425.         return fSeed;
  426.     }
  427.     
  428.     inline void TCollection::Grab()
  429.     {
  430.         (&fSemaphore)->Grab();
  431.     }
  432.     
  433.     inline void TCollection::Release()
  434.     {
  435.         (&fSemaphore)->Release();
  436.     }
  437.     
  438. /*******************************************************************************
  439. ** CLASS TLink
  440. **
  441. ** This class implements a link object which can be placed on a linked
  442. ** list.  It is totally non-virtual since it is a trivial class and
  443. ** to keep it at 8 bytes in size.
  444. ********************************************************************************/
  445.  
  446. class TLink
  447. {
  448.     public:
  449.                         TLink(void* value);
  450.                         TLink(TLink* link, void* value);
  451.                         TLink(BooleanParm);
  452.                         TLink();
  453.                         ~TLink();
  454.                         
  455.         void*            operator new(size_t size, TMemoryPool*);    // default size, from a pool
  456.         void*            operator new(size_t);                        // from default pool
  457.         void            operator delete(void* mem) {SLMDeleteOperator(mem);};
  458.         
  459.         void            SetNext(TLink* link);
  460.         TLink*            GetNext() const;
  461.         
  462.         void*            GetValue() const;
  463.         void            SetValue(void*);
  464.         
  465.         void            Append(TLink* newLink);        // append newLink after this
  466.         void            Remove(TLink* previous);    // remove nextLink from list
  467.  
  468.     private:
  469.         TLink*        fNext;
  470.         void*        fValue;
  471. };
  472.  
  473. /*    -----------------------------------------------------------------
  474.     Inline Methods for TLink
  475.     ----------------------------------------------------------------- */
  476.     
  477.     inline void* TLink::operator new(size_t size, TMemoryPool* thePool)
  478.     {
  479.         return SLMNewOperator(size, thePool);
  480.     }
  481.     
  482.     inline void* TLink::operator new(size_t size)
  483.     {
  484.         return SLMNewOperator(size, NULL);
  485.     }
  486.  
  487.     inline TLink::TLink(BooleanParm)
  488.     {}
  489.     
  490.     inline TLink::TLink()
  491.     {
  492.         fNext    = NULL;
  493.         fValue    = NULL;
  494.     }
  495.     
  496.     inline TLink::TLink(void* value)
  497.     {
  498.         fNext    = NULL;
  499.         fValue    = value;
  500.     }
  501.     
  502.     inline TLink::TLink(TLink* link, void* value)
  503.     {
  504.         fNext    = link;
  505.         fValue    = value;
  506.     }
  507.     
  508.     inline TLink::~TLink()
  509.     {
  510.         fNext    = NULL;
  511.         fValue    = NULL;
  512.     }
  513.     
  514.     inline void TLink::SetNext(TLink* link)
  515.     {
  516.         fNext = link;
  517.     }
  518.         
  519.     inline TLink* TLink::GetNext() const
  520.     {
  521.         return fNext;
  522.     }
  523.         
  524.     inline void* TLink::GetValue() const
  525.     {
  526.         return fValue;
  527.     }
  528.     
  529.     inline void TLink::SetValue(void* obj) 
  530.     {
  531.         fValue = obj;
  532.     }
  533.     
  534.     inline void TLink::Append(TLink* newLink)
  535.     {
  536.         newLink->SetNext(fNext);
  537.         fNext = newLink;
  538.     }
  539.     
  540.     inline void TLink::Remove(TLink* previous)
  541.     {
  542.         TLink* link = previous->GetNext();
  543.         previous->SetNext(fNext);
  544.         link->SetNext(NULL);
  545.     }
  546.     
  547. /*******************************************************************************
  548. ** CLASS TPriorityLink
  549. **
  550. ** This class implements a link object which can be placed on a linked
  551. ** list, and can hold a timer or priority value.
  552. ********************************************************************************/
  553.  
  554. #define kNormalPriority        (((unsigned long)-1L) >> 1)
  555. #define kHighestPriority    0
  556. #define kLowestPriority        ((unsigned long)-1L)
  557. #define kToLowerPriority    1
  558.  
  559. class TPriorityLink : public TLink
  560. {
  561.     public:
  562.                         TPriorityLink(BooleanParm);
  563.                         TPriorityLink(void* value);
  564.                         TPriorityLink(TLink* link, void* value);
  565.                         TPriorityLink();
  566.                         
  567.         void            SetPriority(unsigned long);
  568.         unsigned long    GetPriority() const;
  569.     
  570.     private:
  571.         unsigned long    fPriority;
  572. };
  573.  
  574. /*    -----------------------------------------------------------------
  575.     Inline Methods for TPriorityLink
  576.     ----------------------------------------------------------------- */
  577.     
  578.     inline TPriorityLink::TPriorityLink(BooleanParm val) : TLink(val)
  579.     {}
  580.     
  581.     inline TPriorityLink::TPriorityLink()
  582.     {
  583.         fPriority = kNormalPriority;
  584.     }
  585.     
  586.     inline TPriorityLink::TPriorityLink(TLink* link, void* value) : 
  587.         TLink(link, value)
  588.     {
  589.         fPriority = kNormalPriority;
  590.     }
  591.     
  592.     inline TPriorityLink::TPriorityLink(void* value) : TLink(value)
  593.     {
  594.         fPriority = kNormalPriority;
  595.     }
  596.     
  597.     inline void TPriorityLink::SetPriority(unsigned long pri)
  598.     {
  599.         fPriority = pri;
  600.     }
  601.         
  602.     inline unsigned long TPriorityLink::GetPriority() const
  603.     {
  604.         return fPriority;
  605.     }
  606.     
  607. /*******************************************************************************
  608. ** CLASS TSimpleList
  609. **
  610. ** This class implements a simple linked list, which can have objects added
  611. ** at the front or the back of the list.
  612. ********************************************************************************/
  613.  
  614. #define kTSimpleListID "!$slst,1.2"
  615.  
  616. class TSimpleList : public TCollection
  617. {
  618.     friend class    TListIterator;
  619.  
  620.     public:
  621.                                 _CDECL TSimpleList();
  622.                                 _CDECL TSimpleList(TMemoryPool*);
  623.                                 _CDECL TSimpleList(TSimpleList*);
  624.         virtual                    ~_CDECL TSimpleList();
  625.     
  626.         // TCollection overrides
  627.         
  628.         virtual TIterator*        _CDECL CreateIterator(TStandardPool*);
  629.         
  630.         virtual void*            _CDECL Remove(const TMatchObject&);
  631.         virtual Boolean            _CDECL Remove(void*);
  632.         virtual void*            _CDECL Member(const TMatchObject&);
  633.         virtual Boolean            _CDECL Member(const void*);
  634.         
  635.         // New methods
  636.         
  637.         virtual TLink*            _CDECL MemberLink(const void*);
  638.         virtual TLink*            _CDECL MemberLink(const TMatchObject&);
  639.         virtual TLink*            _CDECL RemoveLink(void*);
  640.         virtual TLink*            _CDECL RemoveLink(const TMatchObject&);
  641.  
  642.         virtual TLink*            _CDECL FirstLink() const;
  643.         virtual TLink*            _CDECL LastLink() const;
  644.         virtual    TLink*            _CDECL RemoveFirstLink();
  645.         virtual    TLink*            _CDECL RemoveLastLink();
  646.         virtual    void            _CDECL AddLinkFirst(TLink*);
  647.         virtual    void            _CDECL AddLinkLast(TLink*);
  648.  
  649.         virtual    void*            _CDECL First() const;
  650.         virtual    void*            _CDECL Last() const;
  651.         virtual    void*            _CDECL RemoveFirst();
  652.         virtual    void*            _CDECL RemoveLast();
  653.         virtual    OSErr            _CDECL AddFirst(void*);
  654.         virtual    OSErr            _CDECL AddLast(void*);
  655.         
  656.                 void            SetLinkPool(TMemoryPool*);
  657.                 TMemoryPool*    GetLinkPool() const;
  658.  
  659.     protected:
  660.         virtual OSErr            _CDECL PrivateAdd(void*, long);
  661.         virtual void            _CDECL KillAll(BooleanParm ifDel, PointerType);
  662.         virtual TLink*            _CDECL PrivateFind(const void*, const TMatchObject*, TLink**) const;
  663.  
  664.     private:
  665.                                 TSimpleList(const TSimpleList&);
  666.                 void            operator=(const TSimpleList&);
  667.         
  668.     protected:
  669.     
  670.         TLink*            fList;
  671.         TLink*            fLastInList;
  672.         TMemoryPool*    fLinkPool;
  673. };
  674.  
  675. /*    -----------------------------------------------------------------
  676.     Inline Methods for TSimpleList
  677.     ----------------------------------------------------------------- */
  678.     
  679.     inline void TSimpleList::SetLinkPool(TMemoryPool* thePool)
  680.     {
  681.         fLinkPool = thePool;
  682.     }
  683.  
  684.     inline TMemoryPool* TSimpleList::GetLinkPool() const
  685.     {
  686.         return fLinkPool;
  687.     }
  688.  
  689. /*******************************************************************************
  690. ** CLASS TLinkedList
  691. **
  692. ** This class adds the ability to do things with a linked list based on
  693. ** "after" or "before" rules.
  694. ********************************************************************************/
  695.  
  696. #define kTLinkedListID "slm:coll$llst,1.2"
  697.  
  698. class TLinkedList : public TSimpleList
  699. {
  700.     public:
  701.                                 _CDECL TLinkedList();
  702.                                 _CDECL TLinkedList(TMemoryPool*);
  703.                                 _CDECL TLinkedList(TSimpleList*);
  704.         virtual                    ~_CDECL TLinkedList();
  705.             
  706.         // New methods
  707.                 
  708.         virtual    void*            _CDECL After(const void* obj) const;
  709.         virtual    void*            _CDECL After(const TMatchObject&) const;
  710.         virtual    void*            _CDECL Before(const void* obj) const;
  711.         virtual    void*            _CDECL Before(const TMatchObject&) const;
  712.         
  713.         virtual Boolean            _CDECL AddLinkAfter(TLink*, const TMatchObject&);
  714.         virtual Boolean            _CDECL AddLinkAfter(TLink*, const void* obj);
  715.         virtual Boolean            _CDECL AddLinkBefore(TLink*, const TMatchObject&);
  716.         virtual Boolean            _CDECL AddLinkBefore(TLink*, const void* obj);
  717.         virtual OSErr            _CDECL AddAfter(void*, const TMatchObject&);
  718.         virtual OSErr            _CDECL AddAfter(void*, const void* obj);
  719.         virtual OSErr            _CDECL AddBefore(void*, const TMatchObject&);
  720.         virtual OSErr            _CDECL AddBefore(void*, const void* obj);
  721.  
  722.     private:
  723.                                 TLinkedList(const TLinkedList&);
  724.                 void            operator=(const TLinkedList&);
  725. };
  726.  
  727. /*******************************************************************************
  728. ** CLASS TPriorityList
  729. **
  730. ** This class implements a list where objects are sorted in order of a 
  731. ** priority.
  732. ********************************************************************************/
  733.  
  734. #define kTPriorityListID "!$plst,1.2"
  735.  
  736. class TPriorityList : public TSimpleList
  737. {
  738.     public:
  739.                                 _CDECL TPriorityList();
  740.                                 _CDECL TPriorityList(TMemoryPool*);
  741.                                 _CDECL TPriorityList(TPriorityList*);
  742.         virtual                    ~_CDECL TPriorityList();
  743.     
  744.         // TLinkedList overrides
  745.         
  746.         virtual    OSErr            _CDECL AddFirst(void*);
  747.         virtual    OSErr            _CDECL AddLast(void*);
  748.         virtual    void            _CDECL AddLinkFirst(TLink*);
  749.         virtual    void            _CDECL AddLinkLast(TLink*);
  750.         
  751.         // New methods
  752.         
  753.         virtual    OSErr            _CDECL AddPrioritized(void*, unsigned long pri);
  754.         virtual    void            _CDECL AddLink(TPriorityLink*);
  755.  
  756.     private:
  757.                                 TPriorityList(const TPriorityList&);
  758.                 void            operator=(const TPriorityList&);
  759.         virtual OSErr            _CDECL PrivateAdd(void*, long);
  760. };
  761.     
  762. /*******************************************************************************
  763. ** CLASS TListIterator
  764. **
  765. ** This iterator is used to iterate all collection classes descending from
  766. ** TSimpleList.
  767. ********************************************************************************/
  768.  
  769. #define kTListIteratorID "!$litr,1.2"
  770.  
  771. class TListIterator : public TIterator
  772. {
  773.     public:
  774.                             _CDECL TListIterator(TSimpleList*);
  775.         virtual                ~_CDECL TListIterator();
  776.         
  777.         // TIterator Overrides
  778.         
  779.         virtual    void        _CDECL Reset();
  780.         virtual void*        _CDECL Next();
  781.                 
  782.         virtual Boolean        _CDECL IterationComplete() const;
  783.         virtual Boolean        _CDECL RemoveCurrentObject();
  784.         
  785.         // New methods
  786.         
  787.         virtual TLink*        _CDECL GetCurrentLink() const;
  788.                 void        SetList(TSimpleList*);
  789.                 
  790.     private:
  791.                             TListIterator(const TListIterator&);
  792.                 void        operator=(const TListIterator&);
  793.  
  794.         virtual    TLink*        _CDECL NextLink();
  795.                 
  796.         TSimpleList*    fList;
  797.         TLink*            fPrevLink;
  798.         TLink*            fCurLink;
  799.         long            fSeed;
  800.         Boolean            fComplete;
  801.         Boolean            fFiller;
  802. };
  803.  
  804. /*    -------------------------------------------------------------------------
  805.     Inline methods for TListIterator
  806.     ------------------------------------------------------------------------- */
  807.  
  808.     inline void TListIterator::SetList(TSimpleList* list)
  809.     {
  810.         fList = list;
  811.         Reset();
  812.     }
  813.  
  814. /*******************************************************************************
  815. ** CLASS TArray
  816. **
  817. ** This class implements an array collection, where objects can be efficiently
  818. ** looked at by index, and are added to the end of the array.  Deleting objects
  819. ** moves all higher-indexed objects down by 1 index number.
  820. ********************************************************************************/
  821.  
  822. #define kTArrayID "slm:coll$arry,1.2"
  823.  
  824. class TArray : public TCollection
  825. {
  826.     friend class    TArrayIterator;
  827.  
  828.     public:
  829.                                 _CDECL TArray();
  830.                                 _CDECL TArray(size_t size, TStandardPool* = NULL, 
  831.                                             int growBy = 0);
  832.         virtual                    ~_CDECL TArray();
  833.                 
  834.         virtual Boolean            _CDECL IsValid() const;
  835.                 
  836.                  TStandardPool*    GetGrowPool() const;
  837.                 
  838.         // TCollection overrides
  839.         
  840.         virtual TIterator*        _CDECL CreateIterator(TStandardPool*);
  841.         
  842.         virtual Boolean            _CDECL Remove(void*);
  843.         virtual void*            _CDECL Remove(const TMatchObject&);
  844.         virtual Boolean            _CDECL Member(const void*);
  845.         virtual void*            _CDECL Member(const TMatchObject&);
  846.         
  847.         virtual void*            _CDECL GetIndexedObject(size_t) const;
  848.         
  849.     private:
  850.                                 TArray(const TArray&);
  851.                 void            operator=(const TArray&);
  852.                 void            _CDECL InitArray(size_t size, TStandardPool*, int growBy);
  853.         
  854.     protected:
  855.         virtual void*            _CDECL MemberIndex(const void*, const TMatchObject*, size_t*);
  856.         virtual void*            _CDECL PrivateRemove(void*, const TMatchObject*);
  857.         virtual OSErr            _CDECL PrivateAdd(void*, long);
  858.         virtual void            _CDECL KillAll(BooleanParm ifDel, PointerType);
  859.         virtual Boolean            _CDECL Grow();
  860.  
  861.         void**            fArray;        // memory allocated for the array
  862.         size_t            fSize;        // current size of the array
  863.         long            fGrowBy;    // size to grow by if array is full
  864. };
  865.     
  866. /*******************************************************************************
  867. ** CLASS TArrayIterator
  868. **
  869. ** This class Iterates through a TArray collection
  870. ********************************************************************************/
  871.  
  872. #define kTArrayIteratorID "slm:coll$aitr,1.2"
  873.  
  874. class TArrayIterator : public TIterator
  875. {
  876.     public:
  877.                             _CDECL TArrayIterator(TArray*);
  878.         virtual                ~_CDECL TArrayIterator();
  879.         
  880.         virtual    void        _CDECL Reset();
  881.         virtual void*        _CDECL Next();
  882.         
  883.         virtual Boolean        _CDECL IterationComplete() const;
  884.         virtual Boolean        _CDECL RemoveCurrentObject();
  885.  
  886.     private:
  887.                             TArrayIterator(const TArrayIterator&);
  888.                 void        operator=(const TArrayIterator&);
  889.  
  890.     private:
  891.         TArray*        fArray;
  892.         size_t        fCurIdx;
  893.         long        fSeed;
  894.         Boolean        fComplete;
  895.         Boolean        fFiller;
  896. };
  897.  
  898. /*******************************************************************************
  899. ** Class THashList
  900. ********************************************************************************/
  901.  
  902. #define kTHashListID    "!$hsls,1.2"
  903.  
  904. /*  You need to do a LoadClass on kTHashListGrowerID if you want to call */
  905. /*  THashList::Grow() at interrupt time at some later point. */
  906. #define kTHashListGrowerID    "slm:supp$hlgrw,1.2"
  907.  
  908. struct HashListInfo
  909. {
  910.     size_t    emptySlots;        // number of empty slots in the hash list
  911.     size_t    singleSlots;    // number of slots with only one entry
  912.     size_t    numChains;        // number of slots with more than one entry
  913.     size_t    longestChain;    // the longest chain
  914.     size_t    avgChain;        // the average length of a chain
  915. };
  916.  
  917. class THashList : public TCollection
  918. {
  919.     friend class    THashListIterator;
  920.     
  921.     protected:
  922.                                     _CDECL THashList(BooleanParm);
  923.                                     
  924.     public:
  925.                                     _CDECL THashList();
  926.                                     _CDECL THashList(THashObject*,
  927.                                                    size_t initialSize,
  928.                                                    TMemoryPool* = NULL);
  929.         virtual                        ~_CDECL THashList();
  930.         
  931.         virtual Boolean                _CDECL IsValid() const;
  932.         
  933.         virtual OSErr                _CDECL Grow(size_t newSize);
  934.         
  935.                 OSErr                Rehash();
  936.                 
  937.                 void                SetHashObject(THashObject*);
  938.                 TMemoryPool*        GetLinkPool() const;
  939.                 THashObject*        GetHashObject() const;
  940.                 size_t                GetTableSize() const;
  941.                 void                SetLinkPool(TMemoryPool*);
  942.         
  943.         virtual void                _CDECL GetHashListInfo(HashListInfo&) const;
  944.         
  945.         // TCollection Overrides
  946.         
  947.         virtual TIterator*            _CDECL CreateIterator(TStandardPool*);
  948.     
  949.         virtual void*                _CDECL Remove(const TMatchObject&);
  950.         virtual Boolean                _CDECL Remove(void*);
  951.         virtual void*                _CDECL Member(const TMatchObject&);
  952.         virtual Boolean                _CDECL Member(const void*);
  953.         
  954.     protected:
  955.         virtual OSErr                _CDECL PrivateAdd(void*, long);
  956.         virtual void                _CDECL KillAll(BooleanParm ifDel, PointerType);
  957.  
  958.         virtual void*                _CDECL PrivateFind(const void*,
  959.                                                      const TMatchObject*,
  960.                                                      void** toDel);
  961.                                         
  962.         virtual Boolean                _CDECL IsPrime(size_t num);           
  963.         virtual size_t                _CDECL FixSize(size_t);
  964.                 unsigned long        Hash(const void*);
  965.                  
  966.     private:
  967.                                     THashList(const THashList&);
  968.                 void                operator=(const THashList&);
  969.                 void                _CDECL InitHashList(THashObject*, TMemoryPool*,
  970.                                                       size_t);
  971.     protected:        
  972.         THashObject*        fHasher;
  973.         TMemoryPool*        fLinkPool;
  974.         void**                fTable;
  975.         size_t                fTableSize;
  976.         void**                fGrowTable;
  977.         size_t                fGrowTableSize;
  978.         Boolean                fGrowInProgress;
  979.         Boolean                fFiller;
  980. };
  981.  
  982. /*    -------------------------------------------------------------------------
  983.     Inline methods for THashList
  984.     ------------------------------------------------------------------------- */
  985.  
  986.     inline void THashList::SetHashObject(THashObject* obj)
  987.     {
  988.         fHasher = obj;
  989.     }
  990.     
  991.     inline THashObject* THashList::GetHashObject() const
  992.     {
  993.         return fHasher;
  994.     }
  995.     
  996.     inline void THashList::SetLinkPool(TMemoryPool* pool)
  997.     {
  998.         fLinkPool = pool;
  999.     }
  1000.     
  1001.     inline TMemoryPool* THashList::GetLinkPool() const
  1002.     {
  1003.         return fLinkPool;
  1004.     }
  1005.     
  1006.     inline size_t THashList::GetTableSize() const
  1007.     {
  1008.         return fTableSize;
  1009.     }
  1010.     
  1011.     inline OSErr THashList::Rehash()
  1012.     {
  1013.         return Grow(GetTableSize());
  1014.     }
  1015.  
  1016. /*******************************************************************************
  1017. ** CLASS THashListIterator
  1018. ********************************************************************************/
  1019.  
  1020. #define kTHashListIteratorID "!$hsit,1.2"
  1021.  
  1022. class THashListIterator : public TIterator
  1023. {
  1024.     public:
  1025.                             _CDECL THashListIterator(THashList*,
  1026.                                                     TMatchObject* = NULL);
  1027.         virtual                ~_CDECL THashListIterator();
  1028.         
  1029.         // TIterator Overrides
  1030.         
  1031.         virtual void        _CDECL Reset();
  1032.         virtual void*        _CDECL Next();
  1033.     
  1034.         virtual Boolean        _CDECL IterationComplete() const;
  1035.         virtual Boolean        _CDECL RemoveCurrentObject();
  1036.         
  1037.     protected:        
  1038.         virtual Boolean        _CDECL SetNextTable(int);
  1039.         
  1040.     private:
  1041.                             THashListIterator (const THashListIterator&);
  1042.                 void        operator=(const THashListIterator&);
  1043.         
  1044.     protected:
  1045.         THashList*            fList;
  1046.         long                fSeed;
  1047.         void**                fTable;
  1048.         size_t                fTableSize;
  1049.         TLink*                fLink;
  1050.         size_t                fCell;
  1051.         short                fTableNo;
  1052.         Boolean                fFirst;
  1053.         Boolean                fComplete;
  1054. };
  1055.  
  1056. /*******************************************************************************
  1057. ** CLASS TOperation
  1058. *******************************************************************************/
  1059.  
  1060. #define kTOperationID    "!$oper,1.2"
  1061.  
  1062. #define kRemovedInProcess ((TPriorityLink*)-1L)
  1063.  
  1064. class TOperation : public TDynamic
  1065. {
  1066.     public:
  1067.                                 _CDECL TOperation();
  1068.                                 _CDECL TOperation(long creatorData);
  1069.                                 _CDECL TOperation(void* creatorPtr);
  1070.                                 _CDECL TOperation(ProcessProcPtr, long creatorData);
  1071.                                 _CDECL TOperation(ProcessProcPtr, void* creatorPtr);
  1072.                                 _CDECL TOperation(const TOperation&);
  1073.         virtual                    ~_CDECL TOperation();
  1074.         
  1075.                 TPriorityLink*    GetLink();
  1076.                 
  1077.         virtual void            _CDECL Reset();
  1078.         virtual void            _CDECL Process();
  1079.  
  1080.                 Boolean            WasRemovedInProcess() const;
  1081.                 void            ClearRemovedInProcess();
  1082.                 void            SetDeleteWhenDone();
  1083.                 Boolean            IsBeingRerun() const;
  1084.         
  1085.                 void            SetProcessProc(ProcessProcPtr);
  1086.                 ProcessProcPtr    GetProcessProc() const;
  1087.  
  1088.                 // Timer and Priority are just 2 different ways
  1089.                 // of looking at the same field.
  1090.                 
  1091.                 void            SetTime(const TTime&);
  1092.                 void            SetTime(unsigned long msecs);
  1093.                 void            SetPriority(unsigned long pri);
  1094.                 unsigned long    GetTime() const;
  1095.                 unsigned long    GetPriority() const;
  1096.  
  1097.                 // CreatorData and CreatorPtr are just 2 different ways
  1098.                 // of looking at the same field.
  1099.                 
  1100.                 void*            GetCreatorPtr() const;
  1101.                 long            GetCreatorData() const;
  1102.                 void            SetCreatorPtr(void*);
  1103.                 void            SetCreatorData(long);
  1104.                 
  1105. #if GENERATING68K
  1106.                 GlobalWorld        GetSavedGlobalWorld() const;
  1107.                 void            SetSavedGlobalWorld(GlobalWorld);
  1108. #endif
  1109.         
  1110.                 TLibraryManager* GetSavedClient() const;
  1111.                 void            SetSavedClient(TLibraryManager*);
  1112.         
  1113.     private:
  1114.         
  1115.         ProcessProcPtr            fProc;
  1116.         union
  1117.         {
  1118.             void*        fPtr;
  1119.             long        fLong;
  1120.         }                        fCreatorData;            // Storage for the Creator
  1121.         TPriorityLink            fProcessLink;
  1122. #if GENERATING68K
  1123.         GlobalWorld                fSavedWorld;
  1124. #else
  1125.         TLibraryManager*        fSavedClient;
  1126. #endif
  1127. };
  1128.  
  1129. /*    -----------------------------------------------------------------
  1130.     Inline Methods for TOperation
  1131.     ----------------------------------------------------------------- */
  1132.     
  1133.     inline TPriorityLink* TOperation::GetLink()
  1134.     {
  1135.         return &fProcessLink;
  1136.     }
  1137.     
  1138.     inline Boolean TOperation::WasRemovedInProcess() const
  1139.     {
  1140.         return fProcessLink.GetNext() == kRemovedInProcess;
  1141.     }
  1142.     
  1143.     inline void TOperation::ClearRemovedInProcess()
  1144.     {
  1145.         fProcessLink.SetNext(NULL);
  1146.     }
  1147.     
  1148.     inline Boolean TOperation::IsBeingRerun() const
  1149.     {
  1150.         return fProcessLink.GetPriority() != 0;
  1151.     }
  1152.     
  1153.     inline void TOperation::SetDeleteWhenDone()
  1154.     {
  1155.         fProcessLink.SetNext(kRemovedInProcess);
  1156.     }
  1157.     
  1158.     inline unsigned long TOperation::GetTime() const
  1159.     {
  1160.         return fProcessLink.GetPriority();
  1161.     }
  1162.     
  1163.     inline unsigned long TOperation::GetPriority() const
  1164.     {
  1165.         return fProcessLink.GetPriority();
  1166.     }
  1167.     
  1168.     inline void TOperation::SetTime(unsigned long msec)
  1169.     {
  1170.         fProcessLink.SetPriority(msec);
  1171.     }
  1172.     
  1173.     inline void TOperation::SetProcessProc(ProcessProcPtr proc)
  1174.     {
  1175.         fProc = proc;
  1176.     }
  1177.     
  1178.     inline void TOperation::SetPriority(unsigned long pri)
  1179.     {
  1180.         fProcessLink.SetPriority(pri);
  1181.     }
  1182.     
  1183.     inline void* TOperation::GetCreatorPtr() const
  1184.     {
  1185.         return fCreatorData.fPtr;
  1186.     }
  1187.     
  1188.     inline void TOperation::SetCreatorPtr(void* data)
  1189.     {
  1190.         fCreatorData.fPtr = data;
  1191.     }
  1192.     
  1193.     inline long TOperation::GetCreatorData() const
  1194.     {
  1195.         return fCreatorData.fLong;
  1196.     }
  1197.     
  1198.     inline void TOperation::SetCreatorData(long data)
  1199.     {
  1200.         fCreatorData.fLong = data;
  1201.     }
  1202.         
  1203.     inline ProcessProcPtr TOperation::GetProcessProc() const
  1204.     {
  1205.         return fProc;
  1206.     }
  1207.  
  1208. #if GENERATING68K        
  1209.  
  1210.     inline GlobalWorld TOperation::GetSavedGlobalWorld() const
  1211.     {
  1212.         return fSavedWorld;
  1213.     }
  1214.         
  1215.     inline void TOperation::SetSavedGlobalWorld(GlobalWorld world)
  1216.     {
  1217.         fSavedWorld = world;
  1218.     }
  1219.  
  1220.     inline TLibraryManager* TOperation::GetSavedClient() const
  1221.     {
  1222.         if (fSavedWorld != kInvalidWorld)
  1223.             return GetClientFromWorld(fSavedWorld);
  1224.         else
  1225.             return NULL;
  1226.     }
  1227.         
  1228.     inline void TOperation::SetSavedClient(TLibraryManager* client)
  1229.     {
  1230.         if (client != NULL)
  1231.             fSavedWorld = client->GetGlobalWorld();
  1232.         else
  1233.             fSavedWorld = kInvalidWorld;
  1234.     }
  1235.  
  1236. #else
  1237.  
  1238.     inline TLibraryManager* TOperation::GetSavedClient() const
  1239.     {
  1240.         return fSavedClient;
  1241.     }
  1242.         
  1243.     inline void TOperation::SetSavedClient(TLibraryManager* client)
  1244.     {
  1245.         fSavedClient = client;
  1246.     }
  1247.     
  1248. #endif
  1249.     
  1250. /*******************************************************************************
  1251. ** CLASS TScheduler
  1252. **
  1253. ** This is the base class for all schedulers.  It allows for scheduling
  1254. ** TOperations and removing them from the scheduling queue.
  1255. *******************************************************************************/
  1256.  
  1257. #define kTSchedulerID    "!$sked,1.2"
  1258.  
  1259. class TScheduler : public TDynamic
  1260. {
  1261.     protected:
  1262.                             _CDECL TScheduler();
  1263.                             
  1264.     public:
  1265.         virtual             ~_CDECL TScheduler();
  1266.         
  1267.         virtual Boolean        _CDECL Remove(TOperation*)            = 0;
  1268.         virtual TOperation*    _CDECL Remove(const TMatchObject&)    = 0;
  1269.         virtual TOperation*    _CDECL RemoveNext()                    = 0;
  1270.         virtual Boolean        _CDECL IsEmpty() const                = 0;
  1271.         
  1272.         virtual void        _CDECL Schedule(TOperation*)            = 0;
  1273.         virtual void        _CDECL Run()                            = 0;
  1274.         
  1275. #if GENERATING68K
  1276.                 Boolean        IsSchedulerWorldValid() const;
  1277.                 GlobalWorld    GetSchedulerWorld() const;
  1278.                 void        SetSchedulerWorld(GlobalWorld);
  1279. #endif
  1280.         
  1281.                 Boolean                IsSchedulerClientValid() const;
  1282.                 TLibraryManager*    GetSchedulerClient() const;
  1283.                 void                SetSchedulerClient(TLibraryManager*);
  1284.     protected:
  1285. #if GENERATING68K
  1286.         GlobalWorld            fSchedulerWorld;
  1287. #else
  1288.         TLibraryManager*    fSchedulerClient;
  1289. #endif
  1290. };
  1291.  
  1292. /*    -------------------------------------------------------------------------
  1293.     Inline Methods for class TScheduler
  1294.     ------------------------------------------------------------------------- */
  1295.  
  1296. #if GENERATING68K
  1297.  
  1298.     inline GlobalWorld TScheduler::GetSchedulerWorld() const
  1299.     {
  1300.         return fSchedulerWorld;
  1301.     }
  1302.  
  1303.     inline void TScheduler::SetSchedulerWorld(GlobalWorld world)
  1304.     {
  1305.         fSchedulerWorld = world;
  1306.     }
  1307.  
  1308.     inline Boolean TScheduler::IsSchedulerWorldValid() const
  1309.     {
  1310.         return fSchedulerWorld != kInvalidWorld;
  1311.     }
  1312.  
  1313.     inline TLibraryManager* TScheduler::GetSchedulerClient() const
  1314.     {
  1315.         if (fSchedulerWorld != kInvalidWorld)
  1316.             return GetClientFromWorld(fSchedulerWorld);
  1317.         else
  1318.             return NULL;
  1319.     }
  1320.         
  1321.     inline void TScheduler::SetSchedulerClient(TLibraryManager* client)
  1322.     {
  1323.         if (client != NULL)
  1324.             fSchedulerWorld = client->GetGlobalWorld();
  1325.         else
  1326.             fSchedulerWorld = kInvalidWorld;
  1327.     }
  1328.  
  1329.     inline Boolean TScheduler::IsSchedulerClientValid() const
  1330.     {
  1331.         return GetSchedulerClient() != NULL;
  1332.     }
  1333.  
  1334. #else
  1335.  
  1336.     inline TLibraryManager* TScheduler::GetSchedulerClient() const
  1337.     {
  1338.         return fSchedulerClient;
  1339.     }
  1340.  
  1341.     inline void TScheduler::SetSchedulerClient(TLibraryManager* client)
  1342.     {
  1343.         fSchedulerClient = client;
  1344.     }
  1345.  
  1346.     inline Boolean TScheduler::IsSchedulerClientValid() const
  1347.     {
  1348.         return fSchedulerClient != NULL;
  1349.     }
  1350.  
  1351. #endif
  1352.     
  1353. /*******************************************************************************
  1354. ** CLASS TPriorityScheduler
  1355. **
  1356. ** This class implements a scheduler which simply insures processing
  1357. ** of the TOperations by Priority.
  1358. *******************************************************************************/
  1359.  
  1360. #define kTPrioritySchedulerID    "!$prsk,1.2"
  1361.  
  1362. class TPriorityScheduler : public TScheduler
  1363. {
  1364.     public:
  1365.                             _CDECL TPriorityScheduler();    // autoRun default to false
  1366.                             _CDECL TPriorityScheduler(BooleanParm ifAutoRun);
  1367.         virtual             ~_CDECL TPriorityScheduler();
  1368.         
  1369.         virtual Boolean        _CDECL IsValid() const;
  1370.         
  1371.             // Returns non-zero if an Operation is removed
  1372.         virtual Boolean        _CDECL Remove(TOperation*);
  1373.         virtual TOperation*    _CDECL Remove(const TMatchObject&);
  1374.         virtual TOperation*    _CDECL RemoveNext();
  1375.         virtual Boolean        _CDECL IsEmpty() const;
  1376.         
  1377.             // Default implementation processes TOperations on the
  1378.             // linked list until it is empty, but insures that 2
  1379.             // threads are not doing it at the same time. In 
  1380.             // Non-AutoRun mode, anything scheduled after "Run"
  1381.             // is called will not Run until "Run" is called again.
  1382.         virtual void        _CDECL Run();
  1383.         
  1384.             // Default implementation just throws the TOperation on
  1385.             // the linked list.  If 'ifAutoRun' was set, the Run
  1386.             // method is called.  Otherwise, someone must manually
  1387.             // call Run().
  1388.         virtual void        _CDECL Schedule(TOperation*);
  1389.  
  1390.         virtual void        _CDECL SetAutoRun(BooleanParm);
  1391.         
  1392.     protected:
  1393.                 Boolean        IsAutoRun() const;
  1394.                 Boolean        IsSchedulerDead() const;
  1395.                 void        SetSchedulerDead();
  1396.                 
  1397.         TPriorityList    fList;
  1398.         short            fBusy;
  1399.         short            fFlags;
  1400. };
  1401.  
  1402. /*    -------------------------------------------------------------------------
  1403.     Inline methods for TPriorityScheduler
  1404.     ------------------------------------------------------------------------- */
  1405.  
  1406.     inline Boolean TPriorityScheduler::IsAutoRun() const
  1407.     {
  1408.         return fFlags & 1;
  1409.     }
  1410.  
  1411.     inline Boolean TPriorityScheduler::IsSchedulerDead() const
  1412.     {
  1413.         return fFlags < 0;
  1414.     }
  1415.  
  1416.     inline void TPriorityScheduler::SetSchedulerDead()
  1417.     {
  1418.         fFlags = -1;
  1419.     }
  1420.     
  1421. /*******************************************************************************
  1422. ** CLASS TSerialScheduler
  1423. **
  1424. ** This class implements a scheduler which simply insures FIFO processing
  1425. ** of the TOperations.  It is the same as a TPriorityScheduler, but 
  1426. ** sets the priority of the TOperation to kNormalPriority before
  1427. ** scheduling.
  1428. *******************************************************************************/
  1429.  
  1430. #define kTSerialSchedulerID    "!$srsk,1.2"
  1431.  
  1432. class TSerialScheduler : public TPriorityScheduler
  1433. {
  1434.     public:
  1435.                             _CDECL TSerialScheduler();    // autoRun default to false
  1436.                             _CDECL TSerialScheduler(BooleanParm ifAutoRun);
  1437.         virtual             ~_CDECL TSerialScheduler();
  1438.         
  1439.         virtual void        _CDECL Schedule(TOperation*);
  1440. };
  1441.  
  1442. /*******************************************************************************
  1443. ** CLASS TThreadScheduler
  1444. **
  1445. ** This class implements a lightweight 'thread' task.  In the Macintosh
  1446. ** implementation, it is a TPriorityScheduler.
  1447. *******************************************************************************/
  1448.  
  1449. #define kTThreadSchedulerID    "slm:sked$thsk,1.2"
  1450.  
  1451. class TThreadScheduler : public TPriorityScheduler
  1452. {
  1453.     public:
  1454.     
  1455.                             _CDECL TThreadScheduler();
  1456.         virtual             ~_CDECL TThreadScheduler();
  1457.  
  1458.         virtual void        _CDECL Schedule(TOperation*);
  1459.         
  1460.     protected:
  1461.         virtual void        _CDECL Run();
  1462.         
  1463.     private:        
  1464.         void*        fData;
  1465. };
  1466.  
  1467. /*******************************************************************************
  1468. ** CLASS TTaskScheduler
  1469. **
  1470. ** This class implements a heavy-weight task which can interface to
  1471. ** the operating system.  In the Macintosh, it schedules TOperations to
  1472. ** run at System Task time.
  1473. *******************************************************************************/
  1474.  
  1475. #define kTTaskSchedulerID    "!$task,1.2"
  1476.  
  1477. class TTaskScheduler : public TPriorityScheduler
  1478. {
  1479.     public:
  1480.                             _CDECL TTaskScheduler();
  1481.                             _CDECL TTaskScheduler(unsigned long priority,
  1482.                                                 BooleanParm runToEmpty = false);
  1483.         virtual             ~_CDECL TTaskScheduler();
  1484.         
  1485.         virtual void        _CDECL Schedule(TOperation*);
  1486.         
  1487.         virtual void        _CDECL SetPriority(unsigned long);
  1488.                 void        _CDECL SetRunToEmpty(Boolean);
  1489.         
  1490.     protected:
  1491.                 void        _CDECL ProcessCalled();
  1492.  
  1493.         virtual void        _CDECL Run();
  1494.  
  1495.     private:
  1496.                 void        _CDECL InitTaskScheduler(unsigned long);
  1497.         
  1498.     protected:
  1499.         TOperation        fOperation;
  1500.         
  1501.     private:
  1502.         ProcPtr            fSystem;
  1503.         void*            fData;
  1504. };
  1505.  
  1506. /*    -------------------------------------------------------------------------
  1507.     Inline methods for TTaskScheduler
  1508.     ------------------------------------------------------------------------- */
  1509.  
  1510.     inline void TTaskScheduler::SetRunToEmpty(Boolean runToEmpty)
  1511.     {
  1512.         SetAutoRun(runToEmpty);
  1513.     }
  1514.     
  1515. /*******************************************************************************
  1516. ** CLASS TInterruptScheduler
  1517. **
  1518. ** This class is used by all interrupt service routines to process
  1519. ** incoming data.  All layers above the interrupt service routines
  1520. ** expect to be able to do any processing they want without fear of
  1521. ** interrupts being locked out.  That's what this scheduler insures.
  1522. *******************************************************************************/
  1523.  
  1524. #define kTInterruptSchedulerID    "slm:sked$insk,1.2"
  1525.  
  1526.  
  1527. class TInterruptScheduler : public  TPriorityScheduler
  1528. {
  1529.     public:
  1530.     
  1531.                             _CDECL TInterruptScheduler();
  1532.                             _CDECL TInterruptScheduler(TScheduler*, unsigned long priority);
  1533.         virtual             ~_CDECL TInterruptScheduler();
  1534.     
  1535.         virtual Boolean        _CDECL IsValid() const;
  1536.         
  1537.         virtual void        _CDECL Schedule(TOperation*);
  1538.  
  1539.     protected:
  1540.         virtual void        _CDECL Run();
  1541.         
  1542.     private:
  1543.                 void        InitializeInterruptScheduler(TScheduler*, unsigned long);
  1544.  
  1545.     private:
  1546.         void*            fData;
  1547. };
  1548.  
  1549. /*******************************************************************************
  1550. ** CLASS TTimeScheduler
  1551. **
  1552. ** This class implements a scheduler which will process TOperations
  1553. ** when a requested amount of time has expired.
  1554. *******************************************************************************/
  1555.  
  1556. #define kMaxScheduledTime    ((unsigned long)-1L)
  1557.  
  1558. #define kTTimeSchedulerID    "slm:sked$skti,1.2"
  1559.  
  1560.  
  1561. class TTimeScheduler : public TScheduler
  1562. {
  1563.     public:
  1564.                                 _CDECL TTimeScheduler();
  1565.                                 _CDECL TTimeScheduler(void* data);
  1566.                                 _CDECL TTimeScheduler(TScheduler*, unsigned long priority);
  1567.         virtual                 ~_CDECL TTimeScheduler();
  1568.     
  1569.         virtual Boolean            _CDECL IsValid() const;
  1570.         
  1571.         virtual Boolean            _CDECL Remove(TOperation*);
  1572.         virtual TOperation*        _CDECL Remove(const TMatchObject&);
  1573.         virtual TOperation*        _CDECL RemoveNext();
  1574.         virtual void            _CDECL Schedule(TOperation*);
  1575.         virtual Boolean            _CDECL IsEmpty() const;
  1576.         
  1577.         virtual Boolean            _CDECL Reschedule(TOperation*, unsigned long time);
  1578.         virtual void            _CDECL SetAutoReschedule(BooleanParm);
  1579.  
  1580.         virtual Boolean            _CDECL DeleteInProcessOperation(TOperation* op);
  1581.         virtual Boolean            _CDECL RerunInProcessOperation(TOperation* op);
  1582.         
  1583.     protected:
  1584.         virtual void            _CDECL Run();
  1585.         virtual Boolean            _CDECL ProcessTimerEvent();
  1586.         virtual TOperation*        _CDECL PrivateRemove(TOperation*, const TMatchObject*);
  1587.         virtual TPriorityLink*    _CDECL GetNextOperation(void*);
  1588.         virtual void            _CDECL ProcessOperation();
  1589.                 void*            GetData() const;
  1590.                         
  1591.     private:    
  1592.                 void            InitializeTimeScheduler(TScheduler*, unsigned long);
  1593.                 
  1594.     private:    
  1595.         void*                fData;
  1596.         unsigned short        fTime;
  1597.         Boolean                fDead;
  1598.         char                fIfProcessing;
  1599.         TPriorityLink*        fList;
  1600.         TSimpleList            fReadyList;
  1601.         
  1602.     protected:
  1603.         long                fSeed;
  1604.         
  1605.     private:
  1606.         Boolean                fBusy;
  1607.         Boolean                fFiller;
  1608. };
  1609.  
  1610. /*    -------------------------------------------------------------------------
  1611.     Inline methods for TTimeScheduler
  1612.     ------------------------------------------------------------------------- */
  1613.  
  1614.     inline void* TTimeScheduler::GetData() const
  1615.     {
  1616.         return fData;
  1617.     }
  1618.     
  1619.  
  1620. /*******************************************************************************
  1621. ** CLASS TNotifier
  1622. **
  1623. ** This class and its subclasses are used for asynchronous notification
  1624. ** of events.
  1625. ********************************************************************************/
  1626.  
  1627. #define kTNotifierID "!$noti,1.2"
  1628.  
  1629. class TNotifier : public TDynamic
  1630. {
  1631.     public:
  1632.                             _CDECL TNotifier();
  1633.         virtual                ~_CDECL TNotifier();
  1634.         
  1635.         virtual void        _CDECL Notify(EventCode, OSErrParm = kNoError, 
  1636.                                         void* = NULL) = 0;
  1637.  
  1638.     protected:
  1639. #if GENERATING68K
  1640.         GlobalWorld            fWorld;        // global world when contructed
  1641. #else
  1642.         TLibraryManager*     fClient;    // current client when constructed
  1643.     #endif
  1644. };
  1645.  
  1646. /*******************************************************************************
  1647. ** CLASS TProcNotifier
  1648. **
  1649. ** This class is the base class for Notifiers that call a "C" procedure
  1650. ** for notification.  If the "refPtr" is left NULL, it will be replaced
  1651. ** with a pointer to the TProcNotifier itself.
  1652. *******************************************************************************/
  1653.  
  1654. #define kTProcNotifierID "!$pnot,1.2"
  1655.  
  1656. class TProcNotifier : public TNotifier
  1657. {
  1658.     public:
  1659.                         _CDECL TProcNotifier(NotifyProcPtr, void* refPtr = NULL);
  1660.                         _CDECL TProcNotifier(const TProcNotifier&);
  1661.         virtual            ~_CDECL TProcNotifier();
  1662.         
  1663.         virtual void    _CDECL Notify(EventCode, OSErrParm = kNoError,
  1664.                                     void* notifyData = NULL);
  1665.             
  1666.     private:
  1667.         NotifyProcPtr    fProc;
  1668.         void*            fPtr;
  1669. };
  1670.  
  1671. /*******************************************************************************
  1672. ** CLASS TMethodNotifier
  1673. **
  1674. ** This class is the base class for Notifiers that call a method in an object.
  1675. *******************************************************************************/
  1676.  
  1677. #define kTMethodNotifierID "!$mnot,1.2"
  1678.  
  1679. class TMethodNotifier : public TNotifier
  1680. {
  1681.     public:
  1682.         //
  1683.         //    We pass an extra long parameter that is always set to -1 when SCpp clients
  1684.         //    use the TMethodNotifier constructor. This is because SCpp method pointers
  1685.         //    are always 4 byte pointers (sometimes to a "thunk") while CFront uses
  1686.         //    8 byte mptrs to determine the method. By having SCpp clients pass the -1
  1687.         //    flag, the TMethodNotifier constructor is able to tell what kind of
  1688.         //    method ponter is being passed to it and call it properly.
  1689.         //
  1690. #ifdef __SC__
  1691.                             _CDECL TMethodNotifier(TDynamic*, NotifyMethodPtr, long = -1);
  1692. #else
  1693.                             _CDECL TMethodNotifier(TDynamic*, NotifyMethodPtr);
  1694. #endif
  1695.                             _CDECL TMethodNotifier(const TMethodNotifier&);
  1696.         virtual                ~_CDECL TMethodNotifier();
  1697.         
  1698.         virtual void        _CDECL Notify(EventCode, OSErrParm = kNoError,
  1699.                                         void* notifyData = NULL);
  1700.  
  1701.                 TDynamic*    GetObject() const;
  1702.         
  1703.     private:
  1704.         TDynamic*        fObject;
  1705.         unsigned short    fOffset;
  1706.         signed short    fIndex;
  1707.         NotifyProcPtr    fMethod;
  1708. };
  1709.     
  1710. /*    -----------------------------------------------------------------
  1711.     Inlines for TMethodNotifier
  1712.     ----------------------------------------------------------------- */
  1713.  
  1714.     inline TDynamic* TMethodNotifier::GetObject() const
  1715.     {
  1716.         return fObject;
  1717.     }
  1718.  
  1719. /*******************************************************************************
  1720. ** CLASS TMemoryPool
  1721. **
  1722. ** This is the abstract class from which memory allocators should
  1723. ** descend.
  1724. ********************************************************************************/
  1725.  
  1726. struct PoolInfo
  1727. {
  1728.     size_t    fFreeBytes;
  1729.     size_t    fLargestBlock;
  1730.     size_t    fMaxUsage;
  1731.     size_t    fCurSize;
  1732. };
  1733.  
  1734. #define kTMemoryPoolID "!$pool,1.2"
  1735.  
  1736. extern "C" void* NewPool(size_t, size_t, ZoneType, MemoryType);
  1737. extern "C" void* NewPoolWithZone(size_t, size_t, void*, MemoryType);
  1738. extern "C" void DeletePool(void*);
  1739.  
  1740. class TMemoryPool : public TDynamic
  1741. {
  1742.     public:
  1743.         virtual                 ~_CDECL TMemoryPool();
  1744.         
  1745.                 void*         operator new(size_t size, size_t poolSize, ZoneType zType,
  1746.                                           MemoryType mType = kNormalMemory)
  1747.                     { return NewPool(size, poolSize, zType, mType); }
  1748.                 void*        operator new(size_t size, size_t poolSize, void* zone,
  1749.                                          MemoryType mType = kNormalMemory)
  1750.                     { return NewPoolWithZone(size, poolSize, zone, mType); }
  1751.                 void*        operator new(size_t size)
  1752.                     { return NewPool(size, 0, kCurrentZone, kNormalMemory); }
  1753.                 void        operator delete(void* ptr)
  1754.                     { DeletePool(ptr); }
  1755.         
  1756.         virtual void*            _CDECL Allocate(size_t)                = 0;
  1757.         virtual void*            _CDECL Reallocate(void*, size_t)        = 0;
  1758.         virtual void            _CDECL Free(void*)                    = 0;
  1759.         virtual    size_t            _CDECL GetSize(void*) const            = 0;
  1760.  
  1761.         virtual Boolean            _CDECL CheckPool() const                = 0;
  1762.         virtual void            _CDECL GetPoolInfo(PoolInfo&) const;
  1763.         virtual    void            _CDECL TracePoolInfo() const;
  1764.  
  1765.         virtual Boolean            _CDECL AddMemoryToPool(size_t);
  1766.         virtual void            _CDECL DownsizePool();
  1767.         virtual size_t            _CDECL GetLargestBlockSize() const     = 0;
  1768.                 size_t            _CDECL GetCurrentPoolSize() const;
  1769.         
  1770.                 void            SetNotifier(TPoolNotifier*);
  1771.                 TPoolNotifier*    GetNotifier() const;
  1772.                 void            SetNotifyMarks(size_t low, size_t high = (size_t)-1L);
  1773.                 
  1774.         static    TMemoryPool*    _CDECL RecoverPool(void*);
  1775.         static    void*            _CDECL AllocateMemory(size_t);
  1776.         static    void*            _CDECL AllocateMemory(TMemoryPool*, size_t);
  1777.         static    void*            _CDECL ReallocateMemory(void*, size_t);
  1778.         static    void            _CDECL FreeMemory(void*);
  1779.         static    size_t            _CDECL GetMemorySize(void*);
  1780.         
  1781.     protected:
  1782.                                 _CDECL TMemoryPool();
  1783.         virtual Boolean            _CDECL PrivateAddMemoryToPool(void*, size_t) = 0;
  1784.         virtual Boolean            _CDECL RemoveBlockFromPool(void*, size_t);
  1785.         
  1786.     private:
  1787.                                 TMemoryPool(const TMemoryPool&);
  1788.                 void            operator=(const TMemoryPool&);
  1789.         
  1790.     private:
  1791.         void*            fMemList;
  1792.         
  1793.     protected:
  1794.         size_t            fSize;
  1795.         size_t            fLowMark;
  1796.         size_t            fHighMark;
  1797.         size_t            fMaxUsed;
  1798.         size_t            fCurFree;
  1799.         void*            fZone;
  1800.         unsigned char    fMemType;
  1801.         short            fFiller;
  1802.         TPoolNotifier*    fNotifier;
  1803.         unsigned long    fSeed;
  1804.         TMacSemaphore    fSemaphore;
  1805. };
  1806.  
  1807. /*    -----------------------------------------------------------------
  1808.     Inline Methods for TMemoryPool
  1809.     
  1810.     The TMemoryPool inlines are located after the TStandardPool declaration
  1811.     below.
  1812.     ----------------------------------------------------------------- */
  1813.  
  1814. /*******************************************************************************
  1815. ** CLASS TStandardPool
  1816. **
  1817. ** The general purpose interrupt capable storage allocator.
  1818. ********************************************************************************/
  1819.  
  1820. #define kStandardPoolChunkOverhead    12
  1821.  
  1822. #define kTStandardPoolID "!$stdp,1.2"
  1823.  
  1824. class TStandardPool : public TMemoryPool
  1825. {
  1826.     public:
  1827.                                 _CDECL TStandardPool();
  1828.         virtual                 ~_CDECL TStandardPool();
  1829.  
  1830.         virtual Boolean            _CDECL IsValid() const;
  1831.  
  1832.         // TMemoryPool Overrides
  1833.         
  1834.         virtual void*            _CDECL Allocate(size_t);
  1835.         virtual void*            _CDECL Reallocate(void*, size_t);
  1836.         virtual void            _CDECL Free(void*);
  1837.         virtual size_t            _CDECL GetSize(void*) const;
  1838.         virtual Boolean            _CDECL CheckPool() const;
  1839.         virtual size_t            _CDECL GetLargestBlockSize() const;
  1840.     
  1841.     protected:
  1842.         virtual Boolean            _CDECL PrivateAddMemoryToPool(void*, size_t);
  1843.         virtual Boolean            _CDECL RemoveBlockFromPool(void*, size_t);
  1844.         
  1845.                                 _CDECL TStandardPool(size_t objSize);
  1846.                                 
  1847.     private:
  1848.                                 TStandardPool(const TStandardPool&);
  1849.                 void            operator=(const TStandardPool&);
  1850.                 
  1851.                 void            _CDECL InitStandardPool(size_t objSize);
  1852.         
  1853.                 Boolean            _CDECL FreeChunks(void*, size_t);
  1854.                 void            _CDECL InternalFree(void*);
  1855.                 
  1856.     protected:    
  1857.         void*            fList;
  1858.     
  1859.     private:
  1860.         void*            fChunks[15];
  1861.         void*            fFiller1;
  1862. };
  1863.     
  1864. /*******************************************************************************
  1865. ** Inline Methods for TMemoryPool
  1866. **
  1867. ** We move them down here since at least one of them requires TStandardPool
  1868. ** to already be defined.
  1869. ********************************************************************************/
  1870.  
  1871.     inline void TMemoryPool::SetNotifyMarks(size_t low, size_t high)
  1872.     {
  1873.         fLowMark = low;
  1874.         fHighMark= high;
  1875.     }
  1876.     
  1877.     inline TPoolNotifier* TMemoryPool::GetNotifier() const
  1878.     {
  1879.         return fNotifier;
  1880.     }
  1881.  
  1882.     inline void TMemoryPool::SetNotifier(TPoolNotifier* nt)
  1883.     {
  1884.         fNotifier = nt;
  1885.     }
  1886.  
  1887.     inline size_t TMemoryPool::GetCurrentPoolSize() const
  1888.     {
  1889.         return fSize;
  1890.     }
  1891.     
  1892.     inline void* TMemoryPool::AllocateMemory(TMemoryPool* thePool, size_t size)
  1893.     {
  1894.         return thePool->Allocate(size);
  1895.     }
  1896.     
  1897.     inline void* TMemoryPool::AllocateMemory(size_t size)
  1898.     {
  1899.         return ((TMemoryPool*)::GetDefaultPool())->Allocate(size);
  1900.     }
  1901.  
  1902. /*******************************************************************************
  1903. ** CLASS TChunkyPool
  1904. **
  1905. ** This class implements a Pool where the memory returned is always
  1906. ** the same size (a "chunk").
  1907. ********************************************************************************/
  1908.  
  1909. #define kChunkyPoolChunkOverhead    4
  1910.  
  1911. #define kTChunkyPoolID "!$chkp,1.2"
  1912.  
  1913. class TChunkyPool : public TMemoryPool
  1914. {
  1915.     public:
  1916.                                 _CDECL TChunkyPool(size_t chunkSize);
  1917.         virtual                    ~_CDECL TChunkyPool();
  1918.         
  1919.         virtual Boolean            _CDECL IsValid() const;
  1920.         
  1921.         // TMemoryPool Overrides
  1922.         
  1923.         virtual void*            _CDECL Allocate(size_t size);
  1924.         virtual void*            _CDECL Reallocate(void*, size_t);
  1925.         virtual void            _CDECL Free(void*);
  1926.         virtual size_t            _CDECL GetSize(void*) const;
  1927.         virtual Boolean            _CDECL CheckPool() const;
  1928.         virtual size_t            _CDECL GetLargestBlockSize() const;
  1929.  
  1930.     protected:        
  1931.         virtual Boolean            _CDECL PrivateAddMemoryToPool(void*, size_t);
  1932.         virtual Boolean            _CDECL RemoveBlockFromPool(void*, size_t);
  1933.         
  1934.     public:
  1935.         // New methods
  1936.     
  1937.                 size_t            GetChunkSize() const;
  1938.                 size_t            GetNumberOfChunks() const;
  1939.                 
  1940.     private:
  1941.                                 TChunkyPool(const TChunkyPool&);
  1942.                 void            operator=(const TChunkyPool&);
  1943.  
  1944.         size_t            fNumberOfChunks;
  1945.         size_t            fChunkSize;
  1946.         void*            fFreeList;
  1947. };
  1948.  
  1949. /*    -----------------------------------------------------------------
  1950.     Inline Methods for TChunkyPool
  1951.     ----------------------------------------------------------------- */
  1952.     
  1953.     inline size_t TChunkyPool::GetChunkSize() const
  1954.     {
  1955.         return fChunkSize;
  1956.     }
  1957.     
  1958.     inline size_t TChunkyPool::GetNumberOfChunks() const
  1959.     {
  1960.         return fNumberOfChunks;
  1961.     }
  1962.  
  1963. /*******************************************************************************
  1964. ** CLASS TGrowOperation
  1965. **
  1966. ** See TPoolNotifier below
  1967. ********************************************************************************/
  1968.  
  1969. #define kTGrowOperationID    "!$gwop,1.2"
  1970.  
  1971. class TGrowOperation : public TOperation
  1972. {
  1973.     public:
  1974.                         _CDECL TGrowOperation();
  1975.         virtual            ~_CDECL TGrowOperation();
  1976.         
  1977.         virtual    void    _CDECL Process();
  1978.  
  1979.         size_t        fGrowBy;
  1980.         Boolean*    fOpInUse;
  1981. };
  1982.  
  1983. /*******************************************************************************
  1984. ** CLASS TPoolNotifier
  1985. **
  1986. ** Used by TMemoryPools so they can be notified when the pool reaches a low or
  1987. ** high water mark. The TGrowOperation is not processed at interrupt time so it
  1988. ** is always safe for it to grow the pool.
  1989. ********************************************************************************/
  1990.  
  1991. #define kTPoolNotifierID    "!$plnt,1.2"
  1992.  
  1993. class TPoolNotifier : public TNotifier
  1994. {
  1995.     public:
  1996.                         _CDECL TPoolNotifier(unsigned int growBy = 10, 
  1997.                                            unsigned int minGrow = 128);
  1998.         virtual            ~_CDECL TPoolNotifier();
  1999.  
  2000.         virtual void    _CDECL Notify(EventCode, OSErrParm = kNoError, void* = NULL);
  2001.         virtual size_t    _CDECL GrowBy(TMemoryPool*, size_t);
  2002.         
  2003.     private:
  2004.                 void    _CDECL InitNotifier(unsigned int, unsigned int);
  2005.     
  2006.         TGrowOperation    fOperation;
  2007.         unsigned short    fMinSize;
  2008.         unsigned short    fGrowBy;
  2009.         Boolean            fOpInUse;
  2010.         short            fFiller;
  2011. };
  2012.  
  2013. /*******************************************************************************
  2014. ** CLASS TArbitrator
  2015. *******************************************************************************/
  2016.  
  2017. #define kTArbitratorID    "!$arbt,1.2"
  2018.  
  2019. #define kRequestIDPrefix '?'
  2020. #define kRequestIDPrefixSize 1
  2021.  
  2022. typedef int    TokenRequestType;
  2023.  
  2024. #define kInvalidTokenRequest    ((TokenRequestType)0)
  2025. #define kRequestTokenRequest    ((TokenRequestType)1)
  2026. #define kExclusiveTokenRequest    ((TokenRequestType)2)
  2027. #define kSharedTokenRequest        ((TokenRequestType)3)
  2028.     
  2029. class TArbitrator : public THashObject
  2030. {
  2031.     friend class    TToken;
  2032.     public:
  2033.                                     _CDECL TArbitrator(TStandardPool* = NULL,
  2034.                                                      size_t defSize = 0);
  2035.         virtual                        ~_CDECL TArbitrator();
  2036.         
  2037.         virtual OSErr                _CDECL RegisterObject(const char* theID, void* theObject);
  2038.         virtual    void*                _CDECL UnregisterObject(const char* theID);
  2039.         virtual void*                _CDECL LookupObject(const char* theID);
  2040.  
  2041.         virtual OSErr                _CDECL RegisterToken(TToken*);
  2042.         virtual TToken*                _CDECL GetToken(const char* theID, TokenRequestType);
  2043.  
  2044.         virtual TRequestToken*        _CDECL PassiveRequest(const char* theID, TokenRequestType,
  2045.                                                         TNotifier* = NULL,
  2046.                                                         BooleanParm registerIfFirst = false);
  2047.         virtual TRequestToken*        _CDECL ActiveRequest(const char* theID, TokenRequestType,
  2048.                                                        TNotifier* = NULL,
  2049.                                                        BooleanParm registerIfFirst = false);
  2050.         virtual TRequestToken*         _CDECL GetRequest(const char* theID);
  2051.  
  2052.         virtual Boolean                _CDECL NotifyOwners(TRequestToken* theRequest);
  2053.         virtual unsigned long        _CDECL Hash(const void*) const;
  2054.  
  2055.         virtual TToken*                _CDECL NewToken(const char* theID, void* = NULL);
  2056.  
  2057.     private: // methods
  2058.         virtual void                _CDECL ReleaseToken(TToken* theToken);
  2059.         virtual TRequestToken*         _CDECL NewRequestToken(const char* theID, TokenRequestType,
  2060.                                                          TNotifier* = NULL);
  2061.     public:
  2062.         virtual void                _CDECL UnregisterToken(TToken*);
  2063.  
  2064.     private: // data
  2065.         TCollection*    fHashList;
  2066. };
  2067.  
  2068. /*******************************************************************************
  2069. ** Class TTokenNotification (inline methods only)
  2070. *******************************************************************************/
  2071.  
  2072. class TTokenNotification
  2073. {
  2074.     public:
  2075.                             _CDECL  TTokenNotification(TToken*, TRequestToken*);
  2076.                             ~_CDECL TTokenNotification();
  2077.         TToken*                GetToken();
  2078.         TRequestToken*        GetRequestToken();
  2079.     private:
  2080.         TToken*                fToken;
  2081.         TRequestToken*        fRequestToken;
  2082. };
  2083.  
  2084. /*    -----------------------------------------------------------------
  2085.     inline methods for TTokenNotification
  2086.     ----------------------------------------------------------------- */
  2087.     
  2088.     inline TToken* TTokenNotification::GetToken()
  2089.     {
  2090.         return fToken;
  2091.     }
  2092.     
  2093.     inline TRequestToken* TTokenNotification::GetRequestToken()
  2094.     {
  2095.         return fRequestToken;
  2096.     }
  2097.     
  2098.     
  2099. /*******************************************************************************
  2100. ** CLASS TToken
  2101. *******************************************************************************/
  2102.  
  2103. #define kTTokenID    "!$tokn,1.2"
  2104.  
  2105. class TToken : public TMatchObject
  2106. {
  2107.     friend class    TArbitrator;
  2108.  
  2109.     public:
  2110.                                     _CDECL TToken();
  2111.                                     _CDECL TToken(const char*);
  2112.         virtual                        ~_CDECL TToken();
  2113.  
  2114.         // TMatchObject methods
  2115.  
  2116.         virtual Boolean                _CDECL IsEqual(const void*) const;
  2117.         virtual unsigned long        _CDECL Hash() const;
  2118.  
  2119.         // new methods
  2120.  
  2121.         virtual Boolean                _CDECL Get(TokenRequestType);
  2122.         virtual void                _CDECL Release();
  2123.         virtual Boolean                _CDECL Request(TRequestToken*);
  2124.         virtual Boolean                _CDECL Notify(TRequestToken*);
  2125.         virtual TokenRequestType    _CDECL GetRequestType() const;
  2126.  
  2127.         virtual void                _CDECL SetID(const char*);
  2128.                 const char*            GetID() const;
  2129.  
  2130.                 void*                GetObject() const;
  2131.                 void                SetObject(void* theObject);
  2132.  
  2133.                 TNotifier*            GetNotifier() const;
  2134.                 void                SetNotifier(TNotifier*);
  2135.         
  2136.                 long                GetUseCount() const;
  2137.  
  2138.     private:
  2139.         virtual void                _CDECL ReallyRelease();
  2140.  
  2141.     protected:
  2142.         TMacSemaphore                fSemaphore;
  2143.         char*                        fID;
  2144.         void*                        fObject;
  2145.         TArbitrator*                fArbitrator;
  2146.         long                        fUseCount;
  2147.         TNotifier*                    fNotifier;
  2148. };
  2149.  
  2150. /*    -----------------------------------------------------------------
  2151.     inlines for TToken
  2152.     ----------------------------------------------------------------- */
  2153.     
  2154.     inline const char* TToken::GetID() const
  2155.     {
  2156.         return fID;
  2157.     }
  2158.     
  2159.     inline void* TToken::GetObject() const
  2160.     {
  2161.         return fObject;
  2162.     }
  2163.     
  2164.     inline void TToken::SetObject(void* theObject)
  2165.     {
  2166.         fObject = theObject;
  2167.     }
  2168.     
  2169.     inline TNotifier* TToken::GetNotifier() const
  2170.     {
  2171.         return fNotifier;
  2172.     }
  2173.     
  2174.     inline void TToken::SetNotifier(TNotifier* theNotifier)
  2175.     {
  2176.         fNotifier = theNotifier;
  2177.     }
  2178.     
  2179.     inline long TToken::GetUseCount() const
  2180.     {
  2181.         return fUseCount;
  2182.     }
  2183.  
  2184. /*******************************************************************************
  2185. ** CLASS TRequestToken 
  2186. *******************************************************************************/
  2187.  
  2188. #define kTRequestTokenID    "!$rqtk,1.2"
  2189.  
  2190. class TRequestToken : public TToken
  2191. {
  2192.     friend class     TArbitrator;
  2193.  
  2194.     public:
  2195.         virtual                        ~_CDECL TRequestToken();
  2196.  
  2197.         // TMatchObject methods
  2198.  
  2199.         virtual Boolean                _CDECL IsEqual(const void*) const;
  2200.         virtual unsigned long        _CDECL Hash() const;
  2201.  
  2202.         // new methods
  2203.  
  2204.         virtual Boolean                _CDECL Give(TToken* theToken);
  2205.         virtual TToken*                _CDECL Exchange();
  2206.         virtual void                _CDECL RequestAgain();
  2207.  
  2208.         virtual    TokenRequestType    _CDECL GetRequestType() const;
  2209.         virtual    void                _CDECL SetRequestType(TokenRequestType);
  2210.  
  2211.                 Boolean                IsTokenRegistered() const;
  2212.  
  2213.     private:
  2214.                                     _CDECL TRequestToken();
  2215.  
  2216.     private: // data
  2217.         Boolean                        fTokenRegistered;
  2218.         Boolean                        fActive;
  2219.         short                        fFiller;
  2220.         TokenRequestType            fRequestType;
  2221. };
  2222.  
  2223. /*    -----------------------------------------------------------------
  2224.     inlines for TRequestToken
  2225.     ----------------------------------------------------------------- */
  2226.  
  2227.     inline Boolean TRequestToken::IsTokenRegistered() const
  2228.     {
  2229.         return fTokenRegistered;
  2230.     }
  2231.     
  2232.     
  2233. /*******************************************************************************
  2234. ** class TClassInfo
  2235. ********************************************************************************/
  2236.  
  2237. #define kTClassInfoID "slm:supp$clif,1.2"
  2238.  
  2239. class TClassInfo : public TIterator
  2240. {
  2241.     friend class TLibraryManager;
  2242.  
  2243.     public:
  2244.         virtual                 ~_CDECL TClassInfo();
  2245.  
  2246.     // TIterator overrides
  2247.  
  2248.         virtual    void            _CDECL Reset();
  2249.         virtual void*            _CDECL Next();    // safe to cast to TClassID* or char*
  2250.  
  2251.         virtual Boolean            _CDECL IterationComplete() const;
  2252.         virtual Boolean            _CDECL RemoveCurrentObject();    // do nothing instead
  2253.  
  2254.     // new methods
  2255.  
  2256.                 void            SetBaseClassID(const TClassID& classID);
  2257.  
  2258.                 TClassID*        GetClassID();
  2259.         virtual    TClassID*        _CDECL GetParentID(size_t idx = 0);
  2260.                 TLibrary*        GetLibrary() const;
  2261.                 TLibraryFile*    GetLibraryFile() const;
  2262.                 unsigned short    GetVersion() const;
  2263.                 unsigned short    GetMinVersion() const;
  2264.  
  2265.                 Boolean            GetNewObjectFlag() const;
  2266.                 Boolean            GetPreloadFlag() const;
  2267.                 Boolean            GetFunctionSetFlag() const;
  2268.                 size_t            GetSize() const;
  2269.  
  2270.     private:
  2271.                                 _CDECL TClassInfo();
  2272.  
  2273.     private:
  2274.         TClassID                fBaseClassID;
  2275.         TClassID                fClassID;
  2276.         TLibrary*                fLibrary;
  2277.         TLibraryFile*            fLibraryFile;
  2278.         unsigned short            fVersion;            // Class version
  2279.         unsigned short            fMinVersion;        // minimum supported version
  2280.         Boolean                    fNewObjectFlag;
  2281.         Boolean                    fPreloadFlag;
  2282.         Boolean                    fFunctionSetFlag;
  2283.         Boolean                    fFiller;
  2284.         size_t                    fSize;
  2285.         TClassID                fParentID;
  2286. };
  2287.  
  2288. /*    -------------------------------------------------------------------------
  2289.     inline methods of TClassInfo
  2290.     ------------------------------------------------------------------------- */
  2291.     
  2292.     inline void TClassInfo::SetBaseClassID(const TClassID& classID)
  2293.     {
  2294.         fBaseClassID = classID;
  2295.         Reset();
  2296.     }
  2297.     
  2298.     inline TClassID* TClassInfo::GetClassID()
  2299.     {
  2300.         return &fClassID;
  2301.     }
  2302.     
  2303.     inline TLibrary* TClassInfo::GetLibrary() const
  2304.     {
  2305.         return fLibrary;
  2306.     }
  2307.     
  2308.     inline TLibraryFile* TClassInfo::GetLibraryFile() const
  2309.     {
  2310.         return fLibraryFile;
  2311.     }
  2312.     
  2313.     inline unsigned short TClassInfo::GetVersion() const
  2314.     {
  2315.         return fVersion;
  2316.     }
  2317.     
  2318.     inline unsigned short TClassInfo::GetMinVersion() const
  2319.     {
  2320.         return fMinVersion;
  2321.     }
  2322.         
  2323.     inline Boolean TClassInfo::GetNewObjectFlag() const
  2324.     {
  2325.         return fNewObjectFlag;
  2326.     }
  2327.     
  2328.     inline Boolean TClassInfo::GetPreloadFlag() const
  2329.     {
  2330.         return fPreloadFlag;
  2331.     }
  2332.     
  2333.     inline Boolean TClassInfo::GetFunctionSetFlag() const
  2334.     {
  2335.         return fFunctionSetFlag;
  2336.     }
  2337.     
  2338.     inline size_t TClassInfo::GetSize() const
  2339.     {
  2340.         return fSize;
  2341.     }
  2342.  
  2343. /**********************************************************************
  2344. ** class TFileSpec
  2345. **
  2346. ** TFileSpec is a base class for specifying the location of a library
  2347. ** file (TLibraryFile) in a file system or OS independent way. The 
  2348. ** subclasses contain the details and the base class is used to compare
  2349. ** them or to pass them around without worry about the contents.
  2350. **
  2351. ** Currently only the TMacFileSpec is supported since this is how the
  2352. ** SLM tracks library files on the Mac OS. There is a chance that in the
  2353. ** furture it may track files under System 7.0 using TFileIDFileSpec so
  2354. ** you should write your 7.0 code to handle either type. The
  2355. ** IsFileSpecTypeSupported() routine will tell you if the specified
  2356. ** TFileSpec subclass is supported.
  2357. **
  2358. ** Generally you don't need to be concerned with with TFileSpecs unless
  2359. ** you are going to call RegisterLibraryFile(), RegisterLibraryFileFolder(),
  2360. ** or TLibraryFile::GetFileSpec().
  2361. ***********************************************************************/
  2362.  
  2363. // Different types of TFileSpecs we can have.
  2364. typedef unsigned int FileSpecType;
  2365.  
  2366. #define kUnknownFileSpecType    ((FileSpecType)0)
  2367. #define kMacType                ((FileSpecType)1)
  2368. #define kFileIDType                ((FileSpecType)2)
  2369. #define kMaxFileSpecType        ((FileSpecType)255)
  2370.  
  2371. class TFileSpec;
  2372. class TMacFileSpec;
  2373. class TFileIDFileSpec;
  2374.  
  2375. extern "C" Boolean IsFileSpecTypeSupported(FileSpecType);
  2376. extern "C" Boolean CompareFileSpecs(const void* f1, const void* f2);
  2377.  
  2378. class TFileSpec
  2379. {
  2380.     public:
  2381.         void*            operator new(size_t size, TMemoryPool *thePool)
  2382.                             { return SLMNewOperator(size, thePool); }
  2383.         void*            operator new(size_t size)
  2384.                             { return SLMNewOperator(size, NULL); }
  2385.         void            operator delete(void* obj, size_t)
  2386.                             { SLMDeleteOperator(obj); }
  2387.                                     
  2388.         FileSpecType    GetType() const;
  2389.         unsigned char    GetSize() const;
  2390.     
  2391.                         // compare operators
  2392.  
  2393.         Boolean            operator==(const TFileSpec&) const;
  2394.         Boolean            operator!=(const TFileSpec&) const;
  2395.  
  2396.                         // cast operators
  2397.  
  2398.                         operator const TMacFileSpec&() const;
  2399.                         operator const TFileIDFileSpec&() const;
  2400.     
  2401.         unsigned char    fType;
  2402.         unsigned char    fSize;
  2403. };
  2404.  
  2405.     inline FileSpecType TFileSpec::GetType() const
  2406.     {
  2407.         return fType;
  2408.     }
  2409.     
  2410.     inline unsigned char TFileSpec::GetSize() const
  2411.     {
  2412.         return fSize;
  2413.     }
  2414.  
  2415.     //
  2416.     // compare operators
  2417.     //
  2418.  
  2419.     inline Boolean TFileSpec::operator==(const TFileSpec& fileSpec) const
  2420.     {
  2421.         return (CompareFileSpecs(&fileSpec, this));
  2422.     }
  2423.  
  2424.     inline Boolean TFileSpec::operator!=(const TFileSpec& fileSpec) const
  2425.     {
  2426.         return (!CompareFileSpecs(&fileSpec, this));
  2427.     }
  2428.     
  2429.     //
  2430.     //    cast operators
  2431.     //
  2432.     
  2433.     inline TFileSpec::operator const TMacFileSpec&() const
  2434.     {
  2435.         return *(const TMacFileSpec*)this;
  2436.     }
  2437.     
  2438.     inline TFileSpec::operator const TFileIDFileSpec&() const
  2439.     {
  2440.         return *(const TFileIDFileSpec*)this;
  2441.     }
  2442.  
  2443.  
  2444. /**********************************************************************
  2445. ** class TMacFileSpec
  2446. **
  2447. ** TMacFileSpec keeps track of the file by using an file name, volume
  2448. ** refNum, and directory id. When newing a TMacFileSpec, you must
  2449. ** pass the length of the file name (not including the length byte)
  2450. ** to the new operator.
  2451. ***********************************************************************/
  2452.  
  2453. extern "C" void InitMacFileSpec(TMacFileSpec *spec, int vRefNum, long parID, const Str63 name);
  2454.  
  2455. class TMacFileSpec : public TFileSpec
  2456. {
  2457.     public:    
  2458.                     TMacFileSpec(const TMacFileSpec&);
  2459.                     TMacFileSpec(int vRefNum, long parID, const Str63 name);
  2460.  
  2461.         void*        operator new(size_t, size_t fileNameLen, TMemoryPool *thePool = NULL)
  2462.                         {
  2463.                             return SLMNewOperator(
  2464.                                 (sizeof(TMacFileSpec) - 
  2465.                                  sizeof(Str63) + 
  2466.                                  fileNameLen+1), thePool);
  2467.                         }
  2468.         void*        operator new(size_t size)
  2469.                         { return SLMNewOperator(size, NULL); }
  2470.                         
  2471.         void        operator delete(void* obj)
  2472.                         { SLMDeleteOperator(obj); }
  2473.     
  2474.         short    fVRefNum;    // volume refNum of volume file is on
  2475.         long    fParID;        // dirID of the folder file is in
  2476.         Str63    fName;        // name of the file
  2477. };
  2478.  
  2479.     inline TMacFileSpec::TMacFileSpec(const TMacFileSpec& fileSpec)
  2480.     {
  2481.         InitMacFileSpec(this, fileSpec.fVRefNum, fileSpec.fParID, fileSpec.fName );
  2482.     }
  2483.         
  2484.     inline TMacFileSpec::TMacFileSpec(int vRefNum, long parID, const Str63 name)
  2485.     {
  2486.         InitMacFileSpec(this, vRefNum, parID, name);
  2487.     }
  2488.         
  2489.  
  2490. /**********************************************************************
  2491. ** class TFileIDFileSpec
  2492. **
  2493. ** TFileIDFileSpec keeps track of library files by fileID and vRefNum.
  2494. ***********************************************************************/
  2495.  
  2496. // Some macros to make accessing fields without doing a cast easier
  2497. #define GetFileIDFromFileSpec(x)    (((const TFileIDFileSpec&)x).fFileID)
  2498. #define GetVRefNumFromFileSpec(x)    (((const TFileIDFileSpec&)x).fVRefNum)
  2499.  
  2500. extern "C" void InitFileIDFileSpec(TFileIDFileSpec *spec, int vRefNum, long fileID);
  2501.  
  2502. class TFileIDFileSpec : public TFileSpec
  2503. {
  2504.     public:
  2505.                     TFileIDFileSpec(const TFileIDFileSpec&);
  2506.                     TFileIDFileSpec(int vRefNum, long fileID);
  2507.                 
  2508.         short        fVRefNum;    // volume refNum
  2509.         long        fFileID;    // FileID 
  2510. };
  2511.  
  2512.     inline TFileIDFileSpec::TFileIDFileSpec(const TFileIDFileSpec& fileSpec)
  2513.     {
  2514.         InitFileIDFileSpec(this, GetVRefNumFromFileSpec(fileSpec),
  2515.                            GetFileIDFromFileSpec(fileSpec));
  2516.     }
  2517.     
  2518.     inline TFileIDFileSpec::TFileIDFileSpec(int vRefNum, long fileID)
  2519.     {
  2520.         InitFileIDFileSpec(this, vRefNum, fileID);
  2521.     }
  2522.     
  2523. /*******************************************************************************
  2524. ** Class TLibraryFile
  2525. **
  2526. ** Used mainly to get resources out of a library file. A "C" interface is also
  2527. ** provided in TLibraryManagerUtilities.h
  2528. *******************************************************************************/
  2529.  
  2530. #define kTLibraryFileID "!$lfil,1.2"
  2531.  
  2532. extern "C" TLibraryFile* GetLocalLibraryFile();
  2533.     
  2534. class TLibraryFile : public TDynamic 
  2535. {
  2536.     protected:
  2537.         virtual             ~_CDECL TLibraryFile();
  2538.                             _CDECL TLibraryFile();
  2539.  
  2540.         // This is the old prelight/postflight that we need to keep around so 1.0
  2541.         // clients will still work. SLM 1.1 clients should never call it. Use the
  2542.         // new calls further below
  2543.         
  2544. #if GENERATING68K
  2545.         virtual    OSErr        _CDECL OldPreflight(short& savedRefNum) = 0;
  2546.         virtual    OSErr        _CDECL OldPostflight(short savedRefNum) = 0;
  2547. #endif
  2548.         
  2549.     public:
  2550.         virtual    Ptr            _CDECL GetSharedResource(ResType, int theID, OSErr* = NULL) = 0;
  2551.         virtual    Ptr            _CDECL GetSharedIndResource(ResType, int index, OSErr* = NULL) = 0;
  2552.         virtual    Ptr            _CDECL GetSharedNamedResource(ResType, const char* name,
  2553.                                                         OSErr* = NULL) = 0;
  2554.         
  2555.         virtual    void        _CDECL ReleaseSharedResource(Ptr) = 0;
  2556.         virtual long        _CDECL CountSharedResources(ResType) = 0;
  2557.         
  2558.         virtual    size_t        _CDECL GetSharedResourceUseCount(Ptr) = 0;
  2559.         virtual    OSErr        _CDECL GetSharedResourceInfo(Ptr, size_t* theSize = NULL,
  2560.                                                        short* theID = NULL, ResType* = NULL,
  2561.                                                        char* theName = NULL) = 0;
  2562.  
  2563.         virtual long        _CDECL GetRefNum() const = 0;
  2564.         virtual TFileSpec*    _CDECL GetFileSpec() const = 0;
  2565.         
  2566.         virtual    OSErr        _CDECL OpenLibraryFile() = 0;
  2567.         virtual    OSErr        _CDECL CloseLibraryFile() = 0;
  2568.  
  2569.         virtual    OSErr        _CDECL Preflight(long& savedRefNum) = 0;
  2570.         virtual    OSErr        _CDECL Postflight(long savedRefNum) = 0;
  2571. };
  2572.  
  2573. /*******************************************************************************
  2574. ** CLASS TBitmap
  2575. *******************************************************************************/
  2576.  
  2577. #define kTBitmapID "slm:supp$bmap,1.2"
  2578.  
  2579. class TBitmap : public TDynamic
  2580. {
  2581.     public:
  2582.                                 _CDECL TBitmap(size_t numBits, TMemoryPool* pool);
  2583.                                 _CDECL TBitmap(void* bits, size_t nBits);
  2584.         virtual                    ~_CDECL TBitmap();
  2585.         
  2586.         virtual Boolean            _CDECL IsValid() const;
  2587.         
  2588.         // NOTE: There is no ErrorChecking on these first 3 calls.
  2589.         
  2590.         virtual    Boolean            _CDECL SetBit(size_t bitnum);
  2591.         virtual    Boolean            _CDECL ClearBit(size_t bitnum);
  2592.         virtual    Boolean            _CDECL TestBit(size_t bitnum);
  2593.                 
  2594.                 // These return -1 if no free bits
  2595.                 
  2596.         virtual    long            _CDECL SetFirstClearBit();                
  2597.         virtual    long            _CDECL SetFirstClearBit(size_t butnum, size_t numbits);
  2598.     
  2599.     private:
  2600.                 void            InitBitmap(size_t numBits, TMemoryPool* pool);
  2601.                 void            InitBitmap(void* bits, size_t nBits);
  2602.         
  2603.         unsigned char*            fBits;
  2604.         size_t                    fNumberBits;
  2605.         Boolean                    fIsNewd;
  2606.         Boolean                    fFiller;
  2607. };
  2608.  
  2609. /*******************************************************************************
  2610. ** CLASS TFastRandom
  2611. ********************************************************************************/
  2612.  
  2613. #define kTFastRandomID    "slm:supp$frnd,1.2"
  2614.  
  2615. const unsigned long    kMaxFastRandom    = 1771874;
  2616.  
  2617. class TFastRandom : public TDynamic
  2618. {
  2619.     public:
  2620.                                 _CDECL TFastRandom();
  2621.                                 _CDECL TFastRandom(unsigned long seed);
  2622.         virtual                    ~_CDECL TFastRandom();
  2623.         
  2624.         virtual void            _CDECL SetSeed(unsigned long seed);
  2625.         virtual void            _CDECL SetSeed();
  2626.                 unsigned long    GetSeed() const;
  2627.                 
  2628.         virtual unsigned long    _CDECL GetRandom();
  2629.         virtual unsigned long    _CDECL GetRandomNumber(unsigned long lo,
  2630.                                                      unsigned long hi);
  2631.         
  2632.     protected:
  2633.         unsigned long    fSeed;
  2634. };
  2635.  
  2636. /*    -------------------------------------------------------------------------
  2637.     Inline method for TFastRandom
  2638.     ------------------------------------------------------------------------- */
  2639.  
  2640.     inline unsigned long TFastRandom::GetSeed() const
  2641.     {
  2642.         return fSeed;
  2643.     }
  2644.     
  2645. /*******************************************************************************
  2646. ** CLASS TSimpleRandom
  2647. ********************************************************************************/
  2648.  
  2649. #define kTSimpleRandomID    "slm:supp$srnd,1.2"
  2650.  
  2651. const unsigned long    kMaxSimpleRandom    = 2145740624;
  2652.  
  2653. class TSimpleRandom : public TFastRandom
  2654. {
  2655.     public:
  2656.                                 _CDECL TSimpleRandom();
  2657.                                 _CDECL TSimpleRandom(unsigned long seed);
  2658.                                 _CDECL TSimpleRandom(unsigned long im, unsigned long ia,
  2659.                                                    unsigned long ic);
  2660.         virtual                    ~_CDECL TSimpleRandom();
  2661.         
  2662.         virtual unsigned long    _CDECL GetRandom();
  2663.         virtual unsigned long    _CDECL GetRandomNumber(unsigned long lo,
  2664.                                                      unsigned long hi);
  2665.         
  2666.     protected:
  2667.         unsigned long    fIM;
  2668.         unsigned long    fIA;
  2669.         unsigned long    fIC;
  2670. };
  2671.  
  2672. /*******************************************************************************
  2673. ** CLASS TDoubleLong
  2674. **
  2675. ** Implements a TDynamic double long (64 bits).  Normally this is used
  2676. ** as a superclass for some other class which has a 64-bit value as its 
  2677. ** comparable/hashing value  (the default hash value is the low 32-bits).
  2678. *******************************************************************************/
  2679.  
  2680. #define kTDoubleLongID "slm:supp$dbll,1.2"
  2681.  
  2682. class TDoubleLong : public TMatchObject
  2683. {
  2684.     public:
  2685.                                 _CDECL TDoubleLong(const TDoubleLong&);
  2686.                                 _CDECL TDoubleLong(unsigned long low, long hi);
  2687.                                 _CDECL TDoubleLong(long l);
  2688.                                 _CDECL TDoubleLong();
  2689.         virtual                    ~_CDECL TDoubleLong();
  2690.     
  2691.         virtual    OSErr            _CDECL Inflate(TFormattedStream&);
  2692.         virtual    OSErr            _CDECL Flatten(TFormattedStream&) const;
  2693.         
  2694.         virtual Boolean            _CDECL IsEqual(const void*) const;
  2695.         virtual unsigned long    _CDECL Hash() const;
  2696.         
  2697.         virtual double            _CDECL ConvertToDouble() const;
  2698.                 void            GetWide(wide&) const;
  2699.                 
  2700.                                 operator double() const;
  2701.                                 operator unsigned long() const;
  2702.                                 
  2703.         virtual    TDoubleLong&    _CDECL Add(const TDoubleLong&);
  2704.         virtual    TDoubleLong&    _CDECL Subtract(const TDoubleLong&);
  2705.         virtual    TDoubleLong&    _CDECL Multiply(const TDoubleLong&);
  2706.         virtual    TDoubleLong&    _CDECL Divide(const TDoubleLong&);
  2707.         virtual    TDoubleLong&    _CDECL Modulo(const TDoubleLong&);
  2708.         virtual    TDoubleLong&    _CDECL RShift(unsigned int);
  2709.         virtual    TDoubleLong&    _CDECL LShift(unsigned int);
  2710.         virtual TDoubleLong&    _CDECL Negate();
  2711.         virtual short            _CDECL Compare(const void*) const;
  2712.         
  2713.                 TDoubleLong&    operator=(const TDoubleLong&);
  2714.                 TDoubleLong&    operator+=(const TDoubleLong&);
  2715.                 TDoubleLong&    operator-=(const TDoubleLong&);
  2716.                 TDoubleLong&    operator*=(const TDoubleLong&);
  2717.                 TDoubleLong&    operator/=(const TDoubleLong&);
  2718.                 TDoubleLong&    operator%=(const TDoubleLong&);
  2719.                 TDoubleLong&    operator&=(const TDoubleLong&);
  2720.                 TDoubleLong&    operator|=(const TDoubleLong&);
  2721.                 TDoubleLong&    operator^=(const TDoubleLong&);
  2722.                 
  2723.                 TDoubleLong        operator+(const TDoubleLong&) const;
  2724.                 TDoubleLong        operator-(const TDoubleLong&) const;
  2725.                 TDoubleLong        operator*(const TDoubleLong&) const;
  2726.                 TDoubleLong        operator/(const TDoubleLong&) const;
  2727.                 TDoubleLong        operator%(const TDoubleLong&) const;
  2728.                 TDoubleLong        operator&(const TDoubleLong&) const;
  2729.                 TDoubleLong        operator|(const TDoubleLong&) const;
  2730.                 TDoubleLong        operator^(const TDoubleLong&) const;
  2731.                 TDoubleLong        operator~() const;
  2732.                 TDoubleLong        operator-() const;
  2733.             
  2734.                 TDoubleLong        operator<<(unsigned int) const;
  2735.                 TDoubleLong        operator>>(unsigned int) const;
  2736.     
  2737.                 Boolean            operator>(const TDoubleLong&) const;
  2738.                 Boolean            operator<(const TDoubleLong&) const;
  2739.                 Boolean            operator<=(const TDoubleLong&) const;
  2740.                 Boolean            operator>=(const TDoubleLong&) const;
  2741.                 Boolean            operator==(const TDoubleLong&) const;
  2742.                 Boolean            operator!=(const TDoubleLong&) const;
  2743.                                 
  2744.     protected:
  2745.         long            fHiBits;
  2746.         unsigned long    fLoBits;
  2747. };
  2748.  
  2749. /*    -----------------------------------------------------------------
  2750.     Inline Methods for TDoubleLong
  2751.     ----------------------------------------------------------------- */
  2752.     
  2753.     inline TDoubleLong::operator unsigned long() const
  2754.     {
  2755.         return fLoBits;
  2756.     }
  2757.     
  2758.     inline TDoubleLong::operator double() const
  2759.     {
  2760.         return ConvertToDouble();
  2761.     }
  2762.  
  2763.     inline void TDoubleLong::GetWide(wide& tw) const
  2764.     {
  2765.         tw.hi = fHiBits;
  2766.         tw.lo = fLoBits;
  2767.     }
  2768.     
  2769.     inline TDoubleLong TDoubleLong::operator &(const TDoubleLong& val) const
  2770.     {
  2771.         return TDoubleLong(fLoBits & val.fLoBits, fHiBits & val.fHiBits);
  2772.     }
  2773.     
  2774.     inline TDoubleLong& TDoubleLong::operator =(const TDoubleLong& val)
  2775.     {
  2776.         fHiBits = val.fHiBits;
  2777.         fLoBits = val.fLoBits;
  2778.         return *this;
  2779.     }
  2780.     
  2781.     inline TDoubleLong& TDoubleLong::operator +=(const TDoubleLong& val)
  2782.     {
  2783.         return Add(val);
  2784.     }
  2785.     
  2786.     inline TDoubleLong& TDoubleLong::operator -=(const TDoubleLong& val)
  2787.     {
  2788.         return Subtract(val);
  2789.     }
  2790.     
  2791.     inline TDoubleLong& TDoubleLong::operator *=(const TDoubleLong& val)
  2792.     {
  2793.         return Multiply(val);
  2794.     }
  2795.     
  2796.     inline TDoubleLong& TDoubleLong::operator /=(const TDoubleLong& val)
  2797.     {
  2798.         return Divide(val);
  2799.     }
  2800.             
  2801.     inline TDoubleLong& TDoubleLong::operator %=(const TDoubleLong& val)
  2802.     {
  2803.         return Modulo(val);
  2804.     }
  2805.  
  2806.     inline TDoubleLong& TDoubleLong::operator &=(const TDoubleLong& val)
  2807.     {
  2808.         fHiBits &= val.fHiBits;
  2809.         fLoBits &= val.fLoBits;
  2810.         return *this;
  2811.     }
  2812.     
  2813.     inline TDoubleLong& TDoubleLong::operator |=(const TDoubleLong& val)
  2814.     {
  2815.         fHiBits |= val.fHiBits;
  2816.         fLoBits |= val.fLoBits;
  2817.         return *this;
  2818.     }
  2819.     
  2820.     inline TDoubleLong& TDoubleLong::operator ^=(const TDoubleLong& val)
  2821.     {
  2822.         fHiBits ^= val.fHiBits;
  2823.         fLoBits ^= val.fLoBits;
  2824.         return *this;
  2825.     }
  2826.     
  2827.     inline TDoubleLong TDoubleLong::operator +(const TDoubleLong& val) const
  2828.     {
  2829.         TDoubleLong    temp(*this);
  2830.         (&temp)->Add(val);
  2831.         return temp;
  2832.     }
  2833.     
  2834.     inline TDoubleLong TDoubleLong::operator -(const TDoubleLong& val) const
  2835.     {
  2836.         TDoubleLong    temp(*this);
  2837.         (&temp)->Subtract(val);
  2838.         return temp;
  2839.     }
  2840.     
  2841.     inline TDoubleLong TDoubleLong::operator *(const TDoubleLong& val) const
  2842.     {
  2843.         TDoubleLong    temp(*this);
  2844.         (&temp)->Multiply(val);
  2845.         return temp;
  2846.     }
  2847.     
  2848.     inline TDoubleLong TDoubleLong::operator /(const TDoubleLong& val) const
  2849.     {
  2850.         TDoubleLong    temp(*this);
  2851.         (&temp)->Divide(val);
  2852.         return temp;
  2853.     }
  2854.     
  2855.     inline TDoubleLong TDoubleLong::operator %(const TDoubleLong& val) const
  2856.     {
  2857.         TDoubleLong    temp(*this);
  2858.         (&temp)->Modulo(val);
  2859.         return temp;
  2860.     }
  2861.     
  2862.     inline TDoubleLong TDoubleLong::operator |(const TDoubleLong& val) const
  2863.     {
  2864.         return TDoubleLong(fLoBits | val.fLoBits, fHiBits | val.fHiBits);
  2865.     }
  2866.     
  2867.     inline TDoubleLong TDoubleLong::operator ^(const TDoubleLong& val) const
  2868.     {
  2869.         return TDoubleLong(fLoBits ^ val.fLoBits, fHiBits ^ val.fHiBits);
  2870.     }
  2871.     
  2872.     inline TDoubleLong TDoubleLong::operator~() const
  2873.     {
  2874.         return TDoubleLong(~fLoBits, ~fHiBits);
  2875.     }
  2876.     
  2877.     inline TDoubleLong TDoubleLong::operator -() const
  2878.     {
  2879.         TDoubleLong    temp(*this);
  2880.         (&temp)->Negate();
  2881.         return temp;
  2882.     }
  2883.     
  2884.     inline TDoubleLong TDoubleLong::operator >>(unsigned int val) const
  2885.     {
  2886.         TDoubleLong    temp(*this);
  2887.         (&temp)->RShift(val);
  2888.         return temp;
  2889.     }
  2890.     
  2891.     inline TDoubleLong TDoubleLong::operator <<(unsigned int val) const
  2892.     {
  2893.         TDoubleLong    temp(*this);
  2894.         (&temp)->LShift(val);
  2895.         return temp;
  2896.     }
  2897.     
  2898.     inline Boolean TDoubleLong::operator ==(const TDoubleLong& val) const
  2899.     {
  2900.         return fLoBits == val.fLoBits && fHiBits == val.fHiBits;
  2901.     }
  2902.     
  2903.     inline Boolean TDoubleLong::operator !=(const TDoubleLong& val) const
  2904.     {
  2905.         return fLoBits != val.fLoBits || fHiBits != val.fHiBits;
  2906.     }
  2907.  
  2908.     inline Boolean TDoubleLong::operator >(const TDoubleLong& val) const
  2909.     {
  2910.         return Compare(&val) > 0;
  2911.     }
  2912.     
  2913.     inline Boolean TDoubleLong::operator >=(const TDoubleLong& val) const
  2914.     {
  2915.         return Compare(&val) >= 0;
  2916.     }
  2917.     
  2918.     inline Boolean TDoubleLong::operator <(const TDoubleLong& val) const
  2919.     {
  2920.         return Compare(&val) < 0;
  2921.     }
  2922.     
  2923.     inline Boolean TDoubleLong::operator <=(const TDoubleLong& val) const
  2924.     {
  2925.         return Compare(&val) <= 0;
  2926.     }
  2927.     
  2928. /*******************************************************************************
  2929. ** CLASS THashDoubleLong
  2930. **
  2931. ** Class to hash a TDoubleLong.  The 'const void*' parameter is a 
  2932. ** pointer to a TDoubleLong object.
  2933. *******************************************************************************/
  2934.  
  2935. #define kTHashDoubleLongID "slm:supp$hdbl,1.2"
  2936.  
  2937. class THashDoubleLong : public THashObject
  2938. {
  2939.     public:
  2940.                                 _CDECL THashDoubleLong();
  2941.         virtual                    ~_CDECL THashDoubleLong();
  2942.         
  2943.         virtual unsigned long    _CDECL Hash(const void*) const;
  2944. };
  2945.  
  2946. /*******************************************************************************
  2947. ** CLASS TTime
  2948. **
  2949. ** This is the superclass for all Time-related classes.  Internally,
  2950. ** all times are stored as microSeconds, and the casting operators
  2951. ** for the TTime class return values converted to microseconds.
  2952. *******************************************************************************/
  2953.  
  2954. #define kTTimeID "slm:supp$time,1.2"
  2955.  
  2956. class TTime : public TDoubleLong
  2957. {
  2958.     public:
  2959.                                 _CDECL TTime();
  2960.                                 _CDECL TTime(unsigned long microseconds);
  2961.                                 _CDECL TTime(const TDoubleLong&);
  2962.                                 _CDECL TTime(const TTime&);
  2963.         virtual                    ~_CDECL TTime();
  2964.         
  2965.                 void            SetTime(const TTime&);
  2966.                 
  2967.                 void            SetMicroseconds(unsigned long);
  2968.         virtual    void            _CDECL SetMilliseconds(unsigned long);
  2969.         virtual    void            _CDECL SetSeconds(unsigned long);
  2970.                 
  2971.                 unsigned long    GetMicroseconds() const;
  2972.         virtual    unsigned long    _CDECL GetMilliseconds() const;
  2973.         virtual    unsigned long    _CDECL GetSeconds() const;
  2974. };
  2975.  
  2976. /*    -----------------------------------------------------------------
  2977.     Inline Methods for TTime
  2978.     ----------------------------------------------------------------- */
  2979.  
  2980.     inline void TTime::SetTime(const TTime& time)
  2981.     {
  2982.         fLoBits    = time.fLoBits;
  2983.         fHiBits    = time.fHiBits;
  2984.     }
  2985.     
  2986.     inline void TTime::SetMicroseconds(unsigned long val)
  2987.     {
  2988.         fLoBits    = val;
  2989.         fHiBits    = 0;
  2990.     }
  2991.     
  2992.     inline unsigned long TTime::GetMicroseconds() const
  2993.     {
  2994.         return fLoBits;
  2995.     }
  2996.  
  2997. /*******************************************************************************
  2998. ** CLASS TMicroseconds
  2999. *******************************************************************************/
  3000.  
  3001. #define kTMicrosecondsID "slm:supp$mics,1.2"
  3002.  
  3003. class TMicroseconds : public TTime
  3004. {
  3005.     public:
  3006.                                 _CDECL TMicroseconds();
  3007.                                 _CDECL TMicroseconds(unsigned long msecs);
  3008.                                 ~_CDECL TMicroseconds();
  3009.  
  3010.                 operator        unsigned long() const;
  3011.         virtual double            _CDECL ConvertToDouble() const;
  3012.                                 operator double() const;
  3013.         
  3014.     private:
  3015.                                 TMicroseconds(const TMicroseconds&);
  3016.                 void            operator=(const TMicroseconds&);
  3017. };
  3018.  
  3019. /*    -----------------------------------------------------------------
  3020.     Inline Methods for TMicroseconds
  3021.     ----------------------------------------------------------------- */
  3022.     
  3023.     inline TMicroseconds::operator unsigned long() const
  3024.     {
  3025.         return GetMicroseconds();
  3026.     }
  3027.  
  3028.     inline TMicroseconds::operator double() const
  3029.     {
  3030.         return ConvertToDouble();
  3031.     }
  3032.  
  3033. /*******************************************************************************
  3034. ** CLASS TMilliseconds
  3035. *******************************************************************************/
  3036.  
  3037. #define kTMillisecondsID "slm:supp$mils,1.2"
  3038.  
  3039. class TMilliseconds : public TTime
  3040. {
  3041.     public:
  3042.                                 _CDECL TMilliseconds();
  3043.                                 _CDECL TMilliseconds(unsigned long msecs);
  3044.                                 ~_CDECL TMilliseconds();
  3045.  
  3046.                 operator        unsigned long() const;
  3047.         virtual double            _CDECL ConvertToDouble() const;
  3048.                                 operator double() const;
  3049.         
  3050.     private:
  3051.                                 TMilliseconds(const TMilliseconds&);
  3052.                 void            operator=(const TMilliseconds&);
  3053. };
  3054.  
  3055. /*    -----------------------------------------------------------------
  3056.     Inline Methods for TMilliseconds
  3057.     ----------------------------------------------------------------- */
  3058.     
  3059.     inline TMilliseconds::operator unsigned long() const
  3060.     {
  3061.         return GetMilliseconds();
  3062.     }
  3063.     
  3064.     inline TMilliseconds::operator double() const
  3065.     {
  3066.         return ConvertToDouble();
  3067.     }
  3068.     
  3069. /*******************************************************************************
  3070. ** CLASS TSeconds
  3071. *******************************************************************************/
  3072.  
  3073. #define kTSecondsID "slm:supp$secs,1.2"
  3074.  
  3075. class TSeconds : public TTime
  3076. {
  3077.     public:
  3078.                                 _CDECL TSeconds();
  3079.                                 _CDECL TSeconds(unsigned long secs);
  3080.                                 ~_CDECL TSeconds();
  3081.  
  3082.                 operator        unsigned long() const;
  3083.         virtual double            _CDECL ConvertToDouble() const;
  3084.                                 operator double() const;
  3085.         
  3086.     private:
  3087.                                 TSeconds(const TSeconds&);
  3088.                 void            operator=(const TSeconds&);
  3089. };
  3090.  
  3091. /*    -----------------------------------------------------------------
  3092.     Inline Methods for TSeconds
  3093.     ----------------------------------------------------------------- */
  3094.  
  3095.     inline TSeconds::operator unsigned long() const
  3096.     {
  3097.         return GetSeconds();
  3098.     }
  3099.     
  3100.     inline TSeconds::operator double() const
  3101.     {
  3102.         return ConvertToDouble();
  3103.     }
  3104.     
  3105. /*******************************************************************************
  3106. ** CLASS TTimeStamp
  3107. *******************************************************************************/
  3108.  
  3109. #define kTTimeStampID "slm:supp$tstm,1.2"
  3110.  
  3111. class TTimeStamp : public TTime
  3112. {
  3113.     public:
  3114.                             _CDECL TTimeStamp();
  3115.         virtual                ~_CDECL TTimeStamp();
  3116.     
  3117.         virtual    void        _CDECL SetTimeStamp();
  3118.         
  3119.     private:
  3120.                                 TTimeStamp(const TTimeStamp&);
  3121.                 void            operator=(const TTimeStamp&);
  3122. };
  3123.  
  3124. /*******************************************************************************
  3125. ** CLASS TStopwatch
  3126. *******************************************************************************/
  3127.  
  3128. #define kTStopwatchID "slm:supp$stpw,1.2"
  3129.  
  3130. class TStopwatch : public TTimeStamp
  3131. {
  3132.     public:
  3133.                                 _CDECL TStopwatch();
  3134.         virtual                    ~_CDECL TStopwatch();
  3135.     
  3136.         virtual    void            _CDECL Reset();
  3137.  
  3138.         virtual    unsigned long    _CDECL ElapsedMicroseconds() const;
  3139.         virtual    unsigned long    _CDECL ElapsedMilliseconds() const;
  3140.         virtual    unsigned long    _CDECL ElapsedSeconds() const;
  3141.         
  3142.     private:
  3143.                                 TStopwatch(const TStopwatch&);
  3144.                 void            operator=(const TStopwatch&);
  3145. };
  3146.     
  3147. /*******************************************************************************
  3148. ** CLASS TTraceLog
  3149. **
  3150. ** An object for doing debug tracing with.
  3151. ********************************************************************************/
  3152.  
  3153. #define kTTraceLogID "slm:dbug$tlog,1.2"
  3154.  
  3155. class TTraceLog : public TDynamic 
  3156. {
  3157.     public:
  3158.                                 _CDECL TTraceLog();
  3159.         virtual                    ~_CDECL TTraceLog();
  3160.     
  3161.         virtual void            _CDECL Trace(char *formatStr, ...) const;
  3162.         
  3163.     // New methods
  3164.         
  3165.                 Boolean            IsTraceLogOn() const;
  3166.                 void            TraceLogOn();
  3167.                 void            TraceLogOff();
  3168.                 
  3169.         virtual    void            _CDECL TraceFormatted(char* outstr) const = 0;
  3170.         virtual    void            _CDECL TraceUnformatted(void* argp) const;
  3171.  
  3172.     protected:
  3173.                 void            SetTracePool(TStandardPool*);
  3174.                 TStandardPool*    GetTracePool() const;
  3175.  
  3176.     private:
  3177.                                 TTraceLog(const TTraceLog&);
  3178.                 void            operator=(const TTraceLog&);
  3179.         
  3180.         Boolean                    fTracing;
  3181.         Boolean                    fFiller1;
  3182.  
  3183.         //
  3184.         //    We blew it on GENERATING68K by not getting the fTracePool field aligned on
  3185.         //    a long word boundary. Since it is accessed by inline methods, we can't
  3186.         //    safely change its alignment. In order to make the object layout the
  3187.         //    same for powerpc, we define the field as 2 shorts instead.
  3188.         //
  3189. #if GENERATING68K
  3190.         TStandardPool*            fTracePool;
  3191. #else
  3192.         unsigned short            fTracePoolHi;
  3193.         unsigned short            fTracePoolLo;
  3194. #endif
  3195.         short                    fFiller2;
  3196. };
  3197.  
  3198. /*    -----------------------------------------------------------------
  3199.     Inline Methods for TTraceLog
  3200.     ----------------------------------------------------------------- */
  3201.     
  3202.     inline void TTraceLog::SetTracePool(TStandardPool* pool)
  3203.     {
  3204. #if GENERATING68K
  3205.         fTracePool = pool;
  3206. #else
  3207.         fTracePoolHi = (unsigned short)((unsigned long)pool >> 16);
  3208.         fTracePoolLo = (unsigned short)((unsigned long)pool);
  3209. #endif
  3210.     }
  3211.     
  3212.     inline TStandardPool* TTraceLog::GetTracePool() const
  3213.     {
  3214. #if GENERATING68K
  3215.         return fTracePool;
  3216. #else
  3217.         return (TStandardPool*)(fTracePoolHi << 16 | fTracePoolLo);
  3218. #endif
  3219.     }
  3220.  
  3221.     inline Boolean TTraceLog::IsTraceLogOn() const
  3222.     {
  3223.         return fTracing;
  3224.     }
  3225.     
  3226.     inline void TTraceLog::TraceLogOn()
  3227.     {
  3228.         if (GetTracePool() != NULL)
  3229.             fTracing = true;
  3230.     }
  3231.     
  3232.     inline void TTraceLog::TraceLogOff()
  3233.     {
  3234.         fTracing = false;
  3235.     }
  3236.  
  3237. /*******************************************************************************
  3238. ** Some inlines that rely on other inlines so we just do them here to prevent
  3239. ** circular dependency problems.
  3240. ********************************************************************************/
  3241.  
  3242. /*    -------------------------------------------------------------------------
  3243.     Inline methods for TArray
  3244.     ------------------------------------------------------------------------- */
  3245.  
  3246.     inline TStandardPool* TArray::GetGrowPool() const
  3247.     {
  3248.         return (TStandardPool*)TMemoryPool::RecoverPool(fArray);
  3249.     }
  3250.  
  3251. #endif
  3252.  
  3253. #endif
  3254.