Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
site_set_impl.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_CORE_INTERNAL_SITE_SET_IMPL_HH
27 # define MLN_CORE_INTERNAL_SITE_SET_IMPL_HH
28 
31 
32 # include <mln/core/concept/site_set.hh>
33 # include <mln/accu/shape/bbox.hh>
34 
35 
36 
37 namespace mln
38 {
39 
40  namespace internal
41  {
42 
45  template <typename Sc>
46  struct site_set_impl;
47 
48 
49 
50  // For .nsites()
51 
52  template <typename trait_nsites, typename Sc>
53  struct site_set_impl__nsites
54  {
55  protected:
56  template <typename T>
57  void update_nsites_(const T&); // No-op.
58  };
59 
60  template <typename Sc>
61  struct site_set_impl__nsites< trait::site_set::nsites::known, Sc>
62  {
63  site_set_impl__nsites();
64  unsigned nsites() const;
65  protected:
66  void update_nsites_(const mln_site(Sc)& p);
67  template <typename S>
68  void update_nsites_(const Site_Set<S>& s);
69  unsigned nsites_;
70  };
71 
72 
73  // For .bbox()
74 
75  template <typename trait_bbox, typename Sc>
76  struct site_set_impl__bbox
77  {
78  typedef const mln::box<mln_site(Sc)>& q_box;
79  q_box bbox() const;
80 
81  protected:
82  void update_bbox_(const mln_site(Sc)& p);
83  template <typename S>
84  void update_bbox_(const Site_Set<S>& s);
85 
86  accu::shape::bbox<mln_site(Sc)> bb_;
87  };
88 
89  template <typename Sc>
90  struct site_set_impl__bbox< trait::site_set::nsites::unknown, Sc >
91  {
92  protected:
93  template <typename T>
94  void update_bbox_(const T&); // No-op.
95  };
96 
97 
98  // Facade.
99 
100  template <typename Sc>
101  struct site_set_impl
102  : site_set_impl__nsites< mln_trait_site_set_nsites(Sc), Sc>,
103  site_set_impl__bbox < mln_trait_site_set_bbox(Sc), Sc>
104  {
105  };
106 
107 
108 
109 
110 # ifndef MLN_INCLUDE_ONLY
111 
112 
113  // site_set_impl__nsites
114 
115  template <typename trait_nsites, typename Sc>
116  template <typename T>
117  inline
118  void
119  site_set_impl__nsites<trait_nsites, Sc>::update_nsites_(const T&)
120  {
121  // No-op.
122  }
123 
124  template <typename Sc>
125  inline
126  site_set_impl__nsites<trait::site_set::nsites::known, Sc>::site_set_impl__nsites()
127  : nsites_(0)
128  {
129  }
130 
131  template <typename Sc>
132  inline
133  unsigned
134  site_set_impl__nsites<trait::site_set::nsites::known, Sc>::nsites() const
135  {
136  return nsites_;
137  }
138 
139  template <typename Sc>
140  inline
141  void
142  site_set_impl__nsites<trait::site_set::nsites::known, Sc>::update_nsites_(const mln_site(Sc)&)
143  {
144  ++nsites_;
145  }
146 
147  template <typename Sc>
148  template <typename S>
149  inline
150  void
151  site_set_impl__nsites<trait::site_set::nsites::known, Sc>::update_nsites_(const Site_Set<S>& s)
152  {
153  nsites_ += exact(s).nsites();
154  }
155 
156  // site_set_impl__bbox
157 
158  template <typename trait_bbox, typename Sc>
159  inline
160  typename site_set_impl__bbox<trait_bbox, Sc>::q_box
161  site_set_impl__bbox<trait_bbox, Sc>::bbox() const
162  {
163  return bb_.to_result();
164  }
165 
166  template <typename trait_bbox, typename Sc>
167  inline
168  void
169  site_set_impl__bbox<trait_bbox, Sc>::update_bbox_(const mln_site(Sc)& p)
170  {
171  bb_.take(p);
172  }
173 
174  template <typename trait_bbox, typename Sc>
175  template <typename S>
176  inline
177  void
178  site_set_impl__bbox<trait_bbox, Sc>::update_bbox_(const Site_Set<S>& s)
179  {
180  bb_.take(exact(s).bbox());
181  }
182 
183  template <typename Sc>
184  template <typename T>
185  inline
186  void
187  site_set_impl__bbox< trait::site_set::nsites::unknown, Sc >::update_bbox_(const T&)
188  {
189  // No-op.
190  }
191 
192 # endif // ! MLN_INCLUDE_ONLY
193 
194  } // end of namespace mln::internal
195 
196 } // end of namespace mln
197 
198 
199 #endif // ! MLN_CORE_INTERNAL_SITE_SET_IMPL_HH