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_ABSTRACT_IMAGE_WITH_IMPL_HH
00029 # define OLENA_CORE_ABSTRACT_IMAGE_WITH_IMPL_HH
00030
00031 # include <oln/core/abstract/image_with_type_with_dim.hh>
00032 # include <oln/core/impl/image_impl.hh>
00033
00034
00035 namespace oln {
00036
00037 namespace abstract {
00038
00039 template<class Impl, class Exact>
00040 class image_with_impl;
00041
00042 }
00043
00051 template<class Impl, class Exact>
00052 struct image_traits<abstract::image_with_impl<Impl, Exact> > :
00053 public image_traits<typename abstract::image_with_dim<image_id<Exact>::dim, Exact> >,
00054 public image_traits<typename abstract::image_with_type<typename image_id<Exact>::value_type, Exact> >
00055 {
00056 typedef Impl impl_type;
00057 };
00058
00059
00060
00061 namespace abstract {
00062
00068 template<class Impl, class Exact>
00069 class image_with_impl:
00070 public image_with_type_with_dim_switch<Exact>::ret
00071 {
00072 public:
00073
00074 typedef typename image_traits<Exact>::point_type point_type;
00080 typedef typename image_traits<Exact>::iter_type iter_type;
00086 typedef typename image_traits<Exact>::fwd_iter_type fwd_iter_type;
00088 typedef typename image_traits<Exact>::bkd_iter_type bkd_iter_type;
00090 typedef typename image_traits<Exact>::value_type value_type;
00094 typedef typename image_traits<Exact>::size_type size_type;
00099 typedef typename image_traits<Exact>::impl_type impl_type ;
00102 typedef image_with_impl<Impl, Exact> self_type;
00103 typedef Exact exact_type;
00104 typedef typename image_with_type_with_dim_switch<Exact>::ret super_type;
00105 friend class image<exact_type>;
00106 friend class image_with_dim<image_id<Exact>::dim, exact_type>;
00107 friend class image_with_type<typename image_id<Exact>::value_type, Exact>;
00108
00109
00110
00119 image_with_impl(self_type& rhs)
00120 : super_type(rhs)
00121 {
00122 assertion(rhs.has_impl());
00123 impl_ = rhs.impl();
00124 impl_->ref();
00125 }
00126
00134 exact_type&
00135 operator=(self_type rhs)
00136 {
00137 return this->exact().assign(rhs.exact());
00138 }
00139
00141
00142 const impl_type*
00143 impl() const
00144 {
00145 return impl_;
00146 }
00147
00152 const size_type&
00153 size() const
00154 {
00155 assertion(has_impl());
00156 return this->exact().impl()->size();
00157 }
00158
00160
00161 impl_type*
00162 impl()
00163 {
00164 return impl_;
00165 }
00166
00167 static std::string
00168 name()
00169 {
00170 return
00171 std::string("abstract::image_with_impl<")
00172 + Impl::name() + ", "
00173 + Exact::name() + ">";
00174 }
00175
00180 void
00181 clone_to(impl_type* output_data) const
00182 {
00183 assertion(impl_ != 0);
00184 impl()->clone_to(output_data);
00185 }
00186
00188
00189 void
00190 clear()
00191 {
00192 if (impl_ != 0)
00193 {
00194 impl_->unref();
00195 impl_ = 0;
00196 }
00197 }
00198
00199 protected:
00200
00210 const value_type
00211 at(const point_type& p) const
00212 {
00213 return impl_->at(p);
00214 }
00215
00216
00226 value_type&
00227 at(const point_type& p)
00228 {
00229 return impl_->at(p);
00230 }
00231
00239 exact_type&
00240 assign(exact_type rhs)
00241 {
00242 assertion(rhs.impl() != 0);
00243 if ( &rhs == this )
00244 return this->exact();
00245 if (this->impl() != 0)
00246 this->impl()->unref();
00247 this->impl_ = rhs.impl();
00248 this->impl()->ref();
00249 return this->exact();
00250 }
00251
00252 ~image_with_impl()
00253 {
00254 clear();
00255 }
00256
00261 image_with_impl() : impl_(0)
00262 {}
00263
00265
00266 image_with_impl(impl_type* impl) :
00267 super_type(),
00268 impl_(impl)
00269 {
00270 impl_->ref();
00271 }
00272
00273 private:
00274
00279 impl_type* impl_;
00280
00281 image_with_impl(const self_type& rhs);
00282
00283 };
00284
00285 }
00286
00287 }
00288
00289 #endif // ! OLENA_CORE_ABSTRACT_IMAGE_WITH_IMPL_HH