r3501: Verify constness of "thru" image morpher

URL: https://svn.lrde.epita.fr/svn/oln/trunk ChangeLog: 2009-03-09 Frederic Bour <bour@lrde.epita.fr> Verify constness of "thru" image morpher. * milena/mln/trait/image/props.hh: Correct small typos errors. * milena/sandbox/fred/fun/abs.hh, * milena/sandbox/fred/fun/cos.hh, * milena/sandbox/fred/fun/inc.hh, * milena/sandbox/fred/fun/norm.hh, * milena/sandbox/fred/fun/red.hh: Namespace name desambiguation. * milena/sandbox/fred/fun/thru.cc, * milena/sandbox/fred/fun/thru_morpher.hh: Verify constness (WIP). --- mln/trait/image/props.hh | 8 +-- sandbox/fred/fun/abs.hh | 4 - sandbox/fred/fun/cos.hh | 4 - sandbox/fred/fun/inc.hh | 4 - sandbox/fred/fun/norm.hh | 12 ++-- sandbox/fred/fun/red.hh | 4 - sandbox/fred/fun/thru.cc | 1 sandbox/fred/fun/thru_morpher.hh | 94 ++++++++++++++++++++++++++++++--------- 8 files changed, 92 insertions(+), 39 deletions(-) Index: trunk/milena/mln/trait/image/props.hh =================================================================== --- trunk/milena/mln/trait/image/props.hh (revision 3500) +++ trunk/milena/mln/trait/image/props.hh (revision 3501) @@ -393,7 +393,7 @@ { struct any { protected: any() {} }; struct slow : any { std::string name() const { return "speed::slow"; } }; - struct fast : any { std::string name() const { return "speedw::fast"; } }; + struct fast : any { std::string name() const { return "speed::fast"; } }; struct fastest : fast { std::string name() const { return "speed::fastest"; } }; }; @@ -502,11 +502,11 @@ struct any { protected: any() {} }; struct some : any { protected: some() {} }; struct read - : some { std::string name() const { return "pw_io::read"; } }; + : some { std::string name() const { return "vw_io::read"; } }; struct read_write - : some { std::string name() const { return "pw_io::read_write"; } }; + : some { std::string name() const { return "vw_io::read_write"; } }; struct none - : any { std::string name() const { return "pw_io::none"; } }; + : any { std::string name() const { return "vw_io::none"; } }; }; // vw_set: /any/ Index: trunk/milena/sandbox/fred/fun/cos.hh =================================================================== --- trunk/milena/sandbox/fred/fun/cos.hh (revision 3500) +++ trunk/milena/sandbox/fred/fun/cos.hh (revision 3501) @@ -18,7 +18,7 @@ namespace trait { template <typename T> - struct set_unary_<fun::cos, mln::value::Floating, T> + struct set_unary_<mln::fun::cos, mln::value::Floating, T> { typedef set_unary_ ret; typedef T result; @@ -39,7 +39,7 @@ namespace meta { - typedef unary<fun::cos> cos; + typedef unary<mln::fun::cos> cos; } } Index: trunk/milena/sandbox/fred/fun/abs.hh =================================================================== --- trunk/milena/sandbox/fred/fun/abs.hh (revision 3500) +++ trunk/milena/sandbox/fred/fun/abs.hh (revision 3501) @@ -17,7 +17,7 @@ namespace trait { template <typename T> - struct set_unary_<fun::abs, mln::value::Scalar, T> + struct set_unary_<mln::fun::abs, mln::value::Scalar, T> { typedef set_unary_ ret; typedef T result; @@ -33,7 +33,7 @@ namespace meta { - typedef unary<fun::abs> abs; + typedef unary<mln::fun::abs> abs; } } Index: trunk/milena/sandbox/fred/fun/thru.cc =================================================================== --- trunk/milena/sandbox/fred/fun/thru.cc (revision 3500) +++ trunk/milena/sandbox/fred/fun/thru.cc (revision 3501) @@ -8,6 +8,7 @@ #include <iostream> #define dbg_print(val) std::cout << #val << "\n\t -> \t" << (val) << std::endl + int main() { using namespace mln; Index: trunk/milena/sandbox/fred/fun/inc.hh =================================================================== --- trunk/milena/sandbox/fred/fun/inc.hh (revision 3500) +++ trunk/milena/sandbox/fred/fun/inc.hh (revision 3501) @@ -15,7 +15,7 @@ namespace trait { template <typename T> - struct set_unary_<fun::inc, mln::value::Scalar, T> + struct set_unary_<mln::fun::inc, mln::value::Scalar, T> { typedef set_unary_ ret; typedef T result; @@ -36,7 +36,7 @@ namespace meta { - typedef unary<fun::inc> inc; + typedef unary<mln::fun::inc> inc; } } Index: trunk/milena/sandbox/fred/fun/red.hh =================================================================== --- trunk/milena/sandbox/fred/fun/red.hh (revision 3500) +++ trunk/milena/sandbox/fred/fun/red.hh (revision 3501) @@ -16,7 +16,7 @@ namespace trait { template <unsigned n> - struct set_precise_unary_<fun::red, mln::value::rgb<n> > + struct set_precise_unary_<mln::fun::red, mln::value::rgb<n> > { typedef set_precise_unary_ ret; typedef mln::value::rgb<n> argument; @@ -37,7 +37,7 @@ namespace meta { - typedef unary<fun::red> red; + typedef unary<mln::fun::red> red; } } Index: trunk/milena/sandbox/fred/fun/norm.hh =================================================================== --- trunk/milena/sandbox/fred/fun/norm.hh (revision 3500) +++ trunk/milena/sandbox/fred/fun/norm.hh (revision 3501) @@ -25,7 +25,7 @@ namespace trait { template <unsigned n, typename T> - struct set_precise_unary_<fun::norm::l1, mln::algebra::vec<n, T> > + struct set_precise_unary_<mln::fun::norm::l1, mln::algebra::vec<n, T> > { typedef set_precise_unary_ ret; typedef mln::algebra::vec<n, T> argument; @@ -44,7 +44,7 @@ }; template <unsigned n, typename T> - struct set_precise_unary_<fun::norm::l2, mln::algebra::vec<n, T> > + struct set_precise_unary_<mln::fun::norm::l2, mln::algebra::vec<n, T> > { typedef set_precise_unary_ ret; typedef mln::algebra::vec<n, T> argument; @@ -63,7 +63,7 @@ }; template <unsigned n, typename T> - struct set_precise_unary_<fun::norm::linfty, mln::algebra::vec<n, T> > + struct set_precise_unary_<mln::fun::norm::linfty, mln::algebra::vec<n, T> > { typedef set_precise_unary_ ret; typedef mln::algebra::vec<n, T> argument; @@ -86,9 +86,9 @@ { namespace norm { - typedef unary<fun::norm::l1> l1; - typedef unary<fun::norm::l2> l2; - typedef unary<fun::norm::linfty> linfty; + typedef unary<mln::fun::norm::l1> l1; + typedef unary<mln::fun::norm::l2> l2; + typedef unary<mln::fun::norm::linfty> linfty; } } } Index: trunk/milena/sandbox/fred/fun/thru_morpher.hh =================================================================== --- trunk/milena/sandbox/fred/fun/thru_morpher.hh (revision 3500) +++ trunk/milena/sandbox/fred/fun/thru_morpher.hh (revision 3501) @@ -30,7 +30,9 @@ # define THRU_HH # include <mln/core/internal/image_value_morpher.hh> +# include <mln/metal/bexpr.hh> # include "meta_function.hh" +# include "unary.hh" // For is_assignable trait // FIXME: constness of thru_image @@ -40,9 +42,23 @@ // Forward declaration. template <typename I, typename F> struct thru_image; - namespace internal { + template <typename I, typename F> struct thru_image_write; + template <typename I, typename F> struct thru_image_read; + + /// Find correct implementation + template <typename I, typename F> + struct thru_find_impl + { + typedef thru_image_write<I, F> write; + typedef thru_image_read<I, F> read; + typedef mlc_if(mlc_and(typename trait::fun::is_assignable<F>::ret, + mlc_and(mlc_not(mlc_is_const(I)), + mlc_equal(mln_trait_image_pw_io(I), + trait::image::pw_io::read_write))), + write, read) ret; + }; /// Data structure for \c mln::thru_image<I>. template <typename I, typename F> @@ -62,7 +78,7 @@ { template <typename I, typename F> - struct image_< thru_image<I, F> > : image_< I > // Same as I except... + struct image_< thru_image<I, F> > : image_< typename mln::internal::thru_find_impl<I, F>::ret > // Same as I except... { // ...these changes. typedef trait::image::category::value_morpher category; @@ -70,14 +86,29 @@ typedef trait::image::value_access::computed value_access; }; + template <typename I, typename F> + struct image_< mln::internal::thru_image_write<I, F> > : image_< I > // Same as I except... + { + typedef trait::image::vw_io::read_write vw_io; + }; + + template <typename I, typename F> + struct image_< mln::internal::thru_image_read<I, F> > : image_< I > // Same as I except... + { + typedef trait::image::vw_io::read vw_io; + }; + } // end of namespace mln::trait // FIXME: Doc! + namespace internal + { + template <typename I, typename F> - class thru_image : public internal::image_value_morpher< I, typename F::result, thru_image<I,F> > + class thru_image_read : public internal::image_value_morpher< I, typename F::result, thru_image<I,F> > { public: @@ -90,23 +121,39 @@ /// Value associated type. typedef typename F::result value; + /// Return type of read-only access. + typedef typename F::result rvalue; + + rvalue operator()(const mln_psite(I)& p) const; + + }; + + // Inheritance from read ?! + template <typename I, typename F> + class thru_image_write : public thru_image_read<I,F> + { + public: + /// Type returned by the read-write pixel value operator. typedef typename F::lresult lvalue; - /// Return type of read-only access. - typedef typename F::result rvalue; + using thru_image_read<I,F>::operator(); + lvalue operator()(const mln_psite(I)& p); + + }; + } + + template <typename I, typename F> + class thru_image : public internal::thru_find_impl<I, F>::ret + { + public: thru_image(); thru_image(I& ima); thru_image(I& ima, const F& f); - // Initialize an empty image. void init_(I& ima, const F& f); - rvalue operator()(const mln_psite(I)& p) const; - - lvalue operator()(const mln_psite(I)& p); - /// Const promotion via conversion. operator thru_image<const I, F>() const; }; @@ -116,7 +163,7 @@ Image<I>& ima); template <typename I, typename F> - thru_image<const I, F> thru(const mln::Function<F>& f, + const thru_image<const I, F> thru(const mln::Function<F>& f, const Image<I>& ima); template <typename I, typename M> @@ -124,7 +171,7 @@ thru(const mln::Meta_Function<M>& f, Image<I>& ima); template <typename I, typename M> - thru_image<const I, mln_fun_with(M, mln_value(I))> + const thru_image<const I, mln_fun_with(M, mln_value(I))> thru(const mln::Meta_Function<M>& f, const Image<I>& ima); # ifndef MLN_INCLUDE_ONLY @@ -180,17 +227,19 @@ template <typename I, typename F> inline - typename thru_image<I, F>::rvalue - thru_image<I, F>::operator()(const mln_psite(I)& p) const + thru_image<I, F>::operator thru_image<const I, F>() const { - mln_precondition(this->is_valid()); - return this->data_->f_(this->data_->ima_(p)); + thru_image<const I, F> tmp(this->data_->ima_, this->data_->f_); + return tmp; } + namespace internal + { + template <typename I, typename F> inline - typename thru_image<I, F>::lvalue - thru_image<I, F>::operator()(const mln_psite(I)& p) + typename thru_image_read<I, F>::rvalue + thru_image_read<I, F>::operator()(const mln_psite(I)& p) const { mln_precondition(this->is_valid()); return this->data_->f_(this->data_->ima_(p)); @@ -198,10 +247,13 @@ template <typename I, typename F> inline - thru_image<I, F>::operator thru_image<const I, F>() const + typename thru_image_write<I, F>::lvalue + thru_image_write<I, F>::operator()(const mln_psite(I)& p) { - thru_image<const I, F> tmp(this->data_->ima_, this->data_->default_value_); - return tmp; + mln_precondition(this->is_valid()); + return this->data_->f_(this->data_->ima_(p)); + } + } // thru
participants (1)
-
Frederic Bour