https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add progressive histogram and median in milena.
* tests/median.cc: New.
* mln/value/vset.hh: Rename as...
* mln/value/set.hh: ... this new file.
* tests/vset.cc: Update.
* tests/histo.cc: New.
* mln/histo: New.
* mln/core/concept/value_set.hh: Update.
* mln/core/concept/doc/value_set.hh: Update.
* mln/value/histo.hh: New.
* mln/value/median.hh: New.
* mln/value/int_u.hh: Update.
mln/core/concept/doc/value_set.hh | 4
mln/core/concept/value_set.hh | 3
mln/value/histo.hh | 206 ++++++++++++++++++++++++++++
mln/value/int_u.hh | 11 +
mln/value/median.hh | 270 ++++++++++++++++++++++++++++++++++++++
mln/value/set.hh | 61 +++++++-
tests/histo.cc | 67 +++++++++
tests/median.cc | 184 +++++++++++++++++++++++++
tests/vset.cc | 6
9 files changed, 798 insertions(+), 14 deletions(-)
Index: tests/median.cc
--- tests/median.cc (revision 0)
+++ tests/median.cc (revision 0)
@@ -0,0 +1,184 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file tests/median.cc
+ *
+ * \brief Tests on mln::value::median<S>.
+ */
+
+#include <mln/value/int_u.hh>
+#include <mln/value/median.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using namespace mln::value;
+
+ typedef set_<int_u8> S;
+
+ median<S> m(S::the());
+
+
+ {
+
+ unsigned vals[] = { 42, 69, 51, 12, 51, 12, 42 };
+ unsigned n = sizeof(vals)/sizeof(unsigned);
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "taking " << vals[i] << ':' << std::endl;
+ m.take(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ for (int i = int(n) - 1; i >= 0; --i)
+ {
+ std::cout << "untaking " << vals[i] << ':' << std::endl;
+ m.untake(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ }
+
+
+ {
+
+ unsigned vals[] = { 42, 69, 51, 12, 51, 12, 42 };
+ unsigned n = sizeof(vals)/sizeof(unsigned);
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "taking " << vals[i] << ':' << std::endl;
+ m.take(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "untaking " << vals[i] << ':' << std::endl;
+ m.untake(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ }
+
+
+
+ {
+
+ unsigned vals[] = { 42, 42, 69, 69, 51, 51, 12, 12, 51, 51, 12, 12, 42, 42 };
+ unsigned n = sizeof(vals)/sizeof(unsigned);
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "taking " << vals[i] << ':' << std::endl;
+ m.take(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ for (int i = int(n) - 1; i >= 0; --i)
+ {
+ std::cout << "untaking " << vals[i] << ':' << std::endl;
+ m.untake(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ }
+
+
+ {
+
+ unsigned vals[] = { 42, 42, 69, 69, 51, 51, 12, 12, 51, 51, 12, 12, 42, 42 };
+ unsigned n = sizeof(vals)/sizeof(unsigned);
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "taking " << vals[i] << ':' << std::endl;
+ m.take(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "untaking " << vals[i] << ':' << std::endl;
+ m.untake(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ }
+
+
+
+
+ {
+
+ unsigned vals[] = { 42, 69, 51, 12, 51, 12, 42, 69, 51, 12, 51, 12, 42 };
+ unsigned n = sizeof(vals)/sizeof(unsigned);
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "taking " << vals[i] << ':' << std::endl;
+ m.take(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ for (int i = int(n) - 1; i >= 0; --i)
+ {
+ std::cout << "untaking " << vals[i] << ':' << std::endl;
+ m.untake(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ }
+
+
+ {
+
+ unsigned vals[] = { 42, 69, 51, 12, 51, 12, 42, 69, 51, 12, 51, 12, 42 };
+ unsigned n = sizeof(vals)/sizeof(unsigned);
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "taking " << vals[i] << ':' << std::endl;
+ m.take(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ std::cout << "untaking " << vals[i] << ':' << std::endl;
+ m.untake(vals[i]);
+ std::cout << m << std::endl;
+ }
+
+ }
+
+
+
+}
Index: tests/vset.cc
--- tests/vset.cc (revision 1002)
+++ tests/vset.cc (working copy)
@@ -27,11 +27,11 @@
/*! \file tests/vset.cc
*
- * \brief Tests on mln::vset.
+ * \brief Tests on mln::value::set_<T>.
*/
#include <mln/value/int_u.hh>
-#include <mln/value/vset.hh>
+#include <mln/value/set.hh>
@@ -43,7 +43,7 @@
// typedef value::int_u8 T;
// typedef short T;
- typedef value::vset_<T> S;
+ typedef value::set_<T> S;
S s;
{
Index: tests/histo.cc
--- tests/histo.cc (revision 0)
+++ tests/histo.cc (revision 0)
@@ -0,0 +1,67 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file tests/histo.cc
+ *
+ * \brief Tests on mln::value::histo<S>.
+ */
+
+#include <mln/value/int_u.hh>
+#include <mln/value/set.hh>
+#include <mln/value/histo.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using namespace mln::value;
+
+
+ histo_on_type<bool> h;
+
+ for (unsigned i = 0; i < 5; ++i)
+ h.take(false);
+ for (unsigned i = 0; i < 2; ++i)
+ h.take(true);
+ h.untake(true);
+
+ std::cout << h << std::endl;
+ std::cout << h[0] * 10 + h[1] << std::endl;
+ std::cout << h(false) * 10 + h(true) << std::endl;
+
+ h.clear();
+ std::cout << h << std::endl;
+
+
+ // ...
+
+
+ typedef value::set_<int_u8> S;
+ histo_on_set<S> h_u8(S::the());
+ std::cout << h_u8 << std::endl;
+}
Index: mln/core/concept/value_set.hh
--- mln/core/concept/value_set.hh (revision 1002)
+++ mln/core/concept/value_set.hh (working copy)
@@ -53,7 +53,10 @@
typedef bkd_viter;
bool has(const value& v) const;
+
value operator[](std::size_t i) const;
+ std::size_t index_of(const value& v) const;
+
std::size_t nvalues() const;
*/
Index: mln/core/concept/doc/value_set.hh
--- mln/core/concept/doc/value_set.hh (revision 1002)
+++ mln/core/concept/doc/value_set.hh (working copy)
@@ -72,6 +72,10 @@
/*! \brief Give the \p i-th value of this set.
*/
value operator[](std::size_t i) const;
+
+ /*! \brief Give the index of value \p v in this set.
+ */
+ std::size_t index_of(const value& v) const;
};
} // end of namespace mln::doc
Index: mln/value/histo.hh
--- mln/value/histo.hh (revision 0)
+++ mln/value/histo.hh (revision 0)
@@ -0,0 +1,206 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_VALUE_HISTO_HH
+# define MLN_VALUE_HISTO_HH
+
+/*! \file mln/value/histo.hh
+ *
+ * \brief Define a couple of generic histogram classes.
+ */
+
+# include <vector>
+# include <algorithm>
+
+# include <mln/core/concept/value_set.hh>
+# include <mln/value/set.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /*! Generic histogram class over a value set with type \c S.
+ */
+ template <typename S>
+ struct histo_on_set
+ {
+ histo_on_set(const Value_Set<S>& s);
+
+ typedef mln_value(S) value;
+
+ void take(const value& v);
+ void untake(const value& v);
+ void clear();
+
+ std::size_t operator()(const value& v) const;
+ std::size_t operator[](std::size_t i) const;
+ std::size_t nvalues() const;
+ std::size_t sum() const;
+
+ const std::vector<std::size_t>& vec() const;
+
+ const S& vset() const;
+
+ protected:
+
+ const S& s_;
+ std::vector<std::size_t> h_;
+ std::size_t sum_;
+ };
+
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const histo_on_set<S>& h);
+
+
+
+
+ /*! Generic histogram class over the set of values of type \c T.
+ */
+ template <typename T>
+ struct histo_on_type : public histo_on_set< set_<T> >
+ {
+ histo_on_type();
+ };
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // histo_on_set<S>
+
+ template <typename S>
+ histo_on_set<S>::histo_on_set(const Value_Set<S>& s)
+ : s_(exact(s)),
+ h_(exact(s).nvalues(), 0),
+ sum_(0)
+ {
+ }
+
+ template <typename S>
+ void
+ histo_on_set<S>::take(const value& v)
+ {
+ ++h_[s_.index_of(v)];
+ ++sum_;
+ }
+
+ template <typename S>
+ void
+ histo_on_set<S>::untake(const value& v)
+ {
+ mln_precondition(h_[s_.index_of(v)] > 0);
+ mln_precondition(sum_ > 0);
+ --h_[s_.index_of(v)];
+ --sum_;
+ }
+
+ template <typename S>
+ void
+ histo_on_set<S>::clear()
+ {
+ std::fill(h_.begin(), h_.end(), 0);
+ }
+
+ template <typename S>
+ std::size_t
+ histo_on_set<S>::operator()(const value& v) const
+ {
+ return h_[s_.index_of(v)];
+ }
+
+ template <typename S>
+ std::size_t
+ histo_on_set<S>::operator[](std::size_t i) const
+ {
+ mln_precondition(i < s_.nvalues());
+ return h_[i];
+ }
+
+ template <typename S>
+ std::size_t
+ histo_on_set<S>::nvalues() const
+ {
+ return s_.nvalues();
+ }
+
+ template <typename S>
+ std::size_t
+ histo_on_set<S>::sum() const
+ {
+ return sum_;
+ }
+
+ template <typename S>
+ const std::vector<std::size_t>&
+ histo_on_set<S>::vec() const
+ {
+ return h_;
+ }
+
+ template <typename S>
+ const S&
+ histo_on_set<S>::vset() const
+ {
+ return s_;
+ }
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const histo_on_set<S>& h)
+ {
+ mln_viter(S) v(h.vset());
+ for_all(v)
+ ostr << v << ':' << h(v) << ' ';
+ ostr << std::endl;
+ return ostr;
+ }
+
+
+ // histo_on_type<T>
+
+ template <typename T>
+ histo_on_type<T>::histo_on_type()
+ : histo_on_set< set_<T> >(set_<T>::the())
+ {
+ }
+
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_HISTO_HH
Index: mln/value/set.hh
--- mln/value/set.hh (revision 1002)
+++ mln/value/set.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_VALUE_VSET_HH
-# define MLN_VALUE_VSET_HH
+#ifndef MLN_VALUE_SET_HH
+# define MLN_VALUE_SET_HH
/*! \file mln/value/vset.hh
*
@@ -48,37 +48,55 @@
template <typename S> struct bkd_viter_;
- /*! Class that defines the properties of the value type \c T.
+ /*! Class that defines the set of values of type \c T.
+ *
+ * This is an exhaustive value set over \c T.
*/
template <typename T>
- struct vset_ : public Value_Set< vset_<T> >
+ struct set_ : public Value_Set< set_<T> >
{
+ /// Value associated type.
typedef T value;
- typedef fwd_viter_< vset_<T> > fwd_viter;
- typedef bkd_viter_< vset_<T> > bkd_viter;
+ /// Forward Viter associated type.
+ typedef fwd_viter_< set_<T> > fwd_viter;
+
+ /// Backward Viter associated type.
+ typedef bkd_viter_< set_<T> > bkd_viter;
+
+ /// Viter associated type.
typedef fwd_viter viter;
+ /// Test if \p v belongs to this set: always true!
bool has(const T& v) const;
+ /// Give the \p i-th value.
T operator[](std::size_t i) const;
+ /// Give the index of value \p v in this set.
+ std::size_t index_of(const T& v) const;
+
+ /// Give the number of values.
std::size_t nvalues() const;
+
+ /// Return a singleton.
+ static const set_<T>& the();
};
+
# ifndef MLN_INCLUDE_ONLY
template <typename T>
bool
- vset_<T>::has(const T& v) const
+ set_<T>::has(const T& v) const
{
return true;
}
template <typename T>
T
- vset_<T>::operator[](std::size_t i) const
+ set_<T>::operator[](std::size_t i) const
{
mln_precondition(i < nvalues());
return mln_min(T) + i;
@@ -86,19 +104,42 @@
template <typename T>
std::size_t
- vset_<T>::nvalues() const
+ set_<T>::index_of(const T& v) const
+ {
+ return v - mln_min(T);
+ }
+
+ template <typename T>
+ std::size_t
+ set_<T>::nvalues() const
{
return mln_card(T);
}
+ template <typename T>
+ const set_<T>&
+ set_<T>::the()
+ {
+ static set_<T> the_;
+ return the_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::value
+
+
+ typedef value::set_<bool> Booleans;
+ typedef value::set_<int> integers();
+ typedef value::set_<unsigned> naturals();
+
+
+
} // end of namespace mln
# include <mln/value/viter.hh>
-#endif // ! MLN_VALUE_VSET_HH
+#endif // ! MLN_VALUE_SET_HH
Index: mln/value/median.hh
--- mln/value/median.hh (revision 0)
+++ mln/value/median.hh (revision 0)
@@ -0,0 +1,270 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_VALUE_MEDIAN_HH
+# define MLN_VALUE_MEDIAN_HH
+
+/*! \file mln/value/median.hh
+ *
+ * \brief Define FIXME
+ */
+
+# include <mln/value/histo.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /*! Generic median function based on histogram over a value set
+ * with type \c S.
+ */
+ template <typename S>
+ struct median
+ {
+ typedef mln_value(S) value;
+
+ median(const Value_Set<S>& s);
+
+ void take(const value& v);
+ void untake(const value& v);
+ void clear();
+
+ operator value() const;
+ value to_value() const;
+
+ // FIXME: remove
+ void debug__() const
+ {
+ std::cout << " i = " << i_
+ << " v = " << v_
+ << " s = " << sum_minus_ << " ; " << h_[i_] << " ; " << sum_plus_ << " = " << h_.sum()
+ << std::endl;
+ }
+
+ protected:
+
+ histo_on_set<S> h_;
+ const S& s_; // derived from h_
+
+ std::size_t sum_minus_, sum_plus_;
+
+ std::size_t i_; // the median index
+ value v_; // the median value
+
+ // Auxiliary methods
+ void go_minus_();
+ void go_plus_();
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename S>
+ median<S>::median(const Value_Set<S>& s)
+ : h_(s),
+ s_(h_.vset())
+ {
+ clear();
+ }
+
+
+ template <typename S>
+ void
+ median<S>::take(const value& v)
+ {
+ // update h_
+ h_.take(v);
+
+ // particular case:
+ // current state was initialization
+ if (h_[i_] = 0)
+ {
+ // std::cout << "init!" << std::endl;
+ i_ = s_.index_of(v);
+ v_ = v;
+ return;
+ }
+
+ // particular case:
+ // the median does not change
+ if (v = v_)
+ {
+ // std::cout << "no change!" << std::endl;
+ return;
+ }
+
+ // general case:
+
+ if (v < v_)
+ {
+ ++sum_minus_;
+ if (2 * sum_minus_ > h_.sum())
+ go_minus_();
+ }
+ else
+ // v > v_
+ {
+ ++sum_plus_;
+ if (2 * sum_plus_ > h_.sum())
+ go_plus_();
+ }
+ }
+
+
+ template <typename S>
+ void
+ median<S>::untake(const value& v)
+ {
+ mln_precondition(h_(v) != 0);
+
+ // update h_
+ h_.untake(v);
+
+ // particular case:
+ // the only value has been removed
+ if (h_.sum() = 0)
+ {
+ clear();
+ return;
+ }
+
+ // general case:
+ if (v < v_)
+ {
+ --sum_minus_;
+ if (2 * sum_plus_ > h_.sum())
+ go_plus_();
+ }
+ else if (v > v_)
+ {
+ --sum_plus_;
+ if (2 * sum_minus_ > h_.sum())
+ go_minus_();
+ }
+ else
+ // v = v_
+ {
+ if (h_[i_] = 0)
+ {
+ // go to the heaviest side
+ if (sum_plus_ > sum_minus_)
+ go_plus_();
+ else
+ go_minus_(); // default when both sides are balanced
+ }
+ else
+ {
+ if (2 * sum_plus_ > h_.sum())
+ go_plus_();
+ else if (2 * sum_minus_ > h_.sum())
+ go_minus_();
+ // else no change
+ }
+ }
+ }
+
+
+ template <typename S>
+ void
+ median<S>::go_minus_()
+ {
+ do
+ {
+ sum_plus_ += h_[i_];
+ do
+ --i_;
+ while (h_[i_] = 0);
+ sum_minus_ -= h_[i_];
+ }
+ while (2 * sum_minus_ > h_.sum());
+ v_ = s_[i_];
+ }
+
+
+ template <typename S>
+ void
+ median<S>::go_plus_()
+ {
+ do
+ {
+ sum_minus_ += h_[i_];
+ do
+ ++i_;
+ while (h_[i_] = 0);
+ sum_plus_ -= h_[i_];
+ }
+ while (2 * sum_plus_ > h_.sum());
+ v_ = s_[i_];
+ }
+
+
+ template <typename S>
+ void
+ median<S>::clear()
+ {
+ h_.clear();
+ sum_minus_ = 0;
+ sum_plus_ = 0;
+ i_ = (mln_max(value) - mln_min(value)) / 2;
+ v_ = s_[i_];
+ }
+
+ template <typename S>
+ median<S>::operator typename median<S>::value () const
+ {
+ return v_;
+ }
+
+ template <typename S>
+ typename median<S>::value
+ median<S>::to_value() const
+ {
+ return v_;
+ }
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const median<S>& m)
+ {
+ m.debug__();
+ return ostr << m.to_value();
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_MEDIAN_HH
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1002)
+++ mln/value/int_u.hh (working copy)
@@ -86,8 +86,17 @@
};
+ // Fwd decl.
+ template <typename T> struct vset_;
+
+
/// Alias for unsigned 8bit integers.
- typedef value::int_u_<8> int_u8;
+ typedef int_u_<8> int_u8;
+
+ /// Alias for the set of unsigned 8bit integers.
+ typedef vset_<int_u8> int_u8_set;
+
+
/*! \brief Print an int_u8 \p i into the output stream \p ostr.
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add materials to handle values in milena.
* tests/vset.cc: New.
* tests/int_u8.cc: New.
* TODO: New.
* mln/core/concept/value_set.hh: New.
* mln/core/concept/viter.hh: New.
* mln/core/concept/doc/value_set.hh: New.
* mln/core/concept/doc/viter.hh: New.
* mln/core/concept/value.hh: New.
* mln/value/vset.hh: New.
* mln/value/viter.hh: New.
* mln/value/int_u.hh: New.
* mln/value/internal: New.
* mln/value/internal/value_like.hh: New.
* doc/Doxyfile.in (PREDEFINED): Add mln_viter et al.
* mln/core/macros.hh: Sort.
(mln_enc, mln_equiv): New.
* mln/value/props.hh (mln_card, card): New.
TODO | 25 ++++
doc/Doxyfile.in | 3
mln/core/concept/doc/value_set.hh | 79 +++++++++++++
mln/core/concept/doc/viter.hh | 58 +++++++++
mln/core/concept/value.hh | 73 ++++++++++++
mln/core/concept/value_set.hh | 88 ++++++++++++++
mln/core/concept/viter.hh | 104 +++++++++++++++++
mln/core/macros.hh | 97 ++++++++++++----
mln/value/int_u.hh | 130 ++++++++++++++++++++++
mln/value/internal/value_like.hh | 135 ++++++++++++++++++++++
mln/value/props.hh | 14 ++
mln/value/viter.hh | 224 ++++++++++++++++++++++++++++++++++++++
mln/value/vset.hh | 104 +++++++++++++++++
tests/int_u8.cc | 49 ++++++++
tests/vset.cc | 63 ++++++++++
15 files changed, 1220 insertions(+), 26 deletions(-)
Index: tests/vset.cc
--- tests/vset.cc (revision 0)
+++ tests/vset.cc (revision 0)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file tests/vset.cc
+ *
+ * \brief Tests on mln::vset.
+ */
+
+#include <mln/value/int_u.hh>
+#include <mln/value/vset.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef bool T;
+ // typedef value::int_u8 T;
+ // typedef short T;
+
+ typedef value::vset_<T> S;
+ S s;
+
+ {
+ S::fwd_viter v(s);
+ for_all(v)
+ std::cout << v << ' ';
+ std::cout << std::endl;
+ }
+
+ {
+ S::bkd_viter v(s);
+ for_all(v)
+ std::cout << v << ' ';
+ std::cout << std::endl;
+ }
+
+}
Index: tests/int_u8.cc
--- tests/int_u8.cc (revision 0)
+++ tests/int_u8.cc (revision 0)
@@ -0,0 +1,49 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file tests/int_u8.cc
+ *
+ * \brief Tests on mln::value::int_u8.
+ */
+
+#include <mln/value/int_u.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ int_u8 i = 3;
+ i = 2;
+ mln_assertion(i = 2);
+ mln_assertion(i != 3);
+
+ mln_assertion(-i = -2);
+ mln_assertion(-3 * i = -6);
+}
Index: doc/Doxyfile.in
--- doc/Doxyfile.in (revision 1001)
+++ doc/Doxyfile.in (working copy)
@@ -1051,6 +1051,9 @@
"mln_niter(T)=typename T::niter" \
"mln_fwd_niter(T)=typename T::fwd_niter" \
"mln_bkd_niter(T)=typename T::bkd_niter" \
+ "mln_viter(T)=typename T::viter" \
+ "mln_fwd_viter(T)=typename T::fwd_viter" \
+ "mln_bkd_viter(T)=typename T::bkd_viter" \
"mln_value(T)=typename T::value" \
"mln_rvalue(T)=typename T::rvalue" \
"mln_lvalue(T)=typename T::lvalue" \
Index: TODO
--- TODO (revision 0)
+++ TODO (revision 0)
@@ -0,0 +1,25 @@
+ -*- outline -*-
+
+
+* compilation
+
+g++-4.1 -I.. int_u8.cc -Wall -Wextra -Wconversion
+
+
+* value
+
+Value_Set
+props { ... }
+notion of lowq
++ values() : vset dans Image ?
+
+
+* function
+
+Function_p2v
+Function_p2b
+Function_v2w
+
+F apply(I, F)
+O transform(I, F)
+
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1001)
+++ mln/core/macros.hh (working copy)
@@ -33,63 +33,108 @@
* \brief Definition of the set of milena macros.
*/
-/// Shortcut to access the point type associated to T.
-# define mln_point(T) typename T::point
-/// Shortcut to access the dpoint type associated to T.
-# define mln_dpoint(T) typename T::dpoint
+// b
-/// Shortcut to access the psite type associated to T.
-# define mln_psite(T) typename T::psite
+/// Shortcut to access the bkd_niter type associated to T.
+# define mln_bkd_niter(T) typename T::bkd_niter
-/// Shortcut to access the pset type associated to T.
-# define mln_pset(T) typename T::pset
+/// Shortcut to access the bkd_piter type associated to T.
+# define mln_bkd_piter(T) typename T::bkd_piter
+
+/// Shortcut to access the bkd_qiter type associated to T.
+# define mln_bkd_qiter(T) typename T::bkd_qiter
+
+/// Shortcut to access the bkd_viter type associated to T.
+# define mln_bkd_viter(T) typename T::bkd_viter
/// Shortcut to access the box type associated to T.
# define mln_box(T) typename T::box
+
+// c
+
/// Shortcut to access the coord type associated to T.
# define mln_coord(T) typename T::coord
-/// Shortcut to access the piter type associated to T.
-# define mln_piter(T) typename T::piter
+// d
+
+/// Shortcut to access the dpoint type associated to T.
+# define mln_dpoint(T) typename T::dpoint
+
+
+// e
+
+/// Shortcut to access the encoding type associated to T.
+# define mln_enc(T) typename T::enc
+
+/// Shortcut to access the equivalent type associated to T.
+# define mln_equiv(T) typename T::equiv
+
+
+// f
+
+/// Shortcut to access the fwd_niter type associated to T.
+# define mln_fwd_niter(T) typename T::fwd_niter
/// Shortcut to access the fwd_piter type associated to T.
# define mln_fwd_piter(T) typename T::fwd_piter
-/// Shortcut to access the bkd_piter type associated to T.
-# define mln_bkd_piter(T) typename T::bkd_piter
+/// Shortcut to access the fwd_qiter type associated to T.
+# define mln_fwd_qiter(T) typename T::fwd_qiter
+
+/// Shortcut to access the fwd_viter type associated to T.
+# define mln_fwd_viter(T) typename T::fwd_viter
+
+// l
+
+
+/// Shortcut to access the lvalue type associated to T.
+# define mln_lvalue(T) typename T::lvalue
+
+
+// p
+
+/// Shortcut to access the piter type associated to T.
+# define mln_piter(T) typename T::piter
+
+/// Shortcut to access the pset type associated to T.
+# define mln_pset(T) typename T::pset
+
+/// Shortcut to access the psite type associated to T.
+# define mln_psite(T) typename T::psite
+
+/// Shortcut to access the point type associated to T.
+# define mln_point(T) typename T::point
+
+
+// q
/// Shortcut to access the qiter type associated to T.
# define mln_qiter(T) typename T::qiter
-/// Shortcut to access the fwd_qiter type associated to T.
-# define mln_fwd_qiter(T) typename T::fwd_qiter
-
-/// Shortcut to access the bkd_qiter type associated to T.
-# define mln_bkd_qiter(T) typename T::bkd_qiter
+// n
/// Shortcut to access the niter type associated to T.
# define mln_niter(T) typename T::niter
-/// Shortcut to access the fwd_niter type associated to T.
-# define mln_fwd_niter(T) typename T::fwd_niter
-/// Shortcut to access the bkd_niter type associated to T.
-# define mln_bkd_niter(T) typename T::bkd_niter
+// r
+
+/// Shortcut to access the rvalue type associated to T.
+# define mln_rvalue(T) typename T::rvalue
+// v
+
/// Shortcut to access the value type associated to T.
# define mln_value(T) typename T::value
-/// Shortcut to access the rvalue type associated to T.
-# define mln_rvalue(T) typename T::rvalue
-
-/// Shortcut to access the lvalue type associated to T.
-# define mln_lvalue(T) typename T::lvalue
+/// Shortcut to access the viter type associated to T.
+# define mln_viter(T) typename T::viter
Index: mln/core/concept/value_set.hh
--- mln/core/concept/value_set.hh (revision 0)
+++ mln/core/concept/value_set.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_CORE_CONCEPT_VALUE_SET_HH
+# define MLN_CORE_CONCEPT_VALUE_SET_HH
+
+/*! \file mln/core/concept/value_set.hh
+ * \brief Definition of the concept of mln::Value_Set.
+ */
+
+# include <mln/core/concept/viter.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Base class for implementation classes of sets of values.
+ *
+ * \see mln::doc::Value_Set for a complete documentation of this
+ * class contents.
+ */
+ template <typename E>
+ struct Value_Set : public Object<E>
+ {
+ /*
+ typedef value;
+ typedef viter;
+ typedef fwd_viter;
+ typedef bkd_viter;
+
+ bool has(const value& v) const;
+ value operator[](std::size_t i) const;
+ std::size_t nvalues() const;
+ */
+
+ protected:
+ Value_Set();
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Value_Set<E>::Value_Set()
+ {
+ typedef mln_value(E) value;
+ typedef mln_viter(E) viter;
+ typedef mln_fwd_viter(E) fwd_viter;
+ typedef mln_bkd_viter(E) bkd_viter;
+
+ bool (E::*m1)(const value&) const = & E::has;
+ m1 = 0;
+ value (E::*m2)(std::size_t) const = & E::operator[];
+ m2 = 0;
+ std::size_t (E::*m3)() const = & E::nvalues;
+ m3 = 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_VALUE_SET_HH
Index: mln/core/concept/viter.hh
--- mln/core/concept/viter.hh (revision 0)
+++ mln/core/concept/viter.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_CORE_CONCEPT_VITER_HH
+# define MLN_CORE_CONCEPT_VITER_HH
+
+/*! \file mln/core/concept/viter.hh
+ *
+ * \brief Definition of the concept of mln::Viter.
+ */
+
+# include <mln/core/concept/iterator.hh>
+# include <mln/core/concept/genpoint.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Base class for implementation of classes of iterator on
+ * values.
+ *
+ * An iterator on values is an iterator that browse over a set of
+ * values.
+ *
+ * \see mln::doc::Viter for a complete documentation of this class
+ * contents.
+ */
+ template <typename E>
+ struct Viter : public Iterator<E>
+ {
+ /*
+ typedef value;
+ operator value() const;
+ */
+
+ protected:
+ Viter();
+ };
+
+
+ /*! \brief Print an iterator \p v on value set into the output
+ * stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] v An iterator on value set.
+ *
+ * \pre \p v is a valid.
+ *
+ * \return The modified output stream \p ostr.
+ *
+ * \relates mln::Viter
+ */
+ template <typename E>
+ std::ostream& operator<<(std::ostream& ostr, const Viter<E>& v);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Viter<E>::Viter()
+ {
+ typedef mln_value(E) value;
+ value (E::*m)() const = & E::operator value;
+ m = 0;
+ }
+
+ template <typename E>
+ std::ostream& operator<<(std::ostream& ostr, const Viter<E>& v)
+ {
+ mln_precondition(exact(v).is_valid());
+ return ostr << mln_value(E)(exact(v));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_VITER_HH
Index: mln/core/concept/doc/value_set.hh
--- mln/core/concept/doc/value_set.hh (revision 0)
+++ mln/core/concept/doc/value_set.hh (revision 0)
@@ -0,0 +1,79 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file mln/core/concept/doc/value_set.hh
+ * \brief This file documents the concept of mln::Value_Set.
+ */
+
+namespace mln
+{
+
+ namespace doc
+ {
+
+ /*! \brief Documentation class for mln::Value_Set.
+ *
+ * \see mln::Value_Set
+ */
+ template <typename E>
+ struct Value_Set : public Object<E>
+ {
+ /*! \brief Value associated type.
+ */
+ typedef void value;
+
+ /*! \brief Viter associated type.
+ */
+ typedef void viter;
+
+ /*! \brief Forward Viter associated type.
+ */
+ typedef void fwd_viter;
+
+ /*! \brief Backward Viter associated type.
+ */
+ typedef void bkd_viter;
+
+ /*! \brief Test if \p v belongs to this set of values.
+ *
+ * \param[in] v A value.
+ * \return True if \p v is an element of the set of values.
+ */
+ bool has(const value& v) const;
+
+ /*! \brief Give the number of values in this set.
+ */
+ std::size_t nvalues() const;
+
+ /*! \brief Give the \p i-th value of this set.
+ */
+ value operator[](std::size_t i) const;
+ };
+
+ } // end of namespace mln::doc
+
+} // end of namespace mln
Index: mln/core/concept/doc/viter.hh
--- mln/core/concept/doc/viter.hh (revision 0)
+++ mln/core/concept/doc/viter.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file mln/core/concept/doc/viter.hh
+ * \brief This file documents the concept of mln::Viter.
+ */
+
+namespace mln
+{
+
+ namespace doc
+ {
+
+ /*! \brief Documentation class for mln::Viter.
+ *
+ * \see mln::Viter
+ */
+ template <typename E>
+ struct Viter : public Iterator<E>
+ {
+ /*! \brief Value associated type.
+ */
+ typedef void value;
+
+ /*! \brief Convertion into a value.
+ *
+ * \return A value.
+ */
+ operator value() const;
+ };
+
+ } // end of namespace mln::doc
+
+} // end of namespace mln
Index: mln/core/concept/value.hh
--- mln/core/concept/value.hh (revision 0)
+++ mln/core/concept/value.hh (revision 0)
@@ -0,0 +1,73 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_CORE_CONCEPT_VALUE_HH
+# define MLN_CORE_CONCEPT_VALUE_HH
+
+/*! \file mln/core/concept/value.hh
+ * \brief Definition of the concept of mln::Value.
+ */
+
+# include <mln/core/concept/object.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Base class for implementation classes of values.
+ *
+ * \see mln::doc::Value for a complete documentation of this class
+ * contents.
+ */
+ template <typename E>
+ struct Value : public Object<E>
+ {
+ /*
+ typedef enc; // encoding type
+ typedef equiv; // equivalent type
+ */
+
+ protected:
+ Value();
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Value<E>::Value()
+ {
+ typedef mln_enc(E) enc;
+ typedef mln_equiv(E) equiv;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_VALUE_HH
Index: mln/value/vset.hh
--- mln/value/vset.hh (revision 0)
+++ mln/value/vset.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_VALUE_VSET_HH
+# define MLN_VALUE_VSET_HH
+
+/*! \file mln/value/vset.hh
+ *
+ * \brief Define some basic sets of values from value types.
+ */
+
+# include <mln/core/concept/value_set.hh>
+# include <mln/value/props.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ // Fwd decls.
+ template <typename S> struct fwd_viter_;
+ template <typename S> struct bkd_viter_;
+
+
+ /*! Class that defines the properties of the value type \c T.
+ */
+ template <typename T>
+ struct vset_ : public Value_Set< vset_<T> >
+ {
+ typedef T value;
+
+ typedef fwd_viter_< vset_<T> > fwd_viter;
+ typedef bkd_viter_< vset_<T> > bkd_viter;
+ typedef fwd_viter viter;
+
+ bool has(const T& v) const;
+
+ T operator[](std::size_t i) const;
+
+ std::size_t nvalues() const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ bool
+ vset_<T>::has(const T& v) const
+ {
+ return true;
+ }
+
+ template <typename T>
+ T
+ vset_<T>::operator[](std::size_t i) const
+ {
+ mln_precondition(i < nvalues());
+ return mln_min(T) + i;
+ }
+
+ template <typename T>
+ std::size_t
+ vset_<T>::nvalues() const
+ {
+ return mln_card(T);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+# include <mln/value/viter.hh>
+
+
+#endif // ! MLN_VALUE_VSET_HH
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1001)
+++ mln/value/props.hh (working copy)
@@ -45,6 +45,10 @@
# define mln_max(T) mln::value::props<T>::max()
+/// Get the number of values for value type \c T.
+# define mln_card(T) mln::value::props<T>::card()
+
+
namespace mln
{
@@ -62,6 +66,9 @@
/// Maximum value for type \c T.
static T max();
+
+ /// Number of values for type \c T.
+ static std::size_t card();
};
@@ -72,6 +79,7 @@
{
static bool min() { return false; }
static bool max() { return true; }
+ static std::size_t card() { return 2; }
};
// integers
@@ -81,6 +89,7 @@
{
static unsigned char min() { return 0; }
static unsigned char max() { return 255; }
+ static std::size_t card() { return 256; }
};
template <>
@@ -88,6 +97,7 @@
{
static signed char min() { return -128; }
static signed char max() { return 127; }
+ static std::size_t card() { return 256; }
};
template <>
@@ -95,6 +105,7 @@
{
static unsigned short min() { return 0; }
static unsigned short max() { return 65535; }
+ static std::size_t card() { return 65536; }
};
template <>
@@ -102,6 +113,7 @@
{
static signed short min() { return -32768; }
static signed short max() { return 32767; }
+ static std::size_t card() { return 655356; }
};
template <>
@@ -109,6 +121,7 @@
{
static unsigned int min() { return 0; }
static unsigned int max() { return UINT_MAX; }
+ static std::size_t card() { return std::size_t(UINT_MAX) + 1; }
};
template <>
@@ -116,6 +129,7 @@
{
static signed int min() { return INT_MIN; }
static signed int max() { return INT_MAX; }
+ static std::size_t card() { return std::size_t(UINT_MAX) + 1; }
};
template <>
Index: mln/value/viter.hh
--- mln/value/viter.hh (revision 0)
+++ mln/value/viter.hh (revision 0)
@@ -0,0 +1,224 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_VALUE_VITER_HH
+# define MLN_VALUE_VITER_HH
+
+/*! \file mln/value/viter.hh
+ *
+ * \brief Definition of iterators on value sets.
+ */
+
+# include <mln/core/concept/viter.hh>
+
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /*! \brief FIXME: Forward iterator on a set of values.
+ *
+ * The parameter \c S is the type of value set.
+ */
+ template <typename S>
+ struct fwd_viter_ : public Viter< fwd_viter_<S> >
+ {
+ /// Value associated type.
+ typedef mln_value(S) value;
+
+ /// Constructor.
+ fwd_viter_(const Value_Set<S>& s);
+
+ /// Convertion into a value.
+ operator value() const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next value.
+ void next_();
+
+ private:
+
+ const S& s_;
+ std::size_t i_;
+ };
+
+
+
+
+ /*! \brief FIXME: Backward iterator on a set of values.
+ *
+ * The parameter \c S is the type of value set.
+ */
+ template <typename S>
+ struct bkd_viter_ : public Viter< bkd_viter_<S> >
+ {
+ /// Value associated type.
+ typedef mln_value(S) value;
+
+ /// Constructor.
+ bkd_viter_(const Value_Set<S>& s);
+
+ /// Convertion into a value.
+ operator value() const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next value.
+ void next_();
+
+ private:
+
+ const S& s_;
+ std::size_t i_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // fwd_viter_<S>
+
+ template <typename S>
+ fwd_viter_<S>::fwd_viter_(const Value_Set<S>& s)
+ : s_(exact(s))
+ {
+ invalidate();
+ }
+
+ template <typename S>
+ fwd_viter_<S>::operator typename fwd_viter_<S>::value () const
+ {
+ mln_precondition(is_valid());
+ return s_[i_];
+ }
+
+ template <typename S>
+ bool
+ fwd_viter_<S>::is_valid() const
+ {
+ return i_ < s_.nvalues();
+ }
+
+ template <typename S>
+ void
+ fwd_viter_<S>::invalidate()
+ {
+ i_ = s_.nvalues();
+ }
+
+ template <typename S>
+ void
+ fwd_viter_<S>::start()
+ {
+ i_ = 0;
+ }
+
+ template <typename S>
+ void
+ fwd_viter_<S>::next_()
+ {
+ ++i_;
+ }
+
+
+ // bkd_viter_<S>
+
+ template <typename S>
+ bkd_viter_<S>::bkd_viter_(const Value_Set<S>& s)
+ : s_(exact(s))
+ {
+ invalidate();
+ }
+
+ template <typename S>
+ bkd_viter_<S>::operator typename bkd_viter_<S>::value () const
+ {
+ mln_precondition(is_valid());
+ return s_[i_];
+ }
+
+ template <typename S>
+ bool
+ bkd_viter_<S>::is_valid() const
+ {
+ return i_ != s_.nvalues();
+ }
+
+ template <typename S>
+ void
+ bkd_viter_<S>::invalidate()
+ {
+ i_ = s_.nvalues();
+ }
+
+ template <typename S>
+ void
+ bkd_viter_<S>::start()
+ {
+ i_ = s_.nvalues() - 1;
+ }
+
+ template <typename S>
+ void
+ bkd_viter_<S>::next_()
+ {
+ if (i_ = 0)
+ {
+ invalidate();
+ return;
+ }
+ --i_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_VITER_HH
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 0)
+++ mln/value/int_u.hh (revision 0)
@@ -0,0 +1,130 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_VALUE_INT_U_HH
+# define MLN_VALUE_INT_U_HH
+
+/*! \file mln/value/int_u.hh
+ *
+ * \brief Define a generic class for unsigned integers.
+ */
+
+# include <mln/core/concept/value.hh>
+# include <mln/value/internal/value_like.hh>
+# include <mln/value/props.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ namespace internal
+ {
+ template <unsigned n> struct encoding_;
+ template <> struct encoding_<8> { typedef unsigned char ret; };
+ }
+
+
+ /*! \brief Unsigned integer value class.
+ *
+ * The parameter is \c n the number of encoding bits.
+ */
+ template <unsigned n>
+ struct int_u_
+ : public internal::value_like_< typename internal::encoding_<n>::ret,
+ int_u_<n> >
+ {
+ protected:
+ typedef internal::value_like_< typename internal::encoding_<n>::ret,
+ int_u_<n> > super;
+
+ public:
+
+ /// Encoding associated type.
+ typedef typename super::enc enc;
+
+ /// Constructor without argument.
+ int_u_();
+
+ /// Constructor from an integer.
+ int_u_(int i);
+ };
+
+
+
+
+ template <unsigned n>
+ struct props< int_u_<n> > : public props< typename internal::encoding_<n>::ret >
+ {
+ };
+
+
+ /// Alias for unsigned 8bit integers.
+ typedef value::int_u_<8> int_u8;
+
+
+ /*! \brief Print an int_u8 \p i into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] i An int_u8.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ std::ostream& operator<<(std::ostream& ostr, const int_u8& i);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n>
+ int_u_<n>::int_u_()
+ {
+ }
+
+ template <unsigned n>
+ int_u_<n>::int_u_(int i)
+ {
+ mln_precondition(i >= 0);
+ mln_precondition(i <= mln_max(enc));
+ this->v_ = enc(i);
+ }
+
+ std::ostream& operator<<(std::ostream& ostr, const int_u8& i)
+ {
+ return ostr << unsigned(i);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_U_HH
Index: mln/value/internal/value_like.hh
--- mln/value/internal/value_like.hh (revision 0)
+++ mln/value/internal/value_like.hh (revision 0)
@@ -0,0 +1,135 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_VALUE_INTERNAL_VALUE_LIKE_HH
+# define MLN_VALUE_INTERNAL_VALUE_LIKE_HH
+
+/*! \file mln/value/internal/value_like.hh
+ *
+ * \brief Factor code for value classes defined over another type.
+ *
+ * \internal
+ */
+
+# include <mln/core/concept/value.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ namespace internal
+ {
+
+ /*! \brief Base class for value classes defined over another
+ * type.
+ *
+ * \internal
+ *
+ * Parameters are \c V the equivalent value type and \c E the
+ * exact value type.
+ */
+ template <typename V, typename E>
+ struct value_like_ : public Value<E>
+ {
+ /// Encoding associated type.
+ typedef V enc;
+
+ /// Equivalent associated type.
+ typedef V equiv;
+
+ /// Convertion towards equivalent type.
+ operator V() const;
+
+ /// Assignment from equivalent type.
+ E& operator=(const V& v);
+
+ protected:
+ enc v_; /// The actual value.
+ };
+
+
+ /*! \brief General definition of the "equal to" operator between
+ * value-like types.
+ *
+ * \relates value_like_
+ */
+ template <typename V, typename E>
+ bool operator=(const value_like_<V,E>& lhs, const value_like_<V,E>& rhs);
+
+
+ /*! \brief General definition of the "less than" operator
+ * between value-like types.
+ *
+ * \relates value_like_
+ */
+ template <typename V, typename E>
+ bool operator<(const value_like_<V,E>& lhs, const value_like_<V,E>& rhs);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, typename E>
+ value_like_<V, E>::operator V() const
+ {
+ return v_;
+ }
+
+ template <typename V, typename E>
+ E&
+ value_like_<V, E>::operator=(const V& v)
+ {
+ v_ = v;
+ return exact(*this);
+ }
+
+ template <typename V, typename E>
+ bool operator=(const value_like_<V, E>& lhs,
+ const value_like_<V, E>& rhs)
+ {
+ return V(lhs) = V(rhs);
+ }
+
+ template <typename V, typename E>
+ bool operator<(const value_like_<V, E>& lhs,
+ const value_like_<V, E>& rhs)
+ {
+ return V(lhs) < V(rhs);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value::internal
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INTERNAL_VALUE_LIKE_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make milena work correctly with g++-2.95.
* mln/core/exact.hh (force_exact): Move in...
* mln/core/internal/force_exact.hh: ...this new file.
(force_exact_): Now a method and g++-2.95 compatible.
* mln/core/concept/genpoint.hh: Update.
* mln/core/dpoints_piter.hh: Update.
* mln/core/internal/coord_impl.hh: Update.
* tests/window2d.cc: New.
* tests/box2d.cc: New.
* tests/point2d.cc: New.
* tests/dpoint2d.cc: New.
* mln/fun: New.
* mln/fun/all.hh: New.
* mln/core/window.hh (is_centered): Update.
* doc/Doxyfile.in (PREDEFINED): Add extra macros.
* mln/core/point.hh (point_): Change arg from val to fun.
* mln/core/dpoint.hh (dpoint_): Change arg from val to fun.
* mln/core/image2d.hh: Add explicit typedefs.
doc/Doxyfile.in | 12 +++++
mln/core/concept/genpoint.hh | 28 +++++++----
mln/core/dpoint.hh | 11 ++--
mln/core/dpoints_piter.hh | 2
mln/core/exact.hh | 84 -----------------------------------
mln/core/image2d.hh | 11 ++++
mln/core/internal/coord_impl.hh | 55 +++++++++++++++--------
mln/core/internal/force_exact.hh | 62 ++++++++++++++++++++++++++
mln/core/point.hh | 15 +++---
mln/core/window.hh | 3 -
mln/fun/all.hh | 92 +++++++++++++++++++++++++++++++++++++++
tests/box2d.cc | 42 +++++++++++++++++
tests/dpoint2d.cc | 50 +++++++++++++++++++++
tests/point2d.cc | 59 +++++++++++++++++++++++++
tests/window2d.cc | 43 ++++++++++++++++++
15 files changed, 445 insertions(+), 124 deletions(-)
Index: tests/window2d.cc
--- tests/window2d.cc (revision 0)
+++ tests/window2d.cc (revision 0)
@@ -0,0 +1,43 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file tests/window2d.cc
+ *
+ * \brief Tests on mln::window2d.
+ */
+
+#include <mln/core/window2d.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ window2d w;
+ std::cout << w.is_centered() << std::endl;
+}
Index: tests/box2d.cc
--- tests/box2d.cc (revision 0)
+++ tests/box2d.cc (revision 0)
@@ -0,0 +1,42 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file tests/box2d.cc
+ *
+ * \brief Tests on mln::box2d.
+ */
+
+#include <mln/core/box2d.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d b(2, 3);
+}
Index: tests/point2d.cc
--- tests/point2d.cc (revision 0)
+++ tests/point2d.cc (revision 0)
@@ -0,0 +1,59 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file tests/point2d.cc
+ *
+ * \brief Tests on mln::point2d.
+ */
+
+#include <mln/core/point2d.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ point2d p, q;
+
+ // assignment
+
+ p[0] = 4;
+ p.row() += 1;
+ mln_assertion(p.row() = 5 && p[0] = 5);
+ p[1] = 0;
+ p.col() += 1;
+ mln_assertion(p.col() = 1 && p[1] = 1);
+
+ // construction
+ q = mk_point2d(5, 1);
+ mln_assertion(p = q);
+
+ q.set_all(0);
+ for (unsigned i = 0; i < p.dim; ++i)
+ mln_assertion(q[i] = 0);
+}
Index: tests/dpoint2d.cc
--- tests/dpoint2d.cc (revision 0)
+++ tests/dpoint2d.cc (revision 0)
@@ -0,0 +1,50 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/*! \file tests/dpoint2d.cc
+ *
+ * \brief Tests on mln::dpoint2d.
+ */
+
+#include <mln/core/dpoint2d.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ point2d p, q;
+ dpoint2d dp;
+
+ p = mk_point2d(1, 2);
+ q = mk_point2d(4, 7);
+ dp = mk_dpoint2d(3, 5);
+
+ mln_assertion(dp = q - p);
+ mln_assertion(q = p + dp);
+}
Index: doc/Doxyfile.in
--- doc/Doxyfile.in (revision 1000)
+++ doc/Doxyfile.in (working copy)
@@ -1042,6 +1042,18 @@
# instead of the = operator.
PREDEFINED = \
+ "mln_piter(T)=typename T::piter" \
+ "mln_fwd_piter(T)=typename T::fwd_piter" \
+ "mln_bkd_piter(T)=typename T::bkd_piter" \
+ "mln_qiter(T)=typename T::qiter" \
+ "mln_fwd_qiter(T)=typename T::fwd_qiter" \
+ "mln_bkd_qiter(T)=typename T::bkd_qiter" \
+ "mln_niter(T)=typename T::niter" \
+ "mln_fwd_niter(T)=typename T::fwd_niter" \
+ "mln_bkd_niter(T)=typename T::bkd_niter" \
+ "mln_value(T)=typename T::value" \
+ "mln_rvalue(T)=typename T::rvalue" \
+ "mln_lvalue(T)=typename T::lvalue" \
"mln_coord(T)=typename T::coord" \
"mln_point(T)=typename T::point" \
"mln_dpoint(T)=typename T::dpoint"
Index: mln/core/dpoints_piter.hh
--- mln/core/dpoints_piter.hh (revision 1000)
+++ mln/core/dpoints_piter.hh (working copy)
@@ -112,7 +112,7 @@
dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps,
const GenPoint<Pref>& p_ref)
: dps_(exact(dps).vec()),
- p_ref_(* force_exact<Pref>(p_ref).pointer())
+ p_ref_(* p_ref.force_exact_().pointer())
{
invalidate();
}
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1000)
+++ mln/core/point.hh (working copy)
@@ -83,9 +83,10 @@
*/
point_();
- /*! \brief Constructor; all coordinates are set to the value \p c.
+ /*! \brief Constructor; coordinates are set by function \p f.
*/
- point_(C c);
+ template <typename F>
+ point_(F f);
/*! \brief Set all coordinates to the value \p c.
*/
@@ -102,14 +103,14 @@
C point_<n,C>::operator[](unsigned i) const
{
assert(i < n);
- return coord_[i];
+ return this->coord_[i];
}
template <unsigned n, typename C>
C& point_<n,C>::operator[](unsigned i)
{
assert(i < n);
- return coord_[i];
+ return this->coord_[i];
}
template <unsigned n, typename C>
@@ -118,9 +119,11 @@
}
template <unsigned n, typename C>
- point_<n,C>::point_(C c)
+ template <typename F>
+ point_<n,C>::point_(F f)
{
- set_all(c);
+ for (unsigned i = 0; i < n; ++i)
+ coord_[i] = f(i);
}
template <unsigned n, typename C>
Index: mln/core/concept/genpoint.hh
--- mln/core/concept/genpoint.hh (revision 1000)
+++ mln/core/concept/genpoint.hh (working copy)
@@ -36,8 +36,10 @@
# include <mlc/same_coord.hh>
# include <mln/core/concept/object.hh>
+
# include <mln/core/macros.hh>
# include <mln/core/contract.hh>
+# include <mln/core/internal/force_exact.hh>
namespace mln
@@ -57,7 +59,8 @@
* class contents.
*/
template <typename E>
- struct GenPoint // stand-alone class!
+ struct GenPoint
+ // : virtual internal::object_<E>
{
/*
@@ -75,8 +78,11 @@
coord operator[](unsigned i) const;
*/
+ mln_internal_add_force_exact_(GenPoint<E>)
+
protected:
GenPoint();
+
};
@@ -189,8 +195,9 @@
template <typename E>
GenPoint<E>::GenPoint()
{
- const int dim = E::dim;
+ int dim = E::dim;
mln_invariant(dim > 0);
+ dim = 0;
typedef mln_point(E) point;
typedef mln_dpoint(E) dpoint;
typedef mln_coord(E) coord;
@@ -204,8 +211,8 @@
bool operator=(const GenPoint<Pl>& lhs, const GenPoint<Pr>& rhs)
{
// FIXME: mlc::same_grid<Pl, Pr>::check();
- const Pl& lhs_ = force_exact<Pl>(lhs);
- const Pr& rhs_ = force_exact<Pr>(rhs);
+ const Pl& lhs_ = lhs.force_exact_();
+ const Pr& rhs_ = rhs.force_exact_();
mlc::same_point<Pl, Pr>::check();
for (unsigned i = 0; i < Pl::dim; ++i)
if (lhs_[i] != rhs_[i])
@@ -217,8 +224,8 @@
bool operator<(const GenPoint<Pl>& lhs, const GenPoint<Pr>& rhs)
{
// FIXME: mlc::same_grid<Pl, Pr>::check();
- const Pl& lhs_ = force_exact<Pl>(lhs);
- const Pr& rhs_ = force_exact<Pr>(rhs);
+ const Pl& lhs_ = lhs.force_exact_();
+ const Pr& rhs_ = rhs.force_exact_();
for (unsigned i = 0; i < Pl::dim; ++i)
{
if (lhs_[i] = rhs_[i])
@@ -235,8 +242,8 @@
mlc::equal<mln_dpoint(Pl), mln_dpoint(Pr)>::check();
// FIXME: mlc::same_grid<Pl, Pr>::check();
mlc::same_coord<Pl, Pr>::check();
- const Pl& lhs_ = force_exact<Pl>(lhs);
- const Pr& rhs_ = force_exact<Pr>(rhs);
+ const Pl& lhs_ = lhs.force_exact_();
+ const Pr& rhs_ = rhs.force_exact_();
mln_dpoint(Pl) tmp;
for (unsigned i = 0; i < Pl::dim; ++i)
tmp[i] = lhs_[i] - rhs_[i];
@@ -248,7 +255,7 @@
mln_point(P)
operator+(const GenPoint<P>& lhs, const mln_dpoint(P)& rhs)
{
- const P& lhs_ = force_exact<P>(lhs);
+ const P& lhs_ = lhs.force_exact_();
mln_point(P) tmp;
for (unsigned i = 0; i < P::dim; ++i)
tmp[i] = lhs_[i] + rhs[i];
@@ -258,7 +265,8 @@
template <typename P>
std::ostream& operator<<(std::ostream& ostr, const GenPoint<P>& p)
{
- const P& p_ = force_exact<P>(p);
+ const P& p_ = p.force_exact_();
+
ostr << '(';
for (unsigned i = 0; i < P::dim; ++i)
{
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 1000)
+++ mln/core/dpoint.hh (working copy)
@@ -83,9 +83,10 @@
*/
dpoint_();
- /*! \brief Constructor; all coordinates are set to the value \p c.
+ /*! \brief Constructor; coordinates are set by function \p f.
*/
- dpoint_(C c);
+ template <typename F>
+ dpoint_(F f);
/*! \brief Set all coordinates to the value \p c.
*/
@@ -118,9 +119,11 @@
}
template <unsigned n, typename C>
- dpoint_<n,C>::dpoint_(C c)
+ template <typename F>
+ dpoint_<n,C>::dpoint_(F f)
{
- set_all(c);
+ for (unsigned i = 0; i < n; ++i)
+ coord_[i] = f(i);
}
template <unsigned n, typename C>
Index: mln/core/exact.hh
--- mln/core/exact.hh (revision 1000)
+++ mln/core/exact.hh (working copy)
@@ -66,57 +66,6 @@
/// \}
- namespace internal
- {
-
- template <typename E, typename O>
- struct helper_force_exact_
- {
- typedef E ret;
- };
-
- template <typename E, typename O>
- struct helper_force_exact_< E, const O >
- {
- typedef const E ret;
- };
-
- } // end of namespace mln::internal
-
-
- /*! \brief Violent exact cast routine.
- *
- * This cast is an alternative to the mln::exact cast. It is used
- * for objects than do not derive from mln::Object.
- *
- * It preserves the nature (pointer or reference, const or mutable)
- * of its argument. The parameter \a E should not have qualifiers.
- *
- * \warning Prefer not to use this cast!
- *
- * \see mln::exact
- * \todo Move into mln::internal.
- */
- /// \{
-
- template <typename E, typename O>
- E* force_exact(O* ptr);
-
- template <typename E, typename O>
- const E* force_exact(const O* ptr);
-
- template <typename E, typename O>
- typename internal::helper_force_exact_<E, O>::ret & // help g++-3.3
- force_exact(O& ref);
-
- /// \}
-
-
-// template <typename E, typename O>
-// E& force_exact(O& ref);
-
-// template <typename E, typename O>
-// const E& force_exact(const O& ref);
# ifndef MLN_INCLUDE_ONLY
@@ -147,39 +96,6 @@
return *(const E*)(const void*)(&ref);
}
- // force_exact
-
- template <typename E, typename O>
- E* force_exact(O* ptr)
- {
- return (E*)(void*)ptr;
- }
-
- template <typename E, typename O>
- const E* force_exact(const O* ptr)
- {
- return (const E*)(const void*)ptr;
- }
-
-// template <typename E, typename O>
-// E& force_exact(O& ref)
-// {
-// return *(E*)(void*)(&ref);
-// }
-
-// template <typename E, typename O>
-// const E& force_exact(const O& ref)
-// {
-// return *(const E*)(const void*)(&ref);
-// }
-
- template <typename E, typename O>
- typename internal::helper_force_exact_<E, O>::ret &
- force_exact(O& ref)
- {
- return *(E*)(void*)(&ref);
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1000)
+++ mln/core/window.hh (working copy)
@@ -36,6 +36,7 @@
# include <mln/core/concept/window.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/core/dpoint.hh>
+# include <mln/fun/all.hh>
namespace mln
@@ -100,7 +101,7 @@
template <typename D>
bool window_<D>::is_centered() const
{
- static const D origin(0);
+ static const D origin = all(0);
return this->has(origin);
}
Index: mln/core/image2d.hh
--- mln/core/image2d.hh (revision 1000)
+++ mln/core/image2d.hh (working copy)
@@ -48,6 +48,17 @@
template <typename T>
struct image2d : public internal::image_base_< box2d, image2d<T> >
{
+
+ // warning: just to make effective types appear in Doxygen
+ typedef box2d pset;
+ typedef point2d psite;
+ typedef point2d point;
+ typedef mln_fwd_piter(box2d) fwd_piter;
+ typedef mln_bkd_piter(box2d) bkd_piter;
+ typedef fwd_piter piter;
+ // end of warning
+
+
/// Value associated type.
typedef T value;
Index: mln/core/internal/force_exact.hh
--- mln/core/internal/force_exact.hh (revision 0)
+++ mln/core/internal/force_exact.hh (revision 0)
@@ -0,0 +1,62 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_CORE_INTERNAL_FORCE_EXACT_HH
+# define MLN_CORE_INTERNAL_FORCE_EXACT_HH
+
+/*! \file mln/core/internal/force_exact.hh
+ *
+ * \brief Definition of a macro for internal use only.
+ */
+
+
+/*! \brief Macro to add a violent exact cast method.
+ *
+ * \internal
+ *
+ * This cast is an alternative to the mln::exact cast. It is used
+ * for objects than do not derive from mln::Object.
+ *
+ * \warning Do not to use this cast!
+ *
+ * \see mln::exact
+ */
+
+# define mln_internal_add_force_exact_(Type) \
+ \
+ E& force_exact_() const \
+ { \
+ static const E exact_obj; \
+ static const Type& exact_obj_ref = exact_obj; \
+ static const int exact_offset = \
+ (const char*)(void*)(&exact_obj_ref) \
+ - (const char*)(void*)(&exact_obj); \
+ return *(E*)((char*)(this) - exact_offset); \
+ }
+
+
+#endif // ! MLN_CORE_INTERNAL_FORCE_EXACT_HH
Index: mln/core/internal/coord_impl.hh
--- mln/core/internal/coord_impl.hh (revision 1000)
+++ mln/core/internal/coord_impl.hh (working copy)
@@ -30,9 +30,12 @@
/*! \file mln/core/internal/coord_impl.hh
*
+ * \internal
+ *
* \brief Define some implementation classes for generalized points.
*/
+# include <mln/core/internal/force_exact.hh>
# include <mln/core/concept/object.hh>
@@ -42,6 +45,13 @@
namespace internal
{
+ template <typename E>
+ struct coord_impl_base_
+ {
+ mln_internal_add_force_exact_(coord_impl_base_<E>)
+ };
+
+
// coord_impl
/*! \brief Implementation class to equip generalized points with
@@ -54,12 +64,17 @@
template <typename C, typename E>
struct coord_impl_<1, C, E>
+ : coord_impl_base_<E>
{
C ind() const;
+ private:
+ typedef coord_impl_<1, C, E> self_;
+
};
template <typename C, typename E>
struct coord_impl_<2, C, E>
+ : coord_impl_base_<E>
{
C row() const;
C col() const;
@@ -67,6 +82,7 @@
template <typename C, typename E>
struct coord_impl_<3, C, E>
+ : coord_impl_base_<E>
{
C sli() const;
C row() const;
@@ -81,6 +97,7 @@
template <typename C, typename E>
struct mutable_coord_impl_<1, C, E>
+ : coord_impl_base_<E>
{
C ind() const;
C& ind();
@@ -88,6 +105,7 @@
template <typename C, typename E>
struct mutable_coord_impl_<2, C, E>
+ : coord_impl_base_<E>
{
C row() const;
C& row();
@@ -97,6 +115,7 @@
template <typename C, typename E>
struct mutable_coord_impl_<3, C, E>
+ : coord_impl_base_<E>
{
C sli() const;
C& sli();
@@ -116,7 +135,7 @@
template <typename C, typename E>
C coord_impl_<1, C, E>::ind() const
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
// 2
@@ -124,13 +143,13 @@
template <typename C, typename E>
C coord_impl_<2, C, E>::row() const
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
template <typename C, typename E>
C coord_impl_<2, C, E>::col() const
{
- return force_exact<E>(*this)[1];
+ return this->force_exact_()[1];
}
// 3
@@ -138,19 +157,19 @@
template <typename C, typename E>
C coord_impl_<3, C, E>::sli() const
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
template <typename C, typename E>
C coord_impl_<3, C, E>::row() const
{
- return force_exact<E>(*this)[1];
+ return this->force_exact_()[1];
}
template <typename C, typename E>
C coord_impl_<3, C, E>::col() const
{
- return force_exact<E>(*this)[2];
+ return this->force_exact_()[2];
}
@@ -161,13 +180,13 @@
template <typename C, typename E>
C mutable_coord_impl_<1, C, E>::ind() const
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
template <typename C, typename E>
C& mutable_coord_impl_<1, C, E>::ind()
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
// 2
@@ -175,25 +194,25 @@
template <typename C, typename E>
C mutable_coord_impl_<2, C, E>::row() const
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
template <typename C, typename E>
C& mutable_coord_impl_<2, C, E>::row()
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
template <typename C, typename E>
C mutable_coord_impl_<2, C, E>::col() const
{
- return force_exact<E>(*this)[1];
+ return this->force_exact_()[1];
}
template <typename C, typename E>
C& mutable_coord_impl_<2, C, E>::col()
{
- return force_exact<E>(*this)[1];
+ return this->force_exact_()[1];
}
// 3
@@ -201,37 +220,37 @@
template <typename C, typename E>
C mutable_coord_impl_<3, C, E>::sli() const
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
template <typename C, typename E>
C& mutable_coord_impl_<3, C, E>::sli()
{
- return force_exact<E>(*this)[0];
+ return this->force_exact_()[0];
}
template <typename C, typename E>
C mutable_coord_impl_<3, C, E>::row() const
{
- return force_exact<E>(*this)[1];
+ return this->force_exact_()[1];
}
template <typename C, typename E>
C& mutable_coord_impl_<3, C, E>::row()
{
- return force_exact<E>(*this)[1];
+ return this->force_exact_()[1];
}
template <typename C, typename E>
C mutable_coord_impl_<3, C, E>::col() const
{
- return force_exact<E>(*this)[2];
+ return this->force_exact_()[2];
}
template <typename C, typename E>
C& mutable_coord_impl_<3, C, E>::col()
{
- return force_exact<E>(*this)[2];
+ return this->force_exact_()[2];
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/fun/all.hh
--- mln/fun/all.hh (revision 0)
+++ mln/fun/all.hh (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_FUN_ALL_HH
+# define MLN_FUN_ALL_HH
+
+/*! \file mln/fun/all.hh
+ *
+ * \brief FIXME.
+ */
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ template <typename T>
+ struct all
+ {
+ all(T t);
+ template <typename U>
+ T operator()(const U&) const;
+ private:
+ T t_;
+ };
+
+ } // end of namespace mln::fun
+
+ template <typename T>
+ fun::all<T> all(T t);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace fun
+ {
+
+ template <typename T>
+ all<T>::all(T t)
+ : t_(t)
+ {
+ }
+
+ template <typename T>
+ template <typename U>
+ T
+ all<T>::operator()(const U&) const
+ {
+ return t_;
+ }
+
+ } // end of namespace mln::fun
+
+ template <typename T>
+ fun::all<T> all(T t)
+ {
+ fun::all<T> tmp(t);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_ALL_HH
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Draft Draft.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Histogramm : Draft.
* oln/histo: New.
* oln/histo/histo_median.hh: New.
* oln/histo/histo_min.hh: New.
* oln/histo/histogram.hh: New.
canvas/two_pass.hh | 6 +--
histo/histo_median.hh | 85 ++++++++++++++++++++++++++++++++++++++++++++++
histo/histo_min.hh | 90 +++++++++++++++++++++++++++++++++++++++++++++++++
histo/histogram.hh | 69 +++++++++++++++++++++++++++++++++++++
morpho/cc_tarjan_v1.hh | 1
5 files changed, 247 insertions(+), 4 deletions(-)
Index: oln/histo/histo_median.hh
--- oln/histo/histo_median.hh (revision 0)
+++ oln/histo/histo_median.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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_HISTO_MEDIAN_HH
+# define OLN_HISTO_MEDIAN_HH
+
+# include <oln/histo/histogram.hh>
+
+
+namespace oln
+{
+
+ namespace histo_median
+ {
+
+ template <typename T>
+ struct histo_median : public Histogram< histo_median<T> >
+ {
+ histo_median() : imed(this.ival) {}
+
+ void slide(T i)
+ {
+ int last_i = take(i);
+ untake();
+ if (imed == -1)
+ compute_median();
+ else
+ compute_median();
+ }
+
+ void compute_median()
+ {
+ T total = 0;
+ for (int i = 0; i < this.v.size; i++)
+ total += this.v[i];
+
+ imed = 0;
+ T sum = this.v[imed];
+ while (sum < total/2)
+ {
+ ++imed;
+ sum += this.v[imed];
+ }
+ }
+
+ T median() { return this.v[imed]; }
+ private:
+ int& imed;
+ T rest;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::histo_median
+
+} // end of namespace oln
+
+#endif // ! OLN_HISTO_MEDIAN_HH
Index: oln/histo/histo_min.hh
--- oln/histo/histo_min.hh (revision 0)
+++ oln/histo/histo_min.hh (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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_HISTO_HISTO_MIN_HH
+# define OLN_HISTO_HISTO_MIN_HH
+
+# include <oln/histo/histogram.hh>
+# include <oln/core/internal/max_value.hh>
+
+namespace oln
+{
+
+ namespace histo_min
+ {
+
+ template <typename T>
+ struct histo_min : public Histogram< histo_min<T> >
+ {
+ histo_min() : imin(this.ival) {}
+
+ template <typename L>
+ void init(L line)
+ {
+ int i;
+ for (i = 0; i < line.norme; i++)
+ take(oln_max(T));
+ imin = i/2;
+ }
+
+ void slide(T i)
+ {
+ int last_i = take(i);
+ untake();
+ if (imin == -1)
+ compute_min();
+ else if (i < this.v[imin])
+ imin = last_i;
+ }
+
+ void compute_min()
+ {
+ imin = 0;
+ for (int i = 1; i < this.v.size; i++)
+ if (this.v[i] < this.v[imin])
+ imin = i;
+ }
+
+ T min() { return this.v[imin]; }
+ private:
+ int& imin;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::histo_min
+
+} // end of namespace oln
+
+#endif // ! OLN_HISTO_HISTO_MIN_HH
+
+
+
+
Index: oln/histo/histogram.hh
--- oln/histo/histogram.hh (revision 0)
+++ oln/histo/histogram.hh (revision 0)
@@ -0,0 +1,69 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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_HISTO_HISTOGRAM_HH
+# define OLN_HISTO_HISTOGRAM_HH
+
+namespace oln
+{
+
+ /// Concept-class "Histogram".
+
+ template <typename T>
+ struct Histogram
+ {
+ void take(T t)
+ {
+ v.insert(v.begin(), t);
+ if (ival > 0)
+ ival++;
+ return 0;
+ }
+
+ void untake()
+ {
+ if (this.ival == v.size)
+ ival = -1;
+ T ret = v.back();
+ v.pop_back();
+ return ret;
+ }
+
+ T operator()(int i) { return v[i]; }
+ void clean() { v.clear(); }
+
+ protected:
+ Histogram() : ival(-1) {}
+
+ std::vector<unsigned> v;
+ int ival;
+ }; // end of oln::Histogram<Exact>
+
+
+} // end of namespace oln
+
+#endif // ! OLN_HISTO_HISTOGRAM_HH
Index: oln/core/2d/line2d.hh
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 999)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -33,7 +33,6 @@
# include <oln/level/fill.hh>
# include <oln/core/internal/f_ch_value.hh>
-
namespace oln
{
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 999)
+++ oln/canvas/two_pass.hh (working copy)
@@ -37,9 +37,9 @@
namespace canvas
{
- namespace v1
+ namespace v1 // Data owned by f.
{
- template <typename F> // Data owned by f.
+ template <typename F>
void two_pass(F& fun)
{
@@ -109,7 +109,7 @@
}
- namespace v4 // Via Inheritance.
+ namespace v4 // Via static Inheritens.
{
template <typename I, typename Exact>
struct two_pass : public virtual Any<Exact>
Roland Levillain a écrit :
> Good. Thanks!
Posting to olena-patches was involuntary, however should I continue ?
> Ouch! I think this message did not need to be so long. :)
Sorry! :)
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ Président de Prologin \_____)