cleanup-2008 r2269: Add missing init_()

URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena ChangeLog: 2008-09-15 Guillaume Lazzara <z@lrde.epita.fr> Add missing init_(). * milena/mln/core/image/interpolated.hh, * milena/mln/core/image/plain.hh, * milena/mln/core/image/safe.hh, * milena/mln/core/image/sparse_image.hh: Add missing init_() here . * milena/mln/core/image/status.txt: Update cast_image status. --- interpolated.hh | 14 +++++++++++++- plain.hh | 8 ++++---- safe.hh | 26 +++++++++++++++++++++++++- sparse_image.hh | 38 ++++++++++++++++++++++++++++---------- status.txt | 2 +- 5 files changed, 71 insertions(+), 17 deletions(-) Index: branches/cleanup-2008/milena/mln/core/image/status.txt =================================================================== --- branches/cleanup-2008/milena/mln/core/image/status.txt (revision 2268) +++ branches/cleanup-2008/milena/mln/core/image/status.txt (revision 2269) @@ -39,7 +39,7 @@ ** value morpher -KO cast_image +OK cast_image KO value::stack_image ** domain morpher Index: branches/cleanup-2008/milena/mln/core/image/safe.hh =================================================================== --- branches/cleanup-2008/milena/mln/core/image/safe.hh (revision 2268) +++ branches/cleanup-2008/milena/mln/core/image/safe.hh (revision 2269) @@ -93,6 +93,10 @@ safe_image(I& ima); safe_image(I& ima, const mln_value(I)& default_value); + // Initialize an empty image. + void init_(I& ima); + void init_(I& ima, const mln_value(I)& default_value); + mln_rvalue(I) operator()(const mln_psite(I)& p) const; mln_morpher_lvalue(I) operator()(const mln_psite(I)& p); @@ -142,18 +146,38 @@ inline safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value) { - this->data_ = new internal::data< safe_image<I> >(ima, default_value); + mln_precondition(ima.has_data()); + init_(ima, default_value); } template <typename I> inline safe_image<I>::safe_image(I& ima) { + mln_precondition(ima.has_data()); + init_(ima, mln_value(I)()); + } + + template <typename I> + inline + void + safe_image<I>::init_(I& ima) + { + mln_precondition(ima.has_data()); this->data_ = new internal::data< safe_image<I> >(ima, mln_value(I)()); } template <typename I> inline + void + safe_image<I>::init_(I& ima, const mln_value(I)& default_value) + { + mln_precondition(ima.has_data()); + this->data_ = new internal::data< safe_image<I> >(ima, default_value); + } + + template <typename I> + inline mln_rvalue(I) safe_image<I>::operator()(const mln_psite(I)& p) const { Index: branches/cleanup-2008/milena/mln/core/image/interpolated.hh =================================================================== --- branches/cleanup-2008/milena/mln/core/image/interpolated.hh (revision 2268) +++ branches/cleanup-2008/milena/mln/core/image/interpolated.hh (revision 2269) @@ -91,6 +91,9 @@ interpolated(I& ima); interpolated(); + /// Initialize an empty image. + void init_(I& ima); + /// Test if this image has been initialized. bool has_data() const; @@ -133,7 +136,7 @@ interpolated<I>::interpolated(I& ima) { mln_precondition(ima.has_data()); - this->data_ = new internal::data< interpolated<I> >(ima); + init_(ima); } template <typename I> @@ -144,6 +147,15 @@ template <typename I> inline + void + interpolated<I>::init_(I& ima) + { + mln_precondition(ima.has_data()); + this->data_ = new internal::data< interpolated<I> >(ima); + } + + template <typename I> + inline bool interpolated<I>::has_data() const { mln_invariant(this->data_->ima_.has_data()); Index: branches/cleanup-2008/milena/mln/core/image/sparse_image.hh =================================================================== --- branches/cleanup-2008/milena/mln/core/image/sparse_image.hh (revision 2268) +++ branches/cleanup-2008/milena/mln/core/image/sparse_image.hh (revision 2269) @@ -35,7 +35,7 @@ # include <vector> # include <mln/core/internal/image_primary.hh> -# include <mln/core/p_set_of.hh> +# include <mln/core/site_set/p_set_of.hh> # include <mln/core/site_set/p_run.hh> # include <mln/value/set.hh> @@ -55,6 +55,7 @@ struct data< sparse_image<P,T> > { data(); + data(const p_set_of< p_run<P> >& s); /// Domain. p_set_of< p_run<P> > domain_; @@ -106,11 +107,11 @@ */ template <typename P, typename T> class sparse_image - : public internal::image_primary< p_set_of< p_run<P> >, + : public internal::image_primary< P, p_set_of< p_run<P> >, sparse_image<P,T> > { typedef sparse_image<P,T> self_; - typedef internal::image_primary<p_set_of< p_run<P> >, self_> super_; + typedef internal::image_primary<P, p_set_of< p_run<P> >, self_> super_; public: /// Value associated type. @@ -132,6 +133,8 @@ /// Constructor from a set of runs. sparse_image(const p_set_of< p_run<P> >& s); + /// Initialize an empty image. + void init_(const p_set_of< p_run<P> >& s); /// Add a new range to the image. void insert(const p_run<P>& r, const std::vector<T>& vals); @@ -160,13 +163,24 @@ { // internal::data< sparse_image<I,S> > - template <typename P, typename T> inline data< sparse_image<P,T> >::data() { } + template <typename P, typename T> + inline + data< sparse_image<P,T> >::data(const p_set_of< p_run<P> >& s) + { + mln_precondition(s.is_valid()); + this->domain_ = s; + const unsigned nr = s.nelements(); + this->values_.resize(nr); + for (unsigned r = 0; r < nr; ++r) + this->values_[r].resize(s[r].nsites()); + } + } // end of namespace mln::internal @@ -180,14 +194,18 @@ inline sparse_image<P,T>::sparse_image(const p_set_of< p_run<P> >& s) { - this->data_ = new internal::data< sparse_image<P,T> >(); - this->data_->domain_ = s; - const unsigned nr = s.nruns(); - this->data_->values_.resize(nr); - for (unsigned r = 0; r < nr; ++r) - this->data_->values_[r].resize(s.run(r).nsites()); + this->data_ = new internal::data< sparse_image<P,T> >(s); + } + + template <typename P, typename T> + inline + void + sparse_image<P,T>::init_(const p_set_of< p_run<P> >& s) + { + this->data_ = new internal::data< sparse_image<P,T> >(s); } + template <typename P, typename T> inline void Index: branches/cleanup-2008/milena/mln/core/image/plain.hh =================================================================== --- branches/cleanup-2008/milena/mln/core/image/plain.hh (revision 2268) +++ branches/cleanup-2008/milena/mln/core/image/plain.hh (revision 2269) @@ -100,15 +100,15 @@ /// Copy constructor from an image \p ima. plain(const I& ima); + /// Initialize an empty image. + void init_(const I& ima); + /// Assignment operator. plain<I>& operator=(const plain<I>& rhs); /// Assignment operator from an image \p ima. plain<I>& operator=(const I& ima); - /// Initialization routine. - void init(const I& ima); - /// Conversion into an image with type \c I. operator I () const; }; @@ -161,7 +161,7 @@ template <typename I> inline void - plain<I>::init(const I& ima) + plain<I>::init_(const I& ima) { mln_precondition(ima.has_data()); this->data_ = new internal::data< plain<I> >(ima);
participants (1)
-
Guillaume Lazzara