Shiokaze Framework
A research-oriented fluid solver for computer graphics
shared_array3.h
Go to the documentation of this file.
1 /*
2 ** shared_array3.h
3 **
4 ** This is part of Shiokaze, a research-oriented fluid solver for computer graphics.
5 ** Created by Ryoichi Ando <rand@nii.ac.jp> on March 15, 2018.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #ifndef SHKZ_SHARED_ARRAY3_H
26 #define SHKZ_SHARED_ARRAY3_H
27 //
28 #include <typeinfo>
29 #include <functional>
30 #include <cassert>
31 //
32 #include "shared_array_core3.h"
33 #include "array3.h"
34 #include "macarray3.h"
35 //
37 //
39 template<class T> class shared_array3 {
42 public:
53  shared_array3( const shape3 &shape, T initial_value=T(), std::string core_name="" ) {
54  m_array = reinterpret_cast<array3<T> *>(shared_array_core3::borrow_shared(shape,typeid(array3<T>).hash_code(),core_name,
55  []( const shape3 &shape, std::string core_name ) {
57  credit("Shared Array 3D","SharedArray"));
58  return (void *)(new array3<T>(shape,T(),core_name));
59  },
60  []( void *ptr ) {
61  delete reinterpret_cast<array3<T> *>(ptr);
62  }));
63  m_array->clear(initial_value);
64  assert( m_array->shape() == shape );
65  }
74  shared_array3( const typename array3<T>::type3 &type, T initial_value=T() ) : shared_array3(type.shape,initial_value,type.core_name) {
75  m_array->set_type(type);
76  }
83  shared_array3( const array3<T> &array ) : shared_array3(array.type()) {
84  m_array->copy(array);
85  }
91  m_array->clear();
93  }
98  const array3<T>& operator()() const { return *m_array; }
103  array3<T>& operator()() { return *m_array; }
108  array3<T>* operator->() { return get(); }
113  const array3<T>* operator->() const { return get(); }
118  array3<T>* get() { return m_array; }
123  const array3<T>* get() const { return m_array; }
124  //
125 private:
126  array3<T> *m_array;
127 };
128 //
131 template<class T> class shared_macarray3 {
132 public:
143  shared_macarray3( const shape3 &shape, vec3<T> initial_value=vec3<T>(), std::string core_name="" ) {
144  m_array = reinterpret_cast<macarray3<T> *>(shared_array_core3::borrow_shared(shape,typeid(macarray3<T>).hash_code(),core_name,
145  []( const shape3 &shape, std::string core_name ) {
147  credit("Shared MAC Array 3D","SharedMACArray"));
148  return (void *)(new macarray3<T>(shape,T(),core_name));
149  },
150  []( void *ptr ) {
151  delete reinterpret_cast<macarray3<T> *>(ptr);
152  }));
153  assert( m_array->shape() == shape );
154  m_array->clear(initial_value);
155  }
164  shared_macarray3( const typename macarray3<T>::type3 &type, vec3<T> initial_value=vec3<T>() ) : shared_macarray3(type.shape,initial_value,type.core_name) {
165  m_array->set_type(type);
166  }
173  shared_macarray3( const macarray3<T> &array ) : shared_macarray3(array.type()) {
174  m_array->copy(array);
175  }
181  m_array->clear();
183  }
188  const macarray3<T>& operator()() const { return *m_array; }
193  macarray3<T>& operator()() { return *m_array; }
198  macarray3<T>* operator->() { return get(); }
203  const macarray3<T>* operator->() const { return get(); }
208  macarray3<T>* get() { return m_array; }
213  const macarray3<T>* get() const { return m_array; }
214  //
215 private:
216  macarray3<T> *m_array;
217 };
218 //
220 //
221 #endif
222 //
shared_array3::~shared_array3
~shared_array3()
Destructor for shared_array2.
Definition: shared_array3.h:90
shared_macarray3::operator()
macarray3< T > & operator()()
Get the reference to the internal borrowed array.
Definition: shared_array3.h:193
macarray3::type3
Collection of properties of this grid.
Definition: macarray3.h:1043
shared_macarray3::operator->
macarray3< T > * operator->()
Get the pointer to the internal borrowed array.
Definition: shared_array3.h:198
macarray3.h
shared_array3
Storage class that enables sharing pre-allocated arrays.
Definition: shared_array3.h:41
shared_array3::shared_array3
shared_array3(const array3< T > &array)
Borrow a shared array and copy the input.
Definition: shared_array3.h:83
shared_macarray3::operator->
const macarray3< T > * operator->() const
Get the const pointer to the internal borrowed array.
Definition: shared_array3.h:203
shared_array3::shared_array3
shared_array3(const shape3 &shape, T initial_value=T(), std::string core_name="")
Borrow a shared array.
Definition: shared_array3.h:53
shared_macarray3
Storage class that enables sharing pre-allocated arrays for MAC grid.
Definition: shared_array3.h:131
shared_array3::operator()
array3< T > & operator()()
Get the reference to the internal borrowed array.
Definition: shared_array3.h:103
shape3
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
shared_macarray3::shared_macarray3
shared_macarray3(const macarray3< T > &array)
Borrow a shared array and copy the input.
Definition: shared_array3.h:173
shared_macarray3::shared_macarray3
shared_macarray3(const typename macarray3< T >::type3 &type, vec3< T > initial_value=vec3< T >())
Borrow a shared array.
Definition: shared_array3.h:164
shared_array3::get
array3< T > * get()
Get the pointer to the internal borrowed array.
Definition: shared_array3.h:118
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
array3::type3
Collection of properties of this grid.
Definition: array3.h:1821
shared_macarray3::get
macarray3< T > * get()
Get the pointer to the internal borrowed array.
Definition: shared_array3.h:208
shared_macarray3::get
const macarray3< T > * get() const
Get the const pointer to the internal borrowed array.
Definition: shared_array3.h:213
shared_array3::operator->
array3< T > * operator->()
Get the pointer to the internal borrowed array.
Definition: shared_array3.h:108
shared_array_core3.h
array3.h
shared_macarray3::operator()
const macarray3< T > & operator()() const
Get the const reference to the internal borrowed array.
Definition: shared_array3.h:188
configurable::get_global_configuration
static configuration & get_global_configuration()
Get the global settings of the program.
shared_macarray3::shared_macarray3
shared_macarray3(const shape3 &shape, vec3< T > initial_value=vec3< T >(), std::string core_name="")
Borrow a shared MAC array.
Definition: shared_array3.h:143
configuration::auto_group
Class that automates the push and pop groups.
Definition: configuration.h:107
shared_macarray3::~shared_macarray3
~shared_macarray3()
Destructor for shared_macarray2.
Definition: shared_array3.h:180
shared_array_core3::return_shared
static void return_shared(void *array)
Return a borrowed array.
vec
Fixed sized vector structure.
Definition: vec.h:38
shared_array_core3::borrow_shared
static void * borrow_shared(const shape3 &shape, size_t class_hash, std::string core_name, std::function< void *(const shape3 &shape, std::string core_name)> alloc_func, std::function< void(void *ptr)> dealloc_func)
Borrow a shared array.
credit
Class that defines the name, argument name, author's name, email address, date and the version of the...
Definition: credit.h:47
shared_array3::operator->
const array3< T > * operator->() const
Get the const pointer to the internal borrowed array.
Definition: shared_array3.h:113
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
macarray3
Three dimensional staggered grid class designed to be defined as instance member in recursive_configu...
Definition: macarray3.h:37
shared_array3::operator()
const array3< T > & operator()() const
Get the const reference to the internal borrowed array.
Definition: shared_array3.h:98
shared_array3::get
const array3< T > * get() const
Get the const pointer to the internal borrowed array.
Definition: shared_array3.h:123
shared_array3::shared_array3
shared_array3(const typename array3< T >::type3 &type, T initial_value=T())
Borrow a shared array.
Definition: shared_array3.h:74
array3
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42