proto-1.0 170: Prepare naming and tracing features to come.

2005-04-27 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Prepare naming and tracing features to come. * oln/utils/record.hh: New file. * oln/core/2d/image2d.hh (operator=io): Update to not call io. * oln/core/abstract/image_constness.hh (set): Move method's body to... * oln/core/box.hh: ...here. * oln/core/abstract/image.hh (impl_hold_large): Change call to 'impl_hold' to avoid counting a call to 'hold'. (hold, get): Move method's body to... * oln/core/box.hh: ...here. * oln/core/abstract/data_storage.hh (record): New include. (hold, get, set): Add call count. (set_data): Comment cause unused. * oln/core/abstract/image_with_data.hh (operator=): New operator so that we will control the naming process to come. * oln/core/abstract/image_by_delegation.hh (operator=): Likewise. * oln/core/2d/image2d.hh: New constructors with 'naming'. * oln/core/gen/image_with_nbh.hh: Likewise. (join): Add naming. * oln/core/abstract/images.hh: Remove because error-prone when included ---when 'watching' we need 'box' that depends on image hierarchies so including this intermediate file leads to partially defined class. * oln/core/abstract/image_entry.hh: Update file inclusion. * oln/basics.hh: Update. * oln/utils/md5.hh: Likewise. * oln/utils/clone.hh: Likewise. * oln/basics.hh: Likewise. * oln/morpho/stat.hh: Likewise. * oln/morpho/erosion.hh: Likewise. * oln/morpho/closing.hh: Likewise. * oln/morpho/opening.hh: Likewise. Index: oln/core/abstract/image_constness.hh =================================================================== --- oln/core/abstract/image_constness.hh (revision 166) +++ oln/core/abstract/image_constness.hh (working copy) @@ -30,6 +30,18 @@ # include <oln/core/abstract/image.hh> + +// image +// +// ^ +// | +// --------------- +// | | +// +// readonly_image readwrite_image + + + /*! \namespace oln ** \brief oln namespace. */ @@ -100,10 +112,7 @@ ** \see value_box, abstract::image<I>::operator[](point) */ - void set(const point_type& p, const value_type& v) - { - return this->exact().impl_set(p, v); - } + void set(const point_type& p, const value_type& v); // impl is in image_entry.hh // FIXME: NEW: Index: oln/core/abstract/image.hh =================================================================== --- oln/core/abstract/image.hh (revision 166) +++ oln/core/abstract/image.hh (working copy) @@ -247,11 +247,7 @@ ** \see hold_large */ - bool hold(const point_type& p) const - { - precondition(this->npoints() != 0); - return this->exact().impl_hold(p); - } + bool hold(const point_type& p) const; // impl is in box.hh /*! \brief Test if \a p is a proper point to access a value of @@ -287,7 +283,9 @@ bool impl_hold_large(const point_type& p) const { - return this->hold(p); + // it relies on 'impl_hold' to avoid counting one call to + // 'hold' when the effective call is 'hold_large' + return this->exact().impl_hold(p); } @@ -371,10 +369,7 @@ ** \see value_box, abstract::image<I>::operator[](point) */ - const value_type get(const point_type& p) const - { - return this->exact().impl_get(p); - } + const value_type get(const point_type& p) const; // impl is in box.hh // FIXME: patch! Index: oln/core/abstract/data_storage.hh =================================================================== --- oln/core/abstract/data_storage.hh (revision 166) +++ oln/core/abstract/data_storage.hh (working copy) @@ -31,6 +31,7 @@ # include <mlc/any.hh> # include <mlc/to_string.hh> # include <oln/core/typedefs.hh> +# include <oln/utils/record.hh> # define oln_ds_type_of(DataStorageType, Alias) \ @@ -133,6 +134,9 @@ { if (! this->has_data()) return false; +# ifdef OLNTRACE + inc_ncalls("data_hold", *this); +# endif // ! OLNTRACE return this->exact().impl_hold(p); } @@ -140,6 +144,9 @@ { precondition(this->has_data()); precondition(this->hold_large(p)); +# ifdef OLNTRACE + inc_ncalls("data_get", *this); +# endif // ! OLNTRACE return this->exact().impl_get(p); } @@ -147,15 +154,21 @@ { precondition(this->has_data()); precondition(this->hold_large(p)); +# ifdef OLNTRACE + inc_ncalls("data_set", *this); +# endif // ! OLNTRACE this->exact().impl_set(p, v); } - void set_data(const data_type& v) - { - precondition(this->has_data()); - this->exact().impl_set_data(v); - } + // FIXME: commented below cause unused... +// void set_data(const data_type& v) +// { +// precondition(this->has_data()); +// this->exact().impl_set_data(v); +// } + + // polymorphic method with default bool hold_large(const point_type& p) const Index: oln/core/abstract/image_entry.hh =================================================================== --- oln/core/abstract/image_entry.hh (revision 166) +++ oln/core/abstract/image_entry.hh (working copy) @@ -28,7 +28,11 @@ #ifndef OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH # define OLENA_CORE_ABSTRACT_IMAGE_ENTRY_HH -# include <oln/core/abstract/images.hh> +# include <oln/core/abstract/image_constness.hh> +# include <oln/core/abstract/image_dimension.hh> +# include <oln/core/abstract/image_neighbness.hh> +# include <oln/core/abstract/image_typeness.hh> +# include <oln/core/abstract/image_valuedness.hh> Index: oln/core/abstract/images.hh =================================================================== --- oln/core/abstract/images.hh (revision 166) +++ oln/core/abstract/images.hh (working copy) @@ -1,47 +0,0 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory -// -// This file is part of the Olena Library. This library is free -// software; you can redistribute it and/or modify it under the terms -// of the GNU General Public License version 2 as published by the -// Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this library; see the file COPYING. If not, write to -// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. -// -// As a special exception, you may use this file as part of a free -// software library without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to -// produce an executable, this file does not by itself cause the -// resulting executable to be covered by the GNU General Public -// License. This exception does not however invalidate any other -// reasons why the executable file might be covered by the GNU General -// Public License. - -#ifndef OLENA_CORE_ABSTRACT_IMAGES_HH -# define OLENA_CORE_ABSTRACT_IMAGES_HH - - -# include <oln/core/abstract/image.hh> - -// hierarchies: -# include <oln/core/abstract/image_constness.hh> -# include <oln/core/abstract/image_dimension.hh> -# include <oln/core/abstract/image_neighbness.hh> -# include <oln/core/abstract/image_typeness.hh> -# include <oln/core/abstract/image_valuedness.hh> - - -// hierarchy entry -# include <oln/core/abstract/image_entry.hh> - - - -#endif // ! OLENA_CORE_ABSTRACT_IMAGES_HH Index: oln/core/abstract/image_with_data.hh =================================================================== --- oln/core/abstract/image_with_data.hh (revision 166) +++ oln/core/abstract/image_with_data.hh (working copy) @@ -31,6 +31,7 @@ # include <mlc/tracked_ptr.hh> # include <oln/core/abstract/image_entry.hh> +# include <oln/utils/record.hh> /*! \namespace oln @@ -201,6 +202,17 @@ this->data_ = rhs.data_; } + + /*! \brief Op= constructor (protected) with shallow data copy. + */ + image_with_data& operator=(image_with_data& rhs) + { + // FIXME: handle naming here... + this->data_ = rhs.data_; + return *this; + } + + /*! \brief Data storage. */ mlc::tracked_ptr<storage_type> data_; Index: oln/core/abstract/image_by_delegation.hh =================================================================== --- oln/core/abstract/image_by_delegation.hh (revision 166) +++ oln/core/abstract/image_by_delegation.hh (working copy) @@ -92,15 +92,24 @@ this->exact_ptr = (E*)(void*)(this); } + image_by_delegation& operator=(const image_by_delegation& rhs) + { + // FIXME: handle naming here... + this->image_ = rhs.image_; + return *this; + } + box<I> image_; public: - I& image() { return this->image_.unbox(); } + I& image() const { return this->image_.unbox(); } I& impl_delegate() { return this->image_.unbox(); } const I& impl_delegate() const { return this->image_.unbox(); } }; + + /// Const version of image_by_delegation template <typename I, typename E> @@ -125,6 +134,13 @@ this->exact_ptr = (E*)(void*)(this); } + image_by_delegation& operator=(const image_by_delegation& rhs) + { + // FIXME: handle naming here... + this->image_ = rhs.image_; + return *this; + } + box<const I> image_; public: Index: oln/core/2d/image2d.hh =================================================================== --- oln/core/2d/image2d.hh (revision 166) +++ oln/core/2d/image2d.hh (working copy) @@ -32,6 +32,7 @@ # include <oln/core/abstract/image_like_.hh> # include <oln/core/2d/array2d.hh> # include <oln/core/2d/niter2d.hh> +# include <oln/utils/record.hh> /*! \namespace oln @@ -122,46 +123,85 @@ this->exact_ptr = this; } - image2d(const size2d& size) : super_type(size) + image2d(const std::string& name) { this->exact_ptr = this; + registering(*this, name); } + image2d(const size2d& size) : + super_type(size) + { + this->exact_ptr = this; + } + + image2d(const size2d& size, + const std::string& name) : + super_type(size) + { + this->exact_ptr = this; + registering(*this, name); + } + image2d(coord_t nrows, coord_t ncols, size_t border = 2) : super_type(size2d(nrows, ncols, border)) { this->exact_ptr = this; } + image2d(coord_t nrows, coord_t ncols, size_t border, + const std::string& name) : + super_type(size2d(nrows, ncols, border)) + { + this->exact_ptr = this; + registering(*this, name); + } + image2d(image2d& rhs) : super_type(rhs) { this->exact_ptr = this; } - image2d& operator=(image2d& rhs) + + image2d& operator=(image2d rhs) { - if (&rhs == this) - return *this; + // FIXME: check that both objects are *really* different super_type::operator=(rhs); return *this; }; - template <typename I, typename E> - image2d& operator=(abstract::image_like_<I, E> rhs) - { - *this = rhs.real(); - return *this; - } +// image2d& operator=(box<image2d> rhs) +// { +// std::cout << "hop(box)" << std::endl; +// if (&(rhs->unbox()) == this) +// return *this; +// super_type::operator=(rhs.unbox()); +// return *this; +// }; +// template <typename I, typename E> +// image2d& operator=(abstract::image_like_<I, E> rhs) +// { +// *this = rhs.real(); +// return *this; +// } + image2d& operator=(const io::filename& rhs) { - io::do_read(*this, rhs); + // FIXME HERE: hack to avoid calling io +// io::do_read(*this, rhs); + image2d tmp(4, 4); + *this = tmp; return *this; } // FIXME: idem with abstract::image2d<E> (?) + + // without impl + image2d(const image2d&); + }; Index: oln/core/box.hh =================================================================== --- oln/core/box.hh (revision 166) +++ oln/core/box.hh (working copy) @@ -240,7 +240,63 @@ }; -} +} // end of namespace oln + +# include <oln/utils/record.hh> + + + +namespace oln { + + namespace abstract + { + + + /// Implementation of abstract::image<E>::hold(p). + + template <typename E> + bool + image<E>::hold(const oln_type_of(E, point)& p) const + { +# ifdef OLNTRACE + inc_ncalls("hold", *this); +# endif // ! OLNTRACE + return this->exact().impl_hold(p); + } + + + /// Implementation of abstract::image<E>::get(p). + + template <typename E> + const oln_type_of(E, value) + image<E>::get(const oln_type_of(E, point)& p) const + { +# ifdef OLNTRACE + inc_ncalls("get", *this); +# endif // ! OLNTRACE + return this->exact().impl_get(p); + } + + + /// Implementation of abstract::readwrite_image<E>::set(p, v). + + template <typename E> + void + readwrite_image<E>::set(const oln_type_of(E, point)& p, + const oln_type_of(E, value)& v) + { +# ifdef OLNTRACE + inc_ncalls("set", *this); +# endif // ! OLNTRACE + return this->exact().impl_set(p, v); + } + + + } // end of namespace oln::abstract + +} // end of namespace oln + + #endif // ! OLENA_CORE_BOX_HH Index: oln/core/gen/image_with_nbh.hh =================================================================== --- oln/core/gen/image_with_nbh.hh (revision 167) +++ oln/core/gen/image_with_nbh.hh (working copy) @@ -30,7 +30,9 @@ # include <oln/core/abstract/image_with_extension.hh> # include <oln/core/abstract/neighborhood.hh> +# include <oln/utils/record.hh> + namespace oln { // fwd decl @@ -51,6 +53,7 @@ typedef image_with_nbh< oln_type_of(I, concrete), N> concrete_type; }; + template <typename I, typename N> struct image_with_nbh : public abstract::image_with_extension < I, image_with_nbh<I, N> > { @@ -76,13 +79,34 @@ { } + image_with_nbh(const std::string& name) + { + registering(*this, name); + } + + image_with_nbh(const oln_type_of(I, size)& size, + const std::string& name) + { + // FIXME: illegal hardware instruction when uncommented below!!! +// I tmp(size, name); + // FIXME: other attemps below +// registering(tmp, name, true); +// tmp.set_name(name); + + I tmp(size); // FIXME: hack + this->image_ = tmp; + registering(*this, name); //, true); + } + image_with_nbh(abstract::image<I>& image, - const abstract::neighborhood<N>& nbh) : + const abstract::neighborhood<N>& nbh, + const std::string& name) : super_type(image), nbh_(nbh.exact()) { + registering(*this, name); } - + const N& impl_nbh_get() const { return nbh_; @@ -98,10 +122,14 @@ template <typename I, typename N> image_with_nbh<I, N> - join(abstract::image<I>& image, - const abstract::neighborhood<N>& nbh) + join(abstract::image<I>& image, const abstract::neighborhood<N>& nbh) { - image_with_nbh<I, N> tmp(image, nbh); + entering("join(image,nbh)"); + registering(image, "image"); + + image_with_nbh<I, N> tmp(image, nbh, "tmp"); + + exiting("join(image,nbh)"); return tmp; } Index: oln/utils/md5.hh =================================================================== --- oln/utils/md5.hh (revision 166) +++ oln/utils/md5.hh (working copy) @@ -31,7 +31,7 @@ # include <ntg/all.hh> # include <vector> -# include <oln/core/abstract/images.hh> +# include <oln/core/abstract/image_entry.hh> # include <oln/core/abstract/piter.hh> # include <oln/utils/key.hh> Index: oln/utils/record.hh =================================================================== --- oln/utils/record.hh (revision 0) +++ oln/utils/record.hh (revision 0) @@ -0,0 +1,61 @@ +// Copyright (C) 2005 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_OLN_UTILS_RECORD_HH +# define OLENA_OLN_UTILS_RECORD_HH + +# include <string> + + +namespace oln +{ + + void entering(const std::string& local_context_name) + { + } + + void exiting(const std::string& local_context_name) + { + } + + template <typename T> + void inc_ncalls(const std::string& code_name, + const T& obj) + { + } + + template <typename T> + void registering(const T& obj, + const std::string& var_name) + { + } + +} // end of namespace oln + + + +#endif // ! OLENA_OLN_UTILS_RECORD_HH Index: oln/utils/clone.hh =================================================================== --- oln/utils/clone.hh (revision 166) +++ oln/utils/clone.hh (working copy) @@ -29,6 +29,7 @@ # define OLN_UTILS_CLONE_HH # include <oln/basics.hh> +# include <oln/core/abstract/image_operator.hh> namespace oln { Index: oln/basics.hh =================================================================== --- oln/basics.hh (revision 166) +++ oln/basics.hh (working copy) @@ -25,8 +25,6 @@ // reasons why the executable file might be covered by the GNU General // Public License. - - #ifndef OLENA_BASICS_HH # define OLENA_BASICS_HH @@ -47,12 +45,15 @@ // ntg:: +// FIXME: include a fake ntg/decls.hh that should be in oln/ + + // oln:: -# include <oln/core/typedefs.hh> -# include <oln/core/box.hh> +# include <oln/core/coord.hh> // FIXME: why? -# include <oln/core/coord.hh> +# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/image_entry.hh> # include <oln/core/abstract/size.hh> # include <oln/core/abstract/point.hh> @@ -60,9 +61,6 @@ # include <oln/core/abstract/window.hh> # include <oln/core/abstract/neighborhood.hh> -# include <oln/core/abstract/images.hh> -# include <oln/core/abstract/image_operator.hh> - # include <oln/core/abstract/piter.hh> # include <oln/core/abstract/qiter.hh> # include <oln/core/abstract/niter.hh> Index: oln/morpho/stat.hh =================================================================== --- oln/morpho/stat.hh (revision 166) +++ oln/morpho/stat.hh (working copy) @@ -30,7 +30,7 @@ # include <mlc/cmp.hh> # include <ntg/bin.hh> -# include <oln/core/abstract/images.hh> +# include <oln/core/abstract/image_entry.hh> # include <oln/core/abstract/window.hh> # include <oln/funobj/accum.hh> Index: oln/morpho/erosion.hh =================================================================== --- oln/morpho/erosion.hh (revision 166) +++ oln/morpho/erosion.hh (working copy) @@ -31,7 +31,6 @@ # include <mlc/cmp.hh> # include <mlc/to_string.hh> -# include <oln/core/abstract/images.hh> # include <oln/core/abstract/image_operator.hh> # include <oln/morpho/stat.hh> Index: oln/morpho/closing.hh =================================================================== --- oln/morpho/closing.hh (revision 166) +++ oln/morpho/closing.hh (working copy) @@ -31,7 +31,6 @@ # include <mlc/cmp.hh> # include <mlc/to_string.hh> -# include <oln/core/abstract/images.hh> # include <oln/core/abstract/image_operator.hh> # include <oln/morpho/dilation.hh> Index: oln/morpho/opening.hh =================================================================== --- oln/morpho/opening.hh (revision 166) +++ oln/morpho/opening.hh (working copy) @@ -31,7 +31,6 @@ # include <mlc/cmp.hh> # include <mlc/to_string.hh> -# include <oln/core/abstract/images.hh> # include <oln/core/abstract/image_operator.hh> # include <oln/morpho/dilation.hh>
participants (1)
-
Thierry GERAUD