epoc32/include/stdapis/boost/multi_array/index_range.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/multi_array/index_range.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,188 @@
     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_INDEX_RANGE_RG071801_HPP
    1.17 +#define BOOST_INDEX_RANGE_RG071801_HPP
    1.18 +
    1.19 +#include <boost/config.hpp>
    1.20 +#include <utility>
    1.21 +#include <boost/limits.hpp>
    1.22 +
    1.23 +// For representing intervals, also with stride.
    1.24 +// A degenerate range is a range with one element.
    1.25 +
    1.26 +// Thanks to Doug Gregor for the really cool idea of using the
    1.27 +// comparison operators to express various interval types!
    1.28 +
    1.29 +// Internally, we represent the interval as half-open.
    1.30 +
    1.31 +namespace boost {
    1.32 +namespace detail {
    1.33 +namespace multi_array {
    1.34 +
    1.35 +  template <typename Index,typename SizeType>
    1.36 +  class index_range {
    1.37 +  public:
    1.38 +    typedef Index index;
    1.39 +    typedef SizeType size_type;
    1.40 +
    1.41 +  private:
    1.42 +    static index from_start()
    1.43 +      { return (std::numeric_limits<index>::min)(); }
    1.44 +
    1.45 +    static index to_end()
    1.46 +      { return (std::numeric_limits<index>::max)(); }
    1.47 +
    1.48 +  public:
    1.49 +
    1.50 +    index_range()
    1.51 +    {
    1.52 +      start_ = from_start();
    1.53 +      finish_ = to_end();
    1.54 +      stride_ = 1;
    1.55 +      degenerate_ = false;
    1.56 +    }
    1.57 +
    1.58 +    explicit index_range(index pos)
    1.59 +    {
    1.60 +      start_ = pos;
    1.61 +      finish_ = pos+1;
    1.62 +      stride_ = 1;
    1.63 +      degenerate_ = true;
    1.64 +    }
    1.65 +
    1.66 +    explicit index_range(index start, index finish, index stride=1)
    1.67 +      : start_(start), finish_(finish), stride_(stride),
    1.68 +        degenerate_(false)
    1.69 +    { }
    1.70 +
    1.71 +
    1.72 +    // These are for chaining assignments to an index_range
    1.73 +    index_range& start(index s) {
    1.74 +      start_ = s;
    1.75 +      degenerate_ = false;
    1.76 +      return *this;
    1.77 +    }
    1.78 +
    1.79 +    index_range& finish(index f) {
    1.80 +      finish_ = f;
    1.81 +      degenerate_ = false;
    1.82 +      return *this;
    1.83 +    }
    1.84 +
    1.85 +    index_range& stride(index s) { stride_ = s; return *this; }
    1.86 +
    1.87 +    index start() const
    1.88 +    { 
    1.89 +      return start_; 
    1.90 +    }
    1.91 +
    1.92 +    index get_start(index low_index_range = index_range::from_start()) const
    1.93 +    { 
    1.94 +      if (start_ == from_start())
    1.95 +        return low_index_range;
    1.96 +      return start_; 
    1.97 +    }
    1.98 +
    1.99 +    index finish() const
   1.100 +    {
   1.101 +      return finish_;
   1.102 +    }
   1.103 +
   1.104 +    index get_finish(index high_index_range = index_range::to_end()) const
   1.105 +    {
   1.106 +      if (finish_ == to_end())
   1.107 +        return high_index_range;
   1.108 +      return finish_;
   1.109 +    }
   1.110 +
   1.111 +    index stride() const { return stride_; }
   1.112 +
   1.113 +    void set_index_range(index start, index finish, index stride=1)
   1.114 +    {
   1.115 +      start_ = start;
   1.116 +      finish_ = finish;
   1.117 +      stride_ = stride;
   1.118 +    }
   1.119 +
   1.120 +    static index_range all() 
   1.121 +    { return index_range(from_start(), to_end(), 1); }
   1.122 +
   1.123 +    bool is_degenerate() const { return degenerate_; }
   1.124 +
   1.125 +    index_range operator-(index shift) const
   1.126 +    { 
   1.127 +      return index_range(start_ - shift, finish_ - shift, stride_); 
   1.128 +    }
   1.129 +
   1.130 +    index_range operator+(index shift) const
   1.131 +    { 
   1.132 +      return index_range(start_ + shift, finish_ + shift, stride_); 
   1.133 +    }
   1.134 +
   1.135 +    index operator[](unsigned i) const
   1.136 +    {
   1.137 +      return start_ + i * stride_;
   1.138 +    }
   1.139 +
   1.140 +    index operator()(unsigned i) const
   1.141 +    {
   1.142 +      return start_ + i * stride_;
   1.143 +    }
   1.144 +
   1.145 +    // add conversion to std::slice?
   1.146 +
   1.147 +  public:
   1.148 +    index start_, finish_, stride_;
   1.149 +    bool degenerate_;
   1.150 +  };
   1.151 +
   1.152 +  // Express open and closed interval end-points using the comparison
   1.153 +  // operators.
   1.154 +
   1.155 +  // left closed
   1.156 +  template <typename Index, typename SizeType>
   1.157 +  inline index_range<Index,SizeType>
   1.158 +  operator<=(Index s, const index_range<Index,SizeType>& r)
   1.159 +  {
   1.160 +    return index_range<Index,SizeType>(s, r.finish(), r.stride());
   1.161 +  }
   1.162 +
   1.163 +  // left open
   1.164 +  template <typename Index, typename SizeType>
   1.165 +  inline index_range<Index,SizeType>
   1.166 +  operator<(Index s, const index_range<Index,SizeType>& r)
   1.167 +  {
   1.168 +    return index_range<Index,SizeType>(s + 1, r.finish(), r.stride());
   1.169 +  }
   1.170 +
   1.171 +  // right open
   1.172 +  template <typename Index, typename SizeType>
   1.173 +  inline index_range<Index,SizeType>
   1.174 +  operator<(const index_range<Index,SizeType>& r, Index f)
   1.175 +  {
   1.176 +    return index_range<Index,SizeType>(r.start(), f, r.stride());
   1.177 +  }
   1.178 +
   1.179 +  // right closed
   1.180 +  template <typename Index, typename SizeType>
   1.181 +  inline index_range<Index,SizeType>
   1.182 +  operator<=(const index_range<Index,SizeType>& r, Index f)
   1.183 +  {
   1.184 +    return index_range<Index,SizeType>(r.start(), f + 1, r.stride());
   1.185 +  }
   1.186 +
   1.187 +} // namespace multi_array
   1.188 +} // namespace detail  
   1.189 +} // namespace boost
   1.190 +
   1.191 +#endif // BOOST_INDEX_RANGE_RG071801_HPP