Boost logo

Boost-Commit :

From: chochlik_at_[hidden]
Date: 2008-06-13 09:16:33


Author: matus.chochlik
Date: 2008-06-13 09:16:32 EDT (Fri, 13 Jun 2008)
New Revision: 46370
URL: http://svn.boost.org/trac/boost/changeset/46370

Log:
updated the traversal contexts

Text files modified:
   sandbox/mirror/boost/mirror/traversal.hpp | 101 ++++++++++++++++++++++++++++++++-------
   sandbox/mirror/boost/mirror/visitors/dtd_writer.hpp | 92 +++++++++++++++++++++++++++--------
   sandbox/mirror/boost/mirror/visitors/sample.hpp | 16 +++---
   3 files changed, 161 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-13 09:16:32 EDT (Fri, 13 Jun 2008)
@@ -35,6 +35,9 @@
         struct traversal_utils
         {
         protected:
+ typedef typename mpl::push_back<Context, MetaClass>::type
+ ClassContext;
+
                 template <class VisitorType>
                 class attribute_traversal
                 {
@@ -46,54 +49,103 @@
                         : visitor(_visitor)
                         , ptr_to_inst(_ptr_to_inst)
                         {
- visitor.enter_attributes(MetaClass(), MetaAttributes());
+ visitor.enter_attributes(
+ MetaClass(),
+ MetaAttributes(),
+ ClassContext()
+ );
                         }
         
                         ~attribute_traversal(void)
                         {
- visitor.leave_attributes(MetaClass(), MetaAttributes());
+ visitor.leave_attributes(
+ MetaClass(),
+ MetaAttributes(),
+ ClassContext()
+ );
                         }
         
                         template <class MetaAttribute>
                         void operator ()(MetaAttribute ma) const
                         {
- typename mpl::push_back<Context, MetaClass>::type c;
- process_single(ma, c, typename VisitorType::works_on_instances());
+ // update the traversal context
+ typename mpl::push_back<
+ ClassContext,
+ MetaAttributes
+ >::type ctx;
+ //
+ // process a single attribute
+ process_single(
+ ma,
+ ctx,
+ typename VisitorType::works_on_instances()
+ );
                         }
                 private:
                         VisitorType& visitor;
                         typename MetaClass::reflected_type* ptr_to_inst;
 
                         // process single attribute WITH an instance
- template <class MetaAttribute, class NewContext>
- void process_single(MetaAttribute ma, NewContext ctx, mpl::bool_<true>) const
+ template <class MetaAttribute, class AttribsContext>
+ void process_single(
+ MetaAttribute ma,
+ AttribsContext ctx,
+ mpl::bool_<true>
+ ) const
                         {
+ // enter the attribute
                                 visitor.enter_attribute(ma, ctx);
+ //
+ // get the type of the attribute
                                 typedef typename MetaAttribute::type attrib_type;
+ //
+ // the poiner has to be valid
                                 assert(ptr_to_inst != 0);
+ //
+ // get an attribute instance
                                 typedef BOOST_TYPEOF(ma.get(*ptr_to_inst)) instance_type;
                                 instance_type instance(ma.get(*ptr_to_inst));
+ //
+ // traverse the attribute
                                 TraversalType<
                                         BOOST_MIRROR_REFLECT_CLASS(attrib_type),
- typename mpl::push_back<NewContext, MetaAttribute>::type
+ typename mpl::push_back<
+ AttribsContext,
+ MetaAttribute
+ >::type
>::accept(visitor, &instance);
+ //
+ // leave the attribute
                                 visitor.leave_attribute(ma, ctx);
                         }
 
                         // process single attribute W/O an instance
- template <class MetaAttribute, class NewContext>
- void process_single(MetaAttribute ma, NewContext ctx, mpl::bool_<false>) const
+ template <class MetaAttribute, class AttribsContext>
+ void process_single(
+ MetaAttribute ma,
+ AttribsContext ctx,
+ mpl::bool_<false>
+ ) const
                         {
+ // enter the attribute
                                 visitor.enter_attribute(ma, ctx);
+ //
+ // traverse the attributes
                                 typedef typename MetaAttribute::type attrib_type;
                                 TraversalType<
                                         BOOST_MIRROR_REFLECT_CLASS(attrib_type),
- typename mpl::push_back<NewContext, MetaAttribute>::type
+ typename mpl::push_back<
+ AttribsContext,
+ MetaAttribute
+ >::type
>::accept(visitor, 0);
+ //
+ // leave the attributes
                                 visitor.leave_attribute(ma, ctx);
                         }
                 };
         
+ // attribute_traversal factory function
                 template <class VisitorType>
                 static inline attribute_traversal<VisitorType>
                 show_attribs_to(
@@ -116,28 +168,40 @@
                         : visitor(_visitor)
                         , ptr_to_inst(_ptr_to_inst)
                         {
- visitor.enter_base_classes(MetaClass());
+ visitor.enter_base_classes(
+ MetaClass(),
+ ClassContext()
+ );
                         }
         
                         ~base_class_traversal(void)
                         {
- visitor.leave_base_classes(MetaClass());
+ visitor.leave_base_classes(
+ MetaClass(),
+ ClassContext()
+ );
                         }
         
                         template <class MetaInheritance>
                         void operator ()(MetaInheritance mbc) const
                         {
- typedef typename mpl::push_back<Context, MetaClass>::type
- NewContext;
- NewContext ctx;
+ ClassContext ctx;
+ //
+ // enter the base cass
                                 visitor.enter_base_class(mbc, ctx);
- typedef MetaInheritance meta_inheritance;
- typedef typename meta_inheritance::meta_base_class
+ //
+ // get the meta-class of the base class
+ typedef typename MetaInheritance::meta_base_class
                                         meta_base_class;
+ // traverse the base class
                                 TraversalType<
                                         meta_base_class,
- typename mpl::push_back<NewContext, MetaInheritance>::type
+ typename mpl::push_back<
+ ClassContext,
+ MetaInheritance
+ >::type
>::accept(visitor, ptr_to_inst);
+ // leave the base class
                                 visitor.leave_base_class(mbc, ctx);
                         }
                 private:
@@ -145,6 +209,7 @@
                         typename MetaClass::reflected_type* ptr_to_inst;
                 };
 
+ // base class traversal factory function
                 template <class VisitorType>
                 static inline base_class_traversal<VisitorType>
                 show_bases_to(

Modified: sandbox/mirror/boost/mirror/visitors/dtd_writer.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/visitors/dtd_writer.hpp (original)
+++ sandbox/mirror/boost/mirror/visitors/dtd_writer.hpp 2008-06-13 09:16:32 EDT (Fri, 13 Jun 2008)
@@ -19,6 +19,10 @@
 #include <boost/mirror/traits/reflects_global_scope.hpp>
 //
 #include <boost/type_traits/is_fundamental.hpp>
+//
+#include <vector>
+#include <map>
+
 
 namespace boost {
 namespace mirror {
@@ -28,71 +32,115 @@
 class dtd_writer
 {
 public:
+ //! this writer works on types
         typedef mpl::bool_<false> works_on_instances;
 
- dtd_writer(void){ }
+ //! constructs a new dtd writer
+ dtd_writer(const bstring& _docRootName)
+ : documentRootInfo(_docRootName)
+ { }
 
         // enter a class/type
- template <class MetaClass>
- void enter_type(MetaClass)
+ template <class MetaClass, class Context>
+ void enter_type(MetaClass, Context)
         {
         }
 
         // leave the class/type
- template <class MetaClass>
- void leave_type(MetaClass)
+ template <class MetaClass, class Context>
+ void leave_type(MetaClass, Context)
         {
         }
 
- template <class MetaClass>
- inline void enter_base_classes(MetaClass){ }
- template <class MetaClass>
- inline void leave_base_classes(MetaClass){ }
+ template <class MetaClass, class Context>
+ inline void enter_base_classes(MetaClass, Context){ }
+ template <class MetaClass, class Context>
+ inline void leave_base_classes(MetaClass, Context){ }
 
 
         // 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;
         }
 
         // 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;
         }
 
 
- template <class MetaClass, class MetaAttributes>
- void enter_attributes(MetaClass, MetaAttributes)
+ template <class MetaClass, class MetaAttributes, class Context>
+ void enter_attributes(MetaClass, MetaAttributes, Context)
         {
         }
 
- template <class MetaClass, class MetaAttributes>
- void leave_attributes(MetaClass, MetaAttributes)
+ template <class MetaClass, class MetaAttributes, class Context>
+ void leave_attributes(MetaClass, MetaAttributes, Context)
         {
         }
 
- 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;
         }
 
- template <class MetaAttribute>
- void leave_attribute(MetaAttribute)
+ template <class MetaAttribute, class Context>
+ void leave_attribute(MetaAttribute, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;
         }
 
 private:
- std::map<bstring, bstring> lines;
+ // information about a single element
+ struct element_info
+ {
+ // the name of the element
+ bstring name;
+ // the type of the element
+ bstring type_name;
+ //
+ // does not need to occur
+ bool card_zero;
+ // can appear once
+ bool card_one;
+ // can appear multiple times
+ bool card_multi;
+
+ element_info(
+ const bstring& _name,
+ const bstring& _type_name = bstring(),
+ bool _card_zero = false,
+ bool _card_one = true,
+ bool _card_multi = false
+ )
+ : name(_name)
+ , type_name(_type_name)
+ , card_zero(_card_zero)
+ , card_one(_card_one)
+ , card_multi(_card_multi)
+ { }
+ };
+
+ // the information about the root element
+ element_info documentRootInfo;
+
+ // the type for definition of an elements child nodes
+ typedef ::std::vector<element_info> element_nodes;
+ //
+ // the type that is used to store information about various
+ // types of elements
+ typedef ::std::map<bstring, element_nodes> type_info_table;
+ //
+ type_info_table type_infos;
 };
 
 } // namespace visitors

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-13 09:16:32 EDT (Fri, 13 Jun 2008)
@@ -67,10 +67,10 @@
                 bcout << "</type>" << endl;
         }
 
- template <class MetaClass>
- inline void enter_base_classes(MetaClass){ }
- template <class MetaClass>
- inline void leave_base_classes(MetaClass){ }
+ template <class MetaClass, class Context>
+ inline void enter_base_classes(MetaClass, Context){ }
+ template <class MetaClass, class Context>
+ inline void leave_base_classes(MetaClass, Context){ }
 
 
         // enter a base class
@@ -102,8 +102,8 @@
         }
 
 
- template <class MetaClass, class MetaAttributes>
- void enter_attributes(MetaClass, MetaAttributes)
+ template <class MetaClass, class MetaAttributes, class Context>
+ void enter_attributes(MetaClass, MetaAttributes, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;
@@ -120,8 +120,8 @@
                 }
         }
 
- template <class MetaClass, class MetaAttributes>
- void leave_attributes(MetaClass, MetaAttributes)
+ template <class MetaClass, class MetaAttributes, class Context>
+ void leave_attributes(MetaClass, MetaAttributes, Context)
         {
                 using namespace ::std;
                 using namespace ::boost;


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