BALL  1.4.1
autoDeletable.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 
00005 
00006 #ifndef BALL_CONCEPT_AUTODELETABLE_H
00007 #define BALL_CONCEPT_AUTODELETABLE_H
00008 
00009 #ifndef BALL_CONFIG_CONFIG_H
00010 # include <BALL/CONFIG/config.h>
00011 #endif
00012 
00013 #ifndef BALL_COMMON_COMMON_H
00014 # include <BALL/COMMON/debug.h>
00015 #endif
00016 
00017 #ifndef BALL_COMMON_GLOBAL_H
00018 # include <BALL/COMMON/global.h>
00019 #endif
00020 
00021 #include <stdlib.h>
00022 #include <new>
00023 #include <iostream>
00024 
00025 namespace BALL 
00026 {
00027 
00058   class BALL_EXPORT AutoDeletable
00059   {
00060     public:
00061 
00066 
00069     virtual ~AutoDeletable()
00070       ;
00071 
00079     void* operator new(size_t size) 
00080       ;
00081   
00088     void operator delete(void* ptr) 
00089       ;
00090   
00098     void* operator new(size_t size, void* ptr)
00099       ;
00100   
00107     void operator delete(void* ptr, void*)
00108       ;
00109   
00111   
00115   
00122     void setAutoDeletable(bool enable)
00123       ;
00124 
00125     /* This is required for cleaning up in case we want to
00126        valgrind our stuff -- otherwise we get "still reachable"
00127        blocks through this ptr.
00128     */
00129     static void clearLastPtr() { last_ptr_ = 0; }
00131 
00135 
00142     bool isAutoDeletable() const
00143       ;
00145 
00146 
00147     protected:
00148 
00149     /*_ Default constructor.
00150         Should be called by subclasses only. There's no need to construct
00151         AutoDeletable objects by themselves.
00152     */
00153     AutoDeletable()
00154       ;
00155 
00156     /*_ Copy constructor.
00157     */
00158     AutoDeletable(const AutoDeletable& auto_deletable, bool deep = false)
00159       ;
00160 
00161 
00162     private:
00163 
00164     /*_ Flag describing whether the object may be deleted automatically.
00165     */
00166     bool enabled_;
00167 
00168     /*_ The last new pointer.
00169         This pointe ris used internally to determine whether a given 
00170         instance of AutoDeletable was constructed statically or dynamically.
00171     */
00172     static  void* last_ptr_;
00173   };
00174 
00175 # ifndef BALL_NO_INLINE_FUNCTIONS
00176 #   include <BALL/CONCEPT/autoDeletable.iC>
00177 # endif
00178 
00179 } // namespace BALL
00180 
00181 #endif // BALL_CONCEPT_AUTODELETABLE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines