- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- File List
- File Members

# TPointerDeleter.hpp

Go to the documentation of this file.

    00001 #ifndef __TPointerDeleter__
    00002 #define __TPointerDeleter__
    00003
    00007 #include "../Basics/CCountedObject.hpp"
    00008 using Exponent::Basics::CCountedObject;
    00013 namespace Exponent
    00014 {
    00015     namespace Collections
    00016     {
    00034         template<class TypeName> class TPointerDeleter : public CCountedObject
    00035         {
    00037             EXPONENT_CLASS_DECLARATION;
    00040 //  ===========================================================================
    00041
    00042         public:
    00043
    00047             TPointerDeleter();
    00048
    00052             virtual ~TPointerDeleter();
    00053
    00058             virtual void pointerAdded(TypeName *pointer) const = 0;
    00059
    00064             virtual void deletePointer(TypeName *pointer) const = 0;
    00065         };
    00066
    00067 //  ===========================================================================
    00068
    00083         template<class TypeName> class TObjectDeleter : public TPointerDeleter<TypeName>
    00084         {
    00086             EXPONENT_CLASS_DECLARATION;
    00089 //  ===========================================================================
    00090
    00091         public:
    00092
    00096             TObjectDeleter();
    00097
    00101             virtual ~TObjectDeleter();
    00102
    00107             virtual void pointerAdded(TypeName *pointer) const { }
    00108
    00113             virtual void deletePointer(TypeName *pointer) const;
    00114         };
    00115
    00116 //  ===========================================================================
    00117
    00132         template<class TypeName> class TObjectNuller : public TPointerDeleter<TypeName>
    00133         {
    00135             EXPONENT_CLASS_DECLARATION;
    00138 //  ===========================================================================
    00139
    00140         public:
    00141
    00145             TObjectNuller();
    00146
    00150             virtual ~TObjectNuller();
    00151
    00156             virtual void pointerAdded(TypeName *pointer) const { }
    00157
    00162             virtual void deletePointer(TypeName *pointer) const;
    00163         };
    00164
    00165 //  ===========================================================================
    00166
    00181         template<class TypeName> class TCountedObjectDeleter : public TPointerDeleter<TypeName>
    00182         {
    00184             EXPONENT_CLASS_DECLARATION;
    00187 //  ===========================================================================
    00188
    00189         public:
    00190
    00194             TCountedObjectDeleter();
    00195
    00199             virtual ~TCountedObjectDeleter();
    00200
    00205             virtual void pointerAdded(TypeName *pointer) const;
    00206
    00211             virtual void deletePointer(TypeName *pointer) const;
    00212         };
    00213
    00214 //  ===========================================================================
    00215
    00218 //  ===========================================================================
    00219
    00220         EXPONENT_TEMPLATE_CLASS_IMPLEMENTATION(TPointerDeleter<TypeName>, TypeName, CCountedObject);
    00221         EXPONENT_TEMPLATE_CLASS_IMPLEMENTATION_TEMPLATE_PARENT(TObjectDeleter<TypeName>, TypeName, TPointerDeleter<TypeName>, TypeName);
    00222         EXPONENT_TEMPLATE_CLASS_IMPLEMENTATION_TEMPLATE_PARENT(TObjectNuller<TypeName>, TypeName, TPointerDeleter<TypeName>, TypeName);
    00223         EXPONENT_TEMPLATE_CLASS_IMPLEMENTATION_TEMPLATE_PARENT(TCountedObjectDeleter<TypeName>, TypeName, TPointerDeleter<TypeName>, TypeName);
    00224
    00225 //  ===========================================================================
    00226         template<class TypeName> TPointerDeleter<TypeName>::TPointerDeleter()
    00227         {
    00228             EXPONENT_CLASS_CONSTRUCTION(TPointerDeleter<TypeName>);
    00229         }
    00230
    00231 //  ===========================================================================
    00232         template<class TypeName> TPointerDeleter<TypeName>::~TPointerDeleter()
    00233         {
    00234             EXPONENT_CLASS_DESTRUCTION(TPointerDeleter<TypeName>);
    00235         }
    00236
    00237 //  ===========================================================================
    00238         template<class TypeName> TObjectDeleter<TypeName>::TObjectDeleter()
    00239         {
    00240             EXPONENT_CLASS_CONSTRUCTION(TObjectDeleter<TypeName>);
    00241         }
    00242
    00243 //  ===========================================================================
    00244         template<class TypeName> TObjectDeleter<TypeName>::~TObjectDeleter()
    00245         {
    00246             EXPONENT_CLASS_DESTRUCTION(TObjectDeleter<TypeName>);
    00247         }
    00248
    00249 //  ===========================================================================
    00250         template<class TypeName> void TObjectDeleter<TypeName>::deletePointer(TypeName *pointer) const
    00251         {
    00252             FREE_POINTER(pointer);
    00253         }
    00254
    00255 //  ===========================================================================
    00256         template<class TypeName> TObjectNuller<TypeName>::TObjectNuller()
    00257         {
    00258             EXPONENT_CLASS_CONSTRUCTION(TObjectNuller<TypeName>);
    00259         }
    00260
    00261 //  ===========================================================================
    00262         template<class TypeName> TObjectNuller<TypeName>::~TObjectNuller()
    00263         {
    00264             EXPONENT_CLASS_DESTRUCTION(TObjectNuller<TypeName>);
    00265         }
    00266
    00267 //  ===========================================================================
    00268         template<class TypeName> void TObjectNuller<TypeName>::deletePointer(TypeName *pointer) const
    00269         {
    00270             NULL_POINTER(pointer);
    00271         }
    00272
    00273 //  ===========================================================================
    00274         template<class TypeName> TCountedObjectDeleter<TypeName>::TCountedObjectDeleter()
    00275         {
    00276             EXPONENT_CLASS_CONSTRUCTION(TCountedObjectDeleter<TypeName>);
    00277         }
    00278
    00279 //  ===========================================================================
    00280         template<class TypeName> TCountedObjectDeleter<TypeName>::~TCountedObjectDeleter()
    00281         {
    00282             EXPONENT_CLASS_DESTRUCTION(TCountedObjectDeleter<TypeName>);
    00283         }
    00284
    00285 //  ===========================================================================
    00286         template<class TypeName> void TCountedObjectDeleter<TypeName>::pointerAdded(TypeName *pointer) const
    00287         {
    00288             if (pointer)
    00289             {
    00290                 pointer->referenced();
    00291             }
    00292         }
    00293
    00294 //  ===========================================================================
    00295         template<class TypeName> void TCountedObjectDeleter<TypeName>::deletePointer(TypeName *pointer) const
    00296         {
    00297             FORGET_COUNTED_OBJECT(pointer);
    00298         }
    00299
    00301     }
    00302 }
    00303 #endif      // End of TPointerDeleter.hpp