TuttleOFX  1
OfxAllocator.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_PLUGIN_OFXALLOCATOR_HPP_
00002 #define _TUTTLE_PLUGIN_OFXALLOCATOR_HPP_
00003 
00004 #include <tuttle/plugin/global.hpp>
00005 
00006 #include <ofxsMemory.h>
00007 
00008 #include <vector>
00009 #include <list>
00010 #include <string>
00011 #include <iostream>
00012 #include <sstream>
00013 
00014 namespace tuttle {
00015 namespace plugin {
00016 
00017 template <typename T>
00018 class OfxAllocator
00019 {
00020 static int size_all;
00021 
00022 public:
00023         typedef T Type;
00024         typedef size_t size_type;
00025         typedef ptrdiff_t difference_type;
00026         typedef T* pointer;
00027         typedef const T* const_pointer;
00028         typedef T& reference;
00029         typedef const T& const_reference;
00030         typedef T value_type;
00031 
00032 public:
00033         OfxAllocator() {}
00034         OfxAllocator( const OfxAllocator& ) {}
00035         template <class U>
00036         OfxAllocator( const OfxAllocator<U>& ) {}
00037 
00038 public:
00039         pointer allocate( const size_type n, const void* = 0 )
00040         {
00041                 ++size_all;
00042                 //TUTTLE_TLOG( TUTTLE_TRACE, "Use OfxAllocator to allocate" );
00043                 T* t = static_cast<T*>( OFX::memory::allocate( n * sizeof( T ) /*, ImageEffect* handle = 0*/ ) );
00044                 //              T* t = (T*) malloc( n * sizeof(T) );
00045                 //TUTTLE_TLOG( TUTTLE_TRACE, "allocate done (address:" << t << ") (+" << n << ") " << size_all );
00046                 return t;
00047         }
00048 
00049         void deallocate( void* ptr, size_type )
00050         {
00051                 --size_all;
00052                 //TUTTLE_TLOG( TUTTLE_TRACE, "Use OfxAllocator to deallocate (address:" << ptr << ") (-)" << size_all );
00053                 OFX::memory::free( ptr );
00054                 //free( ptr );
00055                 //TUTTLE_TLOG( TUTTLE_TRACE, "deallocate done." );
00056         }
00057 
00058         void construct( pointer p, const T& val ) { new ( (T*) p )T( val ); }
00059 
00060         void destroy( pointer p ) { p->~T(); }
00061 
00062         template <class U>
00063         struct rebind
00064         {
00065                 typedef OfxAllocator<U> other;
00066         };
00067 
00068         OfxAllocator<T>& operator=( const OfxAllocator& ) { return *this; }
00069 
00070         template <class U>
00071         OfxAllocator& operator=( const OfxAllocator<U>& ) { return *this; }
00072 
00073         pointer       address( reference x ) const       { return &x; }
00074         const_pointer address( const_reference x ) const { return &x; }
00075 
00076         size_type max_size() const { return size_t( -1 ); }
00077 };
00078 
00079 template <typename T>
00080 int OfxAllocator<T>::size_all = 0;
00081 
00082 }
00083 }
00084 
00085 #endif
00086