OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
storage_order.hpp
1 /*
2  * storage_order.hpp
3  *
4  * Created on: Jul 1, 2018
5  * Author: i-bird
6  */
7 
8 #ifndef STORAGE_ORDER_HPP_
9 #define STORAGE_ORDER_HPP_
10 
11 #include "types.hpp"
12 #include "array_openfpm.hpp"
13 #include "boost/multi_array/algorithm.hpp"
14 #include <algorithm>
15 #include <cstddef>
16 #include <functional>
17 #include <numeric>
18 #include <vector>
19 
20 namespace openfpm
21 {
22 
23 class c_storage_order;
24 class fortran_storage_order;
25 class ofp_storage_order;
26 
27 template <std::size_t NumDims>
29 {
30 public:
31  typedef detail::multi_array::size_type size_type;
32  template <typename OrderingIter, typename AscendingIter>
33  general_storage_order(OrderingIter ordering,
34  AscendingIter ascending) {
35  boost::detail::multi_array::copy_n(ordering,NumDims,ordering_.begin());
36  }
37 
38  // RG - ideally these would not be necessary, but some compilers
39  // don't like template conversion operators. I suspect that not
40  // too many folk will feel the need to use customized
41  // storage_order objects, I sacrifice that feature for compiler support.
43  for (size_type i=0; i != NumDims; ++i) {
44  ordering_[i] = NumDims - 1 - i;
45  }
46  }
47 
49  for (size_type i=0; i != NumDims; ++i) {
50  ordering_[i] = i;
51  }
52  }
53 
55  {
56  ordering_[0] = 0;
57  for (size_type i=1; i != NumDims; ++i)
58  {ordering_[i] = NumDims - i;}
59  }
60 
61  size_type ordering(size_type dim) const { return ordering_[dim]; }
62 
63 
64  bool operator==(general_storage_order const& rhs) const
65  {
66  return (ordering_ == rhs.ordering_);
67  }
68 
69 protected:
71 };
72 
74 {
75  typedef detail::multi_array::size_type size_type;
76 public:
77  // This is the idiom for creating your own custom storage orders.
78  // Not supported by all compilers though!
79 #ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
80  template <std::size_t NumDims>
81  operator general_storage_order<NumDims>() const
82  {
84 
85  ordering[0] = 0;
86  for (size_type i=1; i != NumDims; ++i)
87  {ordering[i] = NumDims - i;}
88  return general_storage_order<NumDims>(ordering.begin());
89  }
90 #endif
91 };
92 
94 {
95  typedef detail::multi_array::size_type size_type;
96 public:
97  // This is the idiom for creating your own custom storage orders.
98  // Not supported by all compilers though!
99 #ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
100  template <std::size_t NumDims>
101  operator general_storage_order<NumDims>() const {
104 
105  for (size_type i=0; i != NumDims; ++i) {
106  ordering[i] = NumDims - 1 - i;
107  }
108  return general_storage_order<NumDims>(ordering.begin());
109  }
110 #endif
111 };
112 
114 {
115  typedef detail::multi_array::size_type size_type;
116 public:
117  // This is the idiom for creating your own custom storage orders.
118  // Not supported by all compilers though!
119 #ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
120  template <std::size_t NumDims>
121  operator general_storage_order<NumDims>() const
122  {
124 
125  for (size_type i=0; i != NumDims; ++i) {
126  ordering[i] = i;
127  }
128  return general_storage_order<NumDims>(ordering.begin());
129  }
130 #endif
131 };
132 
133 } // namespace openfpm
134 
135 
136 #endif /* STORAGE_ORDER_HPP_ */
convert a type into constant type
Definition: aggregate.hpp:292