Thread: [Cppunit-cvs] cppunit2/include/cpptl scopedptr.h,NONE,1.1 config.h,1.18,1.19 conststring.h,1.6,1.7 f
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-07-04 08:09:48
|
Update of /cvsroot/cppunit/cppunit2/include/cpptl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22058/cpptl Modified Files: config.h conststring.h forwards.h sharedptr.h Added Files: scopedptr.h Log Message: * updated forward declarations * ScopedPtr and SharedPtr now use checked delete (check if type is complete) * added checkedDelete() and checkedArrayDelete() to config.h * added ScopedPtr and ScopedArray. Index: config.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/config.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** config.h 24 Jun 2005 19:47:39 -0000 1.18 --- config.h 4 Jul 2005 08:09:29 -0000 1.19 *************** *** 192,195 **** --- 192,205 ---- #define CPPTL_MAX( a, b ) ((a) > (b) ? a : b) + /*! Cause a compilation error if a type is not complete. + * Typical use if before call to delete operator (ScopedPtr, SharedPtr...). + * (based on boost.checked_delete) + */ + #define CPPTL_CHECK_TYPE_COMPLETE( Type ) \ + { \ + typedef char typeMustBeComplete[ sizeof(Type) ? 1 : -1 ]; \ + (void)sizeof(typeMustBeComplete); \ + } + /////////////////////////////////////////////////////////////////////////// *************** *** 251,254 **** --- 261,278 ---- } + template<class T> + void checkedDelete( T *p ) + { + CPPTL_CHECK_TYPE_COMPLETE( T ) + delete p; + } + + template<class T> + void checkedArrayDelete( T *p ) + { + CPPTL_CHECK_TYPE_COMPLETE( T ) + delete[] p; + } + } // namespace CppTL Index: conststring.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/conststring.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** conststring.h 2 Jul 2005 20:27:35 -0000 1.6 --- conststring.h 4 Jul 2005 08:09:30 -0000 1.7 *************** *** 45,49 **** size_type length() const { ! return end_ - begin_; } --- 45,49 ---- size_type length() const { ! return size_type(end_ - begin_); } Index: forwards.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/forwards.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** forwards.h 3 Mar 2005 20:48:54 -0000 1.4 --- forwards.h 4 Jul 2005 08:09:30 -0000 1.5 *************** *** 10,15 **** --- 10,17 ---- // conststring.h + class ConstCharView; class ConstString; class StringBuffer; + class StringConcatenator; // enumerator.h *************** *** 17,24 **** class AnyEnumerator; - // sharedptr.h - template<class PointeeType> - class SharedPtr; - // functor.h class Functor0; --- 19,22 ---- *************** *** 31,34 **** --- 29,42 ---- class Method; + // scopedptr.h + template<class PointeeType> + class ScopedPtr; + template<class PointeeType> + class ScopedArray; + + // sharedptr.h + template<class PointeeType> + class SharedPtr; + Index: sharedptr.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/sharedptr.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sharedptr.h 28 Feb 2005 20:38:21 -0000 1.4 --- sharedptr.h 4 Jul 2005 08:09:30 -0000 1.5 *************** *** 153,157 **** { if ( releaseCount() ) ! delete static_cast<PointeeType *>( p_ ); } --- 153,157 ---- { if ( releaseCount() ) ! checkedDelete( static_cast<PointeeType *>( p_ ) ); } --- NEW FILE: scopedptr.h --- #ifndef CPPTL_SCOPEDPTR_H_INCLUDED # define CPPTL_SCOPEDPTR_H_INCLUDED # include <cpptl/config.h> namespace CppTL { template<class PointeeType> class ScopedPtr : public NonCopyable { public: typedef ScopedPtr<PointeeType> SelfType; ScopedPtr( PointeeType *p = 0 ) : p_( p ) { } ~ScopedPtr() { checkedDelete( p_ ); } void swap( SelfType &other ) { CppTL::swap( p_, other.p_ ); } void reset( PointeeType *p = 0 ) { SelfType temp(p); swap( temp ); } PointeeType *get() const { return p_; } PointeeType &operator *() const { CPPTL_ASSERT_MESSAGE( p_ != 0, "Attempted to use null pointer" ); return *p_; } PointeeType *operator ->() const { CPPTL_ASSERT_MESSAGE( p_ != 0, "Attempted to use null pointer" ); return p_; } operator bool() const { return p_ != 0; } bool operator !() const { return p_ == 0; } private: PointeeType *p_; }; template<class PointeeType> class ScopedArray : public NonCopyable { public: typedef ScopedArray<PointeeType> SelfType; ScopedArray( PointeeType *p = 0 ) : p_( p ) { } ~ScopedArray() { checkedArrayDelete( p_ ); } void swap( SelfType &other ) { CppTL::swap( p_, other.p_ ); } void reset( PointeeType *p = 0 ) { SelfType temp(p); swap( temp ); } PointeeType *get() const { return p_; } PointeeType &operator *() const { CPPTL_ASSERT_MESSAGE( p_ != 0, "Attempted to use null pointer" ); return *p_; } PointeeType *operator ->() const { CPPTL_ASSERT_MESSAGE( p_ != 0, "Attempted to use null pointer" ); return p_; } operator bool() const { return p_ != 0; } bool operator !() const { return p_ == 0; } private: PointeeType *p_; }; } // namespace CppTL #endif // CPPTL_SCOPEDPTR_H_INCLUDED |