Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* configure.ac: Add i/o test suite.
configure.ac | 1 +
1 files changed, 1 insertion(+)
Index: configure.ac
--- configure.ac (revision 53)
+++ configure.ac (working copy)
@@ -103,6 +103,7 @@
# OLN_TESTS defined in oln-local.m4
OLN_TESTS([core])
OLN_TESTS([sanity])
+ OLN_TESTS([io])
AC_SUBST([OLN_TESTS_SUBDIRS])
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* ntg/real/int_u8.hh: Fix operator==.
* ntg/real/integer.hh: Likewise.
* ntg/enum/enum.hh: Likewise.
* ntg/enum/bin.hh: Likewise.
* ntg/all.hh: New.
* ntg/core/macros.hh: Fix operator==.
* ntg/color/rgb_8.hh: Likewise.
* ntg/color/color.hh: Likewise.
all.hh | 36 ++++++++++++++++++++++++++++++++++
color/color.hh | 12 ++++++-----
color/rgb_8.hh | 58 +++++++++-----------------------------------------------
core/macros.hh | 2 -
enum/bin.hh | 10 ++++-----
enum/enum.hh | 20 ++++++++++++-------
real/int_u8.hh | 14 ++++++++-----
real/integer.hh | 11 +++++++---
8 files changed, 89 insertions(+), 74 deletions(-)
Index: ntg/real/int_u8.hh
--- ntg/real/int_u8.hh (revision 53)
+++ ntg/real/int_u8.hh (working copy)
@@ -83,16 +83,20 @@
return value_;
}
- template <typename V>
- bool impl_eq(const V& rhs) const
+// template <typename V>
+// bool impl_eq(const V& rhs) const
+// {
+// return this->value_ == rhs;
+// }
+
+ bool impl_eq(int rhs) const
{
return this->value_ == rhs;
}
- template <typename V>
- bool impl_not_eq(const V& rhs) const
+ bool impl_eq(const int_u8& rhs) const
{
- return this->value_ != rhs;
+ return this->value_ == (unsigned char)rhs;
}
template <typename V>
Index: ntg/real/integer.hh
--- ntg/real/integer.hh (revision 53)
+++ ntg/real/integer.hh (working copy)
@@ -62,16 +62,21 @@
return this->exact().impl_assign(rhs);
}
- template <typename V>
- bool operator==(const V& rhs) const
+ bool operator==(int rhs) const
{
return this->exact().impl_eq(rhs);
}
+ template <typename I>
+ bool operator==(const integer<I>& rhs) const
+ {
+ return this->exact().impl_eq(rhs.exact());
+ }
+
template <typename V>
bool operator!=(const V& rhs) const
{
- return this->exact().impl_not_eq(rhs);
+ return ! this->operator==(rhs);
}
template <typename V>
Index: ntg/enum/enum.hh
--- ntg/enum/enum.hh (revision 53)
+++ ntg/enum/enum.hh (working copy)
@@ -44,6 +44,7 @@
struct default_props < cat::enum_value >
{
enum { max_val = 0 };
+ enum { depth = 1 };
typedef mlc::no_type io_type;
protected:
@@ -55,25 +56,30 @@
{
typedef E exact_type;
- template <typename V>
- exact_type& operator=(const V& rhs)
+ bool operator==(int rhs) const
{
- return this->exact().impl_assign(rhs);
+ return this->exact().impl_eq(rhs);
}
- template <typename V>
- bool operator==(const V& rhs) const
+ template <typename I>
+ bool operator==(const enum_value<I>& rhs) const
{
- return this->exact().impl_eq(rhs);
+ return this->exact().impl_eq(rhs.exact());
}
template <typename V>
bool operator!=(const V& rhs) const
{
- return this->exact().impl_not_eq(rhs);
+ return ! this->operator==(rhs);
}
template <typename V>
+ exact_type& operator=(const V& rhs)
+ {
+ return this->exact().impl_assign(rhs);
+ }
+
+ template <typename V>
exact_type& operator+(const V& rhs) const
{
return this->exact().impl_add(rhs);
Index: ntg/enum/bin.hh
--- ntg/enum/bin.hh (revision 53)
+++ ntg/enum/bin.hh (working copy)
@@ -69,7 +69,7 @@
template <typename V>
bin& impl_assign(const V& rhs)
{
- this->value_ = rhs % 2;
+ this->value_ = (int)rhs % 2;
return *this;
}
@@ -78,18 +78,18 @@
return value_;
}
- template <typename V>
- bool impl_eq(const V& rhs) const
+ bool impl_eq(const unsigned char& rhs) const
{
return this->value_ == rhs;
}
template <typename V>
- bool impl_not_eq(const V& rhs) const
+ bool impl_eq(const V& rhs) const
{
- return this->value_ != rhs;
+ return this->value_ == (unsigned char)rhs;
}
+
template <typename V>
bin impl_add(const V& rhs) const
{
Index: ntg/all.hh
--- ntg/all.hh (revision 0)
+++ ntg/all.hh (revision 0)
@@ -0,0 +1,36 @@
+// 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 NTG_ALL_HH
+# define NTG_ALL_HH
+
+# include <ntg/core/macros.hh>
+# include <ntg/color/rgb_8.hh>
+# include <ntg/real/int_u8.hh>
+# include <ntg/enum/bin.hh>
+
+#endif // ! NTG_ALL_HH
Index: ntg/core/macros.hh
--- ntg/core/macros.hh (revision 53)
+++ ntg/core/macros.hh (working copy)
@@ -30,7 +30,7 @@
# define ntg_max_val(T) ntg::props<ntg_category_type(T),T>::max_val
-# define ntg_nb_comp(T) ntg::props<ntg_category_type(T),T>::nb_comp
+# define ntg_depth(T) ntg::props<ntg_category_type(T),T>::depth
# define ntg_comp_type(T) typename ntg::props<ntg_category_type(T),T>::comp_type
Index: ntg/color/rgb_8.hh
--- ntg/color/rgb_8.hh (revision 53)
+++ ntg/color/rgb_8.hh (working copy)
@@ -45,7 +45,7 @@
struct props<cat::color, rgb_8> : default_props<cat::color>
{
enum { max_val = 255 };
- enum { nb_comp = 3 };
+ enum { depth = 3 };
typedef char io_type;
typedef unsigned char comp_type;
@@ -84,33 +84,26 @@
rgb_8(const rgb_8& rhs)
{
- this->value_[rgb_red] = rhs.red();
- this->value_[rgb_green] = rhs.green();
- this->value_[rgb_blue] = rhs.blue();
+ this->value_[rgb_red] = rhs[rgb_red];
+ this->value_[rgb_green] = rhs[rgb_green];
+ this->value_[rgb_blue] = rhs[rgb_blue];
}
rgb_8& impl_assign(const rgb_8& rhs)
{
- this->value_[rgb_red] = rhs.red();
- this->value_[rgb_green] = rhs.green();
- this->value_[rgb_blue] = rhs.blue();
+ this->value_[rgb_red] = rhs[rgb_red];
+ this->value_[rgb_green] = rhs[rgb_green];
+ this->value_[rgb_blue] = rhs[rgb_blue];
return *this;
}
bool impl_eq(const rgb_8& rhs) const
{
- return this->value_[rgb_red] == rhs.red() &&
- this->value_[rgb_green] == rhs.green() &&
- this->value_[rgb_blue] == rhs.blue();
+ return this->value_[rgb_red] == rhs[rgb_red] &&
+ this->value_[rgb_green] == rhs[rgb_green] &&
+ this->value_[rgb_blue] == rhs[rgb_blue];
}
- bool impl_not_eq(const rgb_8& rhs) const
- {
- return this->value_[rgb_red] != rhs.red() ||
- this->value_[rgb_green] != rhs.green() ||
- this->value_[rgb_blue] != rhs.blue();
- }
-
unsigned char& impl_op_sqbr(unsigned int i)
{
assert(i < 3);
@@ -123,37 +116,6 @@
return value_[i];
}
-
- unsigned char& red()
- {
- return value_[rgb_red];
- }
-
- const unsigned char red() const
- {
- return value_[rgb_red];
- }
-
- unsigned char& green()
- {
- return value_[rgb_green];
- }
-
- const unsigned char green() const
- {
- return value_[rgb_green];
- }
-
- unsigned char& blue()
- {
- return value_[rgb_blue];
- }
-
- const unsigned char blue() const
- {
- return value_[rgb_blue];
- }
-
private:
unsigned char value_[3];
Index: ntg/color/color.hh
--- ntg/color/color.hh (revision 53)
+++ ntg/color/color.hh (working copy)
@@ -47,7 +47,7 @@
struct default_props < cat::color >
{
enum { max_val = 0 };
- enum { nb_comp = 0 };
+ enum { depth = 0 };
typedef mlc::undefined_type comp_type;
typedef mlc::undefined_type io_type;
@@ -67,14 +67,16 @@
return this->exact.impl_assign(rhs);
}
- bool operator==(const exact_type& rhs) const
+ template <typename I>
+ bool operator==(const color<I>& rhs) const
{
- return this->exact().impl_eq(rhs);
+ return this->exact().impl_eq(rhs.exact());
}
- bool operator!=(const exact_type& rhs) const
+ template <typename V>
+ bool operator!=(const V& rhs) const
{
- return this->exact().impl_not_eq(rhs);
+ return ! this->operator==(rhs);
}
comp_type& operator [](const unsigned int &i)
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* oln/makefile.src: Add new file.
* oln/all.hh: New.
all.hh | 38 ++++++++++++++++++++++++++++++++++++++
makefile.src | 1 +
2 files changed, 39 insertions(+)
Index: oln/makefile.src
--- oln/makefile.src (revision 54)
+++ oln/makefile.src (working copy)
@@ -4,6 +4,7 @@
##
OLN_DEP = \
+ all.hh \
basics.hh \
basics1d.hh \
basics2d.hh \
Index: oln/all.hh
--- oln/all.hh (revision 0)
+++ oln/all.hh (revision 0)
@@ -0,0 +1,38 @@
+// 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 OLN_ALL_HH
+# define OLN_ALL_HH
+
+# include <oln/core/1d/image1d.hh>
+# include <oln/core/2d/image2d.hh>
+# include <oln/core/3d/image3d.hh>
+
+# include <oln/io/write_image.hh>
+# include <oln/io/read_image.hh>
+
+#endif // ! OLN_ALL_HH
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* tests/io: New.
* tests/io/tests: New.
* tests/io/tests/2d: New.
* tests/io/Makefile.am: New.
* tests/io/loadsave.hh: New.
* oln/makefile.src: Add new files.
* oln/io/write_image_2d_pnm.hh: Modify function prototypes.
* oln/io/gz_stream.hh: New. Gz stream classes.
* oln/io/read_image_2d_pnm.hh: Modify function prototypes.
* oln/io/write_image.hh: Add gz stream support.
* oln/io/read_image.hh: Likewise.
* oln/io/utils.hh: Modify function prototypes.
* oln/core/value_box.hh: Add new operator== for value_box.
* oln/core/2d/image2d.hh: Remove debug output.
* img/lena.pgm.gz: New.
* img/lena.pgm: New.
* img/chien.pbm.gz: New.
* img/chien.pbm: New.
* img/lena.ppm.gz: New.
* img/lena.ppm: New.
* img/lena.pbm.gz: New.
* img/lena.pbm: New.
img/lena.pbm | 0
img/lena.pgm | 4
img/lena.ppm | 541 +++++++++++++++++++++++++++++++++++++++++++
oln/core/2d/image2d.hh | 1
oln/core/value_box.hh | 64 ++++-
oln/io/gz_stream.hh | 482 ++++++++++++++++++++++++++++++++++++++
oln/io/read_image.hh | 102 +++++++-
oln/io/read_image_2d_pnm.hh | 134 ++--------
oln/io/utils.hh | 34 --
oln/io/write_image.hh | 65 ++++-
oln/io/write_image_2d_pnm.hh | 39 +--
oln/makefile.src | 1
tests/io/Makefile.am | 9
tests/io/loadsave.hh | 49 +++
tests/io/tests/2d | 52 ++++
15 files changed, 1399 insertions(+), 178 deletions(-)
Index: tests/io/tests/2d
--- tests/io/tests/2d (revision 0)
+++ tests/io/tests/2d (revision 0)
@@ -0,0 +1,52 @@
+// -*- c++ -*-
+// 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.
+
+
+#include "loadsave.hh"
+
+bool
+check(void)
+{
+ bool fail = false;
+
+ typedef oln::image2d<ntg::int_u8> ima_int_u8;
+ typedef oln::image2d<ntg::rgb_8> ima_rgb_8;
+ typedef oln::image2d<ntg::bin> ima_bin;
+
+ fail |= loadsave< ima_int_u8 >(rdata("lena.pgm"), "lena.pgm");
+ fail |= loadsave< ima_bin >(rdata("lena.pbm"), "lena.pbm");
+ fail |= loadsave< ima_rgb_8 >(rdata("lena.ppm"), "lena.ppm");
+
+#if HAVE_ZLIB
+ fail |= loadsave< ima_bin >(rdata("lena.pbm.gz"), "lena.pbm.gz");
+ fail |= loadsave< ima_int_u8 >(rdata("lena.pgm.gz"), "lena.pgm.gz");
+ fail |= loadsave< ima_rgb_8 >(rdata("lena.ppm.gz"), "lena.ppm.gz");
+#endif
+
+ return fail;
+}
Index: tests/io/Makefile.am
--- tests/io/Makefile.am (revision 0)
+++ tests/io/Makefile.am (revision 0)
@@ -0,0 +1,9 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include ../check/Makefile.runtests
+
+noinst_HEADERS = loadsave.hh
+
+CLEANFILES += \
+ lena.ppm lena.pgm lena.pbm \
+ lena.ppm.gz lena.pgm.gz lena.pbm.gz
Index: tests/io/loadsave.hh
--- tests/io/loadsave.hh (revision 0)
+++ tests/io/loadsave.hh (revision 0)
@@ -0,0 +1,49 @@
+#include <oln/basics1d.hh>
+#include <oln/basics2d.hh>
+#include <oln/basics3d.hh>
+#include <oln/all.hh>
+
+#include <ntg/all.hh>
+
+#include "check.hh"
+#include "data.hh"
+
+template<typename E>
+bool compare(const oln::abstract::image<E>& a,
+ const oln::abstract::image<E>& b)
+{
+
+ oln_type_of(E, fwd_piter) it(a.size());
+
+ if (a.size().nrows() != b.size().nrows() ||
+ a.size().ncols() != b.size().ncols())
+ return false;
+
+ for (it.start(); !it.is_valid(); it.next())
+ if (a[it] != b[it])
+ return false;
+
+ return true;
+}
+
+template< typename T >
+bool
+loadsave(const std::string& name, const std::string& savename)
+{
+ bool fail = false;
+
+ T im1, im2;
+ im1 = oln::io::read(name);
+ oln::io::write(im1, savename);
+
+ im2 = oln::io::read(savename);
+
+ if (compare(im1, im2))
+ std::cout << "OK" << std::endl;
+ else
+ {
+ std::cout << "FAILED" << std::endl;
+ fail = true;
+ }
+ return fail;
+}
Index: oln/makefile.src
--- oln/makefile.src (revision 53)
+++ oln/makefile.src (working copy)
@@ -40,6 +40,7 @@
core/value_box.hh \
fancy/iota.hh \
fancy/print.hh \
+ io/gz_stream.hh \
io/read_image.hh \
io/read_image_2d_pnm.hh \
io/utils.hh \
Index: oln/io/write_image_2d_pnm.hh
--- oln/io/write_image_2d_pnm.hh (revision 53)
+++ oln/io/write_image_2d_pnm.hh (working copy)
@@ -59,9 +59,9 @@
typedef ntg_io_type(value_type) io_type;
const I& to_write_;
- std::ofstream& ostr_;
+ std::ostream& ostr_;
- write_image_2d_raw(const I& to_write, std::ofstream& ostr):
+ write_image_2d_raw(const I& to_write, std::ostream& ostr):
to_write_(to_write),
ostr_(ostr)
{}
@@ -70,7 +70,7 @@
{
point2d p;
value_type c;
- bool b;
+ bool b = false;
for (p.row() = 0; p.row() < to_write_.size().nrows(); ++p.row())
for (p.col() = 0; p.col() < to_write_.size().ncols(); ++p.col())
@@ -80,21 +80,25 @@
}
while (b == false)
b = write_value_type(c);
- ostr_.close();
}
bool write_value_type(const ntg::integer<value_type> &c)
{
- ostr_ << (io_type)(c.exact());
+ io_type v = c.exact();
+ ostr_.write((char *)&v, sizeof(io_type));
return true;
}
bool write_value_type(const ntg::color<value_type> &c)
{
- assert ((ntg_nb_comp(value_type) == 3));
+ assert ((ntg_depth(value_type) == 3));
+ io_type v;
for (unsigned i = 0; i < 3; i++)
- ostr_ << (io_type)(c[i]);
+ {
+ v = c[i];
+ ostr_.write((char *)(&v), sizeof(io_type));
+ }
return true;
}
@@ -107,7 +111,7 @@
if (offset == -1)
{
- ostr_ << v;
+ ostr_.write((char *)&v, 1);
offset = 7;
v = 0;
ret = true;
@@ -123,15 +127,15 @@
template <typename I, typename T>
void write(const abstract::image2d<I>& to_write,
const ntg::integer<T>&,
- const std::string& name,
+ std::ostream& ostr,
const std::string& ext)
{
- std::ofstream ostr;
+
point2d p;
size2d s = to_write.size();
if (ext == "pgm")
- if (internal::write_pnm_header(ostr, name, "P5",
+ if (internal::write_pnm_header(ostr, "P5",
s.ncols(), s.nrows(),
ntg_max_val(T)))
{
@@ -139,7 +143,7 @@
tmp.run();
}
else
- std::cerr << "error: unable to write header" << std::endl;
+ std::cerr << "error: unable to write file header" << std::endl;
else
std::cerr << "error: image data type (`integer') does not match"
<< " file extension (`" << ext << "')" << std::endl;
@@ -148,15 +152,15 @@
template <typename I, typename T>
void write(const abstract::image2d<I>& to_write,
const ntg::color<T>&,
- const std::string& name,
+ std::ostream& ostr,
const std::string& ext)
{
- std::ofstream ostr;
+
point2d p;
size2d s = to_write.size();
if (ext == "ppm")
- if (internal::write_pnm_header(ostr, name, "P6",
+ if (internal::write_pnm_header(ostr, "P6",
s.ncols(), s.nrows(),
ntg_max_val(T)))
{
@@ -173,15 +177,14 @@
template <typename I, typename T>
void write(const abstract::image2d<I>& to_write,
const ntg::enum_value<T>&,
- const std::string& name,
+ std::ostream& ostr,
const std::string& ext)
{
- std::ofstream ostr;
point2d p;
size2d s = to_write.size();
if (ext == "pbm")
- if (internal::write_pnm_header(ostr, name, "P4",
+ if (internal::write_pnm_header(ostr, "P4",
s.ncols(), s.nrows(),
ntg_max_val(T)))
{
Index: oln/io/gz_stream.hh
--- oln/io/gz_stream.hh (revision 0)
+++ oln/io/gz_stream.hh (revision 0)
@@ -0,0 +1,482 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 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 OLN_IO_GZ_STREAM_HH
+# define OLN_IO_GZ_STREAM_HH
+
+# include <oln/config/system.hh>
+
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+# include <cassert>
+# include <fstream>
+# include <string>
+# include <zlib.h>
+
+namespace oln {
+
+ namespace io {
+
+ /// Functions for gz files
+ namespace gz {
+
+
+ ///Performs operation on compressed files.
+ class zfilebuf : public std::streambuf
+ {
+ public:
+
+
+ zfilebuf() : file(0), mode(0), own_file_descriptor(0)
+ {
+ inbuf = new char[lenbuf];
+ outbuf = new char[lenbuf];
+ setg(0, 0, 0);
+ setp(outbuf, outbuf + lenbuf);
+ }
+
+ virtual ~zfilebuf()
+ {
+ sync();
+ delete[] inbuf;
+ delete[] outbuf;
+ if (own_file_descriptor)
+ close();
+ }
+
+
+ /*! \brief Return a stream on the file \a name regarding
+ ** the opening mode: \a io_mode.
+ */
+ zfilebuf*
+ open(const char *name, int io_mode)
+ {
+ if (is_open())
+ return 0;
+
+ char char_mode[10];
+ char *p;
+ memset(char_mode,'\0',10);
+ p = char_mode;
+
+ if (io_mode & std::ios::in)
+ {
+ mode = std::ios::in;
+ *p++ = 'r';
+ }
+ else
+ if (io_mode & std::ios::app)
+ {
+ mode = std::ios::app;
+ *p++ = 'a';
+ }
+ else
+ {
+ mode = std::ios::out;
+ *p++ = 'w';
+ }
+ if (io_mode & std::ios::binary)
+ {
+ mode |= std::ios::binary;
+ *p++ = 'b';
+ }
+
+ // Hard code the compression level
+ if (io_mode & (std::ios::out|std::ios::app))
+ *p++ = '9';
+
+ if ((file = gzopen(name, char_mode)) == 0)
+ return 0;
+
+ name_ = name;
+ own_file_descriptor = 1;
+ return this;
+ }
+
+ /*! \brief Attach a stream on \a file_descriptor regarding
+ ** the opening mode: \a io_mode.
+ */
+ zfilebuf*
+ attach(int file_descriptor, int io_mode)
+ {
+ if (is_open())
+ return 0;
+
+ char char_mode[10];
+ char *p;
+ memset(char_mode,'\0',10);
+ p = char_mode;
+
+ if (io_mode & std::ios::in)
+ {
+ mode = std::ios::in;
+ *p++ = 'r';
+ }
+ else
+ if (io_mode & std::ios::app)
+ {
+ mode = std::ios::app;
+ *p++ = 'a';
+ }
+ else
+ {
+ mode = std::ios::out;
+ *p++ = 'w';
+ }
+
+ if (io_mode & std::ios::binary)
+ {
+ mode |= std::ios::binary;
+ *p++ = 'b';
+ }
+
+ // Hard code the compression level
+ if (io_mode & (std::ios::out|std::ios::app))
+ *p++ = '9';
+
+ if ((file = gzdopen(file_descriptor, char_mode)) == 0)
+ return 0;
+
+ own_file_descriptor = 0;
+ return this;
+ }
+
+ /// Close the stream.
+ zfilebuf*
+ close()
+ {
+ if (is_open())
+ {
+ sync();
+ gzclose(file);
+ file = 0;
+ }
+ return this;
+ }
+
+
+ int
+ setcompressionlevel(short comp_level)
+ {
+ return gzsetparams(file, comp_level, -2);
+ }
+
+ int
+ setcompressionstrategy(short comp_strategy)
+ {
+ return gzsetparams(file, -2, comp_strategy);
+ }
+
+ /// Return true if the stream is open, false otherwise.
+ inline int
+ is_open() const
+ { return (file != 0); }
+
+ virtual std::streampos
+ seekoff(std::streamoff off, std::ios::seekdir dir, int) // which)
+ {
+ return std::streampos(gzseek(file, off, dir));
+ }
+
+ /// Flush the buffer associated to the stream.
+ virtual int
+ sync()
+ {
+ if (!is_open())
+ return EOF;
+ return flushbuf();
+ }
+
+ protected:
+
+ /*! \brief Return the next character in the stream.
+ ** On failure, \a EOF is returned.
+ */
+ virtual int
+ underflow()
+ {
+ // If the file hasn't been opened for reading, error.
+ if (!is_open() || !(mode & std::ios::in))
+ return EOF;
+
+ if (in_avail())
+ return (unsigned char) *gptr();
+
+ if (flushbuf() == EOF)
+ return EOF;
+
+ // Attempt to fill the buffer.
+ if (fillbuf() == EOF)
+ return EOF;
+
+ assert (eback());
+
+ return (unsigned char) *gptr();
+ }
+
+ /*! \brief Flush the output buffer associated to the stream
+ ** then write \a c. On failure, \a EOF is returned.
+ */
+
+ virtual int
+ overflow(int c = EOF)
+ {
+ if (!is_open() || !(mode & std::ios::out))
+ return EOF;
+
+ assert (pbase());
+
+ if (flushbuf() == EOF)
+ return EOF;
+
+ if (c != EOF)
+ {
+ *pptr() = c;
+ pbump(1);
+ }
+ return 0;
+ }
+
+ private:
+
+ gzFile file;
+ short mode;
+ short own_file_descriptor;
+ std::string name_;
+ char *inbuf;
+ char *outbuf;
+ static const int lenbuf = 16 * 1024;
+
+ /// Flush the output buffer
+ int
+ flushbuf()
+ {
+ int n = pptr() - outbuf;
+
+ if (n == 0)
+ return 0;
+
+ if (gzwrite(file, outbuf, n) < n)
+ return EOF;
+
+ setp(outbuf, outbuf + lenbuf);
+ return 0;
+ }
+ /// Fill the input buffer.
+ int
+ fillbuf()
+ {
+ int t = gzread(file, inbuf, lenbuf);
+ if (t <= 0) return EOF;
+ setg(inbuf, inbuf, inbuf + t);
+ return t;
+ }
+
+ };
+
+ ///Define an interface for compressed file stream manipulation.
+ class zfilestream_common : virtual public std::ios
+ {
+ friend class zifstream;
+ friend class zofstream;
+ friend zofstream &setcompressionlevel(zofstream &, int);
+ friend zofstream &setcompressionstrategy(zofstream &, int);
+
+ public:
+ virtual ~zfilestream_common() {}
+
+ /*! \brief Open the stream on the file descriptor:
+ ** \a fd regarding the opening mode.
+ */
+ void
+ attach(int fd, int io_mode)
+ {
+ if (!buffer.attach(fd, io_mode))
+ clear(std::ios::failbit | std::ios::badbit);
+ else
+ clear();
+ }
+
+ /*! \brief Open the stream on the file named \a name
+ ** regarding the opening mode.
+ */
+ void
+ open(const char *name, int io_mode)
+ {
+ if (!buffer.open(name, io_mode))
+ clear(std::ios::failbit | std::ios::badbit);
+ else
+ clear();
+ }
+
+ /// Close the current stream.
+ void
+ close()
+ {
+ if (!buffer.close())
+ clear(std::ios::failbit | std::ios::badbit);
+ }
+
+ bool
+ is_open()
+ {
+ return buffer.is_open();
+ }
+
+
+ protected:
+ /// Prevent instantiation.
+ zfilestream_common() : std::ios(zfilestream_common::rdbuf())
+ { }
+
+
+ private:
+ zfilebuf*
+ rdbuf()
+ {
+ return &buffer;
+ }
+
+ zfilebuf buffer;
+ };
+
+
+ /// Read only zstream.
+ class zifstream : public zfilestream_common, public std::istream
+ {
+ public:
+
+ zifstream() : std::istream(zfilestream_common::rdbuf())
+ {
+ clear(std::ios::badbit);
+ }
+
+ /// Open a read only stream on the file named \a name.
+ zifstream(const char *name, int io_mode = std::ios::in) :
+ std::istream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::open(name, io_mode);
+ }
+
+ /// Open a read only stream on the file descriptor \a fd.
+ zifstream(int fd, int io_mode = std::ios::in) :
+ std::istream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::attach(fd, io_mode);
+ }
+
+ virtual ~zifstream() {}
+ };
+
+ class zofstream : public zfilestream_common, public std::ostream {
+
+ public:
+
+ zofstream() : std::ostream(zfilestream_common::rdbuf())
+ {
+ clear(std::ios::badbit);
+ }
+
+ /// Open a write only stream on the file named \a name.
+ zofstream(const char *name, int io_mode = std::ios::out) :
+ std::ostream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::open(name, io_mode);
+ }
+
+ /// Open a write only stream on the file descriptor \a fd.
+ zofstream(int fd, int io_mode = std::ios::out) :
+ std::ostream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::attach(fd, io_mode);
+ }
+
+ virtual ~zofstream() {}
+
+ };
+
+ // Forward declaration.
+ template <class T>
+ class zomanip;
+
+ /// Apply a function on \a s via the operator <<.
+ template <class T>
+ zofstream&
+ operator<<(zofstream &s, const zomanip<T> &m) {
+ return (*m.func)(s, m.val);
+ }
+
+
+ /// Define a pair func / val to perform manipulation on zofstream.
+ template<class T> class zomanip
+ {
+ friend zofstream &operator<< <T>(zofstream &, const zomanip<T> &);
+ public:
+ zomanip(zofstream &(*f)(zofstream &, T), T v) : func(f), val(v) { }
+ private:
+ zofstream &(*func)(zofstream &, T);
+ T val;
+ };
+
+
+ /// Set the compression level of \a s to \a l.
+ inline zofstream&
+ setcompressionlevel(zofstream &s, int l) {
+ (s.rdbuf())->setcompressionlevel(l);
+ return s;
+ }
+
+ /// Set the compression strategy of \a s to \a l.
+ inline zofstream&
+ setcompressionstrategy(zofstream &s, int l)
+ {
+ (s.rdbuf())->setcompressionstrategy(l);
+ return s;
+ }
+
+ /// Specialized version for zomanip<int>
+ inline zomanip<int>
+ setcompressionlevel(int l)
+ {
+ return zomanip<int>(&setcompressionlevel,l);
+ }
+
+ /// Specialized version for zomanip<int>
+ inline zomanip<int>
+ setcompressionstrategy(int l)
+ {
+ return zomanip<int>(&setcompressionstrategy,l);
+ }
+
+ } // end of namespace gz
+
+ } // end of namespace io
+
+} // end of namespace oln
+
+# endif // ! HAVE_ZLIB
+
+#endif // ! OLN_IO_GZ_STREAM_HH
Index: oln/io/read_image_2d_pnm.hh
--- oln/io/read_image_2d_pnm.hh (revision 53)
+++ oln/io/read_image_2d_pnm.hh (working copy)
@@ -1,3 +1,30 @@
+// 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 OLN_IO_READ_IMAGE_2D_PNM_HH
# define OLN_IO_READ_IMAGE_2D_PNM_HH
@@ -59,11 +86,11 @@
typedef ntg_io_type(value_type) io_type;
mlc::box<I> image_;
- std::ifstream& istr_;
+ std::istream& istr_;
internal::pnm_info& info_;
read_image_2d_raw(I& image,
- std::ifstream &istr,
+ std::istream &istr,
internal::pnm_info &info) :
super_type(image),
image_(image),
@@ -97,7 +124,6 @@
read_value_type(c);
tmp[p] = c;
}
- istr_.close();
*image_ = tmp;
}
@@ -110,10 +136,9 @@
void read_value_type(ntg::color<value_type> &c)
{
- assert((ntg_nb_comp(value_type) == 3));
io_type v;
- for (unsigned i = 0; i < 3; i++)
+ for (unsigned i = 0; i < ntg_depth(value_type); i++)
{
istr_.read(&v, sizeof (v));
c[i] = v;
@@ -135,107 +160,20 @@
else
c = 1;
}
-
-
};
- template <typename I, typename T>
+ template <typename I>
void read(abstract::image2d<I>& ima,
- const ntg::integer<T>&,
- const std::string& filename,
- const std::string& ext)
+ std::istream& istr,
+ internal::pnm_info info)
{
- std::ifstream istr;
- internal::pnm_info info;
-
- if (internal::read_pnm_header(istr, info, filename))
- if (ext == "pgm")
- if (info.type == "P5")
- {
- read_image_2d_raw<I> tmp(ima.exact(), istr, info);
- tmp.run();
- tmp.output(ima.exact());
- }
- else if (info.type == "P2")
- std::cerr << "error: read_image_2d_pgm_ascii not implemented"
- << std::endl;
- else
- std::cerr << "error: file header (`" << info.type
- << "') does not match file extension (`"
- << ext << "')" << std::endl;
- else
- std::cerr << "error: image data type (`integer') does not match"
- << " file extension (`" << ext << "')" << std::endl;
- else
- std::cerr << "error: unable to get a valid header" << std::endl;
+ read_image_2d_raw<I> tmp(ima.exact(), istr, info);
+ tmp.run();
+ tmp.output(ima.exact());
}
-
-
- template <typename I, typename T>
- void read(abstract::image2d<I>& ima,
- const ntg::color<T>&,
- const std::string& filename,
- const std::string& ext)
- {
- std::ifstream istr;
- internal::pnm_info info;
-
- if (internal::read_pnm_header(istr, info, filename))
- if (ext == "ppm")
- if (info.type == "P6")
- {
- read_image_2d_raw<I> tmp(ima.exact(), istr, info);
- tmp.run();
- tmp.output(ima.exact());
- }
- else if (info.type == "P3")
- std::cerr << "error: read_image_2d_ppm_ascii not implemented"
- << std::endl;
- else
- std::cerr << "error: file header (`" << info.type
- << "') does not match file extension (`"
- << ext << "')" << std::endl;
- else
- std::cerr << "error: image data type (`color') does not match"
- << " file extension (`" << ext << "')" << std::endl;
- else
- std::cerr << "error: unable to get a valid header" << std::endl;
- }
-
- template <typename I, typename T>
- void read(abstract::image2d<I>& ima,
- const ntg::enum_value<T>&,
- const std::string& filename,
- const std::string& ext)
- {
- std::ifstream istr;
- internal::pnm_info info;
-
- if (internal::read_pnm_header(istr, info, filename))
- if (ext == "pbm")
- if (info.type == "P4")
- {
- read_image_2d_raw<I> tmp(ima.exact(), istr, info);
- tmp.run();
- tmp.output(ima.exact());
- }
- else if (info.type == "P1")
- std::cerr << "error: read_image_2d_ppm_ascii not implemented"
- << std::endl;
- else
- std::cerr << "error: file header (`" << info.type
- << "') does not match file extension (`"
- << ext << "')" << std::endl;
- else
- std::cerr << "error: image data type (`enum_value') does not match"
- << " file extension (`" << ext << "')" << std::endl;
- else
- std::cerr << "error: unable to get a valid header" << std::endl;
- }
-
}
}
Index: oln/io/write_image.hh
--- oln/io/write_image.hh (revision 53)
+++ oln/io/write_image.hh (working copy)
@@ -30,6 +30,7 @@
# include <string>
+# include <oln/io/gz_stream.hh>
# include <oln/io/utils.hh>
# include <oln/io/write_image_2d_pnm.hh>
@@ -38,22 +39,68 @@
namespace io {
template <typename I>
- void write(const abstract::image<I>& im, const std::string& name)
+ void do_write(const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
{
+ typedef oln_type_of(I, value) value_type;
+ value_type t;
+
+ impl::write(ima.exact(), t, ostr, ext);
+ }
+
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ template <typename I>
+ void write_gz(const abstract::image<I>& ima, const std::string& name)
+ {
+ gz::zofstream zostr(name.c_str(), std::ios::out);
+
+ if (zostr.is_open() == false)
+ std::cerr << "error: couldn't open " << name << std::endl;
+ else
+ {
+ std::string ext;
+
+ ext = internal::utils::extension(name.substr(0, name.size() - 3));
+ do_write(ima, zostr, ext);
+ }
+ zostr.close();
+ }
+
+#endif // ! HAVE_ZLIB
+
+ template <typename I>
+ void write_non_gz(const abstract::image<I>& ima,
+ const std::string& name,
+ const std::string& ext)
+ {
+ std::ofstream ostr;
+
+ ostr.open(name.c_str(), std::ifstream::out);
+
+ if (ostr.is_open() == false)
+ std::cerr << "error: couldn't open " << name << std::endl;
+ else
+ do_write(ima, ostr, ext);
+ ostr.close();
+ }
+
+ template <typename I>
+ void write(const abstract::image<I>& ima, const std::string& name)
+ {
std::string ext;
oln_type_of(I, value) t;
ext = internal::utils::extension(name);
- if (ext == "pgm" ||
- ext == "ppm" ||
- ext == "pbm")
- impl::write(im.exact(), t, name, ext);
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ if (ext == "gz")
+ write_gz(ima, name);
else
- std::cerr << "error: output method for '"
- << name.c_str()
- << "' not implemented"
- << std::endl;
+ write_non_gz(ima, name, ext);
+# else
+ write_non_gz(ima, name, ext);
+#endif // ! HAVE_ZLIB
}
}
Index: oln/io/read_image.hh
--- oln/io/read_image.hh (revision 53)
+++ oln/io/read_image.hh (working copy)
@@ -33,8 +33,12 @@
# include <mlc/box.hh>
+# include <ntg/core/macros.hh>
+
+# include <oln/core/properties.hh>
# include <oln/io/read_image_2d_pnm.hh>
# include <oln/io/utils.hh>
+# include <oln/io/gz_stream.hh>
namespace oln {
@@ -59,28 +63,102 @@
return tmp;
}
+
template <typename I>
- void do_read(abstract::image<I>& ima, const filename& name)
+ void read_dispatch_ext(abstract::image<I>& ima,
+ std::istream& istr,
+ const std::string& ext)
+
{
- std::string ext;
- const oln_type_of(I, value) t;
+ if (ext == "pgm" || ext == "pbm" || ext == "ppm" ||
+ ext == "pnm")
+ {
+ internal::pnm_info info;
- ext = internal::utils::extension(name.get());
+ if (internal::read_pnm_header(istr, info))
+ if ((ext == "ppm" || ext == "pnm") && info.type == "P6")
+ impl::read(ima.exact(), istr, info);
+ else if ((ext == "ppm" || ext == "pnm") && info.type == "P3")
+ std::cerr << "error: read_image_2d_ppm_ascii not implemented"
+ << std::endl;
+ else if ((ext == "pbm" || ext == "pnm") && info.type == "P4")
+ impl::read(ima.exact(), istr, info);
+ else if ((ext == "pbm" || ext == "pnm") && info.type == "P1")
+ std::cerr << "error: read_image_2d_ppm_ascii not implemented"
+ << std::endl;
+ else if ((ext == "pgm" || ext == "pnm") && info.type == "P5")
+ impl::read(ima.exact(), istr, info);
+ else if ((ext == "pgm" || ext == "pnm") && info.type == "P2")
+ std::cerr << "error: read_image_2d_ppm_ascii not implemented"
+ << std::endl;
+ else
+ std::cerr << "error: file header (`" << info.type
+ << "') does not match file extension (`"
+ << ext << "')" << std::endl;
+ else
+ std::cerr << "error: unable to get a valid header" << std::endl;
+ }
+ else
+ std::cout << "no input method for '"
+ << ext << "' file extension"
+ << std::endl;
+ }
- if (ext == "pgm" ||
- ext == "pbm" ||
- ext == "ppm")
- impl::read(ima.exact(), t, name.get(), ext);
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ template <typename I>
+ void do_read_gz(abstract::image<I>& ima, const std::string& name)
+ {
+ gz::zifstream zistr(name.c_str(), std::ios::in);
+
+ if (zistr.is_open() == false)
+ std::cerr << "error: couldn't open " << name << std::endl;
else
{
- std::cout << "input method for '"
- << name.get()
- << "' not implemented"
- << std::endl;
+ std::string ext;
+
+ ext = internal::utils::extension(name.substr(0, name.size() - 3));
+ read_dispatch_ext(ima, zistr, ext);
}
+ zistr.close();
+ }
+#endif // ! HAVE_ZLIB
+
+ template <typename I>
+ void do_read_non_gz(abstract::image<I>& ima,
+ const std::string& name,
+ const std::string& ext)
+ {
+ std::ifstream istr;
+
+ istr.open(name.c_str(), std::ifstream::in);
+
+ if (istr.is_open() == false)
+ std::cerr << "error: couldn't open " << name << std::endl;
+ else
+ read_dispatch_ext(ima, istr, ext);
+ istr.close();
}
+ template <typename I>
+ void do_read(abstract::image<I>& ima, const filename& name)
+ {
+ std::string ext;
+
+ ext = internal::utils::extension(name.get());
+
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+
+ if (ext == "gz")
+ do_read_gz(ima, name.get());
+ else
+ do_read_non_gz(ima, name.get(), ext);
+#else
+ do_read_non_gz(ima, name.get(), ext);
+#endif // ! HAVE_ZLIB
+ }
+
+
}
}
Index: oln/io/utils.hh
--- oln/io/utils.hh (revision 53)
+++ oln/io/utils.hh (working copy)
@@ -76,17 +76,13 @@
std::string type;
};
- bool read_pnm_header(std::ifstream& istr,
- internal::pnm_info& info,
- const std::string& name)
+ bool read_pnm_header(std::istream& istr,
+ internal::pnm_info& info)
{
- istr.open(name.c_str(), std::ifstream::in);
-
- if (!istr.is_open())
- return false;
-
std::getline(istr, info.type);
+ info.max_val = 1;
+
// skip comments
while (istr.peek() == '#')
{
@@ -121,11 +117,9 @@
std::getline(istr, line);
}
-
// FIXME: it can be either '\n', 'whitespace', ..., not only '\n'!
-
- // extract or skip maxvalue
if (istr.get() != '\n') return false;
+ // extract or skip maxvalue
if (info.type != "P1" && info.type != "P4")
{
istr >> info.max_val;
@@ -137,29 +131,15 @@
return true;
}
- bool write_pnm_header(std::ofstream& ostr,
- const std::string& name,
+ bool write_pnm_header(std::ostream& ostr,
const std::string& type,
int ncols,
int nrows,
int max_val)
{
if (max_val > 65535)
- {
- std::cerr << "error: can't save " << name
- << ", data type too large"
- << std::endl;
- return false;
- }
+ return false;
- ostr.open(name.c_str(), std::ofstream::out);
-
- if (ostr.is_open() == false)
- {
- std::cerr << "error: couldn't open " << name << std::endl;
- return false;
- }
-
ostr << type << std::endl
<< "# Olena 1.0" << std::endl
<< ncols << " " << nrows << std::endl;
Index: oln/core/value_box.hh
--- oln/core/value_box.hh (revision 53)
+++ oln/core/value_box.hh (working copy)
@@ -79,6 +79,26 @@
typedef oln_type_of(I, point) point_type;
+ /// op==
+
+ bool operator==(const value_box<I>& value) const
+ {
+ return this->value() == value.value();
+ }
+
+ template <typename V>
+ bool operator==(const V& value) const
+ {
+ return this->value() == value;
+ }
+
+ template <typename V>
+ bool operator!=(const V& value) const
+ {
+ return ! this->operator==(value);
+ }
+
+
/*! \brief op=
** FIXME:...
** \return (*this)
@@ -87,7 +107,7 @@
template <typename V>
value_box& operator=(const V& value)
{
- ima_.set(p_, value);
+ this->ima_->set(this->p_, value);
return *this;
}
@@ -103,7 +123,7 @@
template <typename II>
value_box& operator=(const value_box<II>& rhs)
{
- ima_.set(p_, rhs); // automatic conversion from rhs to value_type
+ ima_->set(p_, rhs); // automatic conversion from rhs to value_type
return *this;
}
@@ -118,7 +138,7 @@
template <typename A, typename V>
value_box& set(void (I::*method)(A), const V& value)
{
- ima_.set(p_, method, value);
+ ima_->set(p_, method, value);
return *this;
}
@@ -133,13 +153,13 @@
template <typename V>
operator const V() const
{
- const V value = ima_.get(p_);
+ const V value = ima_->get(p_);
return value;
}
operator const value_type() const
{
- return ima_.get(p_);
+ return ima_->get(p_);
}
@@ -156,7 +176,7 @@
const value_type value() const
{
- return ima_.get(p_);
+ return ima_->get(p_);
}
@@ -180,7 +200,7 @@
/// Ctor (restricted access).
value_box(abstract::image<I>& ima, const point_type& p) :
- ima_(ima.exact()),
+ ima_(&ima.exact()),
p_(p)
{
}
@@ -189,7 +209,7 @@
! attributes !
*------------*/
- I& ima_;
+ I* ima_;
point_type p_;
};
@@ -219,7 +239,25 @@
typedef oln_type_of(I, point) point_type;
+ /// op==
+ bool operator==(const value_box<const I>& value) const
+ {
+ return this->value() == value.value();
+ }
+ template <typename V>
+ bool operator==(const V& value) const
+ {
+ return this->value() == value;
+ }
+
+ template <typename V>
+ bool operator!=(const V& value) const
+ {
+ return ! this->operator==(value);
+ }
+
+
/*! \brief Assignment (op=) is declared but undefined.
*/
@@ -235,13 +273,13 @@
template <typename V>
operator const V() const
{
- const V value = ima_.get(p_);
+ const V value = ima_->get(p_);
return value;
}
operator const value_type() const
{
- return ima_.get(p_);
+ return ima_->get(p_);
}
@@ -258,7 +296,7 @@
const value_type value() const
{
- return ima_.get(p_);
+ return ima_->get(p_);
}
// IDEA: provide op->
@@ -284,7 +322,7 @@
/// Ctor (restricted access).
value_box(const abstract::image<I>& ima, const point_type& p) :
- ima_(ima.exact()),
+ ima_(&ima.exact()),
p_(p)
{
}
@@ -293,7 +331,7 @@
! attributes !
*------------*/
- const I& ima_;
+ const I* ima_;
point_type p_;
};
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 53)
+++ oln/core/2d/image2d.hh (working copy)
@@ -140,7 +140,6 @@
{
if (&rhs == this)
return *this;
- std::cout << "shallow copy" << std::endl;
super_type::operator=(rhs);
return *this;
};
Index: img/lena.pgm.gz
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/lena.pgm.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/lena.pgm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/lena.pgm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/chien.pbm.gz
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/chien.pbm.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/chien.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/chien.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/lena.ppm.gz
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/lena.ppm.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/lena.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/lena.ppm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/lena.pbm.gz
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/lena.pbm.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/lena.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/lena.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
1
0
14 Mar '05
(Au passage, je profite de ce patch pour marquer les fichiers générés
comme ignorés par Subversion.)
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 6 ++++++
tests/check/Makefile.flags | 8 ++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Use the compiler's debug flags in the test suite.
* tests/check/Makefile.flags (AM_CXXFLAGS): Add $(CXXFLAGS_DEBUG).
Property changes on:
___________________________________________________________________
Name: svn:ignore
- aclocal.m4
autom4te.cache
config.hin
configure
Makefile.in
+ Makefile
Makefile.in
aclocal.m4
autom4te.cache
config.h
config.hin
config.log
config.status
configure
diffs.patch
stamp-h1
Property changes on: integre
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile
Makefile.in
Property changes on: integre/tests
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile
Makefile.in
Property changes on: integre/tests/sanity
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile
Makefile.in
incltest.cc
Property changes on: integre/tests/check
___________________________________________________________________
Name: svn:ignore
+ defs
Property changes on: integre/ntg
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile
Makefile.in
Property changes on: olena
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile
Makefile.in
Property changes on: olena/tests
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile
Makefile.in
incltest.cc
Property changes on: olena/tests/sanity
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile
Makefile.in
incltest.cc
Property changes on: olena/tests/core
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile
Makefile.in
runs
Property changes on: olena/tests/check
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ .deps
Makefile
Makefile.in
defs
libolncheck.a
Index: olena/tests/check/Makefile.flags
--- olena/tests/check/Makefile.flags (revision 52)
+++ olena/tests/check/Makefile.flags (working copy)
@@ -1,5 +1,9 @@
# -*- Makefile -*-
-AM_CXXFLAGS = $(CXXFLAGS_OPTIMIZE) $(CXXFLAGS_STRICT_ERRORS) $(ZLIB_CXXFLAGS)
-AM_CPPFLAGS = -I$(top_srcdir)/metalic/tests/check -I$(top_srcdir)/olena/tests/check
+AM_CXXFLAGS = \
+ $(CXXFLAGS_DEBUG) $(CXXFLAGS_OPTIMIZE) \
+ $(CXXFLAGS_STRICT_ERRORS) $(ZLIB_CXXFLAGS)
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/metalic/tests/check \
+ -I$(top_srcdir)/olena/tests/check
AM_LDFLAGS =
1
0
hop
---
:from: Thierry Geraud <theo(a)lrde.epita.fr>
:server:
:subject: "proto-1.0 52: Make it pass make check"
:groups:
- lrde.olena.patches
---
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
* oln/core/3d/fwd_piter3d.hh: New.
* tests/core/tests/readwrite_image: Fix to pass make check.
* tests/core/tests/image_identity: Likewise.
* oln/fancy/print.hh: Likewise.
* oln/core/1d/array1d.hh: Likewise.
* oln/core/1d/fwd_piter1d.hh: Likewise.
* oln/core/1d/point1d.hh: Likewise.
* oln/core/1d/size1d.hh: Likewise.
* oln/core/coord.hh: Likewise.
* oln/core/2d/fwd_piter2d.hh: Likewise.
* oln/core/2d/point2d.hh: Likewise.
* oln/core/2d/size2d.hh: Likewise.
* oln/core/3d/size3d.hh: Likewise.
* oln/core/3d/array3d.hh: Likewise.
* oln/core/3d/image3d.hh: Likewise.
* oln/core/3d/point3d.hh: Likewise.
oln/core/1d/array1d.hh | 18 ++---
oln/core/1d/fwd_piter1d.hh | 4 -
oln/core/1d/point1d.hh | 1
oln/core/1d/size1d.hh | 4 -
oln/core/2d/fwd_piter2d.hh | 27 ++++----
oln/core/2d/point2d.hh | 1
oln/core/2d/size2d.hh | 4 -
oln/core/3d/array3d.hh | 52 ++++++++-------
oln/core/3d/fwd_piter3d.hh | 129 +++++++++++++++++++++++++++++++++++++++
oln/core/3d/image3d.hh | 5 -
oln/core/3d/point3d.hh | 6 -
oln/core/3d/size3d.hh | 14 +---
oln/core/coord.hh | 4 +
oln/fancy/print.hh | 40 +++++-------
tests/core/tests/image_identity | 1
tests/core/tests/readwrite_image | 26 ++++---
16 files changed, 237 insertions(+), 99 deletions(-)
Index: tests/core/tests/readwrite_image
--- tests/core/tests/readwrite_image (revision 51)
+++ tests/core/tests/readwrite_image (working copy)
@@ -11,23 +11,26 @@
struct dummy_image;
template <>
- struct category_type< dummy_image > { typedef cat::image ret; };
+ struct set_category< dummy_image > { typedef category::image ret; };
template <>
- struct props <cat::image, dummy_image> :
- public default_props < cat::image >
+ struct set_super_type< dummy_image > {
+ typedef abstract::image_with_data< dummy_image > ret;
+ };
+
+ template <>
+ struct set_props <category::image, dummy_image> :
+ public props_of < category::image >
{
- typedef prop_of<abstract::readwrite_image> image_constness;
- typedef prop_of<abstract::image2d> image_dimension;
+ typedef is_a<abstract::readwrite_image> image_constness;
+ typedef is_a<abstract::image2d> image_dimension_type;
typedef size2d size_type;
typedef point2d point_type;
typedef ntg::int_u8 value_type;
- typedef mlc_encoding_type_(value_type) value_storage_type;
- typedef array2d<value_storage_type> value_container_type;
-
- typedef mlc::no_type delegated_type;
+ typedef value_type value_storage_type;
+ typedef array2d<value_storage_type> storage_type;
};
struct dummy_image : public abstract::image_with_data< dummy_image >
@@ -55,7 +58,8 @@
bool check()
{
oln::dummy_image ima(3, 3);
- ima[oln::point2d(0,0)] = 42;
- std::cout << ima[oln::point2d(0,0)].value() << std::endl;
+ oln::point2d p(0,0);
+ ima[p] = 51;
+ std::cout << int(ima[p]) << std::endl;
return false;
}
Index: tests/core/tests/image_identity
--- tests/core/tests/image_identity (revision 51)
+++ tests/core/tests/image_identity (working copy)
@@ -1,7 +1,6 @@
#include <oln/core/abstract/image_identity.hh>
#include <oln/core/2d/image2d.hh>
#include <ntg/real/int_u8.hh>
-#include <oln/core/cats.hh>
template <typename I>
Index: oln/fancy/print.hh
--- oln/fancy/print.hh (revision 51)
+++ oln/fancy/print.hh (working copy)
@@ -38,6 +38,7 @@
# include <oln/core/abstract/image_dimension.hh>
# include <oln/core/1d/point1d.hh>
# include <oln/core/2d/point2d.hh>
+# include <oln/core/3d/point3d.hh>
# include <oln/core/coord.hh>
@@ -104,18 +105,15 @@
template <typename E>
void print(const abstract::image1d<E>& input, std::ostream& ostr)
{
- // FIXME: lacks cleaning
for (coord_t index = 0; index < input.size().nindices(); ++index)
- {
- ostr << internal::pp<oln_type_of(E, value)>(input[point1d(index)]) << ' ';
- }
+ ostr << internal::pp<oln_type_of(E, value)>(input[point1d(index)])
+ << ' ';
ostr << std::endl;
}
template <typename E>
void print(const abstract::image2d<E>& input, std::ostream& ostr)
{
- // FIXME: lacks cleaning
for (coord_t row = 0; row < input.size().nrows(); ++row)
{
for (coord_t col = 0; col < input.size().ncols(); ++col)
@@ -124,24 +122,22 @@
}
}
- // FIXME: remove comments when dpoint3d are available.
-// template <typename E>
-// void print(const abstract::image3d<E>& input, std::ostream& ostr)
-// {
-// // FIXME: lacks cleaning
-// for (coord_t slice = 0; slice < input.size().nslices(); ++slice)
-// {
-// for (coord_t row = 0; row < input.size().nrows(); ++row)
-// {
-// for (coord_t col = 0; col < input.size().ncols(); ++col)
-// ostr << internal::pp<oln_value_type(E)>(input[point3d(slice,row,col)])
-// << ' ';
-// ostr << ", ";
-// }
-// ostr << std::endl;
-// }
-// }
+ template <typename E>
+ void print(const abstract::image3d<E>& input, std::ostream& ostr)
+ {
+ for (coord_t slice = 0; slice < input.size().nslices(); ++slice)
+ {
+ for (coord_t row = 0; row < input.size().nrows(); ++row)
+ {
+ for (coord_t col = 0; col < input.size().ncols(); ++col)
+ ostr << internal::pp<oln_type_of(E, value)>(input[point3d(slice,row,col)])
+ << ' ';
+ ostr << std::endl;
+ }
+ ostr << "---" << std::endl;
+ }
+ }
} // end of namespace impl
Index: oln/core/1d/array1d.hh
--- oln/core/1d/array1d.hh (revision 51)
+++ oln/core/1d/array1d.hh (working copy)
@@ -116,7 +116,7 @@
void impl_resize(const size1d& s)
{
- precondition(s.nindices() > 0 and
+ precondition(s.nindices() > 0 &&
s.border() >= 0);
invariant_();
this->clear_data();
@@ -134,14 +134,14 @@
bool impl_hold(const point1d& p) const
{
return
- p.index() >= 0 and
+ p.index() >= 0 &&
p.index() < size_.nindices();
}
bool impl_hold_large(const point1d& p) const
{
return
- p.index() >= - size_.border() and
+ p.index() >= - size_.border() &&
p.index() < size_.nindices() + size_.border();
}
@@ -173,13 +173,13 @@
void invariant_() const
{
- invariant((buffer_ != 0 and
- size_.nindices() > 0 and
+ invariant((buffer_ != 0 &&
+ size_.nindices() > 0 &&
size_.border() >= 0)
- or
- (buffer_ == 0 and
- size_.nindices() == 0 and
- size_.border() == 0));
+ ||
+ (buffer_ == 0 &&
+ size_.nindices().is_undefined() &&
+ size_.border().is_undefined()));
}
};
Index: oln/core/1d/fwd_piter1d.hh
--- oln/core/1d/fwd_piter1d.hh (revision 51)
+++ oln/core/1d/fwd_piter1d.hh (working copy)
@@ -88,9 +88,7 @@
void impl_next()
{
precondition(this->p_.index().is_defined());
- precondition(this->p_.index() >= 0 and this->p_.index() <= this->s_.nindices());
- if (this->p_.index() == this->s_.nindices())
- return;
+ precondition(this->p_.index() >= 0 && this->p_.index() < this->s_.nindices());
++this->p_.index();
postcondition(this->p_.index().is_defined());
}
Index: oln/core/1d/point1d.hh
--- oln/core/1d/point1d.hh (revision 51)
+++ oln/core/1d/point1d.hh (working copy)
@@ -65,6 +65,7 @@
{
point1d()
{
+ // no initialization here so that index_ is 'undef'
}
point1d(coord_t index_) :
Index: oln/core/1d/size1d.hh
--- oln/core/1d/size1d.hh (revision 51)
+++ oln/core/1d/size1d.hh (working copy)
@@ -39,7 +39,9 @@
struct size1d : public abstract::size< size1d >
{
size1d()
- {}
+ {
+ // no initialization here so that members are 'undef'
+ }
size1d(coord_t nindices_) :
nindices_(nindices_),
Index: oln/core/coord.hh
--- oln/core/coord.hh (revision 51)
+++ oln/core/coord.hh (working copy)
@@ -71,6 +71,10 @@
bool operator==(value_type rhs) const
{
+ if (! this->is_defined())
+ {
+ std::cerr << "oops" << std::endl;
+ }
precondition(this->is_defined());
return value_ == rhs;
}
Index: oln/core/2d/fwd_piter2d.hh
--- oln/core/2d/fwd_piter2d.hh (revision 51)
+++ oln/core/2d/fwd_piter2d.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef PROTO_OLN_CORE_2D_FWD_PITER2D_HH
-# define PROTO_OLN_CORE_2D_FWD_PITER2D_HH
+#ifndef OLENA_CORE_2D_FWD_PITER2D_HH
+# define OLENA_CORE_2D_FWD_PITER2D_HH
# include <mlc/contract.hh>
@@ -76,39 +76,42 @@
{
this->p_.row() = 0;
this->p_.col() = 0;
- postcondition(this->p_.row().is_defined() && this->p_.col().is_defined());
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined());
}
bool impl_is_valid() const
{
- precondition(this->p_.row().is_defined() && this->p_.col().is_defined());
+ precondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined());
return this->p_.row() < this->s_.nrows();
}
void impl_next()
{
- precondition(this->p_.row().is_defined() && this->p_.col().is_defined());
- precondition(this->p_.row() >= 0 && this->p_.row() <= this->s_.nrows()
- &&
- this->p_.col() >= 0 && this->p_.col() <= this->s_.ncols());
+ precondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined());
+ precondition(this->p_.row() >= 0 && this->p_.row() < this->s_.nrows() &&
+ this->p_.col() >= 0 && this->p_.col() < this->s_.ncols());
++this->p_.col();
if (this->p_.col() != this->s_.ncols())
return;
this->p_.col() = 0;
- precondition(this->p_.row() != this->s_.nrows());
++this->p_.row();
- postcondition(this->p_.row().is_defined() && this->p_.col().is_defined());
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined());
}
void impl_invalidate()
{
this->p_.row() = this->s_.nrows();
this->p_.col() = this->s_.ncols();
- postcondition(this->p_.row().is_defined() && this->p_.col().is_defined());
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined());
}
};
}
-#endif // ndef PROTO_OLN_CORE_2D_FWD_PITER2D_HH
+#endif // ! OLENA_CORE_2D_FWD_PITER2D_HH
Index: oln/core/2d/point2d.hh
--- oln/core/2d/point2d.hh (revision 51)
+++ oln/core/2d/point2d.hh (working copy)
@@ -63,6 +63,7 @@
{
point2d()
{
+ // no initialization here so that row_ and col_ are 'undef'
}
point2d(coord_t row_, coord_t col_) :
Index: oln/core/2d/size2d.hh
--- oln/core/2d/size2d.hh (revision 51)
+++ oln/core/2d/size2d.hh (working copy)
@@ -39,7 +39,9 @@
struct size2d : public abstract::size< size2d >
{
size2d()
- {}
+ {
+ // no initialization here so that members are 'undef'
+ }
size2d(coord_t nrows_, coord_t ncols_) :
nrows_(nrows_),
Index: oln/core/3d/size3d.hh
--- oln/core/3d/size3d.hh (revision 51)
+++ oln/core/3d/size3d.hh (working copy)
@@ -39,12 +39,10 @@
struct size3d : public abstract::size< size3d >
{
- size3d() :
- nslices_(0),
- nrows_(0),
- ncols_(0),
- border_(0)
- {}
+ size3d()
+ {
+ // no initialization here so that members are 'undef'
+ }
size3d(coord_t nslices_, coord_t nrows_, coord_t ncols_) :
nslices_(nslices_),
@@ -84,8 +82,8 @@
bool impl_eq(const size3d& rhs) const
{
- return this->nslices_ == rhs.nslices_ and
- this->nrows_ == rhs.nrows_ and
+ return this->nslices_ == rhs.nslices_ &&
+ this->nrows_ == rhs.nrows_ &&
this->ncols_ == rhs.ncols_;
}
Index: oln/core/3d/array3d.hh
--- oln/core/3d/array3d.hh (revision 51)
+++ oln/core/3d/array3d.hh (working copy)
@@ -127,9 +127,9 @@
void impl_resize(const size3d& s)
{
- precondition(s.nslices() > 0 and
- s.nrows() > 0 and
- s.ncols() > 0 and
+ precondition(s.nslices() > 0 &&
+ s.nrows() > 0 &&
+ s.ncols() > 0 &&
s.border() >= 0);
invariant_();
this->clear_data();
@@ -167,22 +167,22 @@
bool impl_hold(const point3d& p) const
{
return
- p.slice() >= 0 and
- p.slice() < size_.nslices() and
- p.row() >= 0 and
- p.row() < size_.nrows() and
- p.col() >= 0 and
+ p.slice() >= 0 &&
+ p.slice() < size_.nslices() &&
+ p.row() >= 0 &&
+ p.row() < size_.nrows() &&
+ p.col() >= 0 &&
p.col() < size_.ncols();
}
bool impl_hold_large(const point3d& p) const
{
return
- p.slice() >= - size_.border() and
- p.slice() < size_.nslices() + size_.border() and
- p.row() >= - size_.border() and
- p.row() < size_.nrows() + size_.border() and
- p.col() >= - size_.border() and
+ p.slice() >= - size_.border() &&
+ p.slice() < size_.nslices() + size_.border() &&
+ p.row() >= - size_.border() &&
+ p.row() < size_.nrows() + size_.border() &&
+ p.col() >= - size_.border() &&
p.col() < size_.ncols() + size_.border();
}
@@ -219,19 +219,21 @@
void invariant_() const
{
- invariant((buffer_ != 0 and
- array_ != 0 and
- size_.nslices() > 0 and
- size_.nrows() > 0 and
- size_.ncols() > 0 and
+ invariant((buffer_ != 0 &&
+ array_ != 0 &&
+ array2_ != 0 &&
+ size_.nslices() > 0 &&
+ size_.nrows() > 0 &&
+ size_.ncols() > 0 &&
size_.border() >= 0)
- or
- (buffer_ == 0 and
- array_ == 0 and
- size_.nslices() == 0 and
- size_.nrows() == 0 and
- size_.ncols() == 0 and
- size_.border() == 0));
+ ||
+ (buffer_ == 0 &&
+ array_ == 0 &&
+ array2_ == 0 &&
+ size_.nslices().is_undefined() &&
+ size_.nrows().is_undefined() &&
+ size_.ncols().is_undefined() &&
+ size_.border().is_undefined()));
}
};
Index: oln/core/3d/image3d.hh
--- oln/core/3d/image3d.hh (revision 51)
+++ oln/core/3d/image3d.hh (working copy)
@@ -32,6 +32,7 @@
# include <oln/core/abstract/image_with_data.hh>
# include <oln/core/3d/array3d.hh>
+# include <oln/core/3d/fwd_piter3d.hh>
/*! \namespace oln
** \brief oln namespace.
@@ -67,8 +68,8 @@
typedef point3d point_type;
typedef T value_type;
-// typedef fwd_piter3d piter_type;
-// typedef fwd_piter3d fwd_piter_type;
+ typedef fwd_piter3d piter_type;
+ typedef fwd_piter3d fwd_piter_type;
// please note that value_storage_type means data_type
// since image3d is an image_with_data
Index: oln/core/3d/fwd_piter3d.hh
--- oln/core/3d/fwd_piter3d.hh (revision 0)
+++ oln/core/3d/fwd_piter3d.hh (revision 0)
@@ -0,0 +1,129 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 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_3D_FWD_PITER3D_HH
+# define OLENA_CORE_3D_FWD_PITER3D_HH
+
+# include <mlc/contract.hh>
+
+# include <oln/core/abstract/piter.hh>
+# include <oln/core/3d/point3d.hh>
+# include <oln/core/3d/size3d.hh>
+
+
+namespace oln {
+
+ // fwd decl
+ struct fwd_piter3d;
+
+ // category
+ template <>
+ struct set_category<fwd_piter3d> { typedef category::piter ret; };
+
+
+ // props
+ template <>
+ struct set_props < category::piter, fwd_piter3d > : public props_of<category::piter>
+ {
+ typedef point3d point_type;
+ typedef size3d size_type;
+ };
+
+
+
+ struct fwd_piter3d : public abstract::piter< fwd_piter3d >
+ {
+
+ typedef abstract::piter<fwd_piter3d> super_type;
+
+ fwd_piter3d(const size3d& size) :
+ super_type(size)
+ {
+ this->exact_ptr = this;
+ this->invalidate();
+ }
+
+# if defined __GNUC__ && __GNUC__ >= 3
+ friend class abstract::piter< fwd_piter3d >;
+ protected:
+# endif
+
+ void impl_start()
+ {
+ this->p_.row() = 0;
+ this->p_.col() = 0;
+ this->p_.slice() = 0;
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ }
+
+ bool impl_is_valid() const
+ {
+ precondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ return this->p_.slice() < this->s_.nslices();
+ }
+
+ void impl_next()
+ {
+ precondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ precondition(this->p_.row() >= 0 && this->p_.row() < this->s_.nrows() &&
+ this->p_.col() >= 0 && this->p_.col() < this->s_.ncols() &&
+ this->p_.slice() >= 0 && this->p_.slice() < this->s_.nslices());
+ ++this->p_.col();
+ if (this->p_.col() != this->s_.ncols())
+ return;
+ this->p_.col() = 0;
+ ++this->p_.row();
+ if (this->p_.row() != this->s_.nrows())
+ return;
+ this->p_.row() = 0;
+ ++this->p_.slice();
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ }
+
+ void impl_invalidate()
+ {
+ this->p_.row() = this->s_.nrows();
+ this->p_.col() = this->s_.ncols();
+ this->p_.slice() = this->s_.nslices();
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ }
+
+ };
+}
+
+
+#endif // ! OLENA_CORE_3D_FWD_PITER3D_HH
Index: oln/core/3d/point3d.hh
--- oln/core/3d/point3d.hh (revision 51)
+++ oln/core/3d/point3d.hh (working copy)
@@ -57,11 +57,9 @@
struct point3d : public abstract::point< point3d >
{
- point3d() :
- slice_(0),
- row_(0),
- col_(0)
+ point3d()
{
+ // no initialization here so that slice_, row_, and col_ are 'undef'
}
point3d(coord_t slice_, coord_t row_, coord_t col_) :
1
0
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
* oln/core/entry.hh: Move to...
* oln/core/abstract/entry.hh: ...here.
* oln/core/properties.hh: New.
* tests/core/tests/image1d: Adapt to properties management.
* tests/core/tests/image2d: Likewise.
* tests/core/tests/image3d: Likewise.
* tests/core/tests/image_identity: Likewise.
* tests/core/tests/setget: Likewise.
* oln/fancy/print.hh: Likewise.
* oln/fancy/iota.hh: Likewise.
* oln/basics.hh: Likewise.
* oln/makefile.src: Likewise.
* oln/io/write_image_2d_pnm.hh: Likewise.
* oln/io/read_image_2d_pnm.hh: Likewise.
* oln/io/write_image.hh: Likewise.
* oln/io/read_image.hh: Likewise.
* oln/core/value_box.hh: Likewise.
* oln/core/abstract/image_constness.hh: Likewise.
* oln/core/abstract/image.hh: Likewise.
* oln/core/abstract/piter.hh: Likewise.
* oln/core/abstract/images.hh: Likewise.
* oln/core/abstract/image_with_data.hh: Likewise.
* oln/core/abstract/point.hh: Likewise.
* oln/core/abstract/image_identity.hh: Likewise.
* oln/core/abstract/data_storage.hh: Likewise.
* oln/core/abstract/internal/image_impl.hh: Likewise.
* oln/core/abstract/op.hh: Likewise.
* oln/core/1d/array1d.hh: Likewise.
* oln/core/1d/image1d.hh: Likewise.
* oln/core/1d/fwd_piter1d.hh: Likewise.
* oln/core/1d/point1d.hh: Likewise.
* oln/core/coord.hh: Likewise.
* oln/core/2d/array2d.hh: Likewise.
* oln/core/2d/image2d.hh: Likewise.
* oln/core/2d/fwd_piter2d.hh: Likewise.
* oln/core/2d/point2d.hh: Likewise.
* oln/core/3d/array3d.hh: Likewise.
* oln/core/3d/image3d.hh: Likewise.
* oln/core/3d/point3d.hh: Likewise.
* oln/core/cats.hh: Remove because obsolete.
* oln/core/props.hh: Likewise.
* oln/core/macros.hh: Likewise.
oln/basics.hh | 2
oln/core/1d/array1d.hh | 13 ++
oln/core/1d/fwd_piter1d.hh | 13 ++
oln/core/1d/image1d.hh | 47 ++++++----
oln/core/1d/point1d.hh | 16 ++-
oln/core/2d/array2d.hh | 15 ++-
oln/core/2d/fwd_piter2d.hh | 12 ++
oln/core/2d/image2d.hh | 35 ++++---
oln/core/2d/point2d.hh | 15 ++-
oln/core/3d/array3d.hh | 13 ++
oln/core/3d/image3d.hh | 42 ++++-----
oln/core/3d/point3d.hh | 13 ++
oln/core/abstract/data_storage.hh | 61 +++++++++++--
oln/core/abstract/entry.hh | 83 ++++++++++++++++++
oln/core/abstract/image.hh | 138 +++++++++++++++++++++----------
oln/core/abstract/image_constness.hh | 17 ++-
oln/core/abstract/image_identity.hh | 28 +++++-
oln/core/abstract/image_with_data.hh | 54 ++++++++++--
oln/core/abstract/images.hh | 3
oln/core/abstract/internal/image_impl.hh | 7 -
oln/core/abstract/op.hh | 22 ++++
oln/core/abstract/piter.hh | 45 +++++++---
oln/core/abstract/point.hh | 41 ++++++---
oln/core/cats.hh | 79 -----------------
oln/core/coord.hh | 8 +
oln/core/entry.hh | 66 --------------
oln/core/macros.hh | 86 -------------------
oln/core/properties.hh | 95 +++++++++++++++++++++
oln/core/props.hh | 77 -----------------
oln/core/value_box.hh | 37 ++++----
oln/fancy/iota.hh | 3
oln/fancy/print.hh | 5 -
oln/io/read_image.hh | 4
oln/io/read_image_2d_pnm.hh | 27 ++----
oln/io/write_image.hh | 6 -
oln/io/write_image_2d_pnm.hh | 3
oln/makefile.src | 6 -
tests/core/tests/image1d | 2
tests/core/tests/image2d | 2
tests/core/tests/image3d | 2
tests/core/tests/image_identity | 11 +-
tests/core/tests/setget | 6 -
42 files changed, 700 insertions(+), 560 deletions(-)
Index: tests/core/tests/image1d
--- tests/core/tests/image1d (revision 50)
+++ tests/core/tests/image1d (working copy)
@@ -13,7 +13,7 @@
template <typename I>
-void foo(oln::abstract::image<I>& input, const oln_point_type(I)& p)
+void foo(oln::abstract::image<I>& input, const oln_type_of(I, point)& p)
{
// FIXME: dummy code below
// struct dummy {};
Index: tests/core/tests/image2d
--- tests/core/tests/image2d (revision 50)
+++ tests/core/tests/image2d (working copy)
@@ -13,7 +13,7 @@
template <typename I>
-void foo(oln::abstract::image<I>& input, const oln_point_type(I)& p)
+void foo(oln::abstract::image<I>& input, const oln_type_of(I, point)& p)
{
// FIXME: dummy code below
// struct dummy {};
Index: tests/core/tests/image3d
--- tests/core/tests/image3d (revision 50)
+++ tests/core/tests/image3d (working copy)
@@ -13,7 +13,7 @@
template <typename I>
-void foo(oln::abstract::image<I>& input, const oln_point_type(I)& p)
+void foo(oln::abstract::image<I>& input, const oln_type_of(I, point)& p)
{
// FIXME: dummy code below
// struct dummy {};
Index: tests/core/tests/image_identity
--- tests/core/tests/image_identity (revision 50)
+++ tests/core/tests/image_identity (working copy)
@@ -10,14 +10,14 @@
namespace oln {
template <typename I>
- struct category_type< image_identity<I> >
+ struct set_category< image_identity<I> >
{
- typedef cat::image ret;
+ typedef category::image ret;
};
template <typename I>
- struct props <cat::image, image_identity<I> >
- : public props<cat::image, I>
+ struct set_props < category::image, image_identity<I> >
+ : public get_props < category::image, I >
{
typedef I delegated_type;
};
@@ -25,8 +25,7 @@
}
template <typename I>
-struct image_identity:
- public oln::abstract::image_identity<I, image_identity<I> >
+struct image_identity : public oln::abstract::image_identity<I, image_identity<I> >
{
typedef oln::abstract::image_identity<I, image_identity<I> > super_type;
Index: tests/core/tests/setget
--- tests/core/tests/setget (revision 50)
+++ tests/core/tests/setget (working copy)
@@ -7,13 +7,13 @@
struct dummy_image;
template <>
- struct category_type< dummy_image >
+ struct set_category< dummy_image >
{
- typedef cat::image ret;
+ typedef category::image ret;
};
template <>
- struct props <cat::image, dummy_image>
+ struct set_props < category::image, dummy_image > : public props_of <category::image>
{
typedef int size_type;
typedef int point_type;
Index: oln/fancy/print.hh
--- oln/fancy/print.hh (revision 50)
+++ oln/fancy/print.hh (working copy)
@@ -40,6 +40,7 @@
# include <oln/core/2d/point2d.hh>
# include <oln/core/coord.hh>
+
namespace oln {
namespace fancy {
@@ -106,7 +107,7 @@
// FIXME: lacks cleaning
for (coord_t index = 0; index < input.size().nindices(); ++index)
{
- ostr << internal::pp<oln_value_type(E)>(input[point1d(index)]) << ' ';
+ ostr << internal::pp<oln_type_of(E, value)>(input[point1d(index)]) << ' ';
}
ostr << std::endl;
}
@@ -118,7 +119,7 @@
for (coord_t row = 0; row < input.size().nrows(); ++row)
{
for (coord_t col = 0; col < input.size().ncols(); ++col)
- ostr << internal::pp<oln_value_type(E)>(input[point2d(row,col)]) << ' ';
+ ostr << internal::pp<oln_type_of(E, value)>(input[point2d(row,col)]) << ' ';
ostr << std::endl;
}
}
Index: oln/fancy/iota.hh
--- oln/fancy/iota.hh (revision 50)
+++ oln/fancy/iota.hh (working copy)
@@ -28,7 +28,6 @@
#ifndef OLENA_FANCY_IOTA_HH
# define OLENA_FANCY_IOTA_HH
-# include <oln/core/macros.hh>
# include <oln/core/abstract/image.hh>
# include <oln/core/abstract/piter.hh>
@@ -43,7 +42,7 @@
void iota(abstract::image<I>& inout)
{
unsigned counter = 0;
- oln_piter_type(I) p(inout.size());
+ oln_type_of(I, fwd_piter) p(inout.size());
for_all(p)
inout[p] = ++counter;
}
Index: oln/basics.hh
--- oln/basics.hh (revision 50)
+++ oln/basics.hh (working copy)
@@ -54,7 +54,7 @@
// oln::
# include <oln/core/coord.hh>
-# include <oln/core/macros.hh>
+# include <oln/core/properties.hh>
# include <oln/core/value_box.hh>
# include <oln/core/abstract/size.hh>
Index: oln/makefile.src
--- oln/makefile.src (revision 50)
+++ oln/makefile.src (working copy)
@@ -24,6 +24,7 @@
core/3d/point3d.hh \
core/3d/size3d.hh \
core/abstract/data_storage.hh \
+ core/abstract/entry.hh \
core/abstract/image.hh \
core/abstract/image_constness.hh \
core/abstract/image_identity.hh \
@@ -34,11 +35,8 @@
core/abstract/piter.hh \
core/abstract/point.hh \
core/abstract/size.hh \
- core/cats.hh \
core/coord.hh \
- core/macros.hh \
- core/props.hh \
- core/entry.hh \
+ core/properties.hh \
core/value_box.hh \
fancy/iota.hh \
fancy/print.hh \
Index: oln/io/write_image_2d_pnm.hh
--- oln/io/write_image_2d_pnm.hh (revision 50)
+++ oln/io/write_image_2d_pnm.hh (working copy)
@@ -41,7 +41,6 @@
# include <ntg/color/color.hh>
# include <oln/core/2d/image2d.hh>
-# include <oln/core/macros.hh>
# include <oln/core/abstract/op.hh>
# include <oln/io/utils.hh>
@@ -56,7 +55,7 @@
struct write_image_2d_raw
: public oln::abstract::void_op<write_image_2d_raw<I> >
{
- typedef oln_value_type(I) value_type;
+ typedef oln_type_of(I, value) value_type;
typedef ntg_io_type(value_type) io_type;
const I& to_write_;
Index: oln/io/read_image_2d_pnm.hh
--- oln/io/read_image_2d_pnm.hh (revision 50)
+++ oln/io/read_image_2d_pnm.hh (working copy)
@@ -13,7 +13,6 @@
# include <ntg/color/color.hh>
# include <oln/core/2d/image2d.hh>
-# include <oln/core/macros.hh>
# include <oln/core/abstract/op.hh>
# include <oln/io/utils.hh>
@@ -24,43 +23,39 @@
template <typename I>
struct image2d;
+ // fwd decl
namespace io {
-
namespace impl {
-
- template <typename I>
- struct read_image_2d_raw;
-
+ template <typename I> struct read_image_2d_raw;
}
-
}
+ // category
template <typename I>
- struct category_type< io::impl::read_image_2d_raw<I> >
+ struct set_category < io::impl::read_image_2d_raw<I> >
{
- typedef cat::image ret;
+ typedef category::image ret;
};
+ // super_type
template <typename I>
- struct props <cat::image, io::impl::read_image_2d_raw<I> >
- : public props<cat::image, I>
+ struct set_super_type < io::impl::read_image_2d_raw<I> >
{
- typedef I delegated_type;
+ typedef abstract::op<I, io::impl::read_image_2d_raw<I> > ret;
};
-
namespace io {
namespace impl {
template <typename I>
- struct read_image_2d_raw:
- oln::abstract::op<I, read_image_2d_raw<I> >
+ struct read_image_2d_raw :
+ public oln::abstract::op<I, read_image_2d_raw<I> >
{
typedef oln::abstract::op<I, read_image_2d_raw<I> > super_type;
- typedef oln_value_type(I) value_type;
+ typedef oln_type_of(I, value) value_type;
typedef ntg_io_type(value_type) io_type;
mlc::box<I> image_;
Index: oln/io/write_image.hh
--- oln/io/write_image.hh (revision 50)
+++ oln/io/write_image.hh (working copy)
@@ -37,11 +37,11 @@
namespace io {
- template <typename E>
- void write(const abstract::image<E>& im, const std::string& name)
+ template <typename I>
+ void write(const abstract::image<I>& im, const std::string& name)
{
std::string ext;
- oln_value_type(E) t;
+ oln_type_of(I, value) t;
ext = internal::utils::extension(name);
Index: oln/io/read_image.hh
--- oln/io/read_image.hh (revision 50)
+++ oln/io/read_image.hh (working copy)
@@ -33,8 +33,6 @@
# include <mlc/box.hh>
-# include <oln/core/macros.hh>
-
# include <oln/io/read_image_2d_pnm.hh>
# include <oln/io/utils.hh>
@@ -65,7 +63,7 @@
void do_read(abstract::image<I>& ima, const filename& name)
{
std::string ext;
- const oln_value_type(I) t;
+ const oln_type_of(I, value) t;
ext = internal::utils::extension(name.get());
Index: oln/core/entry.hh
--- oln/core/entry.hh (revision 50)
+++ oln/core/entry.hh (working copy)
@@ -1,66 +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_ENTRY_HH
-# define OLENA_CORE_ENTRY_HH
-
-# include <oln/core/abstract/image_constness.hh>
-# include <oln/core/abstract/image_dimension.hh>
-
-
-namespace oln {
-
- template <template <typename> class Base>
- struct prop_of
- {
- template <typename E>
- struct inherits
- {
- typedef Base<E> ret;
- };
- };
-
- namespace abstract {
-
- template <typename E>
- struct image_entry :
- public props < cat::image, E >::image_constness
- ::template inherits<E>::ret,
- public props < cat::image, E >::image_dimension
- ::template inherits<E>::ret
- // ...
- {
- protected:
- image_entry() {}
- };
-
- }
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_CORE_ENTRY_HH
Index: oln/core/props.hh
--- oln/core/props.hh (revision 50)
+++ oln/core/props.hh (working copy)
@@ -1,77 +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_PROPS_HH
-# define OLENA_CORE_PROPS_HH
-
-# include <mlc/types.hh>
-
-# include <oln/core/cats.hh>
-
-/*! \namespace oln
-** \brief oln namespace.
-*/
-namespace oln {
-
-
- /*! \class default_props
- **
- ** \brief Class that defines properties by default, so properties are
- ** undefined. // FIXME: this doc should be modified...
- **
- ** Practically all typedefs of default_props are thus set to
- ** mlc::undefined_type.
- **
- ** When props<E> is specialized, the programmer should derive that
- ** specialization from another props<E'> or from default_props.
- ** That ensures that an undefined property is set to mlc::undefined_type.
- **
- ** \see props<E>
- */
- template < typename category >
- struct default_props;
-
-
- /*! \class props<E>
- **
- ** Declaration of the trait class for properties.
- ** Parameter E is the targeted type. FIXME: rewrite doc.
- */
- template <typename category, typename type>
- struct props : public default_props <category>
- {};
-
- template <typename category, typename type>
- struct props <category, const type> : public props <category, type>
- {};
-
-
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_CORE_PROPS_HH
Index: oln/core/value_box.hh
--- oln/core/value_box.hh (revision 50)
+++ oln/core/value_box.hh (working copy)
@@ -30,16 +30,11 @@
# include <iostream>
-# include <oln/core/macros.hh>
+# include <oln/core/properties.hh>
-// the proper macro:
-// for use in 'abstract::image::op[](point)'
-# define oln_value_box_type(E) typename oln::value_box<E>
-
-
/*! \namespace oln
** \brief oln namespace.
*/
@@ -78,7 +73,12 @@
public:
+ /// typedefs
+ typedef oln_type_of(I, value) value_type;
+ typedef oln_type_of(I, point) point_type;
+
+
/*! \brief op=
** FIXME:...
** \return (*this)
@@ -103,7 +103,7 @@
template <typename II>
value_box& operator=(const value_box<II>& rhs)
{
- ima_.set(p_, rhs); // automatic conversion from rhs to oln_value_type(I)
+ ima_.set(p_, rhs); // automatic conversion from rhs to value_type
return *this;
}
@@ -137,7 +137,7 @@
return value;
}
- operator const oln_value_type(I)() const
+ operator const value_type() const
{
return ima_.get(p_);
}
@@ -154,7 +154,7 @@
** \return a value (const, temp)
*/
- const oln_value_type(I) value() const
+ const value_type value() const
{
return ima_.get(p_);
}
@@ -179,7 +179,7 @@
/// Ctor (restricted access).
- value_box(abstract::image<I>& ima, const oln_point_type(I)& p) :
+ value_box(abstract::image<I>& ima, const point_type& p) :
ima_(ima.exact()),
p_(p)
{
@@ -190,7 +190,7 @@
*------------*/
I& ima_;
- oln_point_type(I) p_;
+ point_type p_;
};
@@ -213,6 +213,13 @@
public:
+ /// typedefs
+
+ typedef oln_type_of(I, value) value_type;
+ typedef oln_type_of(I, point) point_type;
+
+
+
/*! \brief Assignment (op=) is declared but undefined.
*/
@@ -232,7 +239,7 @@
return value;
}
- operator const oln_value_type(I)() const
+ operator const value_type() const
{
return ima_.get(p_);
}
@@ -249,7 +256,7 @@
** \return a value (const, temp)
*/
- const oln_value_type(I) value() const
+ const value_type value() const
{
return ima_.get(p_);
}
@@ -276,7 +283,7 @@
/// Ctor (restricted access).
- value_box(const abstract::image<I>& ima, const oln_point_type(I)& p) :
+ value_box(const abstract::image<I>& ima, const point_type& p) :
ima_(ima.exact()),
p_(p)
{
@@ -287,7 +294,7 @@
*------------*/
const I& ima_;
- oln_point_type(I) p_;
+ point_type p_;
};
Index: oln/core/macros.hh
--- oln/core/macros.hh (revision 50)
+++ oln/core/macros.hh (working copy)
@@ -1,86 +0,0 @@
-// Copyright (C) 2001, 2003, 2004, 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_MACROS_HH
-# define OLENA_CORE_MACROS_HH
-
-# include <oln/core/cats.hh>
-# include <oln/core/props.hh>
-
-
-
-// FIXME: some crucial (meta-)work to be done here!
-//
-// first, introduce a piece of meta-code to get the proper abstraction
-// from parameter; e.g., if I is an abstract::image then abstraction
-// is abstract::image else etc.
-//
-// second, in macro below, there should be an exact_type from I somewhere
-// cause we cannot be sure that I is an exact type; just think about it...
-
-
-
-
-
-// for oln::abstract::image
-//--------------------------
-
-// unary macros
-
-# define oln_delegated_type(T) typename oln::props<oln_category_type(T),T>::delegated_type
-
-# define oln_size_type(T) typename oln::props<oln_category_type(T),T>::size_type
-# define oln_point_type(T) typename oln::props<oln_category_type(T),T>::point_type
-# define oln_dpoint_type(T) typename oln::props<oln_category_type(T),T>::dpoint_type
-# define oln_value_type(T) typename oln::props<oln_category_type(T),T>::value_type
-# define oln_iter_type(T) typename oln::props<oln_category_type(T),T>::iter_type
-
-# define oln_value_storage_type(T) typename oln::props<oln_category_type(T),T>::value_storage_type
-# define oln_value_container_type(T) typename oln::props<oln_category_type(T),T>::value_container_type
-
-# define oln_piter_type(T) typename oln::props<oln_category_type(T),T>::piter_type
-# define oln_fwd_piter_type(T) typename oln::props<oln_category_type(T),T>::fwd_piter_type
-
-// binary macros
-
-# define oln_ch_value_type(I,V) typename oln::props<oln_category_type(I),I>::ch_value_type<V>::ret
-
-
-// for oln::abstract::data_storage
-
-# define oln_data_type(T) typename oln::props<oln_category_type(T),T>::data_type
-
-
-
-// generic macros
-//----------------
-
-# define oln_typeof( FROM_TYPE, WHAT_TYPE ) typename oln::props<oln_category_type(FROM_TYPE),FROM_TYPE>::WHAT_TYPE##_type
-
-
-
-#endif // ! OLENA_CORE_MACROS_HH
Index: oln/core/abstract/image_constness.hh
--- oln/core/abstract/image_constness.hh (revision 50)
+++ oln/core/abstract/image_constness.hh (working copy)
@@ -87,6 +87,11 @@
*/
+ /// typedef
+
+ typedef oln_type_of(E, point) point_type;
+
+
/*! \brief Write the value \a v at \a p in the current image.
** This method is used in value_box<I>. Client should not use
** this method but abstract::image<I>::operator[](point)
@@ -96,7 +101,7 @@
*/
template <typename V>
- void set(const oln_point_type(E)& p, const V& v)
+ void set(const point_type& p, const V& v)
{
return this->exact().impl_set(p, v);
}
@@ -104,7 +109,7 @@
// FIXME: NEW:
// template <typename A, typename V>
-// void& set(const oln_point_type(E)& p,
+// void& set(const point_type& p,
// void (I::*method)(A),
// const V& value)
// {
@@ -126,10 +131,12 @@
template <typename E>
struct set_image_impl < readwrite_image<E>, E> : public virtual image_impl<E>
{
+ /// typedefs
typedef typename image_impl<E>::D D;
+ typedef oln_type_of(D, point) point_type;
template <typename V>
- void impl_set(const oln_point_type(D)& p, const V& v)
+ void impl_set(const point_type& p, const V& v)
{
this->exact().impl_set_ante(p, v);
this->delegate().impl_set(p, v);
@@ -139,10 +146,10 @@
// extra code; default is 'do nothing':
template <typename V>
- void impl_set_ante(const oln_point_type(D)&, const V&) {}
+ void impl_set_ante(const point_type&, const V&) {}
template <typename V>
- void impl_set_post(const oln_point_type(D)&, const V&) {}
+ void impl_set_post(const point_type&, const V&) {}
};
} // end of namespace oln::abstract::internal
Index: oln/core/abstract/entry.hh
--- oln/core/abstract/entry.hh (revision 0)
+++ oln/core/abstract/entry.hh (revision 0)
@@ -0,0 +1,83 @@
+// 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_ENTRY_HH
+# define OLENA_CORE_ABSTRACT_ENTRY_HH
+
+# include <oln/core/abstract/image_constness.hh>
+# include <oln/core/abstract/image_dimension.hh>
+
+
+// FIXME: this file should move to oln/core/abstract/
+
+
+namespace oln {
+
+
+ // fwd decl
+ namespace abstract {
+ template <typename E> struct image_entry;
+ }
+
+ // category
+ template <typename E>
+ struct set_category < abstract::image_entry<E> >
+ {
+ typedef category::image ret;
+ };
+
+
+
+ namespace abstract {
+
+// namespace internal {
+
+// template < typename isa, typename E >
+// struct inherits
+// {
+// typedef typename isa::template instantiated_with<E>::ret ret;
+// };
+
+// }
+
+ template <typename E>
+ struct image_entry :
+ // intrusive:
+ public oln_type_of_(E, image_constness) ::template instantiated_with<E>::ret,
+ public oln_type_of_(E, image_dimension) ::template instantiated_with<E>::ret
+ // ...
+ {
+ protected:
+ image_entry() {}
+ };
+
+ }
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_ENTRY_HH
Index: oln/core/abstract/image.hh
--- oln/core/abstract/image.hh (revision 50)
+++ oln/core/abstract/image.hh (working copy)
@@ -28,10 +28,10 @@
#ifndef OLENA_CORE_ABSTRACT_IMAGE_HH
# define OLENA_CORE_ABSTRACT_IMAGE_HH
+# include <mlc/types.hh>
+
# include <oln/core/abstract/internal/image_impl.hh>
-# include <oln/core/cats.hh>
-# include <oln/core/props.hh>
-# include <oln/core/macros.hh>
+# include <oln/core/properties.hh>
# include <oln/core/value_box.hh>
@@ -41,37 +41,72 @@
namespace oln {
+ // fwd decl
+ namespace abstract {
+ template <typename E> struct image;
+ template <typename E> struct readonly_image;
+ }
- // FIXME: doc
- template <>
- struct default_props < cat::image >
- {
- typedef mlc::undefined_type delegated_type;
+ // category
+ template <typename E>
+ struct set_category< abstract::image<E> > { typedef category::image ret; };
- typedef mlc::undefined_type size_type;
- typedef mlc::undefined_type point_type;
- typedef mlc::undefined_type value_type;
- typedef mlc::undefined_type piter_type;
- typedef mlc::undefined_type fwd_piter_type;
- typedef mlc::undefined_type value_storage_type;
- typedef mlc::undefined_type value_container_type;
+ /// properties of any type in category::image
- // FIXME: etc.
+ template <typename type>
+ struct props_of <category::image, type>
+ {
+ typedef mlc::true_type user_defined_;
+
+ mlc_decl_prop(category::image, value_type);
+ mlc_decl_prop(category::image, point_type);
+ mlc_decl_prop(category::image, size_type);
+ mlc_decl_prop(category::image, fwd_piter_type);
+ mlc_decl_prop_with_default(category::image, value_storage_type, mlc::no_type);
+ mlc_decl_prop_with_default(category::image, storage_type, mlc::no_type);
+ mlc_decl_prop_with_default(category::image, delegated_type, mlc::no_type);
- template <typename T>
- struct ch_value_type
+ mlc_decl_prop_with_default(category::image, image_constness_type, is_a<abstract::readonly_image>);
+ mlc_decl_prop(category::image, image_dimension_type);
+
+ //...
+
+ static void echo(std::ostream& ostr)
{
- typedef mlc::undefined_type ret;
- };
+ ostr << "props_of(" // FIXME: << typeid(oln::category::image).name()
+ << ", " << typeid(type).name() << ") = {"
+ << " value_type = " << typeid(value_type).name()
+ << " point_type = " << typeid(point_type).name()
+ << " size_type = " << typeid(size_type).name()
+ << " fwd_piter_type = " << typeid(fwd_piter_type).name()
+ << " value_storage_type = " << typeid(value_storage_type).name()
+ << " storage_type = " << typeid(storage_type).name()
+ << " delegated_type = " << typeid(delegated_type).name()
- protected:
- default_props() {}
+ << " image_constness_type = " << typeid(image_constness_type).name()
+ << " image_dimension_type = " << typeid(image_dimension_type).name()
+
+ << " }" << std::endl;
+ }
+
};
+ mlc_register_prop(category::image, value_type);
+ mlc_register_prop(category::image, point_type);
+ mlc_register_prop(category::image, size_type);
+ mlc_register_prop(category::image, fwd_piter_type);
+ mlc_register_prop(category::image, value_storage_type);
+ mlc_register_prop(category::image, storage_type);
+ mlc_register_prop(category::image, delegated_type);
+ mlc_register_prop(category::image, image_constness_type);
+ mlc_register_prop(category::image, image_dimension_type);
+
+
+
/*! \namespace oln::abstract
** \brief oln::abstract namespace.
*/
@@ -92,20 +127,27 @@
struct image : public internal::get_image_impl < image<E>, E>
{
+ /// typedefs
+
+ typedef oln_type_of(E, size) size_type;
+ typedef oln_type_of(E, value) value_type;
+ typedef oln_type_of(E, point) point_type;
+
+
/*------------------*
! abstract methods !
*------------------*/
- /*! \brief Return the size of the current image. Nota bene: this method is abstract-like.it
- ** is a pseudo-abstract method.
+ /*! \brief Return the size of the current image. Nota bene:
+ ** this method is abstract-like.it is a pseudo-abstract method.
**
** \return An object deriving from abstract::size. Ex: if the
** image is an image2d<something>, the returned object is a
** size2d.
*/
- const oln_size_type(E)& size() const
+ const size_type& size() const
{
return this->exact().impl_size();
}
@@ -137,7 +179,7 @@
** \see hold_large
*/
- bool hold(const oln_point_type(E)& p) const
+ bool hold(const point_type& p) const
{
precondition(this->npoints() != 0);
return this->exact().impl_hold(p);
@@ -158,7 +200,7 @@
** \see hold
*/
- bool hold_large(const oln_point_type(E)& p) const
+ bool hold_large(const point_type& p) const
{
precondition(this->npoints() != 0);
return this->exact().impl_hold_large(p);
@@ -175,7 +217,7 @@
** \see hold_large
*/
- bool impl_hold_large(const oln_point_type(E)& p) const
+ bool impl_hold_large(const point_type& p) const
{
return this->hold(p);
}
@@ -196,11 +238,11 @@
** \see value_box
*/
- oln_value_box_type(const E) operator[](const oln_point_type(E)& p) const
+ value_box<const E> operator[](const point_type& p) const
{
precondition(this->npoints() != 0);
precondition(this->hold_large(p));
- oln_value_box_type(const E) tmp(this->exact(), p);
+ value_box<const E> tmp(this->exact(), p);
return tmp;
}
@@ -214,11 +256,11 @@
** \see value_box
*/
- oln_value_box_type(E) operator[](const oln_point_type(E)& p)
+ value_box<E> operator[](const point_type& p)
{
precondition(this->npoints() != 0);
precondition(this->hold_large(p));
- oln_value_box_type(E) tmp(this->exact(), p);
+ value_box<E> tmp(this->exact(), p);
return tmp;
}
@@ -251,7 +293,7 @@
** \see value_box, abstract::image<I>::operator[](point)
*/
- const oln_value_type(E) get(const oln_point_type(E)& p) const
+ const value_type get(const point_type& p) const
{
return this->exact().impl_get(p);
}
@@ -282,13 +324,21 @@
template <typename E>
struct set_image_impl < image<E>, E > : public virtual image_impl<E>
{
+
+ /// typedefs
+
typedef typename image_impl<E>::D D;
+ typedef oln_type_of(D, size) size_type;
+ typedef oln_type_of(D, point) point_type;
+ typedef oln_type_of(D, value) value_type;
+
+
// delegations are "template methods" (Cf. the GOF's book)
- const oln_size_type(D)& impl_size() const
+ const size_type& impl_size() const
{
- const oln_size_type(D)& s = this->delegate().size();
+ const size_type& s = this->delegate().size();
this->exact().impl_size_extra(s);
return s;
}
@@ -300,31 +350,31 @@
return n;
}
- bool impl_hold(const oln_point_type(D)& p) const
+ bool impl_hold(const point_type& p) const
{
this->exact().impl_hold_extra(p);
return this->delegate().hold(p);
}
- bool impl_hold_large(const oln_point_type(D)& p) const
+ bool impl_hold_large(const point_type& p) const
{
this->exact().impl_hold_large_extra(p);
return this->delegate().hold_large(p);
}
- oln_value_box_type(D) operator[](const oln_point_type(D)& p) const
+ value_box<D> operator[](const point_type& p) const
{
precondition(this->hold_large(p));
return this->delegate().operator[](p);
}
- oln_value_box_type(const D) operator[](const oln_point_type(D)& p)
+ value_box<const D> operator[](const point_type& p)
{
precondition(this->hold_large(p));
return this->delegate().operator[](p);
}
- const oln_value_type(D) impl_get(const oln_point_type(D)& p) const
+ const value_type impl_get(const point_type& p) const
{
this->exact().impl_get_extra(p);
return this->delegate().impl_get(p);
@@ -332,13 +382,13 @@
// extra code; default is "do nothing"
- void impl_size_extra(const oln_size_type(D)& s) const {}
+ void impl_size_extra(const size_type& s) const {}
void impl_npoints_extra(unsigned long n) const {}
- void impl_hold_extra(const oln_point_type(D)& p) const {}
- void impl_hold_large_extra(const oln_point_type(D)& p) const {}
+ void impl_hold_extra(const point_type& p) const {}
+ void impl_hold_large_extra(const point_type& p) const {}
- void impl_get_extra(const oln_point_type(D)&) const {}
+ void impl_get_extra(const point_type&) const {}
};
} // end of namespace oln::abstract::internal
Index: oln/core/abstract/piter.hh
--- oln/core/abstract/piter.hh (revision 50)
+++ oln/core/abstract/piter.hh (working copy)
@@ -33,9 +33,7 @@
# include <mlc/contract.hh>
# include <oln/core/abstract/point.hh>
-# include <oln/core/cats.hh>
-# include <oln/core/props.hh>
-# include <oln/core/macros.hh>
+# include <oln/core/properties.hh>
@@ -44,34 +42,55 @@
namespace oln {
+ // fwd decl
namespace abstract {
-
template <typename E> struct piter;
-
}
-
+ // category
template <typename E>
- struct category_type<abstract::piter<E> > { typedef cat::piter ret; };
+ struct set_category< abstract::piter<E> > { typedef category::piter ret; };
- template <>
- struct default_props < cat::piter >
+ /// properties of any type in category::piter
+
+ template <typename type>
+ struct props_of < category::piter, type >
{
- typedef mlc::undefined_type point_type;
- typedef mlc::undefined_type size_type;
+ typedef mlc::true_type user_defined_;
+
+ mlc_decl_prop(category::piter, size_type);
+ mlc_decl_prop(category::piter, point_type);
+
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( category::piter, "
+ << typeid(type).name() << ") = {"
+ << " size_type = " << typeid(size_type).name()
+ << " point_type = " << typeid(point_type).name() << " }" << std::endl;
+ }
+
};
+ mlc_register_prop(category::piter, size_type);
+ mlc_register_prop(category::piter, point_type);
+
+
namespace abstract {
template <typename E>
struct piter : public mlc::any__best_speed<E>
{
+
+ /// typedefs
+
typedef piter<E> self_type;
- typedef oln_point_type(E) point_type;
- typedef oln_size_type(E) size_type;
+ typedef oln_type_of(E, size) size_type;
+ typedef oln_type_of(E, point) point_type;
+
+
void start()
{
this->exact().impl_start();
Index: oln/core/abstract/images.hh
--- oln/core/abstract/images.hh (revision 50)
+++ oln/core/abstract/images.hh (working copy)
@@ -36,7 +36,4 @@
# include <oln/core/abstract/image_constness.hh>
-# include <oln/core/entry.hh>
-
-
#endif // ! OLENA_CORE_ABSTRACT_IMAGES_HH
Index: oln/core/abstract/image_with_data.hh
--- oln/core/abstract/image_with_data.hh (revision 50)
+++ oln/core/abstract/image_with_data.hh (working copy)
@@ -31,15 +31,44 @@
# include <mlc/tracked_ptr.hh>
-# include <oln/core/entry.hh>
-# include <oln/core/macros.hh>
+# include <oln/core/abstract/entry.hh>
+
/*! \namespace oln
** \brief oln namespace.
*/
namespace oln {
+ // fwd decl
+ namespace abstract {
+ template <typename E> class image_with_data;
+ }
+
+ // category
+ template <typename E>
+ struct set_category < abstract::image_with_data<E> >
+ {
+ typedef category::image ret;
+ };
+
+ // super_type
+ template <typename E>
+ struct set_super_type < abstract::image_with_data<E> >
+ {
+ typedef abstract::image_entry<E> ret;
+ };
+
+ // props
+ template <typename E>
+ struct set_props < category::image, abstract::image_with_data<E> > : public props_of<category::image>
+ {
+ // intrusive property:
+ typedef is_a<abstract::readwrite_image> image_constness_type;
+ };
+
+
+
/*! \namespace oln::abstract
** \brief oln::abstract namespace.
*/
@@ -59,7 +88,14 @@
public:
+ /// typedefs
+ typedef oln_type_of(E, size) size_type;
+ typedef oln_type_of(E, point) point_type;
+ typedef oln_type_of(E, value) value_type;
+ typedef oln_type_of(E, storage) storage_type;
+
+
/*! \brief Implement abstract::image<E>::size() so return the
** size of the current image.
**
@@ -68,7 +104,7 @@
** size2d.
*/
- const oln_size_type(E)& impl_size() const
+ const size_type& impl_size() const
{
precondition(this->has_data());
return this->data_->size();
@@ -97,7 +133,7 @@
** \return True if p belongs to the current image, false otherwise.
*/
- bool impl_hold(const oln_point_type(E)& p) const
+ bool impl_hold(const point_type& p) const
{
precondition(this->has_data());
return this->data_->hold(p);
@@ -111,7 +147,7 @@
** \return True if p belongs to the current image, false otherwise.
*/
- const oln_value_type(E) impl_get(const oln_point_type(E)& p) const
+ const value_type impl_get(const point_type& p) const
{
precondition(this->has_data());
return this->data_->get(p);
@@ -123,7 +159,7 @@
*/
template <typename V>
- void impl_set(const oln_point_type(E)& p, const V& v)
+ void impl_set(const point_type& p, const V& v)
{
precondition(this->has_data());
this->data_->set(p, v);
@@ -151,8 +187,8 @@
/*! \brief Constructor (protected) with memory allocation for
** data.
*/
- image_with_data(const oln_size_type(E)& size) :
- data_(new oln_value_container_type(E)(size))
+ image_with_data(const size_type& size) :
+ data_(new storage_type(size))
{
}
@@ -166,7 +202,7 @@
/*! \brief Data storage.
*/
- mlc::tracked_ptr<oln_value_container_type(E)> data_;
+ mlc::tracked_ptr<storage_type> data_;
};
Index: oln/core/abstract/point.hh
--- oln/core/abstract/point.hh (revision 50)
+++ oln/core/abstract/point.hh (working copy)
@@ -29,10 +29,9 @@
# define OLENA_CORE_ABSTRACT_POINT_HH
# include <mlc/any.hh>
+# include <mlc/bool.hh>
-# include <oln/core/cats.hh>
-# include <oln/core/props.hh>
-# include <oln/core/macros.hh>
+# include <oln/core/properties.hh>
/*! \namespace oln
@@ -41,24 +40,37 @@
namespace oln {
- /// fwd decl
+ // fwd decl
namespace abstract {
template <typename E> struct point;
}
+ // category
+ template <typename E>
+ struct set_category< abstract::point<E> > { typedef category::point ret; };
- /*! \class default_props< cat::point >
- **
- ** Default properties for points. Specialization of
- ** default_props<category>.
- */
- template <>
- struct default_props < cat::point >
+
+ /// properties of any type in category::point
+
+ template <typename type>
+ struct props_of < category::point, type >
{
- typedef mlc::undefined_type dpoint_type;
+ typedef mlc::true_type user_defined_;
+
+ mlc_decl_prop(category::point, dpoint_type);
+
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( category::point, "
+ << typeid(type).name() << ") = {"
+ << " dpoint_type = " << typeid(dpoint_type).name() << " }" << std::endl;
+ }
+
};
+ mlc_register_prop(category::point, dpoint_type);
+
/*! \namespace oln::abstract
** \brief oln::abstract namespace.
*/
@@ -95,9 +107,10 @@
return ! this->operator==(rhs);
}
- typedef oln_dpoint_type(E) dpoint_type;
+ // FIXME: doc...
- // FIXME: doc
+ typedef oln_type_of(E, dpoint) dpoint_type;
+
const point operator+(const dpoint_type& dp) const
{
return this->exact().impl_plus(dp);
Index: oln/core/abstract/image_identity.hh
--- oln/core/abstract/image_identity.hh (revision 50)
+++ oln/core/abstract/image_identity.hh (working copy)
@@ -30,14 +30,38 @@
# include <mlc/box.hh>
-# include <oln/core/entry.hh>
+# include <oln/core/properties.hh>
+# include <oln/core/abstract/entry.hh>
+
namespace oln {
+
+ // fwd decl
namespace abstract {
+ template <typename I, typename E> struct image_identity;
+ }
+ // category
+ template <typename I, typename E>
+ struct set_category< abstract::image_identity<I,E> > {
+ typedef category::image ret;
+ };
+
+ // props
+ template <typename I, typename E>
+ struct set_props < category::image, abstract::image_identity<I,E> >
+ : public get_props< category::image, I >
+ {
+ typedef I delegated_type;
+ };
+
+
+
+ namespace abstract {
+
template <typename I, typename E>
- struct image_identity: public abstract::image_entry<E>
+ struct image_identity : public abstract::image_entry<E>
{
protected:
Index: oln/core/abstract/data_storage.hh
--- oln/core/abstract/data_storage.hh (revision 50)
+++ oln/core/abstract/data_storage.hh (working copy)
@@ -30,15 +30,57 @@
# include <mlc/any.hh>
-# include <oln/core/macros.hh>
+# include <oln/core/properties.hh>
+
namespace oln {
+ // fwd decl
namespace abstract {
+ template <typename E> struct data_storage;
+ }
+ // category
+ template <typename E>
+ struct set_category< abstract::data_storage<E> > { typedef category::data_storage ret; };
+
+
+ template <typename type>
+ struct props_of < category::data_storage, type >
+ {
+ typedef mlc::true_type user_defined_;
+
+ mlc_decl_prop(category::data_storage, size_type);
+ mlc_decl_prop(category::data_storage, point_type);
+ mlc_decl_prop(category::data_storage, data_type);
+
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( category::data_storage, "
+ << typeid(type).name() << " ) = {"
+ << " size_type = " << typeid(size_type).name()
+ << " point_type = " << typeid(point_type).name()
+ << " data_type = " << typeid(data_type).name() << " }" << std::endl;
+ }
+
+ };
+
+ mlc_register_prop(category::data_storage, size_type);
+ mlc_register_prop(category::data_storage, point_type);
+ mlc_register_prop(category::data_storage, data_type);
+
+
+ namespace abstract {
+
template <typename E>
struct data_storage : public mlc::any__best_speed<E>
{
+ // typedefs
+
+ typedef oln_type_of(E, size) size_type;
+ typedef oln_type_of(E, point) point_type;
+ typedef oln_type_of(E, data) data_type;
+
// abstract methods
bool has_data() const
@@ -54,12 +96,12 @@
postcondition(! this->has_data());
}
- const oln_size_type(E)& size() const
+ const size_type& size() const
{
return this->exact().impl_size();
}
- void resize(const oln_size_type(E)& s)
+ void resize(const size_type& s)
{
this->exact().impl_resize(s);
}
@@ -71,29 +113,28 @@
return this->exact().impl_npoints();
}
- bool hold(const oln_point_type(E)& p) const
+ bool hold(const point_type& p) const
{
if (! this->has_data())
return false;
return this->exact().impl_hold(p);
}
- const oln_data_type(E) get(const oln_point_type(E)& p) const
+ const data_type get(const point_type& p) const
{
precondition(this->has_data());
precondition(this->hold_large(p));
return this->exact().impl_get(p);
}
- void set(const oln_point_type(E)& p,
- const oln_data_type(E)& v)
+ void set(const point_type& p, const data_type& v)
{
precondition(this->has_data());
precondition(this->hold_large(p));
this->exact().impl_set(p, v);
}
- void set_data(const oln_data_type(E)& v)
+ void set_data(const data_type& v)
{
precondition(this->has_data());
this->exact().impl_set_data(v);
@@ -101,14 +142,14 @@
// polymorphic method with default
- bool hold_large(const oln_point_type(E)& p) const
+ bool hold_large(const point_type& p) const
{
if (! this->has_data())
return false;
return this->exact().impl_hold_large(p);
}
- bool impl_hold_large(const oln_point_type(E)& p) const
+ bool impl_hold_large(const point_type& p) const
{
return this->exact().impl_hold(p);
}
Index: oln/core/abstract/internal/image_impl.hh
--- oln/core/abstract/internal/image_impl.hh (revision 50)
+++ oln/core/abstract/internal/image_impl.hh (working copy)
@@ -30,8 +30,9 @@
# include <mlc/any.hh>
-# include <oln/core/macros.hh>
+# include <oln/core/properties.hh>
+
namespace oln {
namespace abstract {
@@ -45,7 +46,7 @@
// entry point:
template <typename A, typename E>
- struct get_image_impl : public get_image_impl_helper <A, oln_delegated_type(E), E>
+ struct get_image_impl : public get_image_impl_helper <A, oln_type_of(E, delegated), E>
{
};
@@ -67,7 +68,7 @@
template <typename E>
struct image_impl : public mlc::any__best_speed<E>
{
- typedef oln_delegated_type(E) D;
+ typedef oln_type_of(E, delegated) D;
D& delegate() { return this->exact().impl_delegate(); }
const D& delegate() const { return this->exact().impl_delegate(); }
};
Index: oln/core/abstract/op.hh
--- oln/core/abstract/op.hh (revision 50)
+++ oln/core/abstract/op.hh (working copy)
@@ -32,14 +32,28 @@
namespace oln {
+ // fwd decl
namespace abstract {
+ template <typename O, typename E> struct op;
+ }
- template <typename I, typename E>
- struct op : public oln::abstract::image_identity<I, E>
+ // category
+ template <typename O, typename E>
+ struct set_category< abstract::op<O,E> > { typedef category::image ret; };
+
+ // super_type
+ template <typename O, typename E>
+ struct set_super_type< abstract::op<O,E> > { typedef abstract::image_identity<O, E> ret; };
+
+
+ namespace abstract {
+
+ template <typename O, typename E>
+ struct op : public image_identity<O, E>
{
- typedef oln::abstract::image_identity<I, E> super_type;
+ typedef image_identity<O, E> super_type;
- op(I& ref): super_type(ref)
+ op(O& ref) : super_type(ref)
{
this->exact_ptr = (E*)(void*)(this);
}
Index: oln/core/1d/array1d.hh
--- oln/core/1d/array1d.hh (revision 50)
+++ oln/core/1d/array1d.hh (working copy)
@@ -36,13 +36,20 @@
namespace oln {
+ // fwd decl
template <typename T> struct array1d;
- template <typename T>
- struct category_type< array1d<T> > { typedef cat::data_storage ret; };
+ // category
+ template <typename T>
+ struct set_category< array1d<T> > { typedef category::data_storage ret; };
+ // super_type
+ template <typename T>
+ struct set_super_type< array1d<T> > { typedef abstract::data_storage< array1d<T> > ret; };
+
+ // props
template <typename T>
- struct props < cat::data_storage, array1d<T> > // FIXME: add inheritance
+ struct set_props < category::data_storage, array1d<T> > : public props_of<category::data_storage>
{
typedef size1d size_type;
typedef point1d point_type;
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 50)
+++ oln/core/1d/image1d.hh (working copy)
@@ -25,41 +25,44 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLENA_CORE_IMAGE1D_HH
-# define OLENA_CORE_IMAGE1D_HH
+#ifndef OLENA_CORE_1D_IMAGE1D_HH
+# define OLENA_CORE_1D_IMAGE1D_HH
# include <mlc/traits.hh>
# include <oln/core/abstract/image_with_data.hh>
# include <oln/core/1d/array1d.hh>
+# include <oln/core/1d/fwd_piter1d.hh>
+
+
/*! \namespace oln
** \brief oln namespace.
*/
namespace oln {
+
// fwd decl
template <typename T> class image1d;
- // category decl
- template <typename T> struct category_type< image1d<T> > { typedef cat::image ret; };
+ // category
+ template <typename T>
+ struct set_category< image1d<T> > { typedef category::image ret; };
+ // super
+ template <typename T>
+ struct set_super_type < image1d<T> >
+ {
+ typedef abstract::image_with_data< image1d<T> > ret;
+ };
- /*! \class props< abstract::image, image1d<T> >
- **
- ** Properties of common 1D images. Specialization of props<abstraction,type>.
- ** Parameter T is the type of pixel values.
- **
- ** \see image1d<T>, props<category,type>
- */
template <typename T>
- struct props < cat::image, image1d<T> > : public default_props < cat::image >
+ struct set_props < category::image, image1d<T> > : public props_of<category::image>
{
- // intrusive properties
- typedef prop_of<abstract::readwrite_image> image_constness;
- typedef prop_of<abstract::image1d> image_dimension;
+ // intrusive property:
+ typedef is_a<abstract::image1d> image_dimension_type;
typedef mlc::no_type delegated_type;
@@ -67,14 +70,18 @@
typedef point1d point_type;
typedef T value_type;
+ typedef fwd_piter1d piter_type;
+ typedef fwd_piter1d fwd_piter_type;
+
// please note that value_storage_type means data_type
// since image1d is an image_with_data
- typedef mlc_encoding_type(T) value_storage_type;
+ typedef T value_storage_type;
+// typedef mlc_encoding_type(T) value_storage_type;
// please note that value_container_type means
// data_container_type (or value_storage_container_type)
// FIXME: find a better name...
- typedef array1d<value_storage_type> value_container_type;
+ typedef array1d<value_storage_type> storage_type;
// functions
@@ -83,11 +90,13 @@
{
typedef image1d<U> ret;
};
-
};
+
+
+
/*! \class image1d<T>
**
** Common class for 1D images. Pixels values are stored in memory.
@@ -126,4 +135,4 @@
} // end of namespace oln
-#endif // ! OLENA_CORE_IMAGE1D_HH
+#endif // ! OLENA_CORE_1D_IMAGE1D_HH
Index: oln/core/1d/fwd_piter1d.hh
--- oln/core/1d/fwd_piter1d.hh (revision 50)
+++ oln/core/1d/fwd_piter1d.hh (working copy)
@@ -33,22 +33,29 @@
# include <oln/core/abstract/piter.hh>
# include <oln/core/1d/point1d.hh>
# include <oln/core/1d/size1d.hh>
-# include <oln/core/props.hh>
namespace oln {
+
+ // fwd decl
struct fwd_piter1d;
- template <> struct category_type< fwd_piter1d > { typedef cat::piter ret; };
+ // category
+ template <>
+ struct set_category<fwd_piter1d> { typedef category::piter ret; };
+
+ // props
template <>
- struct props < cat::piter, fwd_piter1d > : public default_props< cat::piter >
+ struct set_props < category::piter, fwd_piter1d > : public props_of<category::piter>
{
typedef point1d point_type;
typedef size1d size_type;
};
+
+
struct fwd_piter1d : public abstract::piter< fwd_piter1d >
{
Index: oln/core/1d/point1d.hh
--- oln/core/1d/point1d.hh (revision 50)
+++ oln/core/1d/point1d.hh (working copy)
@@ -32,8 +32,7 @@
# include <oln/core/abstract/point.hh>
# include <oln/core/coord.hh>
-# include <oln/core/cats.hh>
-# include <oln/core/props.hh>
+# include <oln/core/properties.hh>
// FIXME: doc
@@ -41,18 +40,27 @@
namespace oln {
+
struct point1d;
struct dpoint1d;
+ // category
template <>
- struct category_type< point1d > { typedef cat::point ret; };
+ struct set_category< point1d > { typedef category::point ret; };
+ // super_type
template <>
- struct props < cat::point, point1d > : default_props< cat::point >
+ struct set_super_type< point1d > { typedef abstract::point< point1d > ret; };
+
+ // props
+ template <>
+ struct set_props < category::point, point1d > : public props_of<category::point>
{
typedef dpoint1d dpoint_type;
};
+
+
struct point1d : public abstract::point< point1d >
{
point1d()
Index: oln/core/coord.hh
--- oln/core/coord.hh (revision 50)
+++ oln/core/coord.hh (working copy)
@@ -44,6 +44,8 @@
public:
typedef int value_type;
+ static const value_type min_value = INT_MIN;
+ static const value_type max_value = INT_MAX;
coord_t() :
value_(undef_())
@@ -140,13 +142,13 @@
static const coord_t& infty()
{
- static coord_t infty_ = INT_MAX;
+ static coord_t infty_ = max_value;
return infty_;
}
static const coord_t& _infty()
{
- static coord_t _infty_ = INT_MIN + 1;
+ static coord_t _infty_ = min_value + 1;
return _infty_;
}
@@ -158,7 +160,7 @@
static const value_type undef_()
{
- return INT_MIN;
+ return min_value;
}
};
Index: oln/core/2d/array2d.hh
--- oln/core/2d/array2d.hh (revision 50)
+++ oln/core/2d/array2d.hh (working copy)
@@ -35,14 +35,20 @@
namespace oln {
+ // fwd decl
+ template <typename T> struct array2d;
- template <typename T> struct array2d;
+ // category
template <typename T>
- struct category_type< array2d<T> > { typedef cat::data_storage ret; };
+ struct set_category< array2d<T> > { typedef category::data_storage ret; };
-
+ // super_type
+ template <typename T>
+ struct set_super_type< array2d<T> > { typedef abstract::data_storage< array2d<T> > ret; };
+
+ // props
template <typename T>
- struct props < cat::data_storage, array2d<T> > // FIXME: add inheritance
+ struct set_props < category::data_storage, array2d<T> > : public props_of<category::data_storage>
{
typedef size2d size_type;
typedef point2d point_type;
@@ -50,6 +56,7 @@
};
+
template <typename T>
class array2d : public abstract::data_storage< array2d<T> >
{
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 50)
+++ oln/core/2d/image2d.hh (working copy)
@@ -35,6 +35,7 @@
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/fwd_piter2d.hh>
+
/*! \namespace oln
** \brief oln namespace.
*/
@@ -48,28 +49,28 @@
void do_read(abstract::image<I>&, const filename&);
}
+
+
// fwd decl
template <typename T> class image2d;
- // category decl
+ // category
template <typename T>
- struct category_type< image2d<T> > { typedef cat::image ret; };
+ struct set_category< image2d<T> > { typedef category::image ret; };
+ // super
+ template <typename T>
+ struct set_super_type < image2d<T> >
+ {
+ typedef abstract::image_with_data< image2d<T> > ret;
+ };
- /*! \class props< abstract::image, image2d<T> >
- **
- ** Properties of common 2D images. Specialization of props<abstraction,type>.
- ** Parameter T is the type of pixel values.
- **
- ** \see image2d<T>, props<category,type>
- */
template <typename T>
- struct props < cat::image, image2d<T> > : public default_props < cat::image >
+ struct set_props < category::image, image2d<T> > : public props_of<category::image>
{
- // intrusive properties
- typedef prop_of<abstract::readwrite_image> image_constness;
- typedef prop_of<abstract::image2d> image_dimension;
+ // intrusive property:
+ typedef is_a<abstract::image2d> image_dimension_type;
typedef mlc::no_type delegated_type;
@@ -82,12 +83,13 @@
// please note that value_storage_type means data_type
// since image2d is an image_with_data
- typedef mlc_encoding_type(T) value_storage_type;
+ typedef T value_storage_type;
+// typedef mlc_encoding_type(T) value_storage_type;
// please note that value_container_type means
// data_container_type (or value_storage_container_type)
// FIXME: find a better name...
- typedef array2d<value_storage_type> value_container_type;
+ typedef array2d<value_storage_type> storage_type;
// functions
@@ -96,11 +98,12 @@
{
typedef image2d<U> ret;
};
-
};
+
+
/*! \class image2d<T>
**
** Common class for 2D images. Pixels values are stored in memory.
Index: oln/core/2d/fwd_piter2d.hh
--- oln/core/2d/fwd_piter2d.hh (revision 50)
+++ oln/core/2d/fwd_piter2d.hh (working copy)
@@ -33,22 +33,28 @@
# include <oln/core/abstract/piter.hh>
# include <oln/core/2d/point2d.hh>
# include <oln/core/2d/size2d.hh>
-# include <oln/core/props.hh>
namespace oln {
+ // fwd decl
struct fwd_piter2d;
- template <> struct category_type<fwd_piter2d> { typedef cat::piter ret; };
+ // category
+ template <>
+ struct set_category<fwd_piter2d> { typedef category::piter ret; };
+
+ // props
template <>
- struct props < cat::piter, fwd_piter2d > : public default_props<cat::piter>
+ struct set_props < category::piter, fwd_piter2d > : public props_of<category::piter>
{
typedef point2d point_type;
typedef size2d size_type;
};
+
+
struct fwd_piter2d : public abstract::piter< fwd_piter2d >
{
Index: oln/core/2d/point2d.hh
--- oln/core/2d/point2d.hh (revision 50)
+++ oln/core/2d/point2d.hh (working copy)
@@ -30,10 +30,9 @@
# include <iostream>
+# include <oln/core/properties.hh>
# include <oln/core/abstract/point.hh>
# include <oln/core/coord.hh>
-# include <oln/core/cats.hh>
-# include <oln/core/props.hh>
// FIXME: doc!
@@ -43,15 +42,23 @@
struct point2d;
struct dpoint2d;
+ // category
template <>
- struct category_type< point2d > { typedef cat::point ret; };
+ struct set_category< point2d > { typedef category::point ret; };
+ // super_type
template <>
- struct props < cat::point, point2d > : default_props< cat::point >
+ struct set_super_type< point2d > { typedef abstract::point< point2d > ret; };
+
+ // props
+ template <>
+ struct set_props < category::point, point2d > : public props_of<category::point>
{
typedef dpoint2d dpoint_type;
};
+
+
struct point2d : public abstract::point< point2d >
{
point2d()
Index: oln/core/3d/array3d.hh
--- oln/core/3d/array3d.hh (revision 50)
+++ oln/core/3d/array3d.hh (working copy)
@@ -36,13 +36,20 @@
namespace oln {
+ // fwd decl
template <typename T> struct array3d;
+
+ // category
template <typename T>
- struct category_type< array3d<T> > { typedef cat::data_storage ret; };
+ struct set_category< array3d<T> > { typedef category::data_storage ret; };
-
+ // super_type
+ template <typename T>
+ struct set_super_type< array3d<T> > { typedef abstract::data_storage< array3d<T> > ret; };
+
+ // props
template <typename T>
- struct props < cat::data_storage, array3d<T> > // FIXME: add inheritance
+ struct set_props < category::data_storage, array3d<T> > : public props_of<category::data_storage>
{
typedef size3d size_type;
typedef point3d point_type;
Index: oln/core/3d/image3d.hh
--- oln/core/3d/image3d.hh (revision 50)
+++ oln/core/3d/image3d.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLENA_CORE_IMAGE3D_HH
-# define OLENA_CORE_IMAGE3D_HH
+#ifndef OLENA_CORE_3D_IMAGE3D_HH
+# define OLENA_CORE_3D_IMAGE3D_HH
# include <mlc/traits.hh>
@@ -39,28 +39,27 @@
namespace oln {
+
// fwd decl
template <typename T> class image3d;
- // category decl
- template <typename T>
- struct category_type< image3d<T> > { typedef cat::image ret; };
+ // category
+ template <typename T>
+ struct set_category< image3d<T> > { typedef category::image ret; };
+ // super
+ template <typename T>
+ struct set_super_type < image3d<T> >
+ {
+ typedef abstract::image_with_data< image3d<T> > ret;
+ };
- /*! \class props< abstract::image, image3d<T> >
- **
- ** Properties of common 3D images. Specialization of props<abstraction,type>.
- ** Parameter T is the type of pixel values.
- **
- ** \see image3d<T>, props<category,type>
- */
template <typename T>
- struct props < cat::image, image3d<T> > : public default_props < cat::image >
+ struct set_props < category::image, image3d<T> > : public props_of<category::image>
{
- // intrusive properties
- typedef prop_of<abstract::readwrite_image> image_constness;
- typedef prop_of<abstract::image3d> image_dimension;
+ // intrusive property:
+ typedef is_a<abstract::image3d> image_dimension_type;
typedef mlc::no_type delegated_type;
@@ -68,14 +67,18 @@
typedef point3d point_type;
typedef T value_type;
+// typedef fwd_piter3d piter_type;
+// typedef fwd_piter3d fwd_piter_type;
+
// please note that value_storage_type means data_type
// since image3d is an image_with_data
- typedef mlc_encoding_type(T) value_storage_type;
+ typedef T value_storage_type;
+// typedef mlc_encoding_type(T) value_storage_type;
// please note that value_container_type means
// data_container_type (or value_storage_container_type)
// FIXME: find a better name...
- typedef array3d<value_storage_type> value_container_type;
+ typedef array3d<value_storage_type> storage_type;
// functions
@@ -84,7 +87,6 @@
{
typedef image3d<U> ret;
};
-
};
@@ -127,4 +129,4 @@
} // end of namespace oln
-#endif // ! OLENA_CORE_IMAGE3D_HH
+#endif // ! OLENA_CORE_3D_IMAGE3D_HH
Index: oln/core/3d/point3d.hh
--- oln/core/3d/point3d.hh (revision 50)
+++ oln/core/3d/point3d.hh (working copy)
@@ -35,14 +35,21 @@
namespace oln {
- struct dpoint3d; // FIXME: not implemented!!
+
struct point3d;
+ struct dpoint3d;
+ // category
template <>
- struct category_type< point3d > { typedef cat::point ret; };
+ struct set_category< point3d > { typedef category::point ret; };
+ // super_type
template <>
- struct props < cat::point, point3d > : default_props< cat::point >
+ struct set_super_type< point3d > { typedef abstract::point< point3d > ret; };
+
+ // props
+ template <>
+ struct set_props < category::point, point3d > : public props_of<category::point>
{
typedef dpoint3d dpoint_type;
};
Index: oln/core/cats.hh
--- oln/core/cats.hh (revision 50)
+++ oln/core/cats.hh (working copy)
@@ -1,79 +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_CATS_HH
-# define OLENA_CORE_CATS_HH
-
-# include <mlc/types.hh>
-
-
-/*! \macro FIXME:doc
-*/
-
-# define oln_category_type(T) typename oln::category_type<T>::ret
-
-
-
-/*! \namespace oln
-** \brief oln namespace.
-*/
-namespace oln {
-
-
- /*! \class category_type<T>
- **
- ** FIXME: doc
- **
- */
- template <typename T>
- struct category_type
- {
- typedef mlc::undefined_type ret;
- };
-
-
- /*! \namespace oln::cat
- ** \brief oln::cat namespace.
- */
- namespace cat {
-
- struct image;
- struct data_storage;
- struct piter;
- struct point;
- struct size;
- // FIXME:...
-
- } // end of namespace oln::cat
-
-
-} // end of namespace oln
-
-
-
-
-#endif // ! OLENA_CORE_CATS_HH
Index: oln/core/properties.hh
--- oln/core/properties.hh (revision 0)
+++ oln/core/properties.hh (revision 0)
@@ -0,0 +1,95 @@
+// 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_PROPERTIES_HH
+# define OLENA_CORE_PROPERTIES_HH
+
+# include <mlc/properties.hh>
+
+
+/*! \namespace oln
+** \brief oln namespace.
+*/
+namespace oln
+{
+
+ namespace category
+ {
+ struct data_storage;
+ struct image;
+ struct point;
+ struct size;
+ struct piter;
+ struct niter;
+ // FIXME: ...
+ }
+
+ namespace target
+ {
+ struct data_type;
+ struct value_type;
+ struct value_storage_type;
+ struct storage_type;
+ struct point_type;
+ struct dpoint_type;
+ struct fwd_piter_type;
+ struct iter_type;
+ struct delegated_type;
+ struct size_type;
+
+ struct image_constness_type;
+ struct image_dimension_type;
+ // FIXME: ...
+ }
+
+ mlc_equip_namespace_for_properties();
+
+
+ // FIXME: change name?
+ template <template <typename> class abstraction>
+ struct is_a // abstraction
+ {
+ template <typename E>
+ struct instantiated_with // E
+ {
+ typedef abstraction<E> ret;
+ };
+ };
+
+
+} // end of namespace oln
+
+
+
+/// macro to retrieve a type (TARGET) from a class (oln::TYPE)
+
+# define oln_type_of(TYPE, TARGET) mlc_type_of(oln, TYPE, TARGET)
+# define oln_type_of_(TYPE, TARGET) mlc_type_of_(oln, TYPE, TARGET)
+
+
+
+#endif // ! OLENA_CORE_PROPERTIES_HH
1
0
dsl... (connection refused!)
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
* mlc/types.hh (default_type): New.
* mlc/properties.hh: New.
1
0
Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* configure.ac: Add test suite `main' for Integre.
configure.ac | 3 ++-
1 files changed, 2 insertions(+), 1 deletion(-)
Index: configure.ac
--- configure.ac (revision 48)
+++ configure.ac (working copy)
@@ -164,7 +164,7 @@
metalic/tests/check/defs],
[dnl Configuration for the testsuite
- MLC_TESTS_SUBDIRS=""
+ MLC_TESTS_SUBDIRS="main"
AC_CACHE_CHECK([for selection of tests],
[mlc_cv_tests_selection],
@@ -177,6 +177,7 @@
# MLC_TESTS defined in oln-local.m4
+ MLC_TESTS([main])
MLC_TESTS([sanity])
AC_SUBST([MLC_TESTS_SUBDIRS])
3
2
Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* mlc/is_a.hh: New. Test inheritance between two classes.
* tests/main/tests/is_a1: New. Add test for `is_a'.
* tests/main: New. Add new test suite `main'.
* tests/main/tests: New.
* tests/main/Makefile.am: New.
mlc/is_a.hh | 193 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/main/Makefile.am | 3
tests/main/tests/is_a1 | 33 ++++++++
3 files changed, 229 insertions(+)
Index: tests/main/tests/is_a1
--- tests/main/tests/is_a1 (revision 0)
+++ tests/main/tests/is_a1 (revision 0)
@@ -0,0 +1,33 @@
+#include <mlc/bool.hh>
+#include <mlc/is_a.hh>
+
+using namespace mlc;
+
+class A {};
+class B : public A {};
+class C : public B {};
+
+template <class E> class T_A {};
+template <class T> class T_B : public T_A<T> {};
+
+template <class T>
+void foo()
+{
+ is_false<mlc_is_a(int, bool)::ret>::ensure();
+ is_true<mlc_is_a(B, A)::ret>::ensure();
+ is_true<mlc_is_a(C, A)::ret>::ensure();
+ is_false<mlc_is_a(A, B)::ret>::ensure();
+}
+
+int main()
+{
+ is_false<mlc_is_a_(int, bool)::ret>::ensure();
+ is_true<mlc_is_a_(B, A)::ret>::ensure();
+ is_true<mlc_is_a_(C, A)::ret>::ensure();
+ is_false<mlc_is_a_(A, B)::ret>::ensure();
+
+ is_true<mlc_is_a_(T_B<int>, T_A)::ret>::ensure();
+ is_false<mlc_is_a_(T_A<int>, T_B)::ret>::ensure();
+
+ foo<int>();
+}
Index: tests/main/Makefile.am
--- tests/main/Makefile.am (revision 0)
+++ tests/main/Makefile.am (revision 0)
@@ -0,0 +1,3 @@
+## Process this file with Automake to produce Makefile.in -*- Makefile -*-
+
+include ../check/Makefile.runtests
Index: mlc/is_a.hh
--- mlc/is_a.hh (revision 0)
+++ mlc/is_a.hh (revision 0)
@@ -0,0 +1,193 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 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 METALIC_IS_A_HH
+# define METALIC_IS_A_HH
+
+# include <mlc/any.hh>
+# include <mlc/bool.hh>
+
+// private macro so do _not_ use it
+# define is_a__check_result_ \
+sizeof(helper<T ,U >::check( (T *) helper<T,U >::makeT() )) \
+== sizeof(mlc::internal::yes_)
+
+
+namespace mlc
+{
+
+ namespace internal
+ {
+
+ //
+ // wrap
+ //
+ // FIXME: This type is a workaround for g++-2.95 problem with implicit
+ // typename in <foo<T>::ret::dim>,
+ // write <wrap<typename foo<T>::ret>::dim instead.
+ //
+
+ template <class T> struct wrap : public T {};
+
+ } // internal
+
+ /*-----.
+ | is_a |
+ `-----*/
+
+ // FIXME: form is a namespace to avoid g++-3.2 bug with template function
+ // overloading in class.
+
+ namespace form
+ {
+ enum {
+ class_ = 1,
+ template_l_class_g_class_ = 2,
+ template_l_class_class_g_class_ = 3
+ // template_l_unsigned_class_g_class_ = 4
+ // ...
+ };
+
+ template<unsigned id>
+ struct desc
+ { char dummy[id]; };
+
+ template<class T>
+ static desc< class_ > get();
+
+ template<template<class> class T>
+ static desc< template_l_class_g_class_ > get();
+
+ template<template<class,class> class T>
+ static desc< template_l_class_class_g_class_ > get();
+
+ // template<template<unsigned,class> class T>
+ // static desc < template_l_unsigned_class_g_class_ > get();
+
+ // ...
+ }
+
+ namespace internal
+ {
+
+ typedef char yes_;
+ struct no_ { char dummy[2]; };
+
+
+ // dev note : below, is_a_<T,id> is a better factorization
+ // but g++ 2.95.4 has some trouble with it
+
+ template<unsigned id>
+ struct is_a_;
+
+ // _class_
+
+
+ template<>
+ struct is_a_< form::class_ >
+ {
+ typedef is_a_< form::class_ > self;
+
+ template<class T, class U>
+ struct helper
+ {
+ static yes_ check(U*);
+ static no_ check(...);
+ static T* makeT();
+ };
+
+ template<class T, class U>
+ struct check
+ : public mlc::returns_bool_<( is_a__check_result_ )>
+ {
+ };
+ };
+
+ // template_l_class_g_class_
+
+ template<>
+ struct is_a_< form::template_l_class_g_class_ >
+ {
+ typedef is_a_< form::template_l_class_g_class_ > self;
+
+ template<class T, template<class> class U>
+ struct helper
+ {
+ template<class V>
+ static yes_ check(U<V>*);
+ static no_ check(...);
+ static T* makeT();
+ };
+
+ template<class T, template<class> class U>
+ struct check
+ : public mlc::returns_bool_<( is_a__check_result_ )>
+ {
+ };
+ };
+
+ // templatee_l_class_class_g_class_
+
+ template<>
+ struct is_a_< form::template_l_class_class_g_class_ >
+ {
+ typedef is_a_< form::template_l_class_class_g_class_ > self;
+
+ template<class T, template<class,class> class U>
+ struct helper
+ {
+ template<class V, class W>
+ static yes_ check(U<V,W>*);
+ static no_ check(...);
+ static T* makeT();
+ };
+
+ template<class T, template<class,class> class U>
+ struct check
+ : public mlc::returns_bool_<( is_a__check_result_ )>
+ {};
+ };
+
+ } // end of internal
+
+} // end of mlc
+
+// private macros: do _not_ use them
+# define is_a__2nd_is_meta(T,U) mlc::internal::is_a_< id_of_typeform(U) >::check<T, U >
+
+// client macros
+
+# define id_of_typeform(T) sizeof(mlc::form::get<T >())
+
+template <class T>
+struct id_ { typedef T ret; };
+
+// FIXME: can we get rid of mlc::wrap ?
+# define mlc_is_a(T, U) mlc::internal::wrap<typename mlc::internal::is_a_< id_of_typeform(U) >::check<T, U > >
+# define mlc_is_a_(T, U) mlc::internal::wrap<mlc::internal::is_a_< id_of_typeform(U) >::check<T, U > >
+
+#endif // ndef METALIC_IS_A_HH
1
0