Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:06

0001 // Copyright 2002 The Trustees of Indiana University.
0002 
0003 // Use, modification and distribution is subject to the Boost Software 
0004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 //  Boost.MultiArray Library
0008 //  Authors: Ronald Garcia
0009 //           Jeremy Siek
0010 //           Andrew Lumsdaine
0011 //  See http://www.boost.org/libs/multi_array for documentation.
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   // RG - This is to make things work with VC++. So sad, so sad.
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     // RG - ideally these would not be necessary, but some compilers
0044     // don't like template conversion operators.  I suspect that not
0045     // too many folk will feel the need to use customized
0046     // storage_order objects, I sacrifice that feature for compiler support.
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     // This is the idiom for creating your own custom storage orders.
0084     // Not supported by all compilers though!
0085 #ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
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     // This is the idiom for creating your own custom storage orders.
0106     // Not supported by all compilers though! 
0107 #ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
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 } // namespace boost
0124 
0125 #endif