Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OwnedCntrShared.hh

Go to the documentation of this file.
00001 
00020 #ifndef MANGO_OWNED_CONTAINER_SHARED_H
00021 #define MANGO_OWNED_CONTAINER_SHARED_H
00022 
00023 #include "ValidityOwner.hh" // use
00024 #include "CntrCleaner.hh"   // use
00025 #include "CntrClonerFWD.hh" // use
00026 #include "BLinkableFWD.hh"  // inherit
00027 #include "OwnedFWD.hh"      // use
00028 
00029 namespace MangoPtr
00030 {    
00068     template <typename CntrType>
00069     class Owned<CntrType&, OShared>
00070         : protected BLinkable<ForOwnedBy::Wrapper>
00071     {
00072         public:
00074             typedef CntrType ObjectType;
00075 
00077 
00078             inline explicit Owned(CntrType&);
00079             inline Owned(const Owned&);
00080             inline ~Owned();
00082 
00083         public: 
00085 
00086             inline void cloneObjNew(CntrType&) const;
00087             inline void reset();
00089             CntrType& cntr() {return rcntr;}
00091             const CntrType& cntr() const {return rcntr;}
00093             CntrType* operator()() {return &rcntr;}
00095             const CntrType* operator()() const {return &rcntr;}
00097 
00098         private: // data
00099             CntrType& rcntr; 
00100             ValidityOwner ownership; 
00101 
00102 
00103             typedef void (Owned::*DeleteFn)();
00105             const DeleteFn cleanerUpper;
00106         
00107         private: 
00112             void doCleanUp() { CntrCleaner<CntrType>::execute(rcntr); }
00113     };
00114     
00120     template <typename CntrType>
00121     inline 
00122     Owned<CntrType&, OShared>::Owned(CntrType& cntr)
00123         : rcntr(cntr), cleanerUpper(&Owned::doCleanUp) { }
00124     
00133     template <typename CntrType>
00134     inline 
00135     Owned<CntrType&, OShared>::Owned(const Owned& rhs)
00136         : rcntr(rhs.rcntr), ownership(rhs.ownership),
00137           cleanerUpper(&Owned::doCleanUp) {}
00138     
00143     template <typename CntrType>
00144     inline 
00145     Owned<CntrType&, OShared>::~Owned()
00146     {
00147         if (! ownership.isShared()) reset();
00148     }
00149             
00156     template <typename CntrType>
00157     inline void
00158     Owned<CntrType&, OShared>::reset()
00159     {
00160         (this->*cleanerUpper)();
00161         CntrType empty;
00162         assert(empty.empty());
00163         std::swap(empty, rcntr);
00164         assert(rcntr.empty());
00165     }
00166             
00176     template <typename CntrType>
00177     inline void
00178     Owned<CntrType&, OShared>::cloneObjNew(CntrType& dest) 
00179     const 
00180     {
00181         assert(dest.empty()); // to prevent leaks
00182         dest = rcntr;
00183         CntrCloner<CntrType>::execute(dest);
00184     }
00185 } // namespace
00186 
00187 
00188 #endif // MANGO_OWNED_CONTAINER_SHARED_H

Generated on Tue Nov 12 20:43:52 2002 for Mango-ptr Library by doxygen1.2.18