Boost logo

Boost-Commit :

From: chochlik_at_[hidden]
Date: 2008-06-09 12:15:11


Author: matus.chochlik
Date: 2008-06-09 12:15:10 EDT (Mon, 09 Jun 2008)
New Revision: 46274
URL: http://svn.boost.org/trac/boost/changeset/46274

Log:
- Added support for traversal contexts that will be used in meta-path expressions
Added:
   sandbox/mirror/boost/mirror/visitors/dtd_writer.hpp (contents, props changed)
Removed:
   sandbox/mirror/boost/mirror/visitors/fallback.hpp
Text files modified:
   sandbox/mirror/boost/mirror/traversal.hpp | 68 ++++++++++++++++++++++++---------------
   sandbox/mirror/boost/mirror/visitors/sample.hpp | 44 +++++++++++++------------
   2 files changed, 64 insertions(+), 48 deletions(-)

Modified: sandbox/mirror/boost/mirror/traversal.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/traversal.hpp (original)
+++ sandbox/mirror/boost/mirror/traversal.hpp 2008-06-09 12:15:10 EDT (Mon, 09 Jun 2008)
@@ -21,15 +21,16 @@
 namespace mirror {
 
 
-template <class MetaClass> class deep_traversal_of;
-template <class MetaClass> class flat_traversal_of;
+template <class MetaClass, class Context> class deep_traversal_of;
+template <class MetaClass, class Context> class flat_traversal_of;
 
 namespace detail {
 
         template <
- class MetaClass,
+ class MetaClass,
+ class Context,
                 class MetaAttributes,
- template <class> class TraversalType
+ template <class, class> class TraversalType
>
         struct traversal_utils
         {
@@ -56,37 +57,40 @@
                         template <class MetaAttribute>
                         void operator ()(MetaAttribute ma) const
                         {
- process_single(ma, typename VisitorType::works_on_instances());
+ typename mpl::push_back<Context, MetaClass>::type c;
+ process_single(ma, c, typename VisitorType::works_on_instances());
                         }
                 private:
                         VisitorType& visitor;
                         typename MetaClass::reflected_type* ptr_to_inst;
 
                         // process single attribute WITH an instance
- template <class MetaAttribute>
- void process_single(MetaAttribute ma, mpl::bool_<true>) const
+ template <class MetaAttribute, class NewContext>
+ void process_single(MetaAttribute ma, NewContext ctx, mpl::bool_<true>) const
                         {
- visitor.enter_attribute(ma);
+ visitor.enter_attribute(ma, ctx);
                                 typedef typename MetaAttribute::type attrib_type;
                                 assert(ptr_to_inst != 0);
                                 typedef BOOST_TYPEOF(ma.get(*ptr_to_inst)) instance_type;
                                 instance_type instance(ma.get(*ptr_to_inst));
                                 TraversalType<
- BOOST_MIRROR_REFLECT_CLASS(attrib_type)
+ BOOST_MIRROR_REFLECT_CLASS(attrib_type),
+ typename mpl::push_back<NewContext, MetaAttribute>::type
>::accept(visitor, &instance);
- visitor.leave_attribute(ma);
+ visitor.leave_attribute(ma, ctx);
                         }
 
                         // process single attribute W/O an instance
- template <class MetaAttribute>
- void process_single(MetaAttribute ma, mpl::bool_<false>) const
+ template <class MetaAttribute, class NewContext>
+ void process_single(MetaAttribute ma, NewContext ctx, mpl::bool_<false>) const
                         {
- visitor.enter_attribute(ma);
+ visitor.enter_attribute(ma, ctx);
                                 typedef typename MetaAttribute::type attrib_type;
                                 TraversalType<
- BOOST_MIRROR_REFLECT_CLASS(attrib_type)
+ BOOST_MIRROR_REFLECT_CLASS(attrib_type),
+ typename mpl::push_back<NewContext, MetaAttribute>::type
>::accept(visitor, 0);
- visitor.leave_attribute(ma);
+ visitor.leave_attribute(ma, ctx);
                         }
                 };
         
@@ -123,12 +127,18 @@
                         template <class MetaInheritance>
                         void operator ()(MetaInheritance mbc) const
                         {
- visitor.enter_base_class(mbc);
+ typedef typename mpl::push_back<Context, MetaClass>::type
+ NewContext;
+ NewContext ctx;
+ visitor.enter_base_class(mbc, ctx);
                                 typedef MetaInheritance meta_inheritance;
                                 typedef typename meta_inheritance::meta_base_class
                                         meta_base_class;
- TraversalType<meta_base_class>::accept(visitor, ptr_to_inst);
- visitor.leave_base_class(mbc);
+ TraversalType<
+ meta_base_class,
+ typename mpl::push_back<NewContext, MetaInheritance>::type
+ >::accept(visitor, ptr_to_inst);
+ visitor.leave_base_class(mbc, ctx);
                         }
                 private:
                         VisitorType& visitor;
@@ -149,10 +159,11 @@
 
 } // namespace detail
 
-template <class MetaClass>
+template <class MetaClass, class Context = mpl::vector0<> >
 class deep_traversal_of
 : detail::traversal_utils<
- MetaClass,
+ MetaClass,
+ Context,
         typename MetaClass::attributes,
         deep_traversal_of
>
@@ -183,10 +194,11 @@
         )
         {
                 MetaClass mc;
+ Context ctx;
                 // enter the type
- visitor.get().enter_type(mc);
+ visitor.get().enter_type(mc, ctx);
                 // visit the instance
- visitor.get().visit_instance(mc, ptr_to_inst);
+ visitor.get().visit_instance(mc, ctx, ptr_to_inst);
                 // go through the base classes
                 for_each<typename MetaClass::base_classes>(
                         cref(show_bases_to(visitor, ptr_to_inst))
@@ -196,14 +208,15 @@
                         cref(show_attribs_to(visitor, ptr_to_inst))
                 );
                 // leave the type
- visitor.get().leave_type(mc);
+ visitor.get().leave_type(mc, ctx);
         }
 };
 
