
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add external initialization through ''init(target, with, data)''. * oln/core/internal/utils.hh (value1, value2, value3, value4): Rename as... (first, second, third, fourth): ...these. * oln/core/init.hh (init): New version. (with_t, with, init_): New. * oln/core/1d/image1d.hh (plain, skeleton): New. * oln/core/1d/image1d_b.hh: Likewise and update. * oln/core/2d/neighb2d.hh (OLN_ENABLE_DEFAULT): New. (init_): New. * oln/core/2d/array2d.hh: Add FIXMEs. * oln/core/2d/image2d.hh (init_): New. * oln/core/2d/image2d_b.hh: Likewise. * oln/core/2d/box2d.hh (init__): Change sig. * oln/core/2d/point2d.hh (init__): Replace by... (point2d): ...this new ctor. * oln/core/gen/box.hh: Likewise. * oln/core/equipment.hh (include): Add init.hh. * oln/core/gen/op.hh (op_): New ctor. * oln/core/gen/single_value_image.hh: Update. * oln/core/concept/point_set.hh (box): New instant value. * oln/core/concept/grid.hh (include): Remove. * oln/core/concept/point.hh (include): Add grid.hh. (point): New instant value. * oln/core/concept/value.hh: Fix. * oln/core/internal/initializer.hh (operator*): Rename as... (value): ...this. (init__): Secure. * oln/core/internal/op_image_plus_nbh.hh (current): Move. (init_): New. Update. * oln/core/internal/instant_value.hh (oln_decl_instant_value): Move type definitions into internal. (operator M<W>): Add FIXME. * oln/core/internal/image_base.hh (ima): New instant value. (data__): New method. (init_): New. 1d/image1d.hh | 3 + 1d/image1d_b.hh | 21 +++++----- 2d/array2d.hh | 2 2d/box2d.hh | 47 ++++++++++++----------- 2d/image2d.hh | 14 ++++++ 2d/image2d_b.hh | 14 ++++++ 2d/neighb2d.hh | 23 ++++++++++- 2d/point2d.hh | 37 ++++-------------- concept/grid.hh | 1 concept/point.hh | 3 + concept/point_set.hh | 6 ++ concept/value.hh | 3 - equipment.hh | 2 gen/box.hh | 44 +++++++-------------- gen/op.hh | 10 ++++ gen/single_value_image.hh | 10 ++-- init.hh | 85 ++++++++++++++++++++++++++++++++++++++++++ internal/image_base.hh | 47 ++++++++++++++++++++++- internal/initializer.hh | 59 +++++++++++++++++++++-------- internal/instant_value.hh | 22 ++++++++-- internal/op_image_plus_nbh.hh | 78 ++++++++++++++++++++++++++++++++++---- internal/utils.hh | 46 +++++++++++----------- 22 files changed, 428 insertions(+), 149 deletions(-) Index: oln/core/concept/point_set.hh --- oln/core/concept/point_set.hh (revision 875) +++ oln/core/concept/point_set.hh (working copy) @@ -28,13 +28,17 @@ #ifndef OLN_CORE_CONCEPT_POINT_SET_HH # define OLN_CORE_CONCEPT_POINT_SET_HH -# include <ostream> +# include <iostream> # include <oln/core/concept/point.hh> +# include <oln/core/concept/iterator.hh> // for "for_all" namespace oln { + /// Instant value. + oln_decl_instant_value(box); + /// Concept-class "Point_Set". Index: oln/core/concept/grid.hh --- oln/core/concept/grid.hh (revision 875) +++ oln/core/concept/grid.hh (working copy) @@ -30,7 +30,6 @@ # define OLN_CORE_CONCEPT_GRID_HH # include <oln/core/equipment.hh> -# include <oln/core/internal/instant_value.hh> namespace oln Index: oln/core/concept/point.hh --- oln/core/concept/point.hh (revision 875) +++ oln/core/concept/point.hh (working copy) @@ -30,12 +30,15 @@ # define OLN_CORE_CONCEPT_POINT_HH # include <mlc/value.hh> +# include <oln/core/concept/grid.hh> # include <oln/core/concept/operators.hh> namespace oln { + /// Instant value. + oln_decl_instant_value(point); /// Concept-class "Point". Index: oln/core/concept/value.hh --- oln/core/concept/value.hh (revision 875) +++ oln/core/concept/value.hh (working copy) @@ -47,7 +47,8 @@ # ifndef OLN_INCLUDE_ONLY - Value::Value() + template <typename Exact> + Value<Exact>::Value() { } Index: oln/core/init.hh --- oln/core/init.hh (revision 875) +++ oln/core/init.hh (working copy) @@ -38,6 +38,11 @@ { + template <typename D> + internal::initializer_<D> + init(const D& d); + + template <template<class> class M, typename V> internal::initializer_< internal::singleton< M<V> > > init(const internal::instant_value_<M,V>& v); @@ -61,9 +66,49 @@ // ... + const struct with_t {} with = with_t(); + + + /* + * + * // To be specialized. + * template <typename This_, typename Data> + * bool init_(This_* this_, const Data& data); // FIXME: give code? err? + * + */ + + + // The init versions below calls the above init_ routine. + // FIXME: Add oln::Any<*> to signature? + + + // Regular version. + template <typename Target, typename Data> + bool init(Target& target, with_t, const Data& data); + + // Assignment. + template <typename T> + bool init(T& target, with_t, const T& data); + + // Unconst data version. + template <typename Target, typename Data> + bool init(Target& target, with_t, Data& data); + + // Guard: we cannot have "const Target". + template <typename Target, typename Data> + bool init(const Target& target, with_t, const Data& data); + + # ifndef OLN_INCLUDE_ONLY + template <typename D> + internal::initializer_<D> + init(const D& d) + { + return d; + } + template <template<class> class M, typename V> internal::initializer_< internal::singleton< M<V> > > init(const internal::instant_value_<M,V>& v) @@ -96,6 +141,46 @@ // ... + + + // Regular version. + template <typename Target, typename Data> + bool init(Target& target, with_t, const Data& data) + { + return init_(&target, data); + } + + // Assignment. + template <typename T> + bool init(T& target, with_t, const T& data) + { + target = data; + return true; + } + + // Unconst data version. + template <typename Target, typename Data> + bool init(Target& target, with_t, Data& data) + { + return init_(&target, const_cast<const Data&>(data)); + } + + + namespace ERROR + { + template <typename T> + struct initialization_of_temporary_or_const_object_; + } + + // Guard: we cannot have "const Target". + template <typename Target, typename Data> + bool init(const Target&, with_t, const Data&) + { + mlc::abort_< Target, ERROR::initialization_of_temporary_or_const_object_<Target> >::check(); + return false; + } + + # endif // OLN_INCLUDE_ONLY Index: oln/core/1d/image1d.hh --- oln/core/1d/image1d.hh (revision 875) +++ oln/core/1d/image1d.hh (working copy) @@ -56,6 +56,9 @@ typedef box1d pset; typedef array1d_<value, coord> data; + + typedef image1d<T> plain; + typedef image1d<pl::value> skeleton; }; Index: oln/core/1d/image1d_b.hh --- oln/core/1d/image1d_b.hh (revision 875) +++ oln/core/1d/image1d_b.hh (working copy) @@ -63,6 +63,9 @@ typedef internal::triplet< array1d_<T, int>, unsigned, box_<point1d> > data; + + typedef image1d_b<T> plain; + typedef image1d_b<pl::value> skeleton; }; @@ -140,21 +143,21 @@ bool image1d_b<T>::impl_owns_(const point1d& p) const { assert(this->has_data()); - return this->data_->value1.has(p.ind()); + return this->data_->first.has(p.ind()); } template <typename T> bool image1d_b<T>::impl_has(const point1d& p) const { assert(this->has_data()); - return this->data_->value3.has(p); + return this->data_->third.has(p); } template <typename T> const T& image1d_b<T>::impl_read(const point1d& p) const { assert(this->has_data()); - return this->data_->value1(p.ind()); + return this->data_->first(p.ind()); } template <typename T> @@ -162,14 +165,14 @@ { assert(this->has_data()); assert(i < this->npoints()); - return this->data_->value1[i]; + return this->data_->first[i]; } template <typename T> T& image1d_b<T>::impl_read_write(const point1d& p) { assert(this->has_data()); - return this->data_->value1(p.ind()); + return this->data_->first(p.ind()); } template <typename T> @@ -177,28 +180,28 @@ { assert(this->has_data()); assert(i < this->npoints()); - return this->data_->value1[i]; + return this->data_->first[i]; } template <typename T> box1d image1d_b<T>::impl_bbox() const { assert(this->has_data()); - return this->data_->value3; + return this->data_->third; } template <typename T> box1d image1d_b<T>::impl_points() const { assert(this->has_data()); - return this->data_->value3; + return this->data_->third; } template <typename T> unsigned image1d_b<T>::border() const { assert(this->has_data()); - return this->data_->value2; + return this->data_->second; } # endif Index: oln/core/2d/neighb2d.hh --- oln/core/2d/neighb2d.hh (revision 875) +++ oln/core/2d/neighb2d.hh (working copy) @@ -40,6 +40,15 @@ typedef neighb_<dpoint2d> neighb2d; +# ifdef OLN_ENABLE_DEFAULT + + // Default is c4. + template <typename D> + bool init_(neighb2d* this_, const D&); + +# endif // OLN_ENABLE_DEFAULT + + namespace internal { @@ -100,12 +109,24 @@ # ifndef OLN_INCLUDE_ONLY +# ifdef OLN_ENABLE_DEFAULT + + /// Default is c4. + template <typename D> + bool init_(neighb2d* this_, const D&) + { + *this_ = c4; + return true; + } + +# endif // OLN_ENABLE_DEFAULT + const neighb2d c4 = internal::mk_c4(); const neighb2d c8 = internal::mk_c8(); const neighb2d c2r = internal::mk_c2_row(); const neighb2d c2c = internal::mk_c2_col(); -# endif +# endif // OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/2d/array2d.hh --- oln/core/2d/array2d.hh (revision 875) +++ oln/core/2d/array2d.hh (working copy) @@ -99,6 +99,7 @@ precondition(imax >= imin and jmax >= jmin); ilen_ = imax - imin + 1; jlen_ = jmax - jmin + 1; + // FIXME: Test that ilen_ and jlen_ are not huge! allocate_(); } @@ -110,6 +111,7 @@ jlen_(jlen) { precondition(ilen > 0 and jlen > 0); + // FIXME: Test that ilen_ and jlen_ are not huge! imax_ = imin_ + ilen_; jmax_ = jmin_ + ilen_; allocate_(); Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 875) +++ oln/core/2d/image2d.hh (working copy) @@ -104,6 +104,8 @@ box2d impl_points() const; }; + template <typename T, typename D> + bool init_(image2d<T>* this_, const D& dat); # ifndef OLN_INCLUDE_ONLY @@ -217,6 +219,18 @@ return this->bbox(); } + template <typename T, typename D> + bool init_(image2d<T>* this_, const D& dat) + { + precondition(not this_->has_data()); + box2d b; + bool box_ok = init(b, with, dat); + postcondition(box_ok); + this_->data__() = new typename image2d<T>::data(b.pmin().row(), b.pmin().col(), + b.pmax().row(), b.pmax().col()); + return box_ok; + } + # endif Index: oln/core/2d/image2d_b.hh --- oln/core/2d/image2d_b.hh (revision 875) +++ oln/core/2d/image2d_b.hh (working copy) @@ -152,6 +152,8 @@ unsigned border() const; }; + template <typename T, typename D> + bool init_(image2d_b<T>* this_, const D& dat); # ifndef OLN_INCLUDE_ONLY @@ -262,6 +264,18 @@ return this->data_->border; } + template <typename T, typename D> + bool init_(image2d_b<T>* this_, const D& dat) + { + precondition(not this_->has_data()); + box2d b; + bool box_ok = init(b, with, dat); + postcondition(box_ok); + unsigned border = 2; // FIXME: Use init! + this_->data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border); + return box_ok; + } + # endif Index: oln/core/2d/box2d.hh --- oln/core/2d/box2d.hh (revision 875) +++ oln/core/2d/box2d.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_CORE_2D_BOX2D_HH # define OLN_CORE_2D_BOX2D_HH +# include <oln/core/concept/point_set.hh> // for internal::tag::box_t # include <oln/core/2d/point2d.hh> @@ -46,13 +47,13 @@ namespace internal { - template <typename C> - void init__(box2d& b, - const initializer_< pair< nrows_t<C>, ncols_t<C> > >& data); - - template <typename C> - void init__(box2d& b, - const initializer_< triplet< from_t<point2d>, nrows_t<C>, ncols_t<C> > >& data); + template <typename U> + bool init__(tag::box_t, box2d& b, + const pair< nrows_t<U>, ncols_t<U> >& data); + + template <typename U> + bool init__(tag::box_t, box2d& b, + const triplet< from_t<point2d>, nrows_t<U>, ncols_t<U> >& data); } // end of namespace oln::internal @@ -70,29 +71,31 @@ namespace internal { - template <typename C> - void init__(box2d& b, - const initializer_< pair< nrows_t<C>, ncols_t<C> > >& data) - { - C nrows = data->value1.value; - C ncols = data->value2.value; - precondition(nrows > 0 and ncols > 0); + template <typename U> + bool init__(tag::box_t, box2d& b, + const pair< nrows_t<U>, ncols_t<U> >& data) + { + unsigned nrows = data.first.value; + unsigned ncols = data.second.value; + precondition(nrows != 0 and ncols != 0); b.pmin().row() = 0; b.pmin().col() = 0; b.pmax().row() = nrows - 1; b.pmax().col() = ncols - 1; + return true; } - template <typename C> - void init__(box2d& b, - const initializer_< triplet< from_t<point2d>, nrows_t<C>, ncols_t<C> > >& data) - { - C nrows = data->value2.value; - C ncols = data->value3.value; - precondition(nrows > 0 and ncols > 0); - b.pmin() = data->value1.value; + template <typename U> + bool init__(tag::box_t, box2d& b, + const triplet< from_t<point2d>, nrows_t<U>, ncols_t<U> >& data) + { + unsigned nrows = data.second.value; + unsigned ncols = data.third.value; + precondition(nrows != 0 and ncols != 0); + b.pmin() = data.first.value; b.pmax().row() = b.pmin().row() + nrows - 1; b.pmax().col() = b.pmin().col() + ncols - 1; + return true; } } // end of namespace oln::internal Index: oln/core/2d/point2d.hh --- oln/core/2d/point2d.hh (revision 875) +++ oln/core/2d/point2d.hh (working copy) @@ -31,7 +31,6 @@ # include <oln/core/2d/grid2d.hh> # include <oln/core/internal/point2d.hh> -# include <oln/core/init.hh> namespace oln @@ -60,25 +59,18 @@ }; - /// init__ - namespace internal - { - template <typename C> - void init__(point2d& p, - const initializer_< pair< row_t<C>, col_t<C> > >& data); - } - - /// Usual 2D point class. class point2d : public internal::point2d_< point2d > { + typedef internal::initializer_< + internal::pair< internal::row_t<int>, internal::col_t<int> > + > row_col_t; public: /// Ctors. point2d(); - point2d(int row, int col); - template <typename D> - point2d(const internal::initializer_<D>& data); + point2d(int row, int col); // FIXME: Remove! + point2d(const row_col_t& dat); }; @@ -89,27 +81,16 @@ { } - point2d::point2d(int row, int col) + point2d::point2d(int row, int col) // FIXME: Remove! { this->row() = row; this->col() = col; } - template <typename D> - point2d::point2d(const internal::initializer_<D>& data) + point2d::point2d(const point2d::row_col_t& dat) { - internal::init__(*this, data); - } - - namespace internal - { - template <typename C> - void init__(point2d& p, - const initializer_< pair< row_t<C>, col_t<C> > >& data) - { - p.row() = data->value1.value; // FIXME: first - p.col() = data->value2.value; // FIXME: second - } + this->row() = dat->first.value; + this->col() = dat->second.value; } # endif Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 875) +++ oln/core/equipment.hh (working copy) @@ -30,7 +30,7 @@ # include <mlc/contract.hh> # include <oln/stc/scoop.hh> // FIXME: Remove "oln/" later. - +# include <oln/core/init.hh> # define oln_typename_shortcut__(Type, Alias) typename Type::Alias Index: oln/core/gen/box.hh --- oln/core/gen/box.hh (revision 875) +++ oln/core/gen/box.hh (working copy) @@ -32,7 +32,6 @@ # include <oln/core/concept/point.hh> # include <oln/core/concept/iterator_on_points.hh> # include <oln/core/internal/point_set_base.hh> -# include <oln/core/init.hh> namespace oln @@ -64,15 +63,6 @@ }; - /// init__ - namespace internal - { - template <typename P> - void init__(box_<P>& b, - const initializer_< pair< from_t<P>, to_t<P> > >& data); - } - - /// Generic box class based on a point class. template <typename P> @@ -81,6 +71,11 @@ { typedef box_<P> current; typedef internal::point_set_base_<current> super; + + typedef internal::initializer_< + internal::pair< internal::from_t<P>, internal::to_t<P> > + > from_to_t; + public: stc_using(point); @@ -94,6 +89,8 @@ box_(); box_(const P& pmin, const P& pmax); + box_(const from_to_t& data); + template <typename D> box_(const internal::initializer_<D>& data); @@ -227,10 +224,18 @@ } template <typename P> + box_<P>::box_(const typename box_<P>::from_to_t& dat) + { + this->pmin_ = dat->first.value; + this->pmax_ = dat->second.value; + } + + template <typename P> template <typename D> box_<P>::box_(const internal::initializer_<D>& data) { - internal::init__(*this, data); + bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value()); + postcondition(box_ok); } template <typename P> @@ -293,23 +298,6 @@ } - // -------------------- init__ - - - namespace internal - { - - template <typename P> - void init__(box_<P>& b, - const initializer_< pair< from_t<P>, to_t<P> > >& data) - { - b.pmin() = data->value1.value; - b.pmax() = data->value2.value; - } - - } - - // -------------------- box_fwd_piter_<P> Index: oln/core/gen/op.hh --- oln/core/gen/op.hh (revision 875) +++ oln/core/gen/op.hh (working copy) @@ -140,6 +140,8 @@ public: op_(); op_(L& l, R& r); + template <typename D> + op_(const internal::initializer_<D>& data); }; // end of op_<L, OpName, R> @@ -158,6 +160,14 @@ { } + template <typename L, typename OpName, typename R> + template <typename D> + op_<L, OpName, R>::op_(const internal::initializer_<D>& data) + { + bool op_ok = this->super::init__(data); + postcondition(op_ok); + } + # endif # undef super Index: oln/core/gen/single_value_image.hh --- oln/core/gen/single_value_image.hh (revision 875) +++ oln/core/gen/single_value_image.hh (working copy) @@ -120,7 +120,7 @@ single_value_image<Ps, T>::impl_owns_(const typename single_value_image<Ps, T>::point& p) const { assert(this->has_data()); - return this->data_->value1.has(p); + return this->data_->first.has(p); } template <typename Ps, typename T> @@ -128,7 +128,7 @@ single_value_image<Ps, T>::impl_has(const typename single_value_image<Ps, T>::point& p) const { assert(this->has_data()); - return this->data_->value1.has(p); + return this->data_->first.has(p); } template <typename Ps, typename T> @@ -136,7 +136,7 @@ single_value_image<Ps, T>::impl_read(const typename single_value_image<Ps, T>::point&) const { assert(this->has_data()); - return this->data_->value2; + return this->data_->second; } template <typename Ps, typename T> @@ -144,7 +144,7 @@ single_value_image<Ps, T>::impl_points() const { assert(this->has_data()); - return this->data_->value1; + return this->data_->first; } template <typename Ps, typename T> @@ -152,7 +152,7 @@ single_value_image<Ps, T>::change_value(const T& new_value) { assert(this->has_data()); - this->data_->value2 = new_value; + this->data_->second = new_value; } # endif // OLN_INCLUDE_ONLY Index: oln/core/internal/initializer.hh --- oln/core/internal/initializer.hh (revision 875) +++ oln/core/internal/initializer.hh (working copy) @@ -37,12 +37,24 @@ { template <typename S> - struct bad_initialization_of_ + struct no_proper_initialization_found_for_ + { + template <typename D> + struct with_data_being_; + }; + + template <typename S> + struct bad_initialization_call_for_ { template <typename D> struct with_; }; + template <typename S> + struct initialization_call_instead_of_assignment_ + { + }; + } // end of namespace oln::ERROR @@ -55,19 +67,25 @@ struct initializer_ { initializer_(const D& data); - const D& operator*() const; const D* operator->() const; + const D& value() const; protected: D data_; }; + // Decl: explicit error when not defined. template <typename Tag, typename Subject, typename D> - void init__(const Tag& t, Subject& s, const initializer_<D>& d); + bool init__(const Tag& t, Subject& s, const D& d); - template <typename Subject, typename D> - void init__(Subject& s, const initializer_<D>& d); + // Guard: init is not for assignment. + template <typename Tag, typename D> + bool init__(const Tag& t, D& subject, const D& data); + + // Guard: explicit error cause wrong type of last arg. + template <typename Tag, typename Subject, typename D> + bool init__(const Tag& t, Subject& s, const initializer_<D>& d); @@ -79,29 +97,40 @@ {} template <typename D> + const D* + initializer_<D>::operator->() const + { + return &(this->data_); + } + + template <typename D> const D& - initializer_<D>::operator*() const + initializer_<D>::value() const { return this->data_; } - template <typename D> - const D* - initializer_<D>::operator->() const + template <typename Tag, typename D> + bool init__(const Tag&, D& subject, const D& data) { - return &(this->data_); + mlc::abort_<Tag, typename ERROR::initialization_call_instead_of_assignment_<D> >::check(); + return false; } template <typename Tag, typename Subject, typename D> - void init__(const Tag&, Subject&, const initializer_<D>&) + bool init__(const Tag&, Subject&, const D&) { - mlc::abort_<D, typename ERROR::bad_initialization_of_<Subject>::template with_<D> >::check(); + mlc::abort_<Tag, typename ERROR::no_proper_initialization_found_for_<Subject> + ::template with_data_being_<D> >::check(); + return false; } - template <typename Subject, typename D> - void init__(Subject&, const initializer_<D>&) + template <typename Tag, typename Subject, typename D> + bool init__(const Tag&, Subject& s, const initializer_<D>& d) { - mlc::abort_<D, typename ERROR::bad_initialization_of_<Subject>::template with_<D> >::check(); + mlc::abort_<Tag, typename ERROR::bad_initialization_call_for_<Subject> + ::template with_<D> >::check(); + return false; } # endif // OLN_INCLUDE_ONLY Index: oln/core/internal/utils.hh --- oln/core/internal/utils.hh (revision 875) +++ oln/core/internal/utils.hh (working copy) @@ -61,12 +61,12 @@ { pair() {} - pair(T1 value1, T2 value2) - : value1(value1), - value2(value2) + pair(T1 first, T2 second) + : first(first), + second(second) {} - T1 value1; - T2 value2; + T1 first; + T2 second; }; @@ -77,14 +77,14 @@ { triplet() {} - triplet(T1 value1, T2 value2, T3 value3) - : value1(value1), - value2(value2), - value3(value3) - {} - T1 value1; - T2 value2; - T3 value3; + triplet(T1 first, T2 second, T3 third) + : first(first), + second(second), + third(third) + {} + T1 first; + T2 second; + T3 third; }; @@ -95,16 +95,16 @@ { quartet() {} - quartet(T1 value1, T2 value2, T3 value3, T4 value4) - : value1(value1), - value2(value2), - value3(value3), - value4(value4) - {} - T1 value1; - T2 value2; - T3 value3; - T4 value4; + quartet(T1 first, T2 second, T3 third, T4 fourth) + : first(first), + second(second), + third(third), + fourth(fourth) + {} + T1 first; + T2 second; + T3 third; + T4 fourth; }; Index: oln/core/internal/op_image_plus_nbh.hh --- oln/core/internal/op_image_plus_nbh.hh (revision 875) +++ oln/core/internal/op_image_plus_nbh.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH # define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH +# include <oln/core/concept/neighborhood.hh> # include <oln/core/gen/op.hh> # include <oln/core/gen/dpoints_piter.hh> # include <oln/core/internal/image_base.hh> @@ -36,6 +37,13 @@ namespace oln { +# define current \ + special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N > + + // Instant value. + oln_decl_instant_value(nbh); + + /// Fwd decls. template <typename Exact> struct Image; template <typename Exact> struct Neighborhood; @@ -43,7 +51,7 @@ /// Super type. template <typename I, typename N> - struct super_trait_< internal::special_op_<stc::is<Image>, I, plus, stc::is<Neighborhood>, N> > + struct super_trait_< internal::current > { typedef internal::image_extension_< op_<I, plus, N> > ret; }; @@ -51,7 +59,7 @@ /// Virtual types. template <typename I, typename N> - struct vtypes< internal::special_op_<stc::is<Image>, I, plus, stc::is<Neighborhood>, N> > + struct vtypes< internal::current > { typedef op_<I, plus, N> Exact; typedef stc_type(I, point) point__; @@ -94,11 +102,30 @@ special_op_(I& ima, N& n); }; + } // end of namespace oln::internal + + + // init + + template <typename I, typename N, typename D> + bool init_(internal::current* target, const D& dat); + + template <typename N, typename I> + bool init(Neighborhood<N>& target, + with_t, + const internal::current& dat); + + template <typename I, typename N> + bool init(Image<I>& target, + with_t, + const internal::current& dat); + + # ifndef OLN_INCLUDE_ONLY -# define current \ - special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N > + namespace internal + { template <typename I, typename N> current::special_op_() @@ -116,7 +143,7 @@ current::impl_image() { assert(this->has_data()); - return this->data_->value1; + return this->data_->first; } template <typename I, typename N> @@ -124,7 +151,7 @@ current::impl_image() const { assert(this->has_data()); - return this->data_->value1; + return this->data_->first; } template <typename I, typename N> @@ -132,14 +159,47 @@ current::impl_nbhood() const { assert(this->has_data()); - return this->data_->value2; + return this->data_->second; } -# undef current + } // end of namespace oln::internal + + + // init + + // FIXME: N is nbh? + + template <typename I, typename N, typename D> + bool init_(internal::current* this_, const D& dat) + { + precondition(not this_->has_data()); + this_->data__() = new typename op_<I, plus, N>::data; + bool ima_ok = init(this_->data__()->first, with, dat); + bool nbh_ok = init(this_->data__()->second, with, dat); + postcondition(ima_ok); + postcondition(nbh_ok); + return ima_ok and nbh_ok; + } + + template <typename N, typename I> + bool init_(Neighborhood<N>* this_, + const internal::current& data) + { + *this_ = data.nbhood(); + return true; + } + + template <typename I, typename N> + bool init(Image<I>* this_, + const internal::current& data) + { + *this_ = data.image(); + return true; + } # endif // OLN_INCLUDE_ONLY - } // end of namespace oln::internal +# undef current } // end of namespace oln Index: oln/core/internal/instant_value.hh --- oln/core/internal/instant_value.hh (revision 875) +++ oln/core/internal/instant_value.hh (working copy) @@ -31,16 +31,26 @@ # define oln_decl_instant_value(Name) \ \ +namespace internal \ +{ \ + \ template <typename V> \ -struct Name##_t : public internal::instant_value_< Name##_t, V> \ + struct Name##_t : public instant_value_< Name##_t, V> \ { \ Name##_t(const V& v) { this->value = v; } \ }; \ \ + namespace tag \ + { \ + struct Name##_t {}; \ + } \ + \ +} \ + \ template <typename V> \ -Name##_t<V> Name(const V& v) \ +internal::Name##_t<V> Name(const V& v) \ { \ - return Name##_t<V>(v); \ + return internal::Name##_t<V>(v); \ } \ \ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n @@ -61,8 +71,10 @@ V value; /* + // FIXME: do not compile with g++-3!!! + template <typename W> - operator M<W>() const; // FIXME: do not compile with g++-3!!! + operator M<W>() const; */ }; @@ -70,6 +82,8 @@ # ifndef OLN_INCLUDE_ONLY /* + // FIXME: do not compile with g++-3!!! + template <template<class> class M, typename V> template <typename W> instant_value_<M,V>::operator M<W>() const Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 875) +++ oln/core/internal/image_base.hh (working copy) @@ -53,6 +53,11 @@ + // Instant value. + oln_decl_instant_value(ima); + + + /// Fwd decls. namespace internal @@ -215,6 +220,9 @@ bool has_data() const; + // pseudo-private: + tracked_ptr<data>& data__(); + protected: image_base_(); @@ -323,6 +331,14 @@ { } + template <typename Exact> + tracked_ptr<typename image_base_<Exact>::data>& + image_base_<Exact>::data__() + { + // there is no test here since it is OK even if data_ is unset + return this->data_; + } + /// primitive_image_<Exact> template <typename Exact> @@ -407,12 +423,41 @@ } -# endif +# endif // OLN_INCLUDE_ONLY } // end of namespace oln::internal + + // init + + + template <typename P, typename I> + bool init_(box_<P>* this_, const internal::image_base_<I>& data); + + template <typename Target, typename I> + bool init_(Target* this_, const internal::single_image_morpher_<I>& data); + + +# ifndef OLN_INCLUDE_ONLY + + template <typename P, typename I> + bool init_(box_<P>* this_, const internal::image_base_<I>& data) + { + *this_ = data.bbox(); + return true; + } + + template <typename Target, typename I> + bool init_(Target* this_, const internal::single_image_morpher_<I>& data) + { + return init(*this_, with, data.image()); + } + +# endif // OLN_INCLUDE_ONLY + + } // end of namespace oln