|
Boost-Commit : |
From: chochlik_at_[hidden]
Date: 2008-06-02 12:34:11
Author: matus.chochlik
Date: 2008-06-02 12:34:10 EDT (Mon, 02 Jun 2008)
New Revision: 46048
URL: http://svn.boost.org/trac/boost/changeset/46048
Log:
Updated several things concerning visitors
Text files modified:
sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp | 19 ++++++++
sandbox/mirror/boost/mirror/traversal.hpp | 84 ++++++++++++++++++++++++++++++---------
sandbox/mirror/boost/mirror/visitors/fallback.hpp | 26 +++++++++++
sandbox/mirror/boost/mirror/visitors/sample.hpp | 64 ++++++++++++++++++++++++------
sandbox/mirror/libs/mirror/doc/xml/mirror/_library.xml | 9 ++++
5 files changed, 166 insertions(+), 36 deletions(-)
Modified: sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp (original)
+++ sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp 2008-06-02 12:34:10 EDT (Mon, 02 Jun 2008)
@@ -79,7 +79,6 @@
* after the specific stuff.
*/
#define BOOST_MIRROR_REG_CLASS_OR_TEMPL_ATTRIB_EPILOGUE(NUMBER, TYPE, NAME, TYPENAME_KW) \
- BOOST_MIRROR_DECLARE_ATTRIB_OUTLINE(NUMBER, TYPE, NAME) \
typedef TYPENAME_KW mpl::push_back<_partial_list_##NUMBER, TYPE>::type
@@ -185,6 +184,24 @@
BOOST_MIRROR_REG_TEMPLATE_ATTRIB_DECL_SIMPLE_SET(NUMBER, TYPE, NAME) \
BOOST_MIRROR_REG_TEMPLATE_ATTRIB_EPILOGUE(NUMBER, TYPE, NAME)
+/** This macro declares the meta-data for a single class' attribute outline
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_OUTLINE(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_PROLOGUE(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SIMPLE_GET(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SIMPLE_SET(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_DECLARE_ATTRIB_OUTLINE(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE(NUMBER, TYPE, NAME)
+
+/** This macro declares the meta-data for a single templates attribute
+ */
+#define BOOST_MIRROR_REG_TEMPLATE_ATTRIB_OUTLINE(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_PROLOGUE(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_REG_TEMPLATE_ATTRIB_DECL_SIMPLE_GET(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_REG_TEMPLATE_ATTRIB_DECL_SIMPLE_SET(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_DECLARE_ATTRIB_OUTLINE(NUMBER, TYPE, NAME) \
+ BOOST_MIRROR_REG_TEMPLATE_ATTRIB_EPILOGUE(NUMBER, TYPE, NAME)
+
/** This macro declares the meta-data for a single class' typedefd attribute
*/
#define BOOST_MIRROR_REG_CLASS_ATTRIB_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, NAME) \
Modified: sandbox/mirror/boost/mirror/traversal.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/traversal.hpp (original)
+++ sandbox/mirror/boost/mirror/traversal.hpp 2008-06-02 12:34:10 EDT (Mon, 02 Jun 2008)
@@ -12,17 +12,19 @@
#include <boost/mirror/meta_class.hpp>
#include <boost/mirror/algorithm/for_each.hpp>
+//
+#include <boost/ref.hpp>
namespace boost {
namespace mirror {
-template <class MetaClass> struct deep_traversal_of;
-template <class MetaClass> struct flat_traversal_of;
+template <class MetaClass> class deep_traversal_of;
+template <class MetaClass> class flat_traversal_of;
namespace detail {
- template <class MetaClass>
+ template <class MetaClass, class MetaAttributes>
struct traversal_utils
{
protected:
@@ -30,8 +32,16 @@
class attribute_traversal
{
public:
- attribute_traversal(VisitorType _visitor)
- : visitor(_visitor){ }
+ attribute_traversal(reference_wrapper<VisitorType> _visitor)
+ : visitor(_visitor)
+ {
+ visitor.enter_attributes<MetaClass, MetaAttributes>();
+ }
+
+ ~attribute_traversal(void)
+ {
+ visitor.leave_attributes<MetaClass, MetaAttributes>();
+ }
template <class MetaAttribute>
void operator ()(MetaAttribute ma)
@@ -45,12 +55,12 @@
visitor.leave_attribute(ma);
}
private:
- VisitorType visitor;
+ VisitorType& visitor;
};
template <class VisitorType>
static inline attribute_traversal<VisitorType>
- show_attribs_to(VisitorType visitor)
+ show_attribs_to(reference_wrapper<VisitorType> visitor)
{
return attribute_traversal<VisitorType>(visitor);
}
@@ -59,8 +69,16 @@
class base_class_traversal
{
public:
- base_class_traversal(VisitorType _visitor)
- : visitor(_visitor){ }
+ base_class_traversal(reference_wrapper<VisitorType> _visitor)
+ : visitor(_visitor)
+ {
+ visitor.enter_base_classes<MetaClass>();
+ }
+
+ ~base_class_traversal(void)
+ {
+ visitor.leave_base_classes<MetaClass>();
+ }
template <class MetaInheritance>
void operator ()(MetaInheritance mbc)
@@ -73,12 +91,12 @@
visitor.leave_base_class(mbc);
}
private:
- VisitorType visitor;
+ VisitorType& visitor;
};
template <class VisitorType>
static inline base_class_traversal<VisitorType>
- show_bases_to(VisitorType visitor)
+ show_bases_to(reference_wrapper<VisitorType> visitor)
{
return base_class_traversal<VisitorType>(visitor);
}
@@ -88,31 +106,57 @@
} // namespace detail
template <class MetaClass>
-struct deep_traversal_of : detail::traversal_utils<MetaClass>
+class deep_traversal_of
+: detail::traversal_utils<MetaClass, typename MetaClass::attributes>
{
+public:
template <class VisitorType>
static void accept(VisitorType visitor)
{
+ do_accept(ref<VisitorType>(visitor));
+ }
+ template <class VisitorType>
+ static void accept(reference_wrapper<VisitorType> visitor)
+ {
+ do_accept(visitor);
+ }
+private:
+ template <class VisitorType>
+ static void do_accept(reference_wrapper<VisitorType> visitor)
+ {
typedef MetaClass meta_class;
meta_class mc;
- visitor.enter_type(mc);
- for_each<typename meta_class::base_classes>(show_bases_to(visitor));
- for_each<typename meta_class::attributes>(show_attribs_to(visitor));
- visitor.leave_type(mc);
+ visitor.get().enter_type(mc);
+ for_each<typename meta_class::base_classes>(ref(show_bases_to(visitor)));
+ for_each<typename meta_class::attributes>(ref(show_attribs_to(visitor)));
+ visitor.get().leave_type(mc);
}
};
template <class MetaClass>
-struct flat_traversal_of : detail::traversal_utils<MetaClass>
+class flat_traversal_of
+: detail::traversal_utils<MetaClass, typename MetaClass::all_attributes>
{
+public:
template <class VisitorType>
static void accept(VisitorType visitor)
{
+ do_accept(ref<VisitorType>(visitor));
+ }
+ template <class VisitorType>
+ static void accept(reference_wrapper<VisitorType> visitor)
+ {
+ do_accept(visitor);
+ }
+private:
+ template <class VisitorType>
+ static void do_accept(reference_wrapper<VisitorType> visitor)
+ {
typedef MetaClass meta_class;
meta_class mc;
- visitor.enter_type(mc);
- for_each<typename meta_class::all_attributes>(show_attribs_to(visitor));
- visitor.leave_type(mc);
+ visitor.get().enter_type(mc);
+ for_each<typename meta_class::all_attributes>(ref(show_attribs_to(visitor)));
+ visitor.get().leave_type(mc);
}
};
Modified: sandbox/mirror/boost/mirror/visitors/fallback.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/visitors/fallback.hpp (original)
+++ sandbox/mirror/boost/mirror/visitors/fallback.hpp 2008-06-02 12:34:10 EDT (Mon, 02 Jun 2008)
@@ -21,10 +21,32 @@
struct fallback_visitor
{
template <class MetaClass>
- void enter_type(MetaClass){ }
+ inline void enter_type(MetaClass){ }
template <class MetaClass>
- void leave_type(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
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-02 12:34:10 EDT (Mon, 02 Jun 2008)
@@ -19,11 +19,14 @@
#include <boost/mirror/traits/reflects_global_scope.hpp>
// the base fallback visitor implementation
#include <boost/mirror/visitors/fallback.hpp>
+//
+//
+#include <boost/type_traits/is_fundamental.hpp>
namespace boost {
namespace mirror {
-class sample_visitor : public fallback_visitor
+class sample_visitor
{
public:
sample_visitor(void):indent(0){ }
@@ -61,9 +64,15 @@
bcout << "</type>" << endl;
}
+ template <class MetaClass>
+ inline void enter_base_classes(void){ }
+ template <class MetaClass>
+ inline void leave_base_classes(void){ }
+
+
// enter a base class
- template <class meta_inheritance>
- void enter_base_class(meta_inheritance)
+ template <class MetaInheritance>
+ void enter_base_class(MetaInheritance)
{
using namespace ::std;
using namespace ::boost;
@@ -71,16 +80,16 @@
++indent;
bcout <<
"<base_class number='" <<
- meta_inheritance::position::value <<
+ MetaInheritance::position::value <<
"' is_virtual='"<<
- (reflects_virtual_inheritance<meta_inheritance>::value ? "true" : "false") <<
+ (reflects_virtual_inheritance<MetaInheritance>::value ? "true" : "false") <<
"'>" <<
endl;
}
// leave base class
- template <class MetaClass>
- void leave_base_class(MetaClass)
+ template <class MetaInheritance>
+ void leave_base_class(MetaInheritance)
{
using namespace ::std;
using namespace ::boost;
@@ -89,8 +98,37 @@
bcout << "</base_class>" << endl;
}
- template <class meta_attribute>
- void enter_attribute(meta_attribute)
+
+ template <class MetaClass, class MetaAttributes>
+ void enter_attributes(void)
+ {
+ using namespace ::std;
+ using namespace ::boost;
+ if(!is_fundamental<MetaClass::reflected_type>::value && (mirror::size<MetaAttributes>::value > 0))
+ {
+ print_indentation();
+ ++indent;
+ bcout <<
+ "<attributes>" <<
+ endl;
+ }
+ }
+
+ template <class MetaClass, class MetaAttributes>
+ inline void leave_attributes(void)
+ {
+ using namespace ::std;
+ using namespace ::boost;
+ if(!is_fundamental<MetaClass::reflected_type>::value && (mirror::size<MetaAttributes>::value > 0))
+ {
+ --indent;
+ print_indentation();
+ bcout << "</attributes>" << endl;
+ }
+ }
+
+ template <class MetaAttribute>
+ inline void enter_attribute(MetaAttribute)
{
using namespace ::std;
using namespace ::boost;
@@ -98,15 +136,15 @@
++indent;
bcout <<
"<attribute number='" <<
- meta_attribute::position::value <<
+ MetaAttribute::position::value <<
"' name='" <<
- meta_attribute::base_name() <<
+ MetaAttribute::base_name() <<
"'>" <<
endl;
}
- template <class meta_attribute>
- void leave_attribute(meta_attribute)
+ template <class MetaAttribute>
+ void leave_attribute(MetaAttribute)
{
using namespace ::std;
using namespace ::boost;
Modified: sandbox/mirror/libs/mirror/doc/xml/mirror/_library.xml
==============================================================================
--- sandbox/mirror/libs/mirror/doc/xml/mirror/_library.xml (original)
+++ sandbox/mirror/libs/mirror/doc/xml/mirror/_library.xml 2008-06-02 12:34:10 EDT (Mon, 02 Jun 2008)
@@ -158,5 +158,14 @@
- Tested with MSVC++ 2008 EE On Vista
- Tested with gcc 4.2.1 on FreeBSD
</revision>
+ <revision id="20080516" major="0" minor="1" micro="24" author="m_ch">
+ - Added for-each and reverse-for-each algorithms working on a iterator range
+ - Tested with MSVC++ 2008 EE On Vista
+ </revision>
+ <revision id="20080602" major="0" minor="1" micro="25" author="m_ch">
+ - Added experimental support for class generators
+ - Updated several things concerning visitors
+ - Tested with MSVC++ 2008 EE On Vista
+ </revision>
</revisions>
</library>
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