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 PIECE_MORPHER_HH
00029 # define PIECE_MORPHER_HH
00030
00031 # include <oln/morpher/generic_morpher.hh>
00032
00033 namespace oln {
00034
00035 namespace morpher {
00036
00037 template <class I, class Exact = mlc::final>
00038 struct piece_morpher;
00039 template <class I, class Exact = mlc::final>
00040 struct super_piece_morpher;
00041
00042 }
00043
00045 template <class SrcType, class Exact>
00046 struct image_id< morpher::super_piece_morpher<SrcType, Exact> >
00047 {
00048 typedef typename mlc::exact_vt<
00049 morpher::super_piece_morpher<SrcType, Exact>,
00050 Exact>::ret
00051 exact_type;
00053 };
00054
00056 template <class SrcType, class Exact>
00057 struct image_id< morpher::piece_morpher<SrcType, Exact> >
00058 {
00059 enum {dim = SrcType::dim};
00060 typedef oln_impl_type(SrcType) impl_type;
00062 typedef oln_value_type(SrcType) value_type;
00064 typedef typename mlc::exact_vt<morpher::piece_morpher<SrcType, Exact>,
00065 Exact>::ret exact_type;
00067 typedef oln_point_type(SrcType) point_type;
00068 typedef oln_dpoint_type(SrcType) dpoint_type;
00069 typedef oln_size_type(SrcType) size_type;
00070 typedef oln_iter_type(SrcType) iter_type;
00071 };
00072
00074 template <class SrcType, class Exact>
00075 struct image_traits < morpher::piece_morpher<SrcType, Exact> >
00076 : public
00077 image_traits<
00078 morpher::abstract::generic_morpher<
00079 SrcType,
00080 typename image_id<morpher::piece_morpher<SrcType,
00081 Exact> >::exact_type
00082 >
00083 >
00084 {};
00085
00086
00087 namespace morpher {
00088
00090 template <class SrcType, class Exact>
00091 class super_piece_morpher
00092 : public abstract::generic_morpher<SrcType, Exact>
00093 {
00094
00095 public:
00096
00097 typedef super_piece_morpher<SrcType, Exact> self_type;
00098 typedef typename image_id<self_type>::exact_type exact_type;
00099 typedef abstract::generic_morpher<SrcType, Exact> super_type;
00100
00101 typedef typename image_id<exact_type>::dpoint_type dpoint_type;
00102 typedef typename image_id<exact_type>::size_type size_type;
00103
00104 protected:
00105
00115 super_piece_morpher(const SrcType &ima, const dpoint_type& p,
00116 const size_type& s)
00117 : super_type(ima), size_(s), p_(p)
00118 {}
00119
00120 const size_type size_;
00121 const dpoint_type p_;
00123
00129 super_piece_morpher()
00130 {}
00131
00132 public:
00133
00135 const size_type
00136 size() const
00137 {
00138 return size_;
00139 }
00140
00142 const dpoint_type
00143 ref_point() const
00144 {
00145 return p_;
00146 }
00147
00149 static std::string
00150 name()
00151 {
00152 return "super_piece_morpher<" + super_type::name() + ">";
00153 }
00154
00155 };
00156
00165 template <class SrcType, class Exact>
00166 struct piece_morpher
00167 : public super_piece_morpher<
00168 SrcType,
00169 typename image_id<piece_morpher<SrcType, Exact> >::exact_type
00170 >
00171 {
00172 typedef piece_morpher<SrcType, Exact> self_type;
00173 typedef typename image_id<self_type>::exact_type exact_type;
00174 typedef super_piece_morpher<SrcType, exact_type> super_type;
00175
00176 typedef typename image_id<exact_type>::point_type point_type;
00177 typedef typename image_id<exact_type>::dpoint_type dpoint_type;
00178 typedef typename image_id<exact_type>::size_type size_type;
00179 typedef typename image_id<exact_type>::value_type value_type;
00180
00182 piece_morpher(const SrcType &ima, const dpoint_type p,
00183 const size_type s)
00184 : super_type(ima, p, s)
00185 {}
00186
00188 piece_morpher(const self_type& r)
00189 : super_type(r.get_ima(), r.ref_point(), r.size())
00190 {}
00191
00197 piece_morpher()
00198 {}
00199
00205 value_type&
00206 at(const point_type& p)
00207 {
00208 return const_cast<value_type &>
00209 ( const_cast<SrcType &>(this->ima_)[p + p_] );
00210 }
00211
00217 const value_type
00218 at(const point_type& p) const
00219 {
00220 return this->ima_[p + p_];
00221 }
00222
00227 self_type&
00228 assign(self_type& rhs)
00229 {
00230 oln_iter_type(SrcType) it(rhs);
00231
00232 for_all(it)
00233 this->at(it) = rhs[it];
00234 return this->exact();
00235 }
00236
00240 self_type&
00241 operator=(SrcType& rhs)
00242 {
00243 return this->exact().assign(rhs);
00244 }
00245
00247 static std::string
00248 name()
00249 {
00250 return "piece_morpher<" + super_type::name() + ">";
00251 }
00252
00253 };
00254
00256 template <class SrcType, class Exact>
00257 struct piece_morpher<const SrcType, Exact>
00258 : public super_piece_morpher<
00259 const SrcType,
00260 typename image_id<piece_morpher<const SrcType,
00261 Exact> >::exact_type
00262 >
00263 {
00264 typedef piece_morpher<const SrcType, Exact> self_type;
00265 typedef typename image_id<self_type>::exact_type exact_type;
00266 typedef super_piece_morpher<const SrcType, exact_type> super_type;
00267
00268 typedef typename image_id<exact_type>::point_type point_type;
00269 typedef typename image_id<exact_type>::dpoint_type dpoint_type;
00270 typedef typename image_id<exact_type>::size_type size_type;
00271 typedef typename image_id<exact_type>::value_type value_type;
00272
00279 piece_morpher(const SrcType &ima, const dpoint_type p,
00280 const size_type s)
00281 : super_type(ima, p, s)
00282 {}
00283
00285 piece_morpher(const self_type& r)
00286 : super_type(r.get_ima(), r.ref_point(), r.size())
00287 {}
00288
00294 piece_morpher() {}
00295
00301 const value_type
00302 at(const point_type &p) const
00303 {
00304 return this->ima_[p + p_];
00305 }
00306
00308 static std::string
00309 name()
00310 {
00311 return "piece_morpher<" + super_type::name() + ">";
00312 }
00313
00314 };
00315
00316
00345 template <class I, class PointType, class SizeType>
00346 const piece_morpher<I>
00347 piece_morph(I &ima, const PointType p, const SizeType s)
00348 {
00349 return piece_morpher<I>(ima, p, s);
00350 }
00351
00352
00353 }
00354
00355 }
00356
00357 #endif // !PIECE_MORPHER