Protium
Math and Design Features
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
STLAdapter.h
Go to the documentation of this file.
1 #ifndef Protium_STLAdapter_h_
2 #define Protium_STLAdapter_h_
3 
5 
6 
7 namespace Protium{
8  namespace Allocation{
9 
11 
16  template<typename Host, typename AllocType = SmallObjectAllocator<> >
17  class STLAdapter{
18  public:
20  typedef std::size_t size_type;
21 
23  typedef std::ptrdiff_t difference_type;
24 
26  typedef Host* pointer;
27 
29  typedef const Host * const_pointer;
30 
32  typedef Host & reference;
33 
35  typedef const Host & const_reference;
36 
38  typedef Host value_type;
39 
40  typedef Host* hostPointer;
41  typedef const Host* const_hostPointer;
42  typedef Host& hostRef;
43  typedef const Host& const_hostRef;
44 
46  inline STLAdapter() throw() {}
47 
49  inline STLAdapter(const STLAdapter& ) throw() {}
50 
52  template<typename T>
53  inline STLAdapter(const STLAdapter<T>& ) throw() {}
54 
56  inline ~STLAdapter() throw() {}
57 
59  template<typename T>
60  struct rebind{
62  };
63 
65  Host* address(Host& elem) const {return &elem;}
66 
68  const Host* address(const Host& elem) const {return &elem;}
69 
71  Host* allocate(std::size_t count, const void* hint=0){
72  (void)hint;
73  void* p = AllocType::Instance().Allocate(count*sizeof(Host),true );
74  return reinterpret_cast<Host*>(p);
75  }
76 
78  void deallocate(Host* p, std::size_t size){
79  AllocType::Instance().Deallocate(p, size* sizeof(Host));
80  }
81 
83  std::size_t max_size() const throw(){
84  const std::size_t max = std::size_t(-1);
85  const std::size_t bytes = max/sizeof(Host);
86  return bytes;
87  }
88 
90  void construct(Host* p, const Host& value){
91  new(p) Host(value);
92  }
93 
95  void destroy(Host* p){
96  (void)p;
97  p->~Host();
98  }
99  };
100 
102  template<typename Host>
103  inline bool operator == (const STLAdapter<Host>&, const STLAdapter<Host>& ){
104  return true;
105  }
106 
108  template < typename Host >
109  inline bool operator != ( const STLAdapter< Host > & , const STLAdapter< Host > & )
110  {
111  return false;
112  }
113 
114  }
115 }
116 
117 #endif //File Guardian
const Host & const_reference
Const Reference to host type.
Definition: STLAdapter.h:35
STLAdapter(const STLAdapter &)
Copy constructor utilizes nothing.
Definition: STLAdapter.h:49
bool operator!=(const STLAdapter< Host > &, const STLAdapter< Host > &)
Always returns false. Nothing internal.
Definition: STLAdapter.h:109
const Host * const_pointer
Const Pointer to host type.
Definition: STLAdapter.h:29
Host * address(Host &elem) const
Returns the address of the host object.
Definition: STLAdapter.h:65
const Host * address(const Host &elem) const
Returns the const address of the host object.
Definition: STLAdapter.h:68
void construct(Host *p, const Host &value)
Constructs a copy host instance at the pointer.
Definition: STLAdapter.h:90
std::size_t max_size() const
Returns the maximum number of objects that can be allocated at once.
Definition: STLAdapter.h:83
~STLAdapter()
Nothing to destruct.
Definition: STLAdapter.h:56
Host & reference
Reference to host type.
Definition: STLAdapter.h:32
STLAdapter(const STLAdapter< T > &)
Templated copy constructor does nothing.
Definition: STLAdapter.h:53
STLAdapter()
Default constuctor does nothing.
Definition: STLAdapter.h:46
bool operator==(const STLAdapter< Host > &, const STLAdapter< Host > &)
Always returns true. Nothing internal.
Definition: STLAdapter.h:103
std::ptrdiff_t difference_type
Type to be used when calculating distance between pointers.
Definition: STLAdapter.h:23
Host * pointer
Pointer type to host type.
Definition: STLAdapter.h:26
Allocator to be used by STL containers.
Definition: STLAdapter.h:17
Allows Adapters to use each other.
Definition: STLAdapter.h:60
Host * allocate(std::size_t count, const void *hint=0)
Allocates out a host object type.
Definition: STLAdapter.h:71
void deallocate(Host *p, std::size_t size)
Deallocates host objects up to size.
Definition: STLAdapter.h:78
std::size_t size_type
Size to be used in allocation.
Definition: STLAdapter.h:20
void destroy(Host *p)
Destructs the host instance at p.
Definition: STLAdapter.h:95