$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
static_array.hh
1 // Copyright (C) 2010 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_UTIL_STATIC_ARRAY_HH
27 # define MLN_UTIL_STATIC_ARRAY_HH
28 
29 // FIXME: Add documentation.
30 
31 # include <cstddef>
32 # include <algorithm>
33 
34 # include <mln/core/internal/window_base.hh>
35 # include <mln/core/concept/gdpoint.hh>
36 
37 # include <mln/metal/is_a.hh>
38 # include <mln/util/set.hh>
39 # include <mln/fun/i2v/all_to.hh>
40 # include <mln/norm/linfty.hh>
41 # include <mln/literal/zero.hh>
42 
43 namespace mln
44 {
45 
46  namespace util
47  {
48 
49  template <typename T, std::size_t n>
51  {
52  public:
53  // FIXME: Careful, this ctor initializes nothing.
54  static_array();
55 
56  // FIXME: Find a better way to build this static array.
57  template <typename InputIterator>
58  static_array(InputIterator first, InputIterator last);
59 
60  T& operator[](std::size_t i);
61  const T& operator[](std::size_t i) const;
62 
63  bool has(const T& value) const;
64 
65  private:
66  T data_[n];
67  };
68 
69 
70  template <typename D, std::size_t n>
71  bool
73 
74 
75 # ifndef MLN_INCLUDE_ONLY
76 
77  template <typename T, std::size_t n>
78  inline
80  {
81  }
82 
83  template <typename T, std::size_t n>
84  template <typename InputIterator>
85  inline
86  static_array<T, n>::static_array(InputIterator first, InputIterator last)
87  {
88  mln_precondition(std::distance(first, last) == n);
89  std::copy(first, last, data_);
90  }
91 
92  template <typename T, std::size_t n>
93  inline
94  T&
95  static_array<T, n>::operator[](std::size_t i)
96  {
97  return data_[i];
98  }
99 
100  template <typename T, std::size_t n>
101  inline
102  const T&
103  static_array<T, n>::operator[](std::size_t i) const
104  {
105  return data_[i];
106  }
107 
108  template <typename T, std::size_t n>
109  inline
110  bool
111  static_array<T, n>::has(const T& value) const
112  {
113  return std::find(data_, data_ + n, value) != data_ + n;
114  }
115 
116 
117  template <typename D, std::size_t n>
118  inline
119  bool
120  operator==(const static_array<D, n>& lhs, const static_array<D, n>& rhs)
121  {
122  for(std::size_t i = 0; i < n; ++i)
123  if (lhs[i] != rhs[i])
124  return false;
125  return true;
126  }
127 
128 # endif // ! MLN_INCLUDE_ONLY
129 
130  } // end of namespace mln::util
131 
132 } // end of namespace mln
133 
134 #endif // ! MLN_UTIL_STATIC_ARRAY_HH