* mln/value/label.hh: Include next routine.
* mln/value/next.hh: New.
---
milena/ChangeLog | 8 +++
milena/mln/value/{cast.hh => next.hh} | 92 +++++++++++++++++++++------------
scribo/scribo/core/component_set.hh | 17 ++++---
3 files changed, 77 insertions(+), 40 deletions(-)
copy milena/mln/value/{cast.hh => next.hh} (59%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 1eedf26..a5da997 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,11 @@
+2010-10-21 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add value::next routine.
+
+ * mln/value/label.hh: Include next routine.
+
+ * mln/value/next.hh: New.
+
2010-09-15 Guillaume Lazzara <z(a)lrde.epita.fr>
Temporarily disable static tests on Magick::Quantum type size.
diff --git a/milena/mln/value/cast.hh b/milena/mln/value/next.hh
similarity index 59%
copy from milena/mln/value/cast.hh
copy to milena/mln/value/next.hh
index 0f7939b..e1dac48 100644
--- a/milena/mln/value/cast.hh
+++ b/milena/mln/value/next.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,16 +23,14 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_CAST_HH
-# define MLN_VALUE_CAST_HH
+#ifndef MLN_VALUE_NEXT_HH
+# define MLN_VALUE_NEXT_HH
-/*! \file
- *
- * \brief Definition of the mln::value::cast routine.
- */
+/// \file
+///
+/// Return a given value incremented by 1.
-# include <mln/core/concept/value.hh>
-# include <mln/value/equiv.hh>
+# include <mln/value/label.hh>
namespace mln
@@ -41,59 +39,87 @@ namespace mln
namespace value
{
+ template <typename V>
+ V
+ next(const V&);
- /// Cast a value \p src from type \c Src to type \c Dest.
- template <typename Dest, typename Src>
- Dest cast(const Src& src);
+# ifndef MLN_INCLUDE_ONLY
-# ifndef MLN_INCLUDE_ONLY
+ // Implementations
- namespace internal
+ namespace implementation
{
- template <typename S>
+ namespace generic
+ {
+
+ template <typename V>
+ inline
+ V
+ next(const V& v)
+ {
+ return v + 1;
+ }
+
+ } // end of namespace mln::value::implementation::generic
+
+
+ template <unsigned n>
inline
- const S&
- cast_(const void*, const S& src)
+ mln::value::label<n>
+ next_label(const mln::value::label<n>& v)
{
- return src;
+ return v.next();
}
- template <typename O, typename S>
+ } // end of namespace mln::value::implementation
+
+
+
+ // Dispatch
+
+ namespace internal
+ {
+
+ template <unsigned n>
inline
- const S&
- cast_(const Object<O>*, const S& src)
+ label<n>
+ next_dispatch(const label<n>& v)
{
- return src;
+ return implementation::next_label(v);
}
- template <typename V, typename S>
+
+ template <typename V>
inline
- mln_value_equiv(S)
- cast_(const Value<V>*, const S& src)
+ V
+ next_dispatch(const V& v)
{
- return mln::value::equiv(src);
+ return implementation::generic::next(v);
}
} // end of namespace mln::value::internal
- template <typename Dest, typename Src>
+
+ // Facade
+
+ template <typename V>
inline
- Dest cast(const Src& src)
+ V
+ next(const V& v)
{
- // FIXME: Add static_cast<Dest>?
- // FIXME: Add exact()?
- return static_cast<Dest>(internal::cast_(&src, src));
+ return internal::next_dispatch(v);
}
+
# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln::value
} // end of namespace mln
-
-#endif // ! MLN_VALUE_CAST_HH
+#endif // ! MLN_VALUE_NEXT_HH
diff --git a/scribo/scribo/core/component_set.hh b/scribo/scribo/core/component_set.hh
index b8445eb..937ba4f 100644
--- a/scribo/scribo/core/component_set.hh
+++ b/scribo/scribo/core/component_set.hh
@@ -115,6 +115,9 @@ namespace scribo
typedef mln_result(center_accu_t) center_t;
+ typedef internal::component_set_data<L> data_t;
+ typedef data_t* id_t;
+
public:
/// Constructors
@@ -190,7 +193,7 @@ namespace scribo
const mln::util::array<scribo::component_info>& infos_() const;
/// Unique set Id.
- unsigned id_() const;
+ id_t id_() const;
/// Read/Write access to the underlying labeled image.
@@ -212,7 +215,7 @@ namespace scribo
/// Duplicate the underlying image and create a new component_set.
void init_(const component_set<L>& model);
- mln::util::tracked_ptr< internal::component_set_data<L> > data_;
+ mln::util::tracked_ptr<data_t> data_;
};
@@ -312,7 +315,7 @@ namespace scribo
{
typedef mln_site(L) P;
- infos_.reserve(static_cast<unsigned>(ncomps_) + 1);
+ infos_.reserve(value::next(ncomps_));
infos_.append(component_info()); // Component 0, i.e. the background.
for_all_comp_data(i, attribs)
@@ -330,7 +333,7 @@ namespace scribo
{
typedef mln_site(L) P;
- infos_.reserve(static_cast<unsigned>(ncomps_) + 1);
+ infos_.reserve(value::next(ncomps_));
infos_.append(component_info()); // Component 0, i.e. the background.
for_all_comp_data(i, attribs)
@@ -485,10 +488,10 @@ namespace scribo
template <typename L>
inline
- unsigned
+ typename component_set<L>::id_t
component_set<L>::id_() const
{
- return (unsigned)data_.ptr_;
+ return data_.ptr_;
}
@@ -506,7 +509,7 @@ namespace scribo
mln_concrete(L)
component_set<L>::valid_comps_image_() const
{
- mln::util::array<bool> f(unsigned(this->data_->ncomps_) + 1);
+ mln::util::array<bool> f(value::next(this->data_->ncomps_));
f(0) = true;
for_all_comps(c, (*this))
--
1.5.6.5
Show replies by date