1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/multi_array/storage_order.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,125 @@
1.4 +// Copyright 2002 The Trustees of Indiana University.
1.5 +
1.6 +// Use, modification and distribution is subject to the Boost Software
1.7 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.8 +// http://www.boost.org/LICENSE_1_0.txt)
1.9 +
1.10 +// Boost.MultiArray Library
1.11 +// Authors: Ronald Garcia
1.12 +// Jeremy Siek
1.13 +// Andrew Lumsdaine
1.14 +// See http://www.boost.org/libs/multi_array for documentation.
1.15 +
1.16 +#ifndef BOOST_STORAGE_ORDER_RG071801_HPP
1.17 +#define BOOST_STORAGE_ORDER_RG071801_HPP
1.18 +
1.19 +#include "boost/multi_array/types.hpp"
1.20 +#include "boost/array.hpp"
1.21 +#include "boost/multi_array/algorithm.hpp"
1.22 +#include <algorithm>
1.23 +#include <cstddef>
1.24 +#include <functional>
1.25 +#include <numeric>
1.26 +#include <vector>
1.27 +
1.28 +namespace boost {
1.29 +
1.30 + // RG - This is to make things work with VC++. So sad, so sad.
1.31 + class c_storage_order;
1.32 + class fortran_storage_order;
1.33 +
1.34 + template <std::size_t NumDims>
1.35 + class general_storage_order
1.36 + {
1.37 + public:
1.38 + typedef detail::multi_array::size_type size_type;
1.39 + template <typename OrderingIter, typename AscendingIter>
1.40 + general_storage_order(OrderingIter ordering,
1.41 + AscendingIter ascending) {
1.42 + boost::detail::multi_array::copy_n(ordering,NumDims,ordering_.begin());
1.43 + boost::detail::multi_array::copy_n(ascending,NumDims,ascending_.begin());
1.44 + }
1.45 +
1.46 + // RG - ideally these would not be necessary, but some compilers
1.47 + // don't like template conversion operators. I suspect that not
1.48 + // too many folk will feel the need to use customized
1.49 + // storage_order objects, I sacrifice that feature for compiler support.
1.50 + general_storage_order(const c_storage_order&) {
1.51 + for (size_type i=0; i != NumDims; ++i) {
1.52 + ordering_[i] = NumDims - 1 - i;
1.53 + }
1.54 + ascending_.assign(true);
1.55 + }
1.56 +
1.57 + general_storage_order(const fortran_storage_order&) {
1.58 + for (size_type i=0; i != NumDims; ++i) {
1.59 + ordering_[i] = i;
1.60 + }
1.61 + ascending_.assign(true);
1.62 + }
1.63 +
1.64 + size_type ordering(size_type dim) const { return ordering_[dim]; }
1.65 + bool ascending(size_type dim) const { return ascending_[dim]; }
1.66 +
1.67 + bool all_dims_ascending() const {
1.68 + return std::accumulate(ascending_.begin(),ascending_.end(),true,
1.69 + std::logical_and<bool>());
1.70 + }
1.71 +
1.72 + bool operator==(general_storage_order const& rhs) const {
1.73 + return (ordering_ == rhs.ordering_) &&
1.74 + (ascending_ == rhs.ascending_);
1.75 + }
1.76 +
1.77 + protected:
1.78 + boost::array<size_type,NumDims> ordering_;
1.79 + boost::array<bool,NumDims> ascending_;
1.80 + };
1.81 +
1.82 + class c_storage_order
1.83 + {
1.84 + typedef detail::multi_array::size_type size_type;
1.85 + public:
1.86 + // This is the idiom for creating your own custom storage orders.
1.87 + // Not supported by all compilers though!
1.88 +#ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
1.89 + template <std::size_t NumDims>
1.90 + operator general_storage_order<NumDims>() const {
1.91 + boost::array<size_type,NumDims> ordering;
1.92 + boost::array<bool,NumDims> ascending;
1.93 +
1.94 + for (size_type i=0; i != NumDims; ++i) {
1.95 + ordering[i] = NumDims - 1 - i;
1.96 + ascending[i] = true;
1.97 + }
1.98 + return general_storage_order<NumDims>(ordering.begin(),
1.99 + ascending.begin());
1.100 + }
1.101 +#endif
1.102 + };
1.103 +
1.104 + class fortran_storage_order
1.105 + {
1.106 + typedef detail::multi_array::size_type size_type;
1.107 + public:
1.108 + // This is the idiom for creating your own custom storage orders.
1.109 + // Not supported by all compilers though!
1.110 +#ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
1.111 + template <std::size_t NumDims>
1.112 + operator general_storage_order<NumDims>() const {
1.113 + boost::array<size_type,NumDims> ordering;
1.114 + boost::array<bool,NumDims> ascending;
1.115 +
1.116 + for (size_type i=0; i != NumDims; ++i) {
1.117 + ordering[i] = i;
1.118 + ascending[i] = true;
1.119 + }
1.120 + return general_storage_order<NumDims>(ordering.begin(),
1.121 + ascending.begin());
1.122 + }
1.123 +#endif
1.124 + };
1.125 +
1.126 +} // namespace boost
1.127 +
1.128 +#endif // BOOST_ARRAY_STORAGE_RG071801_HPP