Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
run_image.hh
1 // Copyright (C) 2007, 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_RUN_IMAGE_HH
27 # define MLN_CORE_INTERNAL_RUN_IMAGE_HH
28 
34 # include <mln/core/internal/image_primary.hh>
35 # include <mln/core/site_set/p_run.hh>
36 # include <mln/core/site_set/p_set_of.hh>
37 
38 namespace mln
39 {
40 
41  namespace internal
42  {
43 
49  template <typename T, typename P, typename E>
50  class run_image_ : public internal::image_primary< P, p_set_of< p_run<P> >, E >
51  {
52  protected:
53  run_image_();
54 
55  public:
64  float compression() const;
65 
71  void finalize();
72 
80  P point_at(const mln_psite(p_set_of< p_run<P> >)& ps) const;
81 
86  bool has(const mln_psite(p_set_of< p_run<P> >)& ps) const;
87  };
88 
89 # ifndef MLN_INCLUDE_ONLY
90 
91  template <typename T, typename P, typename E>
92  inline
93  run_image_<T, P, E>::run_image_()
94  {
95  }
96 
97  template <typename T, typename P, typename E>
98  inline
99  float
100  run_image_<T, P, E>::compression() const
101  {
102  return float(exact(this)->data_->memory_size()) /
103  float (sizeof(T) * exact(this)->data_->domain_.bbox().nsites());
104  }
105 
106  template <typename T, typename P, typename E>
107  inline
108  void
109  run_image_<T, P, E>::finalize()
110  {
111  exact(this)->data_->finalize();
112  }
113 
114  template <typename T, typename P, typename E>
115  inline
116  P
117  run_image_<T, P, E>::point_at(const mln_psite(p_set_of< p_run<P> >)& ps) const
118  {
119  const E* ima = exact(this);
120  mln_precondition(ps.index() < ima->data_->domain_.nsites());
121  mln_precondition(ps.p().index() < ima->data_->domain_[ps.index()].length());
122  return ima->data_->domain_[ps.index()][ps.p().index()];
123  }
124 
125  template <typename T, typename P, typename E>
126  inline
127  bool
128  run_image_<T, P, E>::has(const mln_psite(p_set_of< p_run<P> >)& ps) const
129  {
130  const E* ima = exact(this);
131  if (!ima->is_valid())
132  return false;
133  else
134  return (ps.index() < ima->data_->domain_.nsites()
135  && ps.p().index() < ima->data_->domain_[ps.index()].length()
136  && ima->data_->domain_[ps.index()][ps.p().index()] == ps);
137  }
138 
139 # endif // ! MLN_INCLUDE_ONLY
140 
141  } // end of namespace internal
142 
143 } // end of namespace mln
144 
145 
146 #endif // ! MLN_CORE_INTERNAL_RUN_IMAGE_HH