diff --git a/src/common/factory.hpp b/src/common/factory.hpp index 1adc44e69..c9948fcc6 100644 --- a/src/common/factory.hpp +++ b/src/common/factory.hpp @@ -32,24 +32,6 @@ namespace cinelerra { namespace factory { - /** - * Example NOP Allocator using just the normal C++ memory management. - * The intended use is for a Factory instance to iherit from this class. - * Specialized Allocators typically overload operator new and delete. - */ - class VanillaAllocator {}; - - /** - * Example Allocator using plain C memory management. - */ - class MallocAllocator - { - void* operator new (size_t siz) { return malloc (siz); }; - void operator delete (void* p) { if (p) free (p); }; - }; - - typedef VanillaAllocator DefaultALO; // Allocator facility to be used by default //////////////TODO - /** * Wrapping any object created by the Factory into some smart ptr class. * The Factory class inherits this functionallity, so it can be exchanged @@ -66,12 +48,8 @@ namespace cinelerra protected: SMP wrap (T* product) { return SMP (product); } - public: typedef SMP PType; - - typedef void (*DelHandler) (T* victim); ///< custom deleter function - void setDelHandler (DelHandler) {}; ///< if non-standard deleting is necessary }; @@ -82,38 +60,29 @@ namespace cinelerra * the clients get just a smart-pointer or similar handle to the * created object, which will manage the ownership. * - * The provided default implementation uses just std::auto_ptr, - * but delegates the allocation to cinelerra's backend-layer. - * - * @todo actually do the delgation of memory management instead of using VanillaAllocator! + * The provided default implementation uses just std::auto_ptr. */ template - < class T, // the product to be created - class WR = Wrapper, // used for fabricating the wrapper - class ALO = DefaultALO // Allocator facility to be used + < class T, // the product to be created + class WR = Wrapper // used for fabricating the wrapper > - class Factory : public WR, protected ALO + class Factory : public WR { public: /** Object creating facility. * Intended to be over/written/ with a variant taking - * the appropriate number of parameters and using the - * (privately inherited) functions of the allocator. + * the appropriate number of parameters and maybe + * using some special custom allocator. * Note: non-virtual. */ typename WR::PType operator() () { return wrap (new T ); } - protected: - /** this custom deleter function can be used if the - * operator delete call needs to be in the current scope. - * @see RefcountPtr - */ - static void destroy (T* victim) { delete victim; }; }; + /* -- some example and default instantiiations -- */ using std::tr1::shared_ptr; @@ -125,22 +94,11 @@ namespace cinelerra template class Wrapper > { - protected: - shared_ptr wrap (T* product) { return shared_ptr (product, destroy_ ); } + shared_ptr wrap (T* product) { return shared_ptr (product); } public: typedef shared_ptr PType; - - - Wrapper () : destroy_(&stdDelete) { } - - typedef void (*DelHandler) (T* victim); ///< custom deleter function - void setDelHandler (DelHandler d) { this->destroy_ = d; } ///< custom deleter used by shard_ptr - - private: - DelHandler destroy_; - static void stdDelete (T* victim) { delete victim; }; ///< by default just delete objects normally }; @@ -149,20 +107,11 @@ namespace cinelerra * generating refcounting shared_ptr wrapped Objects. Built upon * the corresponding special intstantiation of the Wrapper template. */ - template - < class T, // the product to be created - class ALO = DefaultALO // Allocator facility to be used - > - class RefcountPtr : public Factory >, ALO> + template + class RefcountPtr : public Factory > > { public: typedef shared_ptr PType; - - /** especially the shared_ptr will use Factory::destroy, - * so it is sufficient to make Factory a friend if the - * Target class to be produced has private ctor/dtors - */ - RefcountPtr() { setDelHandler(&this->destroy); } }; @@ -171,14 +120,14 @@ namespace cinelerra * Creating an implementation subclass and wraps into auto_ptr. */ template - < class T, // Interface class - class TImpl, // Implementation class to be created - class ALO = DefaultALO // Allocator facility to be used + < class T, // Interface class + class TImpl // Implementation class to be created > - class PImplPtr : public Factory, ALO> + class PImplPtr : public Factory > { public: typedef std::auto_ptr PType; + PType operator() (){ return wrap (new TImpl); }; }; diff --git a/tests/components/common/factorytest.cpp b/tests/components/common/factorytest.cpp index 877c9ff8e..d680c9767 100644 --- a/tests/components/common/factorytest.cpp +++ b/tests/components/common/factorytest.cpp @@ -76,6 +76,7 @@ namespace cinelerra } friend class ObjFactory; + friend class std::tr1::_Sp_deleter; public: @@ -116,13 +117,6 @@ namespace cinelerra */ PType operator() (uint param) { return wrap (new TargetObj(param) ); } - ObjFactory () { setDelHandler(&destroy); } - - protected: - /** define a custom deleter function, so the actual destrucor call - * happenes within the scope of ObjFactory, which is friend of TargetObj - */ - static void destroy (TargetObj* victim) { delete victim; }; };