Voxel
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
synchronized_heap_host.h
1 #pragma once
2 
3 #ifndef SYNCHRONIZED_HEAP_HOST_H
4 #define SYNCHRONIZED_HEAP_HOST_H
5 
6 
7 
8 
9 #include "synchronized_heap_base.h"
10 #include "platform.h"
11 
12 #include <boost/shared_ptr.hpp>
13 #include <boost/shared_array.hpp>
14 
15 
16 
17 
18 namespace Synchronized {
19 
20 
21 
22 
23 /*==============================================================================
24  Heap< PLATFORM_HOST > specialization
25 ==============================================================================*/
26 
27 
28 template<>
29 struct Heap< PLATFORM_HOST > {
30 
31  template< typename t_Type >
32  struct Pointer;
33 
34 
35  inline Heap();
36 
37 
38  template< typename t_Type >
39  inline Pointer< t_Type > Allocate() const;
40 
41  template< typename t_Type >
42  inline Pointer< t_Type[] > Allocate( size_t const count ) const;
43 
44 
45  inline void Synchronize() const;
46 
47 
48  template< typename t_Type >
49  struct Pointer : public boost::shared_ptr< t_Type const > {
50 
51  typedef typename boost::shared_ptr< t_Type const >::element_type element_type;
52 
53 
54  inline Pointer();
55  inline Pointer( Pointer const& other );
56 
57 
58  inline void Assign( element_type const& data ) const;
59 
60 
61  private:
62 
63  inline Pointer( t_Type* pointer );
64 
65 
66  friend struct Heap;
67  };
68 
69 
70  template< typename t_Type >
71  struct Pointer< t_Type[] > : public boost::shared_array< t_Type const > { // **TODO: in boost 1.53+, shared_ptr< t_Type[] > can substitute for shared_array< t_Type >
72 
73  typedef typename boost::shared_ptr< t_Type const >::element_type element_type;
74 
75 
76  inline Pointer();
77  inline Pointer( Pointer const& other );
78 
79 
80  inline void Assign( size_t const index, element_type const& data ) const;
81 
82 
83  private:
84 
85  inline Pointer( t_Type* array );
86 
87 
88  friend struct Heap;
89  };
90 };
91 
92 
93 
94 
95 /*==============================================================================
96  Heap< PLATFORM_HOST >::Pointer methods
97 ==============================================================================*/
98 
99 
100 template< typename t_Type >
101 Heap< PLATFORM_HOST >::Pointer< t_Type >::Pointer() {
102 }
103 
104 
105 template< typename t_Type >
106 Heap< PLATFORM_HOST >::Pointer< t_Type >::Pointer( Pointer const& other ) : boost::shared_ptr< t_Type const >( other ) {
107 }
108 
109 
110 template< typename t_Type >
111 void Heap< PLATFORM_HOST >::Pointer< t_Type >::Assign( element_type const& data ) const {
112 
113  *const_cast< t_Type* >( boost::shared_ptr< t_Type const >::get() ) = data;
114 }
115 
116 
117 template< typename t_Type >
118 Heap< PLATFORM_HOST >::Pointer< t_Type >::Pointer( t_Type* pointer ) : boost::shared_ptr< t_Type const >( pointer ) {
119 }
120 
121 
122 template< typename t_Type >
123 Heap< PLATFORM_HOST >::Pointer< t_Type[] >::Pointer() {
124 }
125 
126 
127 template< typename t_Type >
128 Heap< PLATFORM_HOST >::Pointer< t_Type[] >::Pointer( Pointer const& other ) : boost::shared_array< t_Type const >( other ) {
129 }
130 
131 
132 template< typename t_Type >
133 void Heap< PLATFORM_HOST >::Pointer< t_Type[] >::Assign( size_t const index, element_type const& data ) const {
134 
135  *const_cast< t_Type* >( boost::shared_array< t_Type const >::get() + index ) = data;
136 }
137 
138 
139 template< typename t_Type >
140 Heap< PLATFORM_HOST >::Pointer< t_Type[] >::Pointer( t_Type* array ) : boost::shared_array< t_Type const >( array ) {
141 }
142 
143 
144 
145 
146 /*==============================================================================
147  Heap< PLATFORM_HOST > methods
148 ==============================================================================*/
149 
150 
151 Heap< PLATFORM_HOST >::Heap() {
152 }
153 
154 
155 template< typename t_Type >
156 Heap< PLATFORM_HOST >::Pointer< t_Type > Heap< PLATFORM_HOST >::Allocate() const {
157 
158  return Pointer< t_Type >( new t_Type );
159 }
160 
161 
162 template< typename t_Type >
163 Heap< PLATFORM_HOST >::Pointer< t_Type[] > Heap< PLATFORM_HOST >::Allocate( size_t const size ) const {
164 
165  return Pointer< t_Type[] >( new t_Type[ size ] );
166 }
167 
168 
169 void Heap< PLATFORM_HOST >::Synchronize() const {
170 }
171 
172 
173 
174 
175 } // namespace Synchronized
176 
177 
178 
179 
180 #endif // SYNCHRONIZED_HEAP_HOST_H