$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
metal/array.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_METAL_ARRAY_HH
27 # define MLN_METAL_ARRAY_HH
28 
29 # include <mln/metal/array1d.hh>
30 # include <mln/metal/array2d.hh>
31 # include <mln/metal/array3d.hh>
32 
33 namespace mln
34 {
35 
36  namespace metal
37  {
38 
39  // a1
40 
41  template<unsigned i, class T, unsigned n> inline
42  T get_at(const array1d<T, n>& arr)
43  {
44  return arr.template get_at_<i>();
45  }
46 
47  template<unsigned i, class T, unsigned n> inline
48  T get(const array1d<T, n>& arr)
49  {
50  return arr.template get_<i>();
51  }
52 
53  // a2
54 
55  template<unsigned row, unsigned col, class T,
56  unsigned r, unsigned c> inline
57  T get_at(const array2d<T, r, c>& arr)
58  {
59  return arr.template get_at_<row, col>();
60  }
61 
62  template<unsigned row, unsigned col, class T,
63  unsigned r, unsigned c> inline
64  T get(const array2d<T, r, c>& arr)
65  {
66  return arr.template get_<row, col>();
67  }
68 
69  // a3
70 
71  template<unsigned sli, unsigned row, unsigned col,
72  class T, unsigned s, unsigned r, unsigned c> inline
73  T get_at(const array3d<T, s, r, c>& arr)
74  {
75  return arr.template get_at_<sli, row, col>();
76  }
77 
78  template<unsigned sli, unsigned row, unsigned col,
79  class T, unsigned s, unsigned r, unsigned c> inline
80  T get_(const array3d<T, s, r, c>& arr)
81  {
82  return arr.template get_<sli, row, col>();
83  }
84 
85  // print
86 
87  template<typename T, unsigned n>
88  std::ostream& operator<<(std::ostream& ostr, const array1d<T, n>& rhs)
89  {
90  for (unsigned i = 0; i < n; ++i)
91  ostr << rhs[i] << " ";
92  ostr << std::endl;
93 
94  return ostr;
95  }
96 
97  template<typename T, unsigned r, unsigned c>
98  std::ostream& operator<<(std::ostream& ostr, const array2d<T, r, c>& rhs)
99  {
100  for (unsigned i = 0; i < r; ++i)
101  {
102  for (unsigned j = 0; j < c; ++j)
103  ostr << rhs(i,j) << '\t';
104  ostr << '\n';
105  }
106  ostr << std::endl;
107 
108  return ostr;
109  }
110 
111  }
112 
113 }
114 
115 #endif // ! MLN_METAL_ARRAY_HH