home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / aplusplus-1.01-src.lha / src / amiga / aplusplus-1.01 / include / aplusplus / environment / Dependencies.h < prev    next >
C/C++ Source or Header  |  1994-05-04  |  2KB  |  43 lines

  1. #ifndef APP_Dependencies_H
  2. #define APP_Dependencies_H
  3. /******************************************************************************
  4.  **
  5.  **    C++ Class Library for the Amiga© system software.
  6.  **
  7.  **    Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  8.  **    All Rights Reserved.
  9.  **
  10.  **    $VER: apphome:APlusPlus/environment/Dependencies.h 1.04 (04.05.94) $
  11.  **    
  12.  ******************************************************************************/
  13.  
  14. extern "C" {
  15. #include <exec/types.h>
  16. }
  17.  
  18. /*****************************************************************************************
  19.       » Shared class «
  20.  
  21.    Objects that are accessed from various other objects that should span the lifetime of
  22.    their accessors can be tracked with the Shared class. The first accessing object creates
  23.    the Shared instance, other objects may participate in the access and the last accessing
  24.    object that releases its hold on the Shared instance causes its destruction.
  25.  
  26.    REMEMBER: Shared objects may only be constructed dynamically via the new operator!
  27.  
  28.  *****************************************************************************************/
  29. class Shared
  30. {
  31.    private:
  32.       WORD participants;
  33.  
  34.    public:
  35.       Shared() { participants = 1; }   // contruction implies an access permission.
  36.       virtual ~Shared() { };     // must be virtual to be able to delete itself correctly.
  37.  
  38.       Shared *participate() { participants++; return this; }
  39.       WORD release() { if (--participants <= 0) { delete this; return 0; } else return participants; }
  40. };
  41.  
  42. #endif
  43.