Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MYGUI_CUSTOM_ALLOCATOR_H__
00024 #define __MYGUI_CUSTOM_ALLOCATOR_H__
00025
00026 #include <memory>
00027 #include <limits>
00028
00029
00030 #include <OgrePrerequisites.h>
00031
00032 #if OGRE_VERSION < MYGUI_DEFINE_VERSION(1, 6, 0)
00033 #include <OgreMemoryManager.h>
00034 #include <OgreNoMemoryMacros.h>
00035 #endif
00036
00037 namespace MyGUI
00038 {
00039
00040 template<typename T>
00041 class Allocator
00042 {
00043 public :
00044
00045 typedef T value_type;
00046 typedef value_type* pointer;
00047 typedef const value_type* const_pointer;
00048 typedef value_type& reference;
00049 typedef const value_type& const_reference;
00050 typedef std::size_t size_type;
00051 typedef std::ptrdiff_t difference_type;
00052
00053 public :
00054
00055 template<typename U>
00056 struct rebind
00057 {
00058 typedef Allocator<U> other;
00059 };
00060
00061 public :
00062 inline explicit Allocator() { }
00063 inline ~Allocator() { }
00064 template<typename U>
00065 inline explicit Allocator(Allocator<U> const&) { }
00066
00067
00068 inline pointer address(reference r) { return &r; }
00069 inline const_pointer address(const_reference r) { return &r; }
00070
00071
00072 inline pointer allocate(size_type cnt, typename std::allocator<void>::const_pointer = 0)
00073 {
00074 return reinterpret_cast<pointer>(::operator new(cnt * sizeof (T)));
00075 }
00076 inline void deallocate(pointer p, size_type)
00077 {
00078 ::operator delete(p);
00079 }
00080
00081
00082 inline size_type max_size() const
00083 {
00084 return std::numeric_limits<size_type>::max() / sizeof(T);
00085 }
00086
00087
00088 inline void construct(pointer p, const T& t) { new(p) T(t); }
00089 inline void destroy(pointer p) { p->~T(); }
00090
00091 inline bool operator==(Allocator const&) { return true; }
00092 inline bool operator!=(Allocator const& a) { return !operator==(a); }
00093 };
00094
00095 }
00096
00097 #if OGRE_VERSION < MYGUI_DEFINE_VERSION(1, 6, 0)
00098 #include <OgreMemoryMacros.h>
00099 #endif
00100
00101 #endif // __MYGUI_CUSTOM_ALLOCATOR_H__