-template <class MetaClass>
+template <class MetaClass, class Context = mpl::vector0<> >
 class flat_traversal_of
 : detail::traversal_utils<
         MetaClass,
+ Context,
         typename MetaClass::all_attributes,
         flat_traversal_of
>
@@ -233,16 +246,17 @@
         )
         {
                 MetaClass mc;
+ Context ctx;
                 // enter the type
- visitor.get().enter_type(mc);
+ visitor.get().enter_type(mc, ctx);
                 // visit the instance
- visitor.get().visit_instance(mc, ptr_to_inst);
+ visitor.get().visit_instance(mc, ctx, ptr_to_inst);
                 // go through all of the class' attributes
                 for_each<typename MetaClass::all_attributes>(
                         cref(show_attribs_to(visitor, ptr_to_inst))
                 );
                 // leave the type
- visitor.get().leave_type(mc);
+ visitor.get().leave_type(mc, ctx);
         }
 };
 

Added: sandbox/mirror/boost/mirror/visitors/dtd_writer.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/visitors/dtd_writer.hpp 2008-06-09 12:15:10 EDT (Mon, 09 Jun 2008)
@@ -0,0 +1,103 @@
+/**
+ * \file boost/mirror/visitors/dtd_writer.hpp
+ * meta-class/type visitor that writes DTD for the given class
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_VISITORS_DTD_WRITER_HPP
+#define BOOST_MIRROR_VISITORS_DTD_WRITER_HPP
+
+// meta namespaces (includes boost/char_type_switch/string.hpp)
+#include <boost/mirror/meta_namespace.hpp>
+// meta types
+#include <boost/mirror/meta_class.hpp>
+// traits
+#include <boost/mirror/traits/reflects_virtual_inheritance.hpp>
+#include <boost/mirror/traits/reflects_global_scope.hpp>
+//
+#include <boost/type_traits/is_fundamental.hpp>
+
+namespace boost {
+namespace mirror {
+
+namespace visitors {
+
+class dtd_writer
+{
+public:
+ typedef mpl::bool_<false> works_on_instances;
+
+ dtd_writer(void){ }
+
+ // enter a class/type
+ template <class MetaClass>
+ void enter_type(MetaClass)
+ {
+ }
+
+ // leave the class/type
+ template <class MetaClass>
+ void leave_type(MetaClass)
+ {
+ }
+
+ template <class MetaClass>
+ inline void enter_base_classes(MetaClass){ }
+ template <class MetaClass>
+ inline void leave_base_classes(MetaClass){ }
+
+
+ // enter a base class
+ template <class MetaInheritance>
+ void enter_base_class(MetaInheritance)
+ {
+ using namespace ::std;
+ using namespace ::boost;
+ }
+
+ // leave base class
+ template <class MetaInheritance>
+ void leave_base_class(MetaInheritance)
+ {
+ using namespace ::std;
+ using namespace ::boost;
+ }
+
+
+ template <class MetaClass, class MetaAttributes>
+ void enter_attributes(MetaClass, MetaAttributes)
+ {
+ }
+
+ template <class MetaClass, class MetaAttributes>
+ void leave_attributes(MetaClass, MetaAttributes)
+ {
+ }
+
+ template <class MetaAttribute>
+ inline void enter_attribute(MetaAttribute)
+ {
+ using namespace ::std;
+ using namespace ::boost;
+ }
+
+ template <class MetaAttribute>
+ void leave_attribute(MetaAttribute)
+ {
+ using namespace ::std;
+ using namespace ::boost;
+ }
+
+private:
+ std::map<bstring, bstring> lines;
+};
+
+} // namespace visitors
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Deleted: sandbox/mirror/boost/mirror/visitors/fallback.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/visitors/fallback.hpp 2008-06-09 12:15:10 EDT (Mon, 09 Jun 2008)
+++ (empty file)
@@ -1,56 +0,0 @@
-/**
- * \file boost/mirror/visitors/fallback.hpp
- * Base implementation of a meta-object visitor
- *
- * Copyright 2008 Matus Chochlik. Distributed under the Boost
- * Software License, Version 1.0. (See accompanying file
- * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-
-#ifndef BOOST_MIRROR_VISITORS_FALLBACK
-#define BOOST_MIRROR_VISITORS_FALLBACK
-
-// meta namespaces (includes boost/char_type_switch/string.hpp)
-#include <boost/mirror/meta_namespace.hpp>
-// meta types
-#include <boost/mirror/meta_type.hpp>
-
-namespace boost {
-namespace mirror {
-
-struct fallback_visitor
-{
- template <class MetaClass>
- inline void enter_type(MetaClass){ }
-
- template <class MetaClass>
- inline void leave_type(MetaClass){ }
-
- template <class MetaClass>
- inline void enter_attributes(void){ }
- template <class MetaClass>
- inline void leave_attributes(void){ }
-
- template <class MetaClass>
- inline void enter_base_classes(void){ }
- template <class MetaClass>
- inline void leave_base_classes(void){ }
-
- template <class MetaInheritance>
- inline void enter_base_class(MetaInheritance){ }
-
- template <class MetaInheritance>
- inline void leave_base_class(MetaInheritance){ }
-
- template <class MetaAttribute>
- inline void enter_attribute(MetaAttribute){ }
-
- template <class MetaAttribute>
- inline void leave_attribute(MetaAttribute){ }
-};
-
-} // namespace mirror
-} // namespace boost
-
-#endif //include guard
-

Modified: sandbox/mirror/boost/mirror/visitors/sample.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/visitors/sample.hpp (original)
+++ sandbox/mirror/boost/mirror/visitors/sample.hpp 2008-06-09 12:15:10 EDT (Mon, 09 Jun 2008)
@@ -17,8 +17,7 @@
 // traits
 #include <boost/mirror/traits/reflects_virtual_inheritance.hpp>
 #include <boost/mirror/traits/reflects_global_scope.hpp>
-// the base fallback visitor implementation
-#include <boost/mirror/visitors/fallback.hpp>
+// container size
 #include <boost/mirror/algorithm/size.hpp>
 //
 //
@@ -36,8 +35,8 @@
         sample_visitor(void):indent(0){ }
 
         // enter a class/type
- template <class MetaClass>
- void enter_type(MetaClass)
+ template <class MetaClass, class Context>
+ void enter_type(MetaClass, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;
@@ -58,8 +57,8 @@
         }
 
         // leave the class/type
- template <class MetaClass>
- void leave_type(MetaClass)
+ template <class MetaClass, class Context>
+ void leave_type(MetaClass, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;
@@ -75,8 +74,8 @@
 
 
         // enter a base class
- template <class MetaInheritance>
- void enter_base_class(MetaInheritance)
+ template <class MetaInheritance, class Context>
+ void enter_base_class(MetaInheritance, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;
@@ -92,8 +91,8 @@
         }
 
         // leave base class
- template <class MetaInheritance>
- void leave_base_class(MetaInheritance)
+ template <class MetaInheritance, class Context>
+ void leave_base_class(MetaInheritance, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;
@@ -137,8 +136,8 @@
                 }
         }
 
- template <class MetaAttribute>
- inline void enter_attribute(MetaAttribute)
+ template <class MetaAttribute, class Context>
+ inline void enter_attribute(MetaAttribute, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;
@@ -153,8 +152,8 @@
                         endl;
         }
 
- template <class MetaAttribute>
- void leave_attribute(MetaAttribute)
+ template <class MetaAttribute, class Context>
+ void leave_attribute(MetaAttribute, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;
@@ -163,10 +162,11 @@
                 bcout << "</attribute>" << endl;
         }
 
- template <class MetaClass, typename InstanceType>
- void visit_instance(MetaClass, InstanceType* ptr_to_inst)
+ template <class MetaClass, class Context, typename InstanceType>
+ void visit_instance(MetaClass, Context ctx, InstanceType* ptr_to_inst)
         {
                 print_value(
+ ctx,
                         ptr_to_inst,
                         is_fundamental<typename MetaClass::reflected_type>()
                 );
@@ -174,17 +174,19 @@
 
 private:
 
- template <typename Type>
- void print_value(Type* ptr_to_inst, mpl::bool_<false>){ }
+ template <typename Type, class Context>
+ void print_value(Context, Type* ptr_to_inst, mpl::bool_<false>){ }
 
- template <typename Type>
- void print_value(Type* ptr_to_inst, mpl::bool_<true>)
+ template <typename Type, class Context>
+ void print_value(Context, Type* ptr_to_inst, mpl::bool_<true>)
         {
                 using namespace ::std;
                 using namespace ::boost;
                 print_indentation();
                 bcout <<
- "<value>" <<
+ "<value depth='" <<
+ mpl::size<Context>::value <<
+ "'>" <<
                         *ptr_to_inst <<
                         "</value>" <<
                         endl;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk