Introduce graph_psite_base.
---
.../{graph_vertex_psite.hh => graph_psite_base.hh} | 126 ++++++++++---------
milena/mln/util/internal/graph_vertex_psite.hh | 109 +++--------------
2 files changed, 82 insertions(+), 153 deletions(-)
copy milena/mln/util/internal/{graph_vertex_psite.hh => graph_psite_base.hh} (51%)
diff --git a/milena/mln/util/internal/graph_vertex_psite.hh
b/milena/mln/util/internal/graph_psite_base.hh
similarity index 51%
copy from milena/mln/util/internal/graph_vertex_psite.hh
copy to milena/mln/util/internal/graph_psite_base.hh
index b2fadf9..fa0fb80 100644
--- a/milena/mln/util/internal/graph_vertex_psite.hh
+++ b/milena/mln/util/internal/graph_psite_base.hh
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_UTIL_INTERNAL_GRAPH_VERTEX_PSITE_HH
-# define MLN_UTIL_INTERNAL_GRAPH_VERTEX_PSITE_HH
+#ifndef MLN_UTIL_INTERNAL_GRAPH_PSITE_BASE_HH
+# define MLN_UTIL_INTERNAL_GRAPH_PSITE_BASE_HH
# include <mln/core/concept/pseudo_site.hh>
@@ -37,8 +37,8 @@ namespace mln
} // end of namespace mln
-/// \file mln/util/internal/graph_vertex_psite.hh
-/// \brief Implementation of p_vertices psite.
+/// \file mln/util/internal/graph_psite_base.hh
+/// \brief Base implementation for graph based psites.
namespace mln
{
@@ -46,38 +46,58 @@ namespace mln
namespace internal
{
- template <typename G, typename F>
- class vertex_psite : public mln::Pseudo_Site< vertex_psite<G, F> >,
- public internal::proxy_impl< const typename F::result&, vertex_psite<G,
F> >
+ template <typename V, typename P, typename S, typename E>
+ class graph_psite_base : public mln::Pseudo_Site<E>,
+ public internal::proxy_impl<const P&, E>
{
- typedef Pseudo_Site< vertex_psite<G, F> > super;
+ typedef Pseudo_Site< graph_psite_base<V, P, S, E> > super;
public:
- typedef p_vertices<G, F> site_set;
- typedef mlc_const(site_set) target;
- typedef typename F::result site;
-
- vertex_psite();
- vertex_psite(const target& t);
-
+ /// Associated types.
+ /// \{
+ typedef P site;
+ typedef S target;
+ /// \}
+
+
+ /// Constructors.
+ /// \{
+ graph_psite_base();
+ /// \p t A site set.
+ /// \sa p_vertices, p_edges.
+ graph_psite_base(const target& t);
+ /// \}
+
+ /// Setters.
+ /// \{
+ /// Change the targe site set.
void change_target(const target& new_target);
- void change_vertex_id(unsigned id_v);
+ /// Update the underlying element's id.
+ /// This element can be an edge, a vertex...
void update_id(unsigned v_id);
+ /// \}
+ /// Return the target (the site set).
const target* target_() const; // Hook to the target.
+ /// Check whether it is valid.
bool is_valid() const;
+ /// Invalidate this psite.
void invalidate();
+ /// Pseudo site Interface
+ /// \{
+ /// Subject type.
typedef const site& q_subject;
+ /// Return the subject.
const site& subj_();
+ /// Return the underlying site.
const site& to_site() const;
-
- const util::vertex<G>& v() const;
+ /// \}
protected:
- target* t_;
- util::vertex<G> v_;
+ mlc_const(target)* t_;
+ V v_;
};
} // end of namespace internal
@@ -93,98 +113,84 @@ namespace mln
namespace internal
{
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
- vertex_psite<G, F>::vertex_psite()
+ graph_psite_base<V, P, S, E>::graph_psite_base()
: t_(0)
{
}
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
- vertex_psite<G, F>::vertex_psite(const target& t)
+ graph_psite_base<V, P, S, E>::graph_psite_base(const target& t)
: t_(0)
{
change_target(t);
}
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
void
- vertex_psite<G, F>::change_target(const target& new_target)
+ graph_psite_base<V, P, S, E>::change_target(const target& new_target)
{
t_ = &new_target;
v_.change_graph(new_target.g());
}
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
void
- vertex_psite<G, F>::change_vertex_id(unsigned id_v)
+ graph_psite_base<V, P, S, E>::update_id(unsigned id)
{
- v_.update_id(id_v);
+ v_.update_id(id);
}
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
- void
- vertex_psite<G, F>::update_id(unsigned v_id)
- {
- v_.update_id(v_id);
- }
-
- template <typename G, typename F>
- inline
- const typename vertex_psite<G, F>::target*
- vertex_psite<G, F>::target_() const
+ const typename graph_psite_base<V, P, S, E>::target*
+ graph_psite_base<V, P, S, E>::target_() const
{
return t_;
}
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
bool
- vertex_psite<G, F>::is_valid() const
+ graph_psite_base<V, P, S, E>::is_valid() const
{
- return t_ != 0 && t_->is_valid();
+ return t_ != 0 && t_->is_valid() && v_.is_valid();
}
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
void
- vertex_psite<G, F>::invalidate()
+ graph_psite_base<V, P, S, E>::invalidate()
{
t_ = 0;
+ v_.invalidate();
}
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
- const typename vertex_psite<G, F>::site&
- vertex_psite<G, F>::subj_()
+ const typename graph_psite_base<V, P, S, E>::site&
+ graph_psite_base<V, P, S, E>::subj_()
{
return to_site();
}
- template <typename G, typename F>
+ template <typename V, typename P, typename S, typename E>
inline
- const typename vertex_psite<G, F>::site&
- vertex_psite<G, F>::to_site() const
+ const typename graph_psite_base<V, P, S, E>::site&
+ graph_psite_base<V, P, S, E>::to_site() const
{
return t_->function()(v_);
}
- template <typename G, typename F>
- inline
- const util::vertex<G>&
- vertex_psite<G, F>::v() const
- {
- return v_;
- }
-
} // end of namespace internal
} // end of namespace mln
+
# endif // !MLN_INCLUDE_ONLY
-#endif // !MLN_UTIL_INTERNAL_GRAPH_VERTEX_PSITE_HH
+#endif // !MLN_UTIL_INTERNAL_GRAPH_PSITE_BASE_HH
diff --git a/milena/mln/util/internal/graph_vertex_psite.hh
b/milena/mln/util/internal/graph_vertex_psite.hh
index b2fadf9..b0b57cd 100644
--- a/milena/mln/util/internal/graph_vertex_psite.hh
+++ b/milena/mln/util/internal/graph_vertex_psite.hh
@@ -29,6 +29,7 @@
# define MLN_UTIL_INTERNAL_GRAPH_VERTEX_PSITE_HH
# include <mln/core/concept/pseudo_site.hh>
+# include <mln/util/internal/graph_psite_base.hh>
namespace mln
{
@@ -47,37 +48,26 @@ namespace mln
{
template <typename G, typename F>
- class vertex_psite : public mln::Pseudo_Site< vertex_psite<G, F> >,
- public internal::proxy_impl< const typename F::result&, vertex_psite<G,
F> >
+ class vertex_psite :
+ public graph_psite_base<util::vertex<G>, typename F::result,
+ p_vertices<G, F>,
+ vertex_psite<G, F> >
{
- typedef Pseudo_Site< vertex_psite<G, F> > super;
+ typedef vertex_psite<G, F> self_;
+ typedef p_vertices<G, F> target_t;
+ typedef graph_psite_base<util::vertex<G>, typename F::result, target_t,
self_> super_;
+ typedef util::vertex<G> vertex_t;
- public:
- typedef p_vertices<G, F> site_set;
- typedef mlc_const(site_set) target;
+ public:
typedef typename F::result site;
vertex_psite();
- vertex_psite(const target& t);
+ vertex_psite(const target_t& t);
- void change_target(const target& new_target);
- void change_vertex_id(unsigned id_v);
- void update_id(unsigned v_id);
-
- const target* target_() const; // Hook to the target.
-
- bool is_valid() const;
- void invalidate();
-
- typedef const site& q_subject;
- const site& subj_();
- const site& to_site() const;
-
- const util::vertex<G>& v() const;
+ const vertex_t& v() const;
protected:
- target* t_;
- util::vertex<G> v_;
+ using super_::v_;
};
} // end of namespace internal
@@ -96,86 +86,19 @@ namespace mln
template <typename G, typename F>
inline
vertex_psite<G, F>::vertex_psite()
- : t_(0)
- {
- }
-
- template <typename G, typename F>
- inline
- vertex_psite<G, F>::vertex_psite(const target& t)
- : t_(0)
- {
- change_target(t);
- }
-
- template <typename G, typename F>
- inline
- void
- vertex_psite<G, F>::change_target(const target& new_target)
- {
- t_ = &new_target;
- v_.change_graph(new_target.g());
- }
-
- template <typename G, typename F>
- inline
- void
- vertex_psite<G, F>::change_vertex_id(unsigned id_v)
- {
- v_.update_id(id_v);
- }
-
- template <typename G, typename F>
- inline
- void
- vertex_psite<G, F>::update_id(unsigned v_id)
- {
- v_.update_id(v_id);
- }
-
- template <typename G, typename F>
- inline
- const typename vertex_psite<G, F>::target*
- vertex_psite<G, F>::target_() const
- {
- return t_;
- }
-
- template <typename G, typename F>
- inline
- bool
- vertex_psite<G, F>::is_valid() const
- {
- return t_ != 0 && t_->is_valid();
- }
-
- template <typename G, typename F>
- inline
- void
- vertex_psite<G, F>::invalidate()
- {
- t_ = 0;
- }
-
- template <typename G, typename F>
- inline
- const typename vertex_psite<G, F>::site&
- vertex_psite<G, F>::subj_()
{
- return to_site();
}
template <typename G, typename F>
inline
- const typename vertex_psite<G, F>::site&
- vertex_psite<G, F>::to_site() const
+ vertex_psite<G, F>::vertex_psite(const target_t& t)
{
- return t_->function()(v_);
+ this->change_target(t);
}
template <typename G, typename F>
inline
- const util::vertex<G>&
+ const typename vertex_psite<G, F>::vertex_t&
vertex_psite<G, F>::v() const
{
return v_;
--
1.5.6.5