https://svn.lrde.epita.fr/svn/oln/trunk/milena
Closes
https://trac.lrde.org/olena/ticket/135.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Have mln::util::vertex_id and mln::util::edge_id be distinct types.
* mln/util/internal/graph_base.hh
(mln::util::gen_id<Tag, Typename>): New class.
(mln::util::vertex_tag, mln::util::edge_tag): New tags
(mln::util::vertex_id, mln::util::edge_id): Define these typedefs
as specializations of mln::util::gen_id instead of unsigned.
(mln::util::graph_base<V, E>::add_edge_): Adjust.
(operator==(const edge<E>&, const edge<E>&))
(operator< (const edge<E>&, const edge<E>&)):
Add missing an inline qualifier.
(mln::util::graph_base<V, E>::vertex(vertex_id)): Have the
declarations and definitions of thee methods have the exact same
signature.
* mln/core/line_graph_psite.hh
(line_graph_psite(const p_line_graph<P>&, util::edge_id))
(mln::util::line_graph_psite<P>::id):
Likewise.
* mln/core/graph_psite.hh
(graph_psite(const p_graph<P>&, util::vertex_id)):
Likewise.
* mln/core/p_line_graph_piter.hh
(p_line_graph_fwd_piter_<P>::next_):
(p_line_graph_bkd_piter_<P>::next_):
Adjust.
* tests/morpho/lena_line_graph_image_wst1.cc: Adjust.
mln/core/graph_psite.hh | 2
mln/core/line_graph_psite.hh | 4
mln/core/p_line_graph_piter.hh | 4
mln/util/internal/graph_base.hh | 160 ++++++++++++++++++++++++++---
tests/morpho/lena_line_graph_image_wst1.cc | 2
5 files changed, 153 insertions(+), 19 deletions(-)
Index: tests/morpho/lena_line_graph_image_wst1.cc
--- tests/morpho/lena_line_graph_image_wst1.cc (revision 2002)
+++ tests/morpho/lena_line_graph_image_wst1.cc (working copy)
@@ -126,7 +126,7 @@
is bad. util:graph<N,E>::add_vertex should return this
id. */
points[p] = id;
- ++id;
+ ++id.to_equiv();
}
// Edges.
Index: mln/core/line_graph_psite.hh
--- mln/core/line_graph_psite.hh (revision 2002)
+++ mln/core/line_graph_psite.hh (working copy)
@@ -61,7 +61,7 @@
/// Construction and assignment.
/// \{
line_graph_psite();
- line_graph_psite(const p_line_graph<P>& plg, unsigned id);
+ line_graph_psite(const p_line_graph<P>& plg, util::edge_id id);
line_graph_psite(const self_& rhs);
self_& operator= (const self_& rhs);
/// \}
@@ -224,7 +224,7 @@
template<typename P>
inline
- util::vertex_id
+ util::edge_id
line_graph_psite<P>::id() const
{
return id_;
Index: mln/core/p_line_graph_piter.hh
--- mln/core/p_line_graph_piter.hh (revision 2002)
+++ mln/core/p_line_graph_piter.hh (working copy)
@@ -281,7 +281,7 @@
void
p_line_graph_fwd_piter_<P>::next_()
{
- ++id_;
+ ++id_.to_equiv();
if (is_valid())
update_();
}
@@ -422,7 +422,7 @@
void
p_line_graph_bkd_piter_<P>::next_()
{
- --id_;
+ --id_.to_equiv();
if (is_valid())
update_();
}
Index: mln/core/graph_psite.hh
--- mln/core/graph_psite.hh (revision 2002)
+++ mln/core/graph_psite.hh (working copy)
@@ -58,7 +58,7 @@
/// Construction and assignment.
/// \{
graph_psite();
- graph_psite(const p_graph<P>& pg_, unsigned id);
+ graph_psite(const p_graph<P>& pg_, util::vertex_id id);
graph_psite(const self_& rhs);
self_& operator= (const self_& rhs);
/// \}
Index: mln/util/internal/graph_base.hh
--- mln/util/internal/graph_base.hh (revision 2002)
+++ mln/util/internal/graph_base.hh (working copy)
@@ -40,35 +40,79 @@
# include <ostream>
# include <mln/core/concept/object.hh>
+
# include <mln/util/ordpair.hh>
+# include <mln/value/builtin/integers.hh>
namespace mln
{
namespace util
{
- /* FIXME: We should create actual types for vertex_id and edge_id,
- (not just typedefs), at least to prevent the user from using a
- vertex_id where an edge_id is expected (and vice versa).
- Conversion to and from unsigned would still be useful, but it
- might be safer to turn them into explicit ones.
+ /*--------------.
+ | Identifiers. |
+ `--------------*/
- See what the Vaucanson team did for the handles of
- vertices/states in their graphs/automata implemenations here:
+ /// \brief Generic identifier/handler.
+ ///
+ /// Inspired by Vaucansons's handlers for automata.
+ ///
+ ///
https://svn.lrde.epita.fr/svn/vaucanson/trunk/include/vaucanson/automata/co…
+ ///
https://svn.lrde.epita.fr/svn/vaucanson/trunk/include/vaucanson/automata/co…
+ //
+ // \todo We /might/ want to integrate this into Milena's value system.
+
+ template <typename Tag, typename Equiv>
+ class gen_id
+ {
+ typedef gen_id<Tag, Equiv> self_t;
-
https://trac.lrde.org/vaucanson/browser/trunk/include/vaucanson/automata/co…
+ public:
+ typedef Equiv equiv;
+
+ gen_id();
+ gen_id(const Equiv& e);
+ self_t& operator=(const Equiv& e);
+
+ const equiv& to_equiv() const;
+ equiv& to_equiv();
+ operator const equiv() const;
+ operator equiv();
+
+ private:
+ equiv e_;
+ };
+
+ /// Compare two identifiers.
+ /// \{
+ template <typename Tag, typename Equiv>
+ bool
+ operator==(const gen_id<Tag, Equiv>& i, const gen_id<Tag, Equiv>&
j);
+
+ template <typename Tag, typename Equiv>
+ bool
+ operator==(const Equiv& i, const gen_id<Tag, Equiv>& j);
+
+ template <typename Tag, typename Equiv>
+ bool
+ operator==(const gen_id<Tag, Equiv>& i, const Equiv j);
+ /// \}
- We /might/ want to integrate this into Milena's value system. */
+ /// Tags.
+ /// \{
+ struct vertex_tag;
+ struct edge_tag;
+ /// \}
/// \brief The type used to identify vertices.
///
/// Used internally as a key to manipulate vertices.
- typedef unsigned vertex_id;
+ typedef gen_id<vertex_tag, unsigned> vertex_id;
/// \brief The type used to identify edges.
///
/// Used internally as a key to manipulate edges.
- typedef unsigned edge_id;
+ typedef gen_id<edge_tag, unsigned> edge_id;
/*---------.
@@ -180,7 +224,7 @@
/// Return the vertex whose id is \a v.
/// \{
util::vertex<V>& vertex(vertex_id v);
- const util::vertex<V>& vertex(edge_id v) const;
+ const util::vertex<V>& vertex(vertex_id v) const;
/// \}
/// Return the edge whose id is \a e.
@@ -242,7 +286,93 @@
# ifndef MLN_INCLUDE_ONLY
+ /*--------------.
+ | Identifiers. |
+ `--------------*/
+
+ template <typename Tag, typename Equiv>
+ inline
+ gen_id<Tag, Equiv>::gen_id()
+ {
+ }
+
+ template <typename Tag, typename Equiv>
+ inline
+ gen_id<Tag, Equiv>::gen_id(const Equiv& e)
+ : e_ (e)
+ {
+ }
+
+ template <typename Tag, typename Equiv>
+ inline
+ gen_id<Tag, Equiv>&
+ gen_id<Tag, Equiv>::operator=(const Equiv& e)
+ {
+ e_ = e;
+ return *this;
+ }
+
+ template <typename Tag, typename Equiv>
+ inline
+ const Equiv&
+ gen_id<Tag, Equiv>::to_equiv() const
+ {
+ return e_;
+ }
+
+ template <typename Tag, typename Equiv>
+ inline
+ Equiv&
+ gen_id<Tag, Equiv>::to_equiv()
+ {
+ return e_;
+ }
+
+ template <typename Tag, typename Equiv>
+ inline
+ gen_id<Tag, Equiv>::operator const Equiv() const
+ {
+ return to_equiv();
+ }
+
+ template <typename Tag, typename Equiv>
+ inline
+ gen_id<Tag, Equiv>::operator Equiv()
+ {
+ return to_equiv();
+ }
+
+
+ template <typename Tag, typename Equiv>
+ inline
+ bool
+ operator==(const gen_id<Tag, Equiv>& i, const gen_id<Tag, Equiv>&
j)
+ {
+ return i.to_equiv() == j.to_equiv();
+ }
+
+ template <typename Tag, typename Equiv>
+ inline
+ bool
+ operator==(const Equiv& i, const gen_id<Tag, Equiv>& j)
+ {
+ return i == j.to_equiv();
+ }
+
+ template <typename Tag, typename Equiv>
+ inline
+ bool
+ operator==(const gen_id<Tag, Equiv>& i, const Equiv j)
+ {
+ return i.to_equiv() == j;
+ }
+
+ /*---------------------.
+ | Operators on edges. |
+ `---------------------*/
+
template <typename E>
+ inline
bool
operator==(const edge<E>& lhs, const edge<E>& rhs)
{
@@ -250,6 +380,7 @@
}
template <typename E>
+ inline
bool
operator< (const edge<E>& lhs, const edge<E>& rhs)
{
@@ -447,7 +578,10 @@
delete edge;
edge = 0;
// Return the erroneous value.
- return mln_max(edge_id);
+ /* FIXME: We have to explicitly extract the numerical
+ equivalent type here, because mln::util::gen_id<T, E>
+ is not compatible with Milena's value system (yet). */
+ return mln_max(edge_id::equiv);
}
else
{