aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-20 00:26:36 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-20 00:26:36 +0000
commit4f59c11d5c5e10b1c70de2961759c49446057fe5 (patch)
treedfe27a541232456da7de67544ccacf9f16fff65e
parentf162820c7f31add0738860c7c355d482dee9f7e0 (diff)
downloadpaludis-4f59c11d5c5e10b1c70de2961759c49446057fe5.tar.gz
paludis-4f59c11d5c5e10b1c70de2961759c49446057fe5.tar.xz
Add Doxygen comments to visitor. Move Visits into visitor_internals since the unwashed masses shouldn't be touching it directy.
-rw-r--r--doc/doc_main.doxygen9
-rw-r--r--paludis/visitor.hh167
2 files changed, 124 insertions, 52 deletions
diff --git a/doc/doc_main.doxygen b/doc/doc_main.doxygen
index a2507f5..f30e12a 100644
--- a/doc/doc_main.doxygen
+++ b/doc/doc_main.doxygen
@@ -182,6 +182,15 @@
* \ingroup Utility
*/
+/** \defgroup Visitor Visitor pattern
+ * Visitor pattern.
+ *
+ * See the GoF book for how visitors work. See the test cases for how to use
+ * it.
+ *
+ * \ingroup Utility
+ */
+
/** \defgroup ConfigFile Configuration handling
* Configuration handling.
*
diff --git a/paludis/visitor.hh b/paludis/visitor.hh
index 639c0e7..d7bece5 100644
--- a/paludis/visitor.hh
+++ b/paludis/visitor.hh
@@ -21,95 +21,153 @@
#ifndef PALUDIS_GUARD_PALUDIS_VISITOR_HH
#define PALUDIS_GUARD_PALUDIS_VISITOR_HH 1
+/** \file
+ * Declares the Visitor and related classes.
+ *
+ * \ingroup Visitor
+ */
+
namespace paludis
{
template <typename NodePtrType_>
class Visits;
+ /**
+ * Internal use for Visitor classes.
+ *
+ * \ingroup Visitor
+ */
namespace visitor_internals
{
+ /**
+ * Used as a default parameter when no type is provided. The n_
+ * parameter is used to avoid inheriting the same class more than once
+ * from a single parent.
+ */
template <unsigned n_>
struct NoType
{
};
+ /**
+ * Make a pointer to a const.
+ */
template <typename>
struct MakePointerToConst;
+ /**
+ * Make a pointer to a const (specialisation for non-const pointers).
+ */
template <typename T_>
struct MakePointerToConst<T_ *>
{
+ /**
+ * Our type.
+ */
typedef const T_ * Type;
};
+
+ /**
+ * Interface: visit a class of NodePtrType_.
+ */
+ template <typename NodePtrType_>
+ class Visits
+ {
+ protected:
+ virtual ~Visits()
+ {
+ }
+
+ public:
+ virtual void visit(NodePtrType_ const) = 0;
+ };
+
+ /**
+ * Interface: don't visit NoType things.
+ */
+ template <unsigned n_>
+ class Visits<const visitor_internals::NoType<n_> * >
+ {
+ protected:
+ ~Visits()
+ {
+ }
+ };
+
+ /**
+ * Interface: don't visit NoType things.
+ */
+ template <unsigned n_>
+ class Visits<visitor_internals::NoType<n_> * >
+ {
+ protected:
+ ~Visits()
+ {
+ }
+ };
}
+ /**
+ * A class that inherits virtually from VisitableInterface can accept a
+ * visitor that is descended from one of the VisitorType_ subclasses.
+ */
template <typename VisitorType_>
class VisitableInterface
{
protected:
+ /**
+ * Destructor.
+ */
virtual ~VisitableInterface()
{
}
public:
+ /**
+ * Accept a visitor.
+ */
virtual void accept(typename VisitorType_::Visitor * const) = 0;
+ /**
+ * Accept a constant visitor.
+ */
virtual void accept(typename VisitorType_::ConstVisitor * const) const = 0;
};
+ /**
+ * A class that inherits (non-virtually) from Visitable provides an
+ * implementation of VisitableInterface.
+ */
template <typename OurType_, typename VisitorType_>
class Visitable :
public virtual VisitableInterface<VisitorType_>
{
protected:
- ~Visitable()
+ /**
+ * Destructor.
+ */
+ virtual ~Visitable()
{
}
public:
virtual void accept(typename VisitorType_::Visitor * const v)
{
- static_cast<Visits<OurType_ *> *>(v)->visit(
+ static_cast<visitor_internals::Visits<OurType_ *> *>(v)->visit(
static_cast<OurType_ *>(this));
}
virtual void accept(typename VisitorType_::ConstVisitor * const v) const
{
- static_cast<Visits<const OurType_ *> *>(v)->visit(
+ static_cast<visitor_internals::Visits<const OurType_ *> *>(v)->visit(
static_cast<const OurType_ *>(this));
}
};
- template <typename NodePtrType_>
- class Visits
- {
- protected:
- virtual ~Visits()
- {
- }
-
- public:
- virtual void visit(NodePtrType_ const) = 0;
- };
-
- template <unsigned n_>
- class Visits<const visitor_internals::NoType<n_> * >
- {
- protected:
- virtual ~Visits()
- {
- }
- };
-
- template <unsigned n_>
- class Visits<visitor_internals::NoType<n_> * >
- {
- protected:
- virtual ~Visits()
- {
- }
- };
-
+ /**
+ * Create the base classes for constant and non-constant visitors to the
+ * specified node types.
+ */
template <
typename N1_,
typename N2_ = visitor_internals::NoType<2> *,
@@ -125,31 +183,36 @@ namespace paludis
private:
VisitorTypes();
-
public:
+ /**
+ * A ConstVisitor descendent visits nodes via a const pointer.
+ */
class ConstVisitor :
- public Visits<typename visitor_internals::MakePointerToConst<N1_>::Type>,
- public Visits<typename visitor_internals::MakePointerToConst<N2_>::Type>,
- public Visits<typename visitor_internals::MakePointerToConst<N3_>::Type>,
- public Visits<typename visitor_internals::MakePointerToConst<N4_>::Type>,
- public Visits<typename visitor_internals::MakePointerToConst<N5_>::Type>,
- public Visits<typename visitor_internals::MakePointerToConst<N6_>::Type>,
- public Visits<typename visitor_internals::MakePointerToConst<N7_>::Type>,
- public Visits<typename visitor_internals::MakePointerToConst<N8_>::Type>,
- public Visits<typename visitor_internals::MakePointerToConst<N9_>::Type>
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N1_>::Type>,
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N2_>::Type>,
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N3_>::Type>,
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N4_>::Type>,
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N5_>::Type>,
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N6_>::Type>,
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N7_>::Type>,
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N8_>::Type>,
+ public visitor_internals::Visits<typename visitor_internals::MakePointerToConst<N9_>::Type>
{
};
+ /**
+ * A Visitor descendent visits nodes via a non-const pointer.
+ */
class Visitor :
- public Visits<N1_>,
- public Visits<N2_>,
- public Visits<N3_>,
- public Visits<N4_>,
- public Visits<N5_>,
- public Visits<N6_>,
- public Visits<N7_>,
- public Visits<N8_>,
- public Visits<N9_>
+ public visitor_internals::Visits<N1_>,
+ public visitor_internals::Visits<N2_>,
+ public visitor_internals::Visits<N3_>,
+ public visitor_internals::Visits<N4_>,
+ public visitor_internals::Visits<N5_>,
+ public visitor_internals::Visits<N6_>,
+ public visitor_internals::Visits<N7_>,
+ public visitor_internals::Visits<N8_>,
+ public visitor_internals::Visits<N9_>
{
};
};