00001 /* 00002 FALCON - The Falcon Programming Language. 00003 FILE: flc_allocator.h 00004 00005 Standard falcon allocator. 00006 ------------------------------------------------------------------- 00007 Author: Giancarlo Niccolai 00008 Begin: mar ago 3 2004 00009 00010 ------------------------------------------------------------------- 00011 (C) Copyright 2004: the FALCON developers (see list in AUTHORS file) 00012 00013 See LICENSE file for licensing details. 00014 */ 00015 00016 #ifndef flc_ALLOCATOR_H 00017 #define flc_ALLOCATOR_H 00018 00019 #include <falcon/memory.h> 00020 00021 namespace Falcon { 00022 00027 template<class _Tp> 00028 class Allocator 00029 { 00030 public: 00031 typedef size_t size_type; 00032 typedef ptrdiff_t difference_type; 00033 typedef _Tp* pointer; 00034 typedef const _Tp* const_pointer; 00035 typedef _Tp& reference; 00036 typedef const _Tp& const_reference; 00037 typedef _Tp value_type; 00038 00039 template<typename _Tp1> 00040 struct rebind 00041 { typedef Allocator<_Tp1> other; }; 00042 00043 Allocator() throw() {} 00044 //Allocator(const Allocator&) throw() {} 00045 template<typename _Tp1> 00046 Allocator(const Allocator<_Tp1>&) throw() {} 00047 ~Allocator() throw() {} 00048 00049 pointer 00050 address(reference __x) const { return &__x; } 00051 00052 const_pointer 00053 address(const_reference __x) const { return &__x; } 00054 00055 size_type max_size() const throw() { return size_t(-1) / sizeof(_Tp); } 00056 00057 void construct(pointer __p, const _Tp& __val) { new(__p) _Tp(__val); } 00058 void destroy(pointer __p) { __p->~_Tp(); } 00059 00060 00061 _Tp* allocate( size_type n, const void* = 0 ) 00062 { 00063 return reinterpret_cast<_Tp*>( memAlloc( n * sizeof( _Tp ) ) ); 00064 } 00065 00066 void deallocate( _Tp* p, size_type n ) 00067 { 00068 memFree( p ); 00069 } 00070 00071 #ifdef _MSC_VER 00072 void deallocate( void* p, size_type n ) 00073 { 00074 memFree( p ); 00075 } 00076 _Tp* _Charalloc( size_type n ) 00077 { 00078 return allocate( n ); 00079 } 00080 #endif 00081 }; 00082 00083 template <class T1, class T2> 00084 bool operator== (const Allocator<T1>& one, 00085 const Allocator<T2>& two) throw() { 00086 if ( &one == &two ) return true; 00087 return false; 00088 } 00089 00090 template <class T1, class T2> 00091 bool operator!= (const Allocator<T1>& one, 00092 const Allocator<T2>& two) throw() { 00093 if ( &one == &two ) return false; 00094 } 00095 00096 } 00097 00098 #endif 00099 /* end of flc_allocator.h */