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

DynTmp.hh

Go to the documentation of this file.
00001 #ifndef NO_PTR_DYNTMP_H
00002 #define NO_PTR_DYNTMP_H
00003 
00023 #include "nullness.hh"  // use
00024 #include "RRefUsage.hh" // contain
00025 #include "Deleter.hh"   // inherit
00026 #include "DynObjKey.hh" // use
00027 #include "NoPtrFwd.hh"  // use
00028 
00029 namespace NoPtr
00030 {
00031     template <typename ObjType>
00032     class DynTmp // inherit so EBO (empty base optimization) possible
00033                  // and privately since not for polymorphism:
00034         : private NoPtrImpl::Deleter<ObjType>
00035     {
00036         public:
00039             DynTmp(const DynTmp& dynmobj) throw()
00040                 : _obj(dynmobj._obj)
00041             {
00042                 dynmobj._obj = NullPtr;
00043                 dynmobj._rrefUsage.moveTo(_rrefUsage);
00044             }
00050             template <typename ObjType2>
00051             DynTmp(const DynTmp<ObjType2>& dynmobj) throw()
00052                 : _obj(dynmobj._obj)
00053             {
00054                 dynmobj._obj = NullPtr;
00055                 dynmobj._rrefUsage.moveTo(_rrefUsage);
00056             }
00061            ~DynTmp()
00062             {
00063                 destroy(_obj);
00064                 _rrefUsage.destroy();
00065             }
00066            
00068             DynTmp(ObjType* ptr) throw(): _obj(ptr) { }
00069             
00074             ObjType* release() throw()
00075             {
00076                 _rrefUsage.destroy();
00077                 ObjType* const tmp = _obj;
00078                 _obj = NullPtr;
00079                 return tmp;
00080             }
00081             
00082         public: // only for DynObj
00083                 
00084             // Create from the DAO held by DynObj
00085             DynTmp(ObjType* ptr, NoPtrImpl::RRefUsageForOwner& rrefUsage,
00086                      NoPtrImpl::DynObjKey<ObjType>) throw()
00087                 : _obj(ptr) {rrefUsage.moveTo(_rrefUsage);}
00088         
00089             /* Deliver the DAO held to a DynObj. The required key
00090                garantees that this method can be called only by a
00091                DynObj, even though the method is public. This avoids
00092                having to make DynObj a friend.
00093                */
00094             template <typename ObjType2>
00095             void deliver( ObjType2*& obj, 
00096                      NoPtrImpl::RRefUsageForOwner& rrefUsage,
00097                      NoPtrImpl::DynObjKey<ObjType2> ) const throw()
00098             {
00099                 obj  = _obj;
00100                 _obj = NullPtr;
00101                 _rrefUsage.moveTo(rrefUsage);
00102             }
00103             
00104         private:
00106             template <typename> friend class DynTmp;
00107             
00108         private:
00109             // data mutable since DynTmp has no logical state per se
00110             mutable ObjType* _obj;
00111             mutable NoPtrImpl::RRefUsageForOwner _rrefUsage;
00112     };
00113 
00123     template <typename ObjType>
00124     DynTmp<ObjType> 
00125     makeDynTmp(ObjType* const newDAO) {return newDAO;}
00126     
00139     template <typename ObjType>
00140     DynTmp<ObjType> 
00141     makeDynObj(ObjType* const newDAO) {return newDAO;}
00142     
00143 } // namespace
00144 
00198 #endif // NO_PTR_DYNTMP_H    

Generated on Mon Aug 4 18:51:23 2003 for NoPtr C++ Library by doxygen 1.3.2