autoDeletable.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: autoDeletable.h,v 1.25 2005/12/23 17:01:40 amoll Exp $
00005 //
00006 
00007 
00008 #ifndef BALL_CONCEPT_AUTODELETABLE_H
00009 #define BALL_CONCEPT_AUTODELETABLE_H
00010 
00011 #ifndef BALL_CONFIG_CONFIG_H
00012 # include <BALL/CONFIG/config.h>
00013 #endif
00014 
00015 #ifndef BALL_COMMON_COMMON_H
00016 # include <BALL/COMMON/debug.h>
00017 #endif
00018 
00019 #ifndef BALL_COMMON_GLOBAL_H
00020 # include <BALL/COMMON/global.h>
00021 #endif
00022 
00023 #include <stdlib.h>
00024 #include <new>
00025 #include <iostream>
00026 
00027 namespace BALL 
00028 {
00029 
00060   class BALL_EXPORT AutoDeletable
00061   {
00062     public:
00063 
00068 
00071     virtual ~AutoDeletable()
00072       ;
00073 
00081     void* operator new(size_t size) 
00082       ;
00083   
00090     void operator delete(void* ptr) 
00091       ;
00092   
00100     void* operator new(size_t size, void* ptr)
00101       ;
00102   
00109     void operator delete(void* ptr, void*)
00110       ;
00111   
00113   
00117   
00124     void setAutoDeletable(bool enable)
00125       ;
00126 
00127     /* This is required for cleaning up in case we want to
00128        valgrind our stuff -- otherwise we get "still reachable"
00129        blocks through this ptr.
00130     */
00131     static void clearLastPtr() { last_ptr_ = 0; }
00133 
00137 
00144     bool isAutoDeletable() const
00145       ;
00147 
00148 
00149     protected:
00150 
00151     /*_ Default constructor.
00152         Should be called by subclasses only. There's no need to construct
00153         AutoDeletable objects by themselves.
00154     */
00155     AutoDeletable()
00156       ;
00157 
00158     /*_ Copy constructor.
00159     */
00160     AutoDeletable(const AutoDeletable& auto_deletable, bool deep = false)
00161       ;
00162 
00163 
00164     private:
00165 
00166     /*_ Flag describing whether the object may be deleted automatically.
00167     */
00168     bool enabled_;
00169 
00170     /*_ The last new pointer.
00171         This pointe ris used internally to determine whether a given 
00172         instance of AutoDeletable was constructed statically or dynamically.
00173     */
00174     static  void* last_ptr_;
00175   };
00176 
00177 # ifndef BALL_NO_INLINE_FUNCTIONS
00178 #   include <BALL/CONCEPT/autoDeletable.iC>
00179 # endif
00180 
00181 } // namespace BALL
00182 
00183 #endif // BALL_CONCEPT_AUTODELETABLE_H