File indexing completed on 2025-01-18 09:42:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_MULTI_ARRAY_STORAGE_ORDER_HPP
0014 #define BOOST_MULTI_ARRAY_STORAGE_ORDER_HPP
0015
0016 #include "boost/multi_array/types.hpp"
0017 #include "boost/array.hpp"
0018 #include "boost/multi_array/algorithm.hpp"
0019 #include <algorithm>
0020 #include <cstddef>
0021 #include <functional>
0022 #include <numeric>
0023 #include <vector>
0024
0025 namespace boost {
0026
0027
0028 class c_storage_order;
0029 class fortran_storage_order;
0030
0031 template <std::size_t NumDims>
0032 class general_storage_order
0033 {
0034 public:
0035 typedef detail::multi_array::size_type size_type;
0036 template <typename OrderingIter, typename AscendingIter>
0037 general_storage_order(OrderingIter ordering,
0038 AscendingIter ascending) {
0039 boost::detail::multi_array::copy_n(ordering,NumDims,ordering_.begin());
0040 boost::detail::multi_array::copy_n(ascending,NumDims,ascending_.begin());
0041 }
0042
0043
0044
0045
0046
0047 general_storage_order(const c_storage_order&) {
0048 for (size_type i=0; i != NumDims; ++i) {
0049 ordering_[i] = NumDims - 1 - i;
0050 }
0051 ascending_.assign(true);
0052 }
0053
0054 general_storage_order(const fortran_storage_order&) {
0055 for (size_type i=0; i != NumDims; ++i) {
0056 ordering_[i] = i;
0057 }
0058 ascending_.assign(true);
0059 }
0060
0061 size_type ordering(size_type dim) const { return ordering_[dim]; }
0062 bool ascending(size_type dim) const { return ascending_[dim]; }
0063
0064 bool all_dims_ascending() const {
0065 return std::accumulate(ascending_.begin(),ascending_.end(),true,
0066 std::logical_and<bool>());
0067 }
0068
0069 bool operator==(general_storage_order const& rhs) const {
0070 return (ordering_ == rhs.ordering_) &&
0071 (ascending_ == rhs.ascending_);
0072 }
0073
0074 protected:
0075 boost::array<size_type,NumDims> ordering_;
0076 boost::array<bool,NumDims> ascending_;
0077 };
0078
0079 class c_storage_order
0080 {
0081 typedef detail::multi_array::size_type size_type;
0082 public:
0083
0084
0085 #ifndef __MWERKS__
0086 template <std::size_t NumDims>
0087 operator general_storage_order<NumDims>() const {
0088 boost::array<size_type,NumDims> ordering;
0089 boost::array<bool,NumDims> ascending;
0090
0091 for (size_type i=0; i != NumDims; ++i) {
0092 ordering[i] = NumDims - 1 - i;
0093 ascending[i] = true;
0094 }
0095 return general_storage_order<NumDims>(ordering.begin(),
0096 ascending.begin());
0097 }
0098 #endif
0099 };
0100
0101 class fortran_storage_order
0102 {
0103 typedef detail::multi_array::size_type size_type;
0104 public:
0105
0106
0107 #ifndef __MWERKS__
0108 template <std::size_t NumDims>
0109 operator general_storage_order<NumDims>() const {
0110 boost::array<size_type,NumDims> ordering;
0111 boost::array<bool,NumDims> ascending;
0112
0113 for (size_type i=0; i != NumDims; ++i) {
0114 ordering[i] = i;
0115 ascending[i] = true;
0116 }
0117 return general_storage_order<NumDims>(ordering.begin(),
0118 ascending.begin());
0119 }
0120 #endif
0121 };
0122
0123 }
0124
0125 #endif