$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
trait/op/plus.cc
1 // Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #include <mln/core/concept/image.hh>
28 #include <mln/value/concept/all.hh>
29 #include <mln/trait/op/plus.hh>
30 #include <mln/value/builtin/all.hh>
31 
32 
33 namespace mln
34 {
35 
36  struct dummy_t {};
37  dummy_t dummy;
38 
39  template <typename T>
40  struct my_image2d : Image< my_image2d<T> >
41  {
42  void m() {}
43 
44 
45  // Dummy typedefs and methods added to comply with interface
46  // requirements of concept Image.
47 
48  typedef dummy_t domain_t;
49  typedef dummy_t site;
50  typedef dummy_t psite;
51  typedef dummy_t piter;
52  typedef dummy_t fwd_piter;
53  typedef dummy_t bkd_piter;
54 
55  bool has(const psite& /* p */) const { return false; }
56  bool is_valid() const { return true; }
57 
58  typedef dummy_t t_eligible_values_set;
59  const t_eligible_values_set& values_eligible() const { return dummy; }
60 
61  typedef dummy_t t_values_space;
62  const t_values_space& values_space() const { return dummy; }
63 
64  typedef dummy_t value;
65  typedef dummy_t rvalue;
66  typedef dummy_t lvalue;
67 
68  rvalue operator()(const psite& /* p */) const { return dummy; }
69  lvalue operator()(const psite& /* p */) { return dummy; }
70 
71  const domain_t& domain() const { return dummy; }
72 
73  typedef dummy_t skeleton;
74 
75  void init_(const dummy_t&) {};
76  };
77 
78 
79  namespace trait
80  {
81 
82  // int + float -> float
83 
84  template <>
85  struct set_precise_binary_< op::plus, int, float >
86  {
87  typedef float ret;
88  };
89 
90 
91  // Image I + Image J -> bool (demo type!)
92 
93  template <typename I, typename J>
94  struct set_binary_< op::plus, Image, I, Image, J >
95  {
96  typedef bool ret;
97  };
98 
99  // precise definition: my_image2d<T> + my_image2d<U> -> my_image2d<V>
100  // ('&' is to avoid compiling an empty class)
101 
102  template <typename T, typename U>
103  struct set_precise_binary_< op::plus, my_image2d<T>, my_image2d<U> >
104  {
105  typedef mln_trait_op_plus(T, U) V;
106  typedef my_image2d<V>& ret;
107  };
108 
109  }
110 
111 }
112 
113 int main()
114 {
115  using namespace mln;
116  {
117  mln_trait_op_plus_(int, float) tmp;
118  tmp = 5.1f;
119  (void) tmp;
120  }
121  {
122  my_image2d<float> ima;
123  my_image2d<float>* ptr = &ima;
124  mln_trait_op_plus_(my_image2d<int>, my_image2d<float>) tmp = *ptr;
125  tmp.m();
126  (void) tmp;
127  }
128 }