~ubuntu-branches/ubuntu/breezy/aqsis/breezy

« back to all changes in this revision

Viewing changes to boost/boost/multi_array/index_gen.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Will Newton
  • Date: 2004-12-07 20:06:49 UTC
  • Revision ID: james.westby@ubuntu.com-20041207200649-fccswkrvp4oc8lmn
Tags: upstream-0.9.3
ImportĀ upstreamĀ versionĀ 0.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2002 Ronald Garcia
 
2
//
 
3
// Permission to copy, use, sell and distribute this software is granted
 
4
// provided this copyright notice appears in all copies. 
 
5
// Permission to modify the code and to distribute modified code is granted
 
6
// provided this copyright notice appears in all copies, and a notice 
 
7
// that the code was modified is included with the copyright notice.
 
8
//
 
9
// This software is provided "as is" without express or implied warranty, 
 
10
// and with no claim as to its suitability for any purpose.
 
11
//
 
12
 
 
13
#ifndef BOOST_INDEX_GEN_RG071801_HPP
 
14
#define BOOST_INDEX_GEN_RG071801_HPP
 
15
 
 
16
#include "boost/array.hpp"
 
17
#include "boost/multi_array/index_range.hpp"
 
18
#include "boost/multi_array/range_list.hpp"
 
19
#include "boost/multi_array/types.hpp"
 
20
#include <algorithm> 
 
21
#include <cstddef>
 
22
 
 
23
namespace boost {
 
24
namespace detail {
 
25
namespace multi_array {
 
26
 
 
27
 
 
28
template <int NumRanges, int NumDims>
 
29
struct index_gen {
 
30
private:
 
31
  typedef index Index;
 
32
  typedef std::size_t SizeType;
 
33
  typedef index_range<Index,SizeType> range;
 
34
public:
 
35
  template <int Dims, int Ranges>
 
36
  struct gen_type {
 
37
    typedef index_gen<Ranges,Dims> type;
 
38
  };
 
39
 
 
40
  typedef typename range_list_generator<range,NumRanges>::type range_list;
 
41
  range_list ranges_;
 
42
 
 
43
  index_gen() { }
 
44
 
 
45
  template <int ND>
 
46
  explicit index_gen(const index_gen<NumRanges-1,ND>& rhs,
 
47
            const index_range<Index,SizeType>& range)
 
48
  {
 
49
    std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin());
 
50
    *ranges_.rbegin() = range;
 
51
  }
 
52
 
 
53
  index_gen<NumRanges+1,NumDims+1>
 
54
  operator[](const index_range<Index,SizeType>& range) const
 
55
  {
 
56
    index_gen<NumRanges+1,NumDims+1> tmp;
 
57
    std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin());
 
58
    *tmp.ranges_.rbegin() = range;
 
59
    return tmp;
 
60
  }
 
61
 
 
62
  index_gen<NumRanges+1,NumDims>
 
63
  operator[](Index idx) const
 
64
  {
 
65
    index_gen<NumRanges+1,NumDims> tmp;
 
66
    std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin());
 
67
    *tmp.ranges_.rbegin() = index_range<Index,SizeType>(idx);
 
68
    return tmp;
 
69
  }    
 
70
 
 
71
  static index_gen<0,0> indices() {
 
72
    return index_gen<0,0>();
 
73
  }
 
74
};
 
75
 
 
76
} // namespace multi_array
 
77
} // namespace detail
 
78
} // namespace boost
 
79
 
 
80
 
 
81
#endif // BOOST_INDEX_GEN_RG071801_HPP