https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Optimize the return of Image::points().
* oln/debug/iota.hh: Update.
* oln/core/rle/rle_image.hh,
* oln/core/sparse/sparse_image.hh: Add assertions; Fix include.
* oln/core/gen/niter_has.hh (pset_): Add &.
* oln/core/concept/image.hh (bbox, points, impl_points): Add &.
* oln/core/concept/image_identity.hh,
* oln/core/rle/rle_image.hh,
* oln/core/sparse/sparse_image.hh,
* oln/core/1d/image1d.hh,
* oln/core/1d/image1d_b.hh,
* oln/core/2d/image2d.hh,
* oln/core/2d/image2d_b.hh,
* oln/core/internal/op_image_restricted_to_pset.hh (impl_points):
Update.
* oln/basics1d.hh,
* oln/basics2d.hh: Remove; obsolete.
* oln/core/internal/utils.hh (pair, triplet): New specializations.
* oln/core/1d/array1d.hh,
* oln/core/2d/array2d.hh: Add method decls without impl.
* oln/core/1d/image1d.hh,
* oln/core/1d/image1d_b.hh,
* oln/core/2d/image2d.hh,
* oln/core/2d/image2d_b.hh: Make use of pair and triplet.
core/1d/array1d.hh | 7 +
core/1d/image1d.hh | 35 ++++-----
core/1d/image1d_b.hh | 20 ++---
core/2d/array2d.hh | 8 ++
core/2d/image2d.hh | 49 +++++++-----
core/2d/image2d_b.hh | 104 ++++++++++-----------------
core/concept/image.hh | 9 +-
core/concept/image_identity.hh | 4 -
core/gen/niter_has.hh | 2
core/internal/op_image_restricted_to_pset.hh | 4 -
core/internal/utils.hh | 75 +++++++++++++++++--
core/rle/rle_image.hh | 17 ++--
core/sparse/sparse_image.hh | 25 ++++--
debug/iota.hh | 4 -
14 files changed, 216 insertions(+), 147 deletions(-)
Index: oln/debug/iota.hh
--- oln/debug/iota.hh (revision 899)
+++ oln/debug/iota.hh (working copy)
@@ -41,8 +41,8 @@
template <typename I>
void iota(Mutable_Image<I>& in_out)
{
- typename I::value v = 0;
- typename I::fwd_piter p(in_out.points());
+ oln_value(I) v = 0;
+ oln_fwd_piter(I) p(in_out.points());
for_all(p)
in_out(p) = v++;
}
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 899)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -26,12 +26,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_IMAGE_HH
-# define OLN_CORE_RLE_RLE_IMAGE_HH
+#ifndef OLN_CORE_GEN_RLE_IMAGE_HH
+# define OLN_CORE_GEN_RLE_IMAGE_HH
# include <map>
-# include <utility>
-
# include <oln/core/internal/image_base.hh>
# include <oln/core/rle/rle_psite.hh>
@@ -97,7 +95,7 @@
rle_image();
/// pset impl_points() const : return image pset
- pset impl_points() const;
+ const pset& impl_points() const;
/// bool impl_owns_(const psite& p) const : same has impl_has
bool impl_owns_(const psite& p) const;
/// void insert(const point& p, unsigned len, value val) : insert a new range on
the image
@@ -118,9 +116,10 @@
}
template <typename P, typename T>
- typename rle_image<P, T>::pset
+ const typename rle_image<P, T>::pset&
rle_image<P, T>::impl_points() const
{
+ assert(this->has_data());
return this->data_->first;
}
@@ -128,6 +127,7 @@
bool
rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p)
const
{
+ assert(this->has_data());
return this->data_->first.has(p.start_);
}
@@ -136,6 +136,7 @@
rle_image<P, T>::insert(const typename rle_image<P, T>::point& p,
unsigned len, rle_image<P, T>::value val)
{
+ assert(this->has_data());
this->data_->first.insert(p, len);
this->data_->second[p] = val;
}
@@ -144,6 +145,7 @@
typename rle_image<P, T>::rvalue
rle_image<P, T>::impl_read(const rle_image<P, T>::psite& ps) const
{
+ assert(this->has_data());
typename std::map<point, value>::const_iterator irun;
irun = this->data_->second.find(ps.start_);
@@ -156,6 +158,7 @@
typename rle_image<P, T>::lvalue
rle_image<P, T>::impl_read_write(const rle_image<P, T>::psite& ps)
{
+ assert(this->has_data());
typename std::map<point, value>::iterator irun;
irun = this->data_->second.find(ps.start_);
@@ -168,4 +171,4 @@
} // end of namespace oln
-#endif // !OLN_CORE_RLE_RLE_IMAGE_HH
+#endif // ! OLN_CORE_GEN_RLE_IMAGE_HH
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 899)
+++ oln/core/concept/image.hh (working copy)
@@ -134,10 +134,10 @@
bool owns_(const psite& p) const;
rvalue operator()(const psite& p) const;
- pset points() const;
+ const pset& points() const;
// With final impl:
- box bbox() const;
+ const box& bbox() const;
protected:
Image();
@@ -438,14 +438,14 @@
}
template <typename Exact>
- typename Image<Exact>::box
+ const typename Image<Exact>::box&
Image<Exact>::bbox() const
{
return this->points().bbox(); // Final impl.
}
template <typename Exact>
- typename Image<Exact>::pset
+ const typename Image<Exact>::pset&
Image<Exact>::points() const
{
return exact(this)->impl_points();
@@ -512,7 +512,6 @@
bool
Point_Wise_Accessible_Image<Exact>::has(const typename
Point_Wise_Accessible_Image<Exact>::point& p) const
{
- // FIXME: precondition(this->owns_(p)); ?
return this->points().has(p);
}
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 899)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -54,7 +54,7 @@
bool impl_owns_(const psite& p) const;
rvalue impl_read(const psite& p) const;
- pset impl_points() const;
+ const pset& impl_points() const;
};
@@ -192,7 +192,7 @@
}
template <typename Exact>
- typename set_impl< Image, behavior::identity, Exact >::pset
+ const typename set_impl< Image, behavior::identity, Exact >::pset&
set_impl< Image, behavior::identity, Exact >::impl_points() const
{
return exact(this)->image().points();
Index: oln/core/sparse/sparse_image.hh
--- oln/core/sparse/sparse_image.hh (revision 899)
+++ oln/core/sparse/sparse_image.hh (working copy)
@@ -25,10 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SPARSE_IMAGE_HH_
-# define SPARSE_IMAGE_HH_
+#ifndef OLN_CORE_GEN_SPARSE_IMAGE_HH
+# define OLN_CORE_GEN_SPARSE_IMAGE_HH
# include <vector>
+# include <map>
+
+# include <oln/core/internal/image_base.hh>
+
+
namespace oln
{
@@ -82,7 +87,7 @@
sparse_image();
- pset impl_points() const;
+ const pset& impl_points() const;
bool impl_owns_(const psite& p) const;
void insert(const point& p, unsigned len, const std::vector<value>&
val);
rvalue impl_read(const psite& p) const;
@@ -90,8 +95,8 @@
};
-# ifndef OLN_INCLUDE_ONLY
+# ifndef OLN_INCLUDE_ONLY
template <typename P, typename T>
sparse_image<P, T>::sparse_image()
@@ -100,9 +105,10 @@
}
template <typename P, typename T>
- typename sparse_image<P, T>::pset
+ const typename sparse_image<P, T>::pset&
sparse_image<P, T>::impl_points() const
{
+ assert(this->has_data());
return this->data_->first;
}
@@ -110,6 +116,7 @@
bool
sparse_image<P, T>::impl_owns_(const typename sparse_image<P,
T>::psite& p) const
{
+ assert(this->has_data());
return this->data_->first.has(p.start_);
}
@@ -117,6 +124,7 @@
void
sparse_image<P, T>::insert(const point& p, unsigned len, const
std::vector<typename sparse_image<P, T>::value>& val)
{
+ assert(this->has_data());
this->data_->first.insert(p, len);
this->data_->second[p] = val;
}
@@ -125,6 +133,7 @@
typename sparse_image<P, T>::rvalue
sparse_image<P, T>::impl_read(const sparse_image<P, T>::psite& ps)
const
{
+ assert(this->has_data());
typename std::map<point, std::vector<value> >::const_iterator irun;
irun.operator= (this->data_->second.find(ps.start_));
@@ -136,6 +145,7 @@
typename sparse_image<P, T>::lvalue
sparse_image<P, T>::impl_read_write(const sparse_image<P, T>::psite&
ps)
{
+ assert(this->has_data());
typename std::map<point, std::vector<value> >::iterator irun;
irun.operator= (this->data_->second.find(ps.start_));
@@ -143,10 +153,9 @@
return irun->second[ps.index_];
}
-
-# endif /* !OLN_INCLUDE_ONLY */
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
-#endif /* !SPARSE_IMAGE_HH_ */
+#endif // ! OLN_CORE_GEN_SPARSE_IMAGE_HH
Index: oln/core/1d/array1d.hh
--- oln/core/1d/array1d.hh (revision 899)
+++ oln/core/1d/array1d.hh (working copy)
@@ -43,6 +43,13 @@
{
public:
+ // Not impled.
+ array1d_();
+ array1d_(const array1d_<T,C>& rhs);
+ void operator=(const array1d_<T,C>&);
+ // end of Not impled.
+
+
/// Ctor.
array1d_(C imin, C imax);
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 899)
+++ oln/core/1d/image1d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_1D_IMAGE1D_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/1d/array1d.hh>
# include <oln/core/1d/box1d.hh>
@@ -41,7 +42,7 @@
template <typename T> class image1d;
- /// Virtual types.
+ // Virtual types.
template <typename T>
struct vtypes< image1d<T> >
{
@@ -55,14 +56,14 @@
typedef T& lvalue;
typedef box1d pset;
- typedef array1d_<value, coord> data;
+ typedef internal::pair< array1d_<value, coord>*, box1d > data;
typedef image1d<T> plain;
typedef image1d<pl::value> skeleton;
};
- /// Super type.
+ // Super type.
template <typename T>
struct super_trait_< image1d<T> >
{
@@ -78,6 +79,7 @@
{
typedef image1d<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array1d_<T, int> array_t;
public:
stc_using(data);
@@ -95,7 +97,7 @@
std::size_t impl_npoints() const;
- box1d impl_points() const;
+ const box1d& impl_points() const;
};
@@ -110,28 +112,30 @@
template <typename T>
image1d<T>::image1d(const box1d& b)
{
- this->data_ = new data(b.pmin().ind(), b.pmax().ind());
+ this->data_ = new data(new array_t(b.pmin().ind(), b.pmax().ind()),
+ b);
}
template <typename T>
image1d<T>::image1d(unsigned n)
{
precondition(n != 0);
- this->data_ = new data(0, n - 1);
+ this->data_ = new data(new array_t(0, n - 1),
+ box1d(0, n - 1));
}
template <typename T>
bool image1d<T>::impl_owns_(const point1d& p) const
{
assert(this->has_data());
- return this->data_->has(p.ind());
+ return this->data_->first.has(p.ind());
}
template <typename T>
const T& image1d<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
- return this->data_->operator()(p.ind());
+ return this->data_->first.operator()(p.ind());
}
template <typename T>
@@ -139,14 +143,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first.operator[](i);
}
template <typename T>
T& image1d<T>::impl_read_write(const point1d& p)
{
assert(this->has_data());
- return this->data_->operator()(p.ind());
+ return this->data_->first.operator()(p.ind());
}
template <typename T>
@@ -154,7 +158,7 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first.operator[](i);
}
template <typename T>
@@ -162,18 +166,17 @@
{
// faster than the default code given by primitive_image_
assert(this->has_data());
- return this->data_->ncells();
+ return this->data_->first.ncells();
}
template <typename T>
- box1d image1d<T>::impl_points() const
+ const box1d& image1d<T>::impl_points() const
{
assert(this->has_data());
- box1d b(this->data_->imin(), this->data_->imax());
- return b;
+ return this->data_->second;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 899)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -46,7 +46,7 @@
template <typename T> class image1d_b;
- /// Virtual types.
+ // Virtual types.
template <typename T>
struct vtypes< image1d_b<T> >
{
@@ -60,9 +60,9 @@
typedef T& lvalue;
typedef box1d pset;
- typedef internal::triplet< array1d_<T, int>,
+ typedef internal::triplet< array1d_<T, int>*,
unsigned,
- box_<point1d> > data;
+ box1d > data;
typedef mlc::true_ vborder;
@@ -71,7 +71,7 @@
};
- /// Super type.
+ // Super type.
template <typename T>
struct super_trait_< image1d_b<T> >
{
@@ -80,7 +80,7 @@
};
- /// General 1D image class.
+ /// General 1D image class with an external virtual border.
template <typename T>
class image1d_b : public internal::plain_primitive_image_< image1d_b<T> >
@@ -105,7 +105,7 @@
std::size_t impl_npoints() const;
- box1d impl_points() const;
+ const box1d& impl_points() const;
unsigned impl_border() const;
};
@@ -122,7 +122,7 @@
template <typename T>
image1d_b<T>::image1d_b(const box1d& b, unsigned border)
{
- this->data_ = new data(array_t(b.pmin().ind() - border,
+ this->data_ = new data(new array_t(b.pmin().ind() - border,
b.pmax().ind() + border),
border,
b);
@@ -132,7 +132,7 @@
image1d_b<T>::image1d_b(unsigned n, unsigned border)
{
precondition(n != 0);
- this->data_ = new data(array_t(- border,
+ this->data_ = new data(new array_t(- border,
n - 1 + border),
border,
box1d(0, n - 1));
@@ -176,7 +176,7 @@
}
template <typename T>
- box1d image1d_b<T>::impl_points() const
+ const box1d& image1d_b<T>::impl_points() const
{
assert(this->has_data());
return this->data_->third;
@@ -189,7 +189,7 @@
return this->data_->second;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/array2d.hh
--- oln/core/2d/array2d.hh (revision 899)
+++ oln/core/2d/array2d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_ARRAY2D_HH
# include <cstddef>
+# include <iostream>
# include <mlc/contract.hh>
@@ -43,6 +44,13 @@
{
public:
+ // Not impled.
+ array2d_();
+ array2d_(const array2d_<T,C>& rhs);
+ void operator=(const array2d_<T,C>&);
+ // end of Not impled.
+
+
/// Ctor.
array2d_(C imin, C jmin, C imax, C jmax);
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 899)
+++ oln/core/2d/image2d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_IMAGE2D_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/box2d.hh>
@@ -55,7 +56,7 @@
typedef T& lvalue;
typedef box2d pset;
- typedef array2d_<value, coord> data;
+ typedef internal::pair< array2d_<value, coord>*, box2d > data;
typedef image2d<T> plain;
typedef image2d<pl::value> skeleton;
@@ -78,6 +79,7 @@
{
typedef image2d<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array2d_<T, int> array_t;
public:
stc_using(data);
@@ -99,7 +101,7 @@
std::size_t impl_npoints() const;
- box2d impl_points() const;
+ const box2d& impl_points() const;
};
template <typename T, typename D>
@@ -116,36 +118,40 @@
template <typename T>
image2d<T>::image2d(const box2d& b)
{
- this->data_ = new data(b.pmin().row(), b.pmin().col(),
- b.pmax().row(), b.pmax().col());
+ this->data_ = new data(new array_t(b.pmin().row(), b.pmin().col(),
+ b.pmax().row(), b.pmax().col()),
+ b);
}
template <typename T>
image2d<T>::image2d(unsigned nrows, unsigned ncols)
{
precondition(nrows != 0 and ncols != 0);
- this->data_ = new data(0, 0, nrows - 1, ncols - 1);
+ this->data_ = new data(new array_t(0, 0,
+ nrows - 1, ncols - 1),
+ box2d(point2d(0, 0),
+ point2d(nrows - 1, ncols - 1)));
}
template <typename T>
bool image2d<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
- return this->data_->has(p.row(), p.col());
+ return this->data_->first.has(p.row(), p.col());
}
template <typename T>
bool image2d<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->has(row, col);
+ return this->data_->first.has(row, col);
}
template <typename T>
const T& image2d<T>::impl_read(const point2d& p) const
{
assert(this->has_data());
- return this->data_->operator()(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -153,21 +159,21 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first[i];
}
template <typename T>
const T& image2d<T>::impl_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->operator()(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
T& image2d<T>::impl_read_write(const point2d& p)
{
assert(this->has_data());
- return this->data_->operator()(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -175,14 +181,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first[i];
}
template <typename T>
T& image2d<T>::impl_at(int row, int col)
{
assert(this->has_data());
- return this->data_->operator()(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
@@ -190,18 +196,14 @@
{
// faster than the default code given by primitive_image_
assert(this->has_data());
- return this->data_->ncells();
+ return this->data_->first.ncells();
}
template <typename T>
- box2d image2d<T>::impl_points() const
+ const box2d& image2d<T>::impl_points() const
{
assert(this->has_data());
- point2d
- pmin(this->data_->imin(), this->data_->jmin()),
- pmax(this->data_->imax(), this->data_->jmax());
- box2d b(pmin, pmax);
- return b;
+ return this->data_->second;
}
template <typename T, typename D>
@@ -211,8 +213,11 @@
box2d b;
bool box_ok = init(b, with, dat);
postcondition(box_ok);
- target.data__() = new typename image2d<T>::data(b.pmin().row(),
b.pmin().col(),
- b.pmax().row(), b.pmax().col());
+ array2d_<T,int> ptr = new array2d_<T,int>(b.pmin().row(),
+ b.pmin().col(),
+ b.pmax().row(),
+ b.pmax().col());
+ target.data__() = new typename image2d<T>::data(ptr, b);
return box_ok;
}
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 899)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_IMAGE2D_B_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/box2d.hh>
@@ -38,49 +39,6 @@
{
- // FIXME: Move it!
-
- namespace internal
- {
-
-
- template <typename P, typename T>
- struct f_point_value_to_array_;
-
- template <typename T>
- struct f_point_value_to_array_< point2d, T >
- {
- typedef array2d_<T, int> ret;
- };
-
-
- template <typename P, typename T>
- struct array_b_
- {
- typedef typename f_point_value_to_array_<P, T>::ret array_t;
- typedef typename P::coord coord;
-
- array_b_(const P& pmin, const P& pmax, unsigned border)
- : array(pmin.row() - border, pmin.col() - border,
- pmax.row() + border, pmax.col() + border),
- border(border),
- box(pmin, pmax)
- {
- }
-
- array_t array;
- unsigned border;
- box_<P> box;
- };
-
-
- } // end of namespace oln::internal
-
-
- // end of FIXME
-
-
-
// Fwd decl.
template <typename T> class image2d_b;
@@ -99,14 +57,14 @@
typedef T& lvalue;
typedef box2d pset;
- typedef internal::array_b_<point2d, T> data;
+ typedef internal::triplet< array2d_<T, int>*,
+ unsigned,
+ box2d > data;
typedef mlc::true_ vborder;
typedef image2d_b<T> plain;
typedef image2d_b<pl::value> skeleton;
-
- // FIXME: wrong qiter!!!
};
@@ -126,6 +84,7 @@
{
typedef image2d_b<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array2d_<T, int> array_t;
public:
stc_using(data);
@@ -147,7 +106,7 @@
std::size_t impl_npoints() const;
- box2d impl_points() const;
+ const box2d& impl_points() const;
unsigned impl_border() const;
std::size_t pad(const dpoint2d& dp) const;
@@ -156,6 +115,10 @@
// template <typename T, typename D>
// bool init_(image2d_b<T>* this_, const D& dat);
+ template <typename T, typename D>
+ bool prepare(image2d_b<T>& target, with_t, const D& dat);
+
+
# ifndef OLN_INCLUDE_ONLY
@@ -167,37 +130,46 @@
template <typename T>
image2d_b<T>::image2d_b(const box2d& b, unsigned border)
{
- this->data_ = new data(b.pmin(), b.pmax(), border);
+ this->data_ = new data(new array_t(b.pmin().row() - border,
+ b.pmin().col() - border,
+ b.pmax().row() + border,
+ b.pmax().col() + border),
+ border,
+ b);
}
template <typename T>
image2d_b<T>::image2d_b(unsigned nrows, unsigned ncols, unsigned border)
{
precondition(nrows != 0 and ncols != 0);
- this->data_ = new data(point2d(0, 0),
- point2d(nrows - 1, ncols - 1),
- border);
+ this->data_ = new data(new array_t(- border,
+ - border,
+ nrows - 1 + border,
+ ncols - 1 + border),
+ border,
+ box2d(point2d(0, 0),
+ point2d(nrows - 1, ncols - 1)));
}
template <typename T>
bool image2d_b<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
- return this->data_->array.has(p.row(), p.col());
+ return this->data_->first.has(p.row(), p.col());
}
template <typename T>
bool image2d_b<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->array.has(row, col);
+ return this->data_->first.has(row, col);
}
template <typename T>
const T& image2d_b<T>::impl_read(const point2d& p) const
{
assert(this->has_data());
- return this->data_->array(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -205,21 +177,21 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->array[i];
+ return this->data_->first[i];
}
template <typename T>
const T& image2d_b<T>::impl_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->array(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
T& image2d_b<T>::impl_read_write(const point2d& p)
{
assert(this->has_data());
- return this->data_->array(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -227,35 +199,35 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->array[i];
+ return this->data_->first[i];
}
template <typename T>
T& image2d_b<T>::impl_at(int row, int col)
{
assert(this->has_data());
- return this->data_->array(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
- box2d image2d_b<T>::impl_points() const
+ const box2d& image2d_b<T>::impl_points() const
{
assert(this->has_data());
- return this->data_->box;
+ return this->data_->third;
}
template <typename T>
unsigned image2d_b<T>::impl_border() const
{
assert(this->has_data());
- return this->data_->border;
+ return this->data_->second;
}
template <typename T>
std::size_t image2d_b<T>::pad(const dpoint2d& dp) const
{
assert(this->has_data());
- return this->data_->array.row_pad() * dp.row() + dp.col();
+ return this->data_->first.row_pad() * dp.row() + dp.col();
}
// template <typename T, typename D>
@@ -278,7 +250,11 @@
bool box_ok = init(b, with, dat);
postcondition(box_ok);
unsigned border = 2; // FIXME: Use init!
- target.data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border);
+ array2d_<T,int> ptr = new array2d_<T,int>(b.pmin().row() - border,
+ b.pmin().col() - border,
+ b.pmax().row() + border,
+ b.pmax().col() + border);
+ target.data__() = new typename image2d_b<T>::data(ptr, border, b);
return box_ok;
}
Index: oln/core/gen/niter_has.hh
--- oln/core/gen/niter_has.hh (revision 899)
+++ oln/core/gen/niter_has.hh (working copy)
@@ -78,7 +78,7 @@
protected:
- const Ps pset_;
+ const Ps& pset_;
}; // end of class oln::niter_has_<P>
Index: oln/core/internal/utils.hh
--- oln/core/internal/utils.hh (revision 899)
+++ oln/core/internal/utils.hh (working copy)
@@ -28,6 +28,8 @@
#ifndef OLN_CORE_INTERNAL_UTILS_HH
# define OLN_CORE_INTERNAL_UTILS_HH
+# include <mlc/contract.hh>
+
namespace oln
{
@@ -36,10 +38,6 @@
{
- // FIXME: Rename attributes as first / second / third / fourth?
-
-
-
/// Simple singleton class.
template <typename T>
@@ -47,12 +45,15 @@
{
singleton()
{}
- singleton(T value)
+ singleton(const T& value)
: value(value)
{}
T value;
};
+ template <typename T>
+ struct singleton< T* >;
+
/// Simple pair class.
@@ -61,7 +62,7 @@
{
pair()
{}
- pair(T1 first, T2 second)
+ pair(const T1& first, const T2& second)
: first(first),
second(second)
{}
@@ -69,6 +70,37 @@
T2 second;
};
+ template <typename T1, typename T2>
+ struct pair< T1*, T2 >
+ {
+ typedef pair<T1*,T2> self_t;
+
+ // Not impled.
+ pair();
+ pair(const self_t&);
+ void operator=(const self_t&);
+ // end of Not impled.
+
+ pair(T1* p_first, const T2& second)
+ : first(*p_first),
+ second(second)
+ {
+ precondition(p_first != 0);
+ }
+ T1& first;
+ T2 second;
+ ~pair()
+ {
+ delete &first;
+ }
+ };
+
+ template <typename T1, typename T2>
+ struct pair< T1, T2* >;
+
+ template <typename T1, typename T2>
+ struct pair< T1*, T2* >;
+
/// Simple triplet class.
@@ -77,7 +109,7 @@
{
triplet()
{}
- triplet(T1 first, T2 second, T3 third)
+ triplet(const T1& first, const T2& second, const T3& third)
: first(first),
second(second),
third(third)
@@ -87,6 +119,33 @@
T3 third;
};
+ template <typename T1, typename T2, typename T3>
+ struct triplet< T1*, T2, T3 >
+ {
+ typedef triplet<T1*,T2,T3> self_t;
+
+ // Not impled.
+ triplet();
+ triplet(const self_t&);
+ void operator=(const self_t&);
+ // end of Not impled.
+
+ triplet(T1* p_first, const T2& second, const T3& third)
+ : first(*p_first),
+ second(second),
+ third(third)
+ {
+ precondition(p_first != 0);
+ }
+ T1& first;
+ T2 second;
+ T3 third;
+ ~triplet()
+ {
+ delete &first;
+ }
+ };
+
/// Simple quartet class.
@@ -95,7 +154,7 @@
{
quartet()
{}
- quartet(T1 first, T2 second, T3 third, T4 fourth)
+ quartet(const T1& first, const T2& second, const T3& third, const
T4& fourth)
: first(first),
second(second),
third(third),
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 899)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -85,7 +85,7 @@
delegatee& impl_image();
const delegatee& impl_image() const;
- pset impl_points() const;
+ const pset& impl_points() const;
protected:
special_op_();
@@ -149,7 +149,7 @@
}
template <typename I, typename S>
- typename current::pset
+ const typename current::pset&
current::impl_points() const
{
assert(this->has_data());