00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OLENA_CORE_IMPL_IMAGE_IMPL_HH
00029 # define OLENA_CORE_IMPL_IMAGE_IMPL_HH
00030
00031 # include <oln/core/internal/fake.hh>
00032 # include <oln/core/coord.hh>
00033 # include <oln/core/abstract/image.hh>
00034 # include <mlc/contract.hh>
00035 # include <mlc/type.hh>
00036
00037 # include <iostream>
00038
00039 namespace oln {
00040
00041 namespace impl {
00042
00043 template<class Exact>
00044 class image_impl;
00045
00046 }
00047
00048 template<class Impl>
00049 struct impl_traits;
00050
00057 template<class Exact>
00058 struct impl_traits<impl::image_impl<Exact> >
00059 {
00060
00061 };
00062
00063 namespace impl {
00064
00070 template<class Exact>
00071 class image_impl : public mlc_hierarchy::any<Exact>
00072 {
00073
00074 public:
00075
00076 typedef typename impl_traits<Exact>::point_type point_type;
00077 typedef typename impl_traits<Exact>::value_type value_type;
00078 typedef typename impl_traits<Exact>::size_type size_type;
00079
00080 typedef Exact exact_type;
00081
00082 image_impl(const size_type s): refcount_(0), size_(s) {}
00083
00084 image_impl() {}
00085
00087
00088 void
00089 ref() const
00090 {
00091 ++refcount_;
00092 }
00093
00098 void
00099 unref() const
00100 {
00101 invariant(refcount_ > 0);
00102 --refcount_;
00103 if (refcount_ == 0)
00104 delete mlc::to_exact(this);
00105 }
00106
00108
00109 const value_type&
00110 at(const point_type& p) const
00111 {
00112 return this->exact().at_(p);
00113 }
00114
00116
00117 value_type&
00118 at(const point_type& p)
00119 {
00120 return this->exact().at_(p);
00121 }
00122
00124
00125 bool
00126 hold(const point_type& p) const
00127 {
00128 return this->exact().hold_(p);
00129 }
00130
00132
00133 bool
00134 hold_large(const point_type& p) const
00135 {
00136 return this->exact().hold_large_(p);
00137 }
00138
00140
00141 void
00142 precondition_hold_large(const point_type& p) const
00143 {
00144 # ifndef NDEBUG
00145 if (! hold_large(p))
00146 std::cerr << "image overflow at (" << p << ")" << std::endl;
00147 # else
00148 (void) p;
00149 # endif
00150 }
00151
00152
00154
00155 void
00156 clone_to(exact_type* output_data) const
00157 {
00158 return this->exact().clone_to_(output_data);
00159 }
00160
00162
00163 const
00164 size_type& size() const
00165 {
00166 return size_;
00167 }
00168
00169 size_type&
00170 size()
00171 {
00172 return size_;
00173 }
00174
00175
00176
00181 void
00182 border_reallocate_and_copy(coord new_border, bool
00183 copy_border)
00184 {
00185 this->exact().border_reallocate_and_copy_(new_border, copy_border);
00186 }
00187
00192 void
00193 border_replicate(void)
00194 {
00195 this->exact().border_replicate_();
00196 }
00197
00202 void
00203 border_mirror(void)
00204 {
00205 this->exact().border_mirror_();
00206 }
00207
00209
00210 void
00211 border_assign(value_type val)
00212 {
00213 this->exact().border_assign_(val);
00214 }
00215
00216 private:
00217
00218 mutable unsigned refcount_;
00219
00220 protected:
00221
00222 size_type size_;
00223
00224 };
00225
00226 }
00227
00228 }
00229
00230 #endif // ! OLENA_CORE_IMPL_IMAGE_IMPL_HH