Chris@16
|
1 // Copyright 2002 The Trustees of Indiana University.
|
Chris@16
|
2
|
Chris@16
|
3 // Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 // Boost.MultiArray Library
|
Chris@16
|
8 // Authors: Ronald Garcia
|
Chris@16
|
9 // Jeremy Siek
|
Chris@16
|
10 // Andrew Lumsdaine
|
Chris@16
|
11 // See http://www.boost.org/libs/multi_array for documentation.
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_EXTENT_GEN_RG071801_HPP
|
Chris@16
|
14 #define BOOST_EXTENT_GEN_RG071801_HPP
|
Chris@16
|
15
|
Chris@16
|
16 #include "boost/multi_array/extent_range.hpp"
|
Chris@16
|
17 #include "boost/multi_array/range_list.hpp"
|
Chris@16
|
18 #include "boost/multi_array/types.hpp"
|
Chris@16
|
19 #include "boost/array.hpp"
|
Chris@16
|
20 #include <algorithm>
|
Chris@16
|
21
|
Chris@16
|
22 namespace boost {
|
Chris@16
|
23 namespace detail {
|
Chris@16
|
24 namespace multi_array {
|
Chris@16
|
25
|
Chris@16
|
26
|
Chris@16
|
27 template <std::size_t NumRanges>
|
Chris@16
|
28 class extent_gen {
|
Chris@16
|
29 public:
|
Chris@16
|
30 typedef boost::detail::multi_array::index index;
|
Chris@16
|
31 typedef boost::detail::multi_array::size_type size_type;
|
Chris@16
|
32 typedef extent_range<index,size_type> range;
|
Chris@16
|
33 private:
|
Chris@16
|
34 typedef typename range_list_generator<range,NumRanges>::type range_list;
|
Chris@16
|
35 public:
|
Chris@16
|
36 template <std::size_t Ranges>
|
Chris@16
|
37 struct gen_type {
|
Chris@16
|
38 typedef extent_gen<Ranges> type;
|
Chris@16
|
39 };
|
Chris@16
|
40
|
Chris@16
|
41 range_list ranges_;
|
Chris@16
|
42
|
Chris@16
|
43 extent_gen() { }
|
Chris@16
|
44
|
Chris@16
|
45 // Used by operator[] to expand extent_gens
|
Chris@16
|
46 extent_gen(const extent_gen<NumRanges-1>& rhs,
|
Chris@16
|
47 const range& a_range)
|
Chris@16
|
48 {
|
Chris@16
|
49 std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin());
|
Chris@16
|
50 *ranges_.rbegin() = a_range;
|
Chris@16
|
51 }
|
Chris@16
|
52
|
Chris@16
|
53 extent_gen<NumRanges+1>
|
Chris@16
|
54 operator[](const range& a_range)
|
Chris@16
|
55 {
|
Chris@16
|
56 return extent_gen<NumRanges+1>(*this,a_range);
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 extent_gen<NumRanges+1>
|
Chris@16
|
60 operator[](index idx)
|
Chris@16
|
61 {
|
Chris@16
|
62 return extent_gen<NumRanges+1>(*this,range(0,idx));
|
Chris@16
|
63 }
|
Chris@16
|
64
|
Chris@16
|
65 static extent_gen<0> extents() {
|
Chris@16
|
66 return extent_gen<0>();
|
Chris@16
|
67 }
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 } // namespace multi_array
|
Chris@16
|
71 } // namespace detail
|
Chris@16
|
72 } // namespace boost
|
Chris@16
|
73
|
Chris@16
|
74
|
Chris@16
|
75 #endif // BOOST_EXTENT_GEN_RG071801_HPP
|