Toolkit.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 1996-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00019 #ifndef _DWFTK_TOOLKIT_H
00020 #define _DWFTK_TOOLKIT_H
00021 
00022 
00027 
00028 #include "dwfcore/Core.h"
00029 #include "dwfcore/STL.h"
00030 
00031 #ifdef  HAVE_CONFIG_H
00032 #include "dwf/config.h"
00033 #endif
00034 
00035 
00036 #ifndef DWFTK_STATIC
00037 
00038 #ifdef  _DWFCORE_WIN32_SYSTEM
00039 #ifdef  DWFTK_EXPORT_API
00040 #define _DWFTK_API          __declspec( dllexport )
00041 #else
00042 #define _DWFTK_API          __declspec( dllimport )
00043 #endif
00044 #else
00045 #define _DWFTK_API
00046 #endif
00047 
00048 #else
00049 #define _DWFTK_API
00050 
00051 #ifndef BSTREAM_STATIC_LIB
00052 #define BSTREAM_STATIC_LIB
00053 #endif
00054 
00055 #endif
00056 
00063 #define _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE
00064 #define _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00065 
00066 #ifndef DWFTK_STATIC
00067 
00068 #undef  _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE
00069 #undef  _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00070 
00071 #define _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE           : virtual public _DWFToolkitMemory
00072 #define _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER    , virtual public _DWFToolkitMemory
00073 
00074 
00075 namespace DWFToolkit
00076 {
00090     class _DWFTK_API _DWFToolkitMemory
00091     {
00092         public:
00093 
00097             void* operator new( size_t );
00098 
00102             void* operator new( size_t, void* );
00103 
00107             void  operator delete( void* );
00108 
00112             void  operator delete( void*, void* );
00113     };
00114 }
00115 
00116 #endif
00117 
00118 
00131 
00132 #ifdef DWFTK_USE_SYSTEM_STL_ALLOCATOR
00133 # define _DWFTK_STL_ALLOCATOR std::allocator
00134 #else
00135 # define _DWFTK_STL_ALLOCATOR DWFTK_STL_Allocator
00136 #endif
00137 
00138 namespace DWFToolkit
00139 {
00151     template<class T >
00152     class DWFTK_STL_Allocator
00153             : public std::allocator<T>
00154             _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00155     {
00156     public:
00157         typedef std::allocator<T>                   _Mybase;
00158         typedef typename _Mybase::value_type        value_type;
00159         typedef typename _Mybase::pointer           pointer;
00160         typedef typename _Mybase::reference         reference;
00161         typedef typename _Mybase::const_pointer     const_pointer;
00162         typedef typename _Mybase::const_reference   const_reference;
00163 
00164         typedef typename _Mybase::size_type         size_type;
00165         typedef typename _Mybase::difference_type   difference_type;
00166 
00167         template<class _Other>
00168             struct rebind
00169             {    // convert a DWFTK_STL_Allocator<_Ty> to a DWFTK_STL_Allocator <_Other>
00170                 typedef DWFTK_STL_Allocator<_Other> other;
00171             };
00172 
00173         inline DWFTK_STL_Allocator() {}
00174         inline ~DWFTK_STL_Allocator() {}
00175         inline DWFTK_STL_Allocator( const DWFTK_STL_Allocator& ) {}
00176         template<typename U>
00177         inline DWFTK_STL_Allocator( const DWFTK_STL_Allocator<U>& ) {}
00178 
00179         /*
00180         template<class _Other>
00181         DWFTK_STL_Allocator<T>& operator=(const DWFTK_STL_Allocator<_Other>&)
00182         {   // assign from a related allocator (do nothing)
00183             return (*this);
00184         }
00185         */
00186 
00187         //
00188         // Intentionally not using DWFCORE_ALLOC, for a few reasons:
00189         //   - DWFCORE_ALLOC_OBJECT doesn't work for this size_t variant of new.
00190         //   - DWFCORE_ALLOC_MEMORY causes random crashes in delete.
00191         //   - We *really* want to be sure to alloc & delete in the same dll,
00192         //     so we're using operator new & delete.
00193         //
00194         pointer allocate( size_type n )
00195         {
00196             size_t nBytes = n * sizeof (T);
00197             return ((pointer) operator new (nBytes) );
00198         }
00199 
00200         pointer allocate( size_type n, const void* /*q*/ ) // ignore hint
00201         {
00202             return allocate( n );
00203         }
00204 
00205         void deallocate( pointer p, size_type /*n*/ )
00206         {
00207             operator delete( p );
00208         }
00209     };
00210 
00211 #ifdef DWFTK_USE_SYSTEM_STL_ALLOCATOR
00212 # define _DWFTK_STD_VECTOR(type) std::vector<type>
00213 # define _DWFTK_STD_MAP_COMP(type1, type2, comp) std::map<type1, type2, comp > 
00214 # define _DWFTK_STD_MAP(type1, type2) _DWFTK_STD_MAP_COMP(type1, type2, less<type1>)
00215 # define _DWFTK_STD_MULTIMAP_COMP(type1, type2, comp) std::multimap<type1, type2, comp > 
00216 # define _DWFTK_STD_MULTIMAP(type1, type2) _DWFTK_STD_MULTIMAP_COMP(type1, type2, less<type1>)
00217 # define _DWFTK_STD_LIST(type) std::list<type>
00218 #else
00219 # define _DWFTK_STD_VECTOR(type) std::vector<type, _DWFTK_STL_ALLOCATOR<type> >
00220 # define _DWFTK_STD_MAP_COMP(type1, type2, comp) std::map<type1, type2, comp, _DWFTK_STL_ALLOCATOR< std::pair<type1 const, type2> > >
00221 # define _DWFTK_STD_MAP(type1, type2) _DWFTK_STD_MAP_COMP(type1, type2, less<type1>)
00222 # define _DWFTK_STD_MULTIMAP_COMP(type1, type2, comp) std::multimap<type1, type2, comp, _DWFTK_STL_ALLOCATOR< std::pair<type1 const, type2> > > 
00223 # define _DWFTK_STD_MULTIMAP(type1, type2) _DWFTK_STD_MULTIMAP_COMP(type1, type2, less<type1>)
00224 # define _DWFTK_STD_LIST(type) std::list<type, _DWFTK_STL_ALLOCATOR<type> >
00225 #endif
00226 
00227 }
00228 
00229 
00230 #endif
00231 

Generated on Tue Jan 6 22:40:05 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5