CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

ZMuseCount.h

Go to the documentation of this file.
00001 #ifndef ZMUSECOUNT_H
00002 #define ZMUSECOUNT_H
00003 
00004 
00005 // ----------------------------------------------------------------------
00006 //
00007 //  ZMuseCount.h - utility class for use in reference-counting
00008 //
00009 //
00010 //  History:
00011 //    19-Sep-1997  WEB  Design stolen, and code adapted, from pp 70-73 of
00012 //      Koenig & Moo: "Ruminations on C++" (1996)
00013 //
00014 // ----------------------------------------------------------------------
00015 
00016 
00017 class ZMuseCount  {
00018 
00019 public:
00020 
00021   // --------------------------
00022   // Constructors & destructor:
00023   // --------------------------
00024 
00025   ZMuseCount();
00026     // Constructor
00027   ZMuseCount( const ZMuseCount & u );
00028     // Copy constructor
00029   ~ZMuseCount();
00030     // Destructor
00031 
00032 
00033   // -----------------------------------
00034   // Functions useful to a handle class:
00035   // -----------------------------------
00036 
00037   bool only();
00038     // Is there exactly one copy of the referent?
00039 
00040   bool makeonly();
00041     // Enables the handle (to a ClassType) to refer to a unique (copy of)
00042     // the referent via the following usage:
00043     //   if ( u.makeonly() )            /* ZMuseCount u;     */
00044     //      p = new ClassType( *p );    /* ClassType * p;  */
00045     // This is useful in implementing copy-on-write semantics
00046     // (i.e., non-shared or value semantics), and would appear just before
00047     // updating (any part of) *p in such a context.
00048 
00049   bool reattach( const ZMuseCount & u );
00050     // Simplifies a handle's implementation of assignment via the following
00051     // usage:
00052     //   if ( u.reattach(h.u) )       /* Handle<ClassType> h; */
00053     //     delete p;                  /* p and u as above     */
00054     //   p = h.p;
00055 
00056 
00057 private:
00058 
00059   int * p;
00060     // *p is the reference counter itself
00061 
00062   ZMuseCount & operator=( const ZMuseCount & );
00063     // Forbidden operation on a ZMuseCount object
00064 
00065 };  // ZMuseCount
00066 
00067 
00068 //#include "CLHEP/RefCount/ZMuseCount.icc"
00069 
00070 
00071 #endif  // ZMUSECOUNT_H

Generated on Thu Jul 1 22:02:31 2010 for CLHEP by  doxygen 1.4.7