home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WREFOBJ.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  3KB  |  95 lines

  1.  
  2. /*************************************************************************
  3.  *
  4.  * WReferenceObject
  5.  *
  6.  *    Implements a base class for referenced objects.
  7.  *
  8.  *************************************************************************/
  9.  
  10. #ifndef _WREFOBJ_HPP_INCLUDED
  11. #define _WREFOBJ_HPP_INCLUDED
  12.  
  13. #ifndef _WNO_PRAGMA_PUSH
  14. #pragma pack(push,8);
  15. #pragma enum int;
  16. #endif
  17.  
  18. //
  19. // WReferenceObject
  20. //
  21.  
  22. class WCMCLASS WReferenceObject : public WObject {
  23.     WDeclareSubclass( WReferenceObject, WObject );
  24.  
  25.         /**********************************************************
  26.          * Constructors and Destructors
  27.          *********************************************************/
  28.  
  29.         // This class is meant to be used as a reference class, with
  30.         // objects allocated via new.  As such we don't allow
  31.         // copies to be made except via explicitly-defined copy
  32.         // methods.
  33.         //
  34.         // All objects are allocated via a static function.
  35.     
  36.     protected:
  37.         WReferenceObject( const WReferenceObject & ref );
  38.         WReferenceObject& operator=( const WReferenceObject & ref );
  39.  
  40.     protected:
  41.         WReferenceObject();
  42.  
  43.     public:
  44.         ~WReferenceObject();
  45.  
  46.         /**********************************************************
  47.          * Properties
  48.          *********************************************************/
  49.  
  50.         // ReferenceCount
  51.  
  52.         virtual WLong GetReferenceCount() const;
  53.  
  54.         /**********************************************************
  55.          * Methods
  56.          *********************************************************/
  57.  
  58.         // Reference
  59.         //
  60.         //    Increments the reference count for the object.
  61.         //    Note that Reference is called once when the object
  62.         //    is created.
  63.  
  64.         virtual WLong Reference();
  65.  
  66.         // Unreference
  67.         //
  68.         //    Decrements the reference count for the object.
  69.         //    When the reference count reaches 0, the object
  70.         //    releases/frees the global memory object and
  71.         //    then does "delete this".  If the returned value is
  72.         //    0 or less, DON'T USE THE OBJECT!
  73.  
  74.         virtual WLong Unreference();
  75.  
  76.         /**********************************************************
  77.          * Private
  78.          *********************************************************/
  79.  
  80.     protected:
  81.         virtual void ReinitSelf();
  82.         virtual void DeleteSelf();
  83.  
  84.     protected:
  85.         WLong      _refCount;  
  86. };
  87.  
  88.  
  89. #ifndef _WNO_PRAGMA_PUSH
  90. #pragma enum pop;
  91. #pragma pack(pop);
  92. #endif
  93.  
  94. #endif // _WREFOBJ_HPP_INCLUDED
  95.