X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftrunk%2FETL%2F_smart_ptr.h;h=a34b8dda4f44d0eae5adce5fd4d8ccbc7dd64e1c;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=4609880c1ebc2fb5fa81216ac84a15e26a06154a;hpb=b3016b249333ac0ab0008d8c6c4d9029b2ff30c9;p=synfig.git diff --git a/ETL/trunk/ETL/_smart_ptr.h b/ETL/trunk/ETL/_smart_ptr.h index 4609880..a34b8dd 100644 --- a/ETL/trunk/ETL/_smart_ptr.h +++ b/ETL/trunk/ETL/_smart_ptr.h @@ -1,7 +1,7 @@ /* ======================================================================== ** Extended Template and Library ** Template Smart Pointer Implementation -** $Id: _smart_ptr.h,v 1.1.1.1 2005/01/04 01:31:48 darco Exp $ +** $Id$ ** ** Copyright (c) 2002 Robert B. Quattlebaum Jr. ** @@ -73,7 +73,7 @@ public: typedef D destructor_type; #ifdef DOXYGEN_SHOULD_SKIP_THIS // #ifdef is not a typo -private: +private: #endif value_type *obj; //!< \internal Pointer to object reference_counter refcount; @@ -128,7 +128,7 @@ public: obj=(pointer)x.get(); refcount=x.refcount; } - + return *this; } @@ -138,31 +138,31 @@ public: { if(x.get()==obj) return *this; - + reset(); if(x.obj) { - + obj=(pointer)x.get(); refcount=x.refcount; } - + return *this; } //! smart_ptr reset procedure void reset() - { + { if(obj) - { + { if(refcount.unique()) destructor_type()(obj); refcount.detach(); obj=0; } } - + void spawn() { operator=(smart_ptr(new T)); } //! Returns number of instances @@ -178,19 +178,6 @@ public: pointer operator->()const { assert(obj); return obj; } - //! Overloaded cast operator -- useful for implicit casts - template - operator smart_ptr() - { - // This next line should provide a syntax check - // to make sure that this cast makes sense. - // If it doesn't, this should have a compiler error. - // Otherwise, it should get optimized right out - // of the code. - //(U*)obj; - - return *reinterpret_cast*>(this); - } operator smart_ptr()const { return smart_ptr(static_cast(obj)); } @@ -217,6 +204,20 @@ public: bool operator!()const { return !obj; } + //! Overloaded cast operator -- useful for implicit casts + template + operator smart_ptr() + { + // This next line should provide a syntax check + // to make sure that this cast makes sense. + // If it doesn't, this should have a compiler error. + // Otherwise, it should get optimized right out + // of the code. + //(U*)obj; + + return *reinterpret_cast*>(this); + } + }; // END of template class smart_ptr // ======================================================================== @@ -268,7 +269,7 @@ public: const count_type& count()const { return refcount; } bool unique()const { return refcount.unique(); } - + reference operator*()const { assert(obj); return *obj; } pointer operator->()const { assert(obj); return obj; }