Boost logo

Boost-Commit :

From: chochlik_at_[hidden]
Date: 2008-04-17 12:58:54


Author: matus.chochlik
Date: 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
New Revision: 44508
URL: http://svn.boost.org/trac/boost/changeset/44508

Log:
Added an elaborate example in registering and reflection of classes
Modified multiple sources
Added:
   sandbox/mirror/boost/mirror/meta_data_fwd.hpp (contents, props changed)
   sandbox/mirror/boost/mirror/reflects_class.hpp (contents, props changed)
   sandbox/mirror/boost/mirror/reflects_namespace.hpp (contents, props changed)
   sandbox/mirror/boost/mirror/reflects_type.hpp (contents, props changed)
   sandbox/mirror/libs/examples/registering/classes.cpp (contents, props changed)
Text files modified:
   sandbox/mirror/boost/mirror/meta_attribs_base.hpp | 112 ++++++++++++++++++++++++++++++++++++++-
   sandbox/mirror/boost/mirror/meta_attribs_getset.hpp | 97 ++++++++++++++++++++++++++++++++++
   sandbox/mirror/boost/mirror/meta_class.hpp | 10 ++
   sandbox/mirror/boost/mirror/meta_namespace.hpp | 12 ---
   sandbox/mirror/boost/mirror/meta_type.hpp | 61 +++++++++------------
   sandbox/mirror/boost/mirror/reflects_global_scope.hpp | 4
   sandbox/mirror/boost/mirror/utils/name_to_stream/type.hpp | 16 +++++
   sandbox/mirror/libs/doc/xml/mirror/_library.xml | 4 +
   sandbox/mirror/libs/examples/registering/namespaces.cpp | 36 ++++++------
   sandbox/mirror/libs/examples/registering/types.cpp | 74 ++++++++++++++++---------
   10 files changed, 328 insertions(+), 98 deletions(-)

Modified: sandbox/mirror/boost/mirror/meta_attribs_base.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_attribs_base.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_attribs_base.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -7,11 +7,13 @@
  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  */
 
-#ifndef BOOST_MIRROR_META_ATTRIBS_SIMPLE
-#define BOOST_MIRROR_META_ATTRIBS_SIMPLE
+#ifndef BOOST_MIRROR_META_ATTRIBS_SIMPLE_HPP
+#define BOOST_MIRROR_META_ATTRIBS_SIMPLE_HPP
 
 // mirror common definitions
 #include <boost/mirror/common_defs.hpp>
+// forward declarations
+#include <boost/mirror/meta_data_fwd.hpp>
 //
 // necessary type traits
 #include <boost/call_traits.hpp>
@@ -19,10 +21,91 @@
 namespace boost {
 namespace mirror {
 
-/** Defaut (empty) list of base attributes of a meta class
+/** Forward declaration of the meta_class_attributes<> template
  */
 template <class the_class, class variant_tag = detail::default_meta_class_variant>
+struct meta_class_attributes;
+
+namespace detail {
+
+/** Forward declaration of the meta_class_attrib_utils<>
+ * template.
+ */
+template <class meta_attributes>
+struct meta_class_attrib_utils;
+
+/** Template used in implementation of the
+ * meta_class_attrib_utils::for_each function
+ */
+template <class meta_attributes, bool last_one>
+struct meta_class_attrib_for_each_impl
+{
+ template <class meta_attrib_op, class meta_class, class position>
+ static void apply(meta_attrib_op, meta_class*, position)
+ {
+ }
+};
+
+template <class meta_attributes>
+struct meta_class_attrib_for_each_impl<meta_attributes, false>
+{
+ template <class meta_attrib_op, class meta_class, int attrib_index>
+ static void apply(meta_attrib_op& op, meta_class*, mpl::int_<attrib_index>)
+ {
+ typedef mpl::int_<attrib_index> position;
+ typedef mpl::int_<position::value+1> next;
+ // get the type of the attribute
+ typedef mpl::at<meta_class::attributes::type_list, position>::type attrib_type;
+ //
+ // execute the operation
+ op((meta_class*)0, position(), (attrib_type*)0);
+ // and move to the next one
+ meta_class_attrib_for_each_impl<
+ meta_attributes,
+ is_same<
+ mpl::int_<mpl::size<meta_class::attributes::type_list>::value>,
+ next
+ >::value
+ >::apply(op, (meta_class*)0, next());
+ }
+};
+
+
+/** This template implements several functions
+ * for the specializations of the meta_class_attributes<>
+ * template.
+ */
+template <class the_class, class variant_tag>
+struct meta_class_attrib_utils<meta_class_attributes<the_class, variant_tag > >
+{
+ typedef the_class base_class;
+ typedef BOOST_MIRROR_REFLECT_CLASS_VT(the_class, variant_tag) meta_class;
+ typedef typename meta_class_attributes<the_class, variant_tag > meta_attributes;
+ /**
+ */
+ template <class meta_attrib_op>
+ static meta_attrib_op for_each(meta_attrib_op op)
+ {
+ meta_class_attrib_for_each_impl<
+ meta_attributes,
+ is_same<
+ mpl::int_<mpl::size<meta_class::attributes::type_list>::value>,
+ mpl::int_<0>
+ >::value
+ >::apply(op, (meta_class*)0, mpl::int_<0>());
+ return op;
+ };
+};
+
+} // namespace detail
+
+/** Defaut (empty) list of base attributes of a meta class
+ */
+template <class the_class, class variant_tag>
 struct meta_class_attributes
+: public detail::meta_class_attrib_utils<
+ meta_class_attributes<the_class, variant_tag>
+>
 {
         typedef mpl::vector<> type_list;
 };
@@ -32,6 +115,9 @@
  */
 #define BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(THE_CLASS) \
         template <> struct meta_class_attributes<THE_CLASS, detail::default_meta_class_variant> \
+ : public detail::meta_class_attrib_utils<\
+ meta_class_attributes<THE_CLASS, detail::default_meta_class_variant> \
+ >\
         { \
                 typedef THE_CLASS the_class; \
                 typedef mpl::vector<>
@@ -53,6 +139,17 @@
 #define BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE(NUMBER, TYPE, NAME) \
         typedef mpl::push_back<_partial_list_##NUMBER, TYPE>::type
 
+/** This is a helper for the BOOST_MIRROR_CLASS_ATTRIB*_TD
+ * macros.
+ * It declares all common things that need to be declared
+ * after the specific stuff.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, NAME) \
+ typedef mpl::push_back<\
+ _partial_list_##NUMBER, \
+ BOOST_MIRROR_TYPEDEFD_SELECTOR(TYPE_NS_ALIAS##_##TYPE, TYPE_NAMESPACE::TYPE)\
+ >::type
+
 /** Helper macro for implementing simple attrib value getting
  * querying scheme
  */
@@ -101,13 +198,20 @@
         BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SIMPLE_SET(NUMBER, TYPE, NAME) \
         BOOST_MIRROR_REG_CLASS_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) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_PROLOGUE(NUMBER, TYPE_NAMESPACE::TYPE, NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SIMPLE_GET(NUMBER, TYPE_NAMESPACE::TYPE, NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SIMPLE_SET(NUMBER, TYPE_NAMESPACE::TYPE, NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, NAME)
+
 /** This macro finishes the declaration of attributes
  * of the given class
  */
 #define BOOST_MIRROR_REG_CLASS_ATTRIBS_END \
         type_list; \
 };
-
 } // namespace mirror
 } // namespace boost
 

Modified: sandbox/mirror/boost/mirror/meta_attribs_getset.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_attribs_getset.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_attribs_getset.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -97,6 +97,25 @@
 #define BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_ONLY(NUMBER, TYPE, ATTRIB_NAME, GETTER_NAME) \
         BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_W_ARGS_ONLY(NUMBER, TYPE, ATTRIB_NAME, GETTER_NAME, (), 0)
 
+
+/** This macro declares a single class' query-only attribute with a getter
+ * member function. Version for typedef'd types.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_W_ARGS_ONLY_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, GETTER_NAME, GETTER_ARGS_TUPLE, ARG_COUNT) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_PROLOGUE(NUMBER, TYPE_NAMESPACE::TYPE, ATTRIB_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_GETTER_ARGS(NUMBER, TYPE_NAMESPACE::TYPE, GETTER_NAME, GETTER_ARGS_TUPLE, ARG_COUNT)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_NO_SETTER(NUMBER, TYPE_NAMESPACE::TYPE)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME)
+
+/** Simpler version of the BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_W_ARGS
+ * for getter functions with no bound arguments
+ * Version for typedef'd types.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_ONLY_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, GETTER_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_W_ARGS_ONLY_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, GETTER_NAME, (), 0)
+
+
+
 /** This macro declares a single class' getter-query-simple-set attribute with a getter
  * member function and a simple value setting scheme.
  */
@@ -113,6 +132,21 @@
         BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_W_ARGS(NUMBER, TYPE, ATTRIB_NAME, GETTER_NAME, (), 0)
 
 
+/** This macro declares a single class' getter-query-simple-set attribute with a getter
+ * member function and a simple value setting scheme.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_W_ARGS_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, GETTER_NAME, GETTER_ARGS_TUPLE, ARG_COUNT) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_PROLOGUE(NUMBER, TYPE_NAMESPACE::TYPE, ATTRIB_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_GETTER_ARGS(NUMBER, TYPE_NAMESPACE::TYPE, GETTER_NAME, GETTER_ARGS_TUPLE, ARG_COUNT)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SIMPLE_SET(NUMBER, TYPE_NAMESPACE::TYPE, ATTRIB_NAME)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME)
+
+/** Simpler version of the BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_W_ARGS
+ * for getter functions with no bound arguments.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_TD(NUMBER, TYPE, TYPE_NS_ALIAS, TYPE_NAMESPACE, ATTRIB_NAME, GETTER_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_W_ARGS_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, GETTER_NAME, (), 0)
+
         
 /** This macro declares a single class' set-only attribute with a setter
  * member function.
@@ -129,6 +163,23 @@
 #define BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_ONLY(NUMBER, TYPE, ATTRIB_NAME, SETTER_NAME) \
         BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_W_ARGS_ONLY(NUMBER, TYPE, ATTRIB_NAME, SETTER_NAME, (BOOST_MIRROR_SETTER_SRC), 1)
 
+
+/** This macro declares a single class' set-only attribute with a setter
+ * member function. Version for typedef'd types.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_W_ARGS_ONLY_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, SETTER_NAME, SETTER_ARGS_TUPLE, ARG_COUNT) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_PROLOGUE(NUMBER, TYPE_NAMESPACE::TYPE, ATTRIB_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_NO_GETTER(NUMBER, TYPE_NAMESPACE::TYPE)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SETTER_ARGS(NUMBER, TYPE_NAMESPACE::TYPE, SETTER_NAME, SETTER_ARGS_TUPLE, ARG_COUNT)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME)
+
+/** Simpler version of the BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_W_ARGS
+ * for getter functions with no bound arguments.
+ * Version for typedef'd types.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_ONLY_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, SETTER_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_W_ARGS_ONLY_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, SETTER_NAME, (BOOST_MIRROR_SETTER_SRC), 1)
+
 
 /** This macro declares a single class' simple-get-setter-set attribute with a setter
  * member function and simple value getting scheme.
@@ -145,6 +196,23 @@
 #define BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER(NUMBER, TYPE, ATTRIB_NAME, SETTER_NAME) \
         BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_W_ARGS(NUMBER, TYPE, ATTRIB_NAME, SETTER_NAME, (BOOST_MIRROR_SETTER_SRC), 1)
 
+/** This macro declares a single class' simple-get-setter-set attribute with a setter
+ * member function and simple value getting scheme.
+ * Version for typedef'd types.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_W_ARGS_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, SETTER_NAME, SETTER_ARGS_TUPLE, ARG_COUNT) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_PROLOGUE(NUMBER, TYPE_NAMESPACE::TYPE, ATTRIB_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SIMPLE_GET(NUMBER, TYPE_NAMESPACE::TYPE, ATTRIB_NAME)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SETTER_ARGS(NUMBER, TYPE_NAMESPACE::TYPE, SETTER_NAME, SETTER_ARGS_TUPLE, ARG_COUNT)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME)
+
+/** Simpler version of the BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_W_ARGS
+ * for setter functions with no bound arguments besides the value to be set.
+ * Version for typedef'd types.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, SETTER_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_W_ARGS_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, SETTER_NAME, (BOOST_MIRROR_SETTER_SRC), 1)
+
 
 /** This macro declares a single class' simple-get-setter-set attribute with a setter
  * member function and simple value getting scheme.
@@ -175,6 +243,35 @@
                 SETTER_NAME, (BOOST_MIRROR_SETTER_SRC), 1\
         )
 
+/** This macro declares a single class' simple-get-setter-set attribute with a setter
+ * member function and simple value getting scheme.
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER_W_ARGS_TD(\
+ NUMBER, \
+ TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, \
+ ATTRIB_NAME, \
+ GETTER_NAME, \
+ GETTER_ARGS_TUPLE, \
+ GETTER_ARG_COUNT, \
+ SETTER_NAME, \
+ SETTER_ARGS_TUPLE, \
+ SETTER_ARG_COUNT\
+) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_PROLOGUE(NUMBER, TYPE_NAMESPACE::TYPE, ATTRIB_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_GETTER_ARGS(NUMBER, TYPE_NAMESPACE::TYPE, GETTER_NAME, GETTER_ARGS_TUPLE, GETTER_ARG_COUNT)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_DECL_SETTER_ARGS(NUMBER, TYPE_NAMESPACE::TYPE, SETTER_NAME, SETTER_ARGS_TUPLE, SETTER_ARG_COUNT)\
+ BOOST_MIRROR_REG_CLASS_ATTRIB_EPILOGUE(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME)
+
+/** Simpler version of the BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER_W_ARGS_TD
+ * for getter and setter functions with no bound arguments
+ */
+#define BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER_TD(NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, GETTER_NAME, SETTER_NAME) \
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER_W_ARGS(\
+ NUMBER, TYPE_NS_ALIAS, TYPE_NAMESPACE, TYPE, ATTRIB_NAME, \
+ GETTER_NAME, (), 0, \
+ SETTER_NAME, (BOOST_MIRROR_SETTER_SRC), 1\
+ )
+
 
 } // namespace mirror
 } // namespace boost

Modified: sandbox/mirror/boost/mirror/meta_class.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_class.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_class.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -32,19 +32,25 @@
 
 /** Meta class - specializes the meta_type for classes
  */
-template <class a_class, class variant_tag = detail::default_meta_class_variant>
+template <
+ class a_class,
+ class variant_tag = detail::default_meta_class_variant
+>
 struct meta_class : public meta_type<a_class>
 {
- typedef typename meta_base_classes<a_class, variant_tag>::list base_classes;
+ typedef typename meta_base_classes<a_class, variant_tag> base_classes;
         typedef typename meta_class_attributes<a_class, variant_tag> attributes;
 };
 
+
 /** This macro should be included in the definition of every class
  * with private or protected members, that should be refleccted
  */
 #define BOOST_MIRROR_FRIENDLY_CLASS(CLASS_NAME) \
                 friend struct ::boost::mirror::meta_class_attributes<CLASS_NAME>;
 
+
+
 } // namespace mirror
 } // namespace boost
 

Added: sandbox/mirror/boost/mirror/meta_data_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/meta_data_fwd.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,83 @@
+/**
+ * \file boost/mirror/meta_data_fwd.hpp
+ * Forward declarations of meta-data templates
+ *
+ * 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_META_DATA_FWD_HPP
+#define BOOST_MIRROR_META_DATA_FWD_HPP
+
+namespace boost {
+namespace mirror {
+
+/** Meta-namespace forward template declaration
+ */
+template<class namespace_alias>
+struct meta_namespace;
+
+/** Macro that expands into the meta_namespace for the
+ * namespace with the given alias.
+ */
+#define BOOST_MIRROR_REFLECT_NAMESPACE(NAMESPACE_ALIAS) \
+ ::boost::mirror::meta_namespace<namespaces::NAMESPACE_ALIAS>
+
+
+
+/** Meta-type forward template declaration
+ */
+template <class base_type>
+struct meta_type;
+
+
+/** Macro that expands into the meta_type for the
+ * given type or class.
+ */
+#define BOOST_MIRROR_REFLECT_TYPE(TYPE) \
+ ::boost::mirror::meta_type<TYPE>
+
+/** Macro that expands into the meta_type for the
+ * given typedefined type.
+ */
+#define BOOST_MIRROR_REFLECT_TYPEDEFD(NAMESPACE_ALIAS, TYPEDEFD) \
+ ::boost::mirror::meta_type< BOOST_MIRROR_TYPEDEFD_SELECTOR(\
+ NAMESPACE_ALIAS##_##TYPEDEFD, \
+ TYPEDEFD\
+ ) >
+
+/** Macro that expands into the meta_type for the
+ * type of the given expression.
+ * To get this going <boost/typeof/typeof.hpp>
+ * has to be included.
+ */
+#define BOOST_MIRROR_REFLECT_TYPEOF(EXPRESSION) \
+ ::boost::mirror::meta_type<BOOST_TYPEOF(EXPRESSION)>
+
+
+
+/** Meta-class template forward declaration
+ */
+template <class a_class, class variant_tag>
+struct meta_class;
+
+/** Macro that expands into the meta_class for the
+ * given type or class.
+ */
+#define BOOST_MIRROR_REFLECT_CLASS(CLASS) \
+ ::boost::mirror::meta_class<CLASS>
+
+/** Macro that expands into the meta_class for the
+ * given type or class.
+ */
+#define BOOST_MIRROR_REFLECT_CLASS_VT(CLASS, VARIANT_TAG) \
+ ::boost::mirror::meta_class<CLASS, VARIANT_TAG>
+
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/boost/mirror/meta_namespace.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_namespace.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_namespace.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -20,15 +20,12 @@
 
 // mirror uses switchable character type
 #include <boost/char_type_switch/string.hpp>
+// forward declarations
+#include <boost/mirror/meta_data_fwd.hpp>
 
 namespace boost {
 namespace mirror {
 
-/** meta-namespace template definition
- */
-template<class namespace_alias>
-struct meta_namespace;
-
 /** defines an alias (_) for the meta-namespace for the global scope
  */
 namespace namespaces { struct _{ }; }
@@ -75,11 +72,6 @@
 // Registration of the ::boost::mirror namespace
 BOOST_MIRROR_REG_META_NAMESPACE(_boost, mirror)
 
-/** Macro that expands into the meta_namespace for the
- * namespace with the given alias.
- */
-#define BOOST_MIRROR_REFLECT_NAMESPACE(NAMESPACE_ALIAS) \
- ::boost::mirror::meta_namespace<namespaces::NAMESPACE_ALIAS>
 
 } // namespace mirror
 } // namespace boost

Modified: sandbox/mirror/boost/mirror/meta_type.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_type.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_type.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -12,30 +12,32 @@
 
 // meta namespaces (includes boost/char_type_switch/string.hpp)
 #include <boost/mirror/meta_namespace.hpp>
+// forward declarations
+#include <boost/mirror/meta_data_fwd.hpp>
 // for declarations of meta-types for groups of types
 #include <boost/preprocessor.hpp>
 
 namespace boost {
 namespace mirror {
 
-/** meta-type template definition
- */
-template <class base_type>
-struct meta_type;
 
 namespace detail {
 
 template <class type_identifier, typename base_type>
-struct typedefd_type_selector;
+struct typedefd_type_selector { };
 
 } // namespace detail
 
+/** Macro that expands into a typedefined type selector
+ */
+#define BOOST_MIRROR_TYPEDEFD_SELECTOR(IDENTIFIER, BASE_TYPE)\
+ ::boost::mirror::detail::typedefd_type_selector< ::boost::mirror::typedefs::IDENTIFIER, BASE_TYPE >
+
 template <class type_identifier, typename base_type>
-struct meta_type< detail::typedefd_type_selector<
+struct meta_type< ::boost::mirror::detail::typedefd_type_selector<
         type_identifier, base_type
> > : meta_type<base_type>{ };
 
-
 /** Macro for declaration of meta-types
  */
 #define BOOST_MIRROR_REG_META_TYPE(NAMESPACE_ALIAS, NAMESPACE, BASE_NAME) \
@@ -50,10 +52,10 @@
  */
 #define BOOST_MIRROR_REG_META_TYPEDEFD(NAMESPACE_ALIAS, NAMESPACE, TYPEDEFD_NAME) \
         namespace typedefs { struct NAMESPACE_ALIAS##_##TYPEDEFD_NAME { }; }\
- template <> struct meta_type< detail::typedefd_type_selector<\
- typedefs::NAMESPACE_ALIAS##_##TYPEDEFD_NAME, \
+ template <> struct meta_type< BOOST_MIRROR_TYPEDEFD_SELECTOR(\
+ NAMESPACE_ALIAS##_##TYPEDEFD_NAME, \
                 NAMESPACE::TYPEDEFD_NAME \
- > > \
+ ) > \
         { \
                 typedef BOOST_MIRROR_REFLECT_NAMESPACE(NAMESPACE_ALIAS) scope; \
                 typedef NAMESPACE::TYPEDEFD_NAME base_type; \
@@ -76,7 +78,7 @@
 #define BOOST_MIRROR_REG_META_TYPE_EMBEDDED(WRAPPER, BASE_TYPE) \
         template <> struct meta_type< WRAPPER::BASE_TYPE > \
         { \
- typedef meta_type< WRAPPER > scope; \
+ typedef meta_class< WRAPPER > scope; \
                 typedef WRAPPER::BASE_TYPE base_type; \
                 static const bchar* base_name (void) {return BOOST_STR_LIT(#BASE_TYPE);}\
         };
@@ -111,6 +113,10 @@
  */
 #undef BOOST_MIRROR_REG_ITH_META_TYPE_NATIVE
 
+/** Register std string and wstring
+ */
+BOOST_MIRROR_REG_META_TYPE(_std, ::std, string)
+BOOST_MIRROR_REG_META_TYPE(_std, ::std, wstring)
 /** Now register the bchar and bstring too
  */
 BOOST_MIRROR_REG_META_TYPEDEFD(_boost, ::boost, bchar)
@@ -126,6 +132,15 @@
         typedef pointee_type* base_type;
 };
 
+/** Meta-types for arrays
+ */
+template <class element_type, size_t size>
+struct meta_type<element_type[size]>
+{
+ typedef typename meta_type<element_type>::scope scope;
+ typedef element_type base_type[size];
+};
+
 /** Meta-types for references
  */
 template <class refered_to_type>
@@ -163,30 +178,6 @@
 };
 
 
-/** Macro that expands into the meta_type for the
- * given type or class.
- */
-#define BOOST_MIRROR_REFLECT_TYPE(TYPE) \
- ::boost::mirror::meta_type<TYPE>
-
-/** Macro that expands into the meta_type for the
- * given typedefined type.
- */
-#define BOOST_MIRROR_REFLECT_TYPEDEFD(NAMESPACE_ALIAS, TYPEDEFD) \
- ::boost::mirror::meta_type< ::boost::mirror::detail::typedefd_type_selector<\
- typedefs::NAMESPACE_ALIAS##_##TYPEDEFD, \
- TYPEDEFD\
- > >
-
-/** Macro that expands into the meta_type for the
- * type of the given expression.
- * To get this going <boost/typeof/typeof.hpp>
- * has to be included.
- */
-#define BOOST_MIRROR_REFLECT_TYPEOF(EXPRESSION) \
- ::boost::mirror::meta_type<BOOST_TYPEOF(EXPRESSION)>
-
-
 } // namespace mirror
 } // namespace boost
 

Added: sandbox/mirror/boost/mirror/reflects_class.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/reflects_class.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,32 @@
+/**
+ * \file boost/mirror/reflects_class.hpp
+ * Meta function that returns true if the given meta-object
+ * reflects a 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_META_REFLECTS_CLASS_HPP
+#define BOOST_MIRROR_META_REFLECTS_CLASS_HPP
+
+// true type/false type for trait templates
+#include <boost/type_traits/integral_constant.hpp>
+#include <boost/mirror/meta_class.hpp>
+
+namespace boost {
+namespace mirror {
+
+template <class meta_object>
+struct reflects_class : public false_type{ };
+
+template <class base_class>
+struct reflects_class<meta_class<base_class> > : public true_type{ };
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/boost/mirror/reflects_global_scope.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/reflects_global_scope.hpp (original)
+++ sandbox/mirror/boost/mirror/reflects_global_scope.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -17,12 +17,12 @@
 namespace boost {
 namespace mirror {
 
-/** Is-global-scope trait template for meta-namespaces
+/** Reflects-global-scope trait template for other meta-namespaces
  */
 template <class meta_namespace>
 struct reflects_global_scope : public false_type{ };
 
-/** Is-global-scope trait specialization for global scope meta_namespace
+/** Reflects-global-scope trait specialization for global scope meta_namespace
  */
 template <>
 struct reflects_global_scope<BOOST_MIRROR_REFLECT_NAMESPACE(_)> : public true_type{ };

Added: sandbox/mirror/boost/mirror/reflects_namespace.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/reflects_namespace.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,32 @@
+/**
+ * \file boost/mirror/reflects_namespace.hpp
+ * Meta function that returns true if the given meta-object
+ * reflects a namespace
+ *
+ * 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_META_REFLECTS_NAMESPACE_HPP
+#define BOOST_MIRROR_META_REFLECTS_NAMESPACE_HPP
+
+// true type/false type for trait templates
+#include <boost/type_traits/integral_constant.hpp>
+#include <boost/mirror/meta_namespace.hpp>
+
+namespace boost {
+namespace mirror {
+
+template <class meta_object>
+struct reflects_namespace : public false_type{ };
+
+template <class namespace_alias>
+struct reflects_namespace<meta_namespace<namespace_alias> > : public true_type{ };
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Added: sandbox/mirror/boost/mirror/reflects_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/reflects_type.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,36 @@
+/**
+ * \file boost/mirror/reflects_types.hpp
+ * Meta function that returns true if the given meta-object
+ * reflects a type
+ *
+ * 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_META_REFLECTS_TYPE_HPP
+#define BOOST_MIRROR_META_REFLECTS_TYPE_HPP
+
+// true type/false type for trait templates
+#include <boost/type_traits/integral_constant.hpp>
+#include <boost/mirror/meta_type.hpp>
+
+namespace boost {
+namespace mirror {
+
+template <class meta_object>
+struct reflects_type : public false_type{ };
+
+template <class base_type>
+struct reflects_type<meta_type<base_type> > : public true_type{ };
+
+
+template <class base_class>
+struct reflects_type<meta_class<base_class> > : public true_type{ };
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/boost/mirror/utils/name_to_stream/type.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/utils/name_to_stream/type.hpp (original)
+++ sandbox/mirror/boost/mirror/utils/name_to_stream/type.hpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -45,6 +45,22 @@
         }
 };
 
+/** Specialization for meta-types for arrays
+ */
+template <typename element_type, size_t size>
+struct name_to_stream_helper<meta_type<const element_type[size]> >
+{
+ template <class out_stream>
+ static out_stream& put(out_stream& s, bool ldng_dbl_cln)
+ {
+ s << BOOST_STR_LIT("const ");
+ return name_to_stream_helper<meta_type<element_type> >::put(s,ldng_dbl_cln) <<
+ BOOST_STR_LIT("[") <<
+ size <<
+ BOOST_STR_LIT("]");
+ }
+};
+
 /** Specialization for meta-types for references
  */
 template <typename refered_to_type>

Modified: sandbox/mirror/libs/doc/xml/mirror/_library.xml
==============================================================================
--- sandbox/mirror/libs/doc/xml/mirror/_library.xml (original)
+++ sandbox/mirror/libs/doc/xml/mirror/_library.xml 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -30,5 +30,9 @@
                         - Updated documentation
                         - Added example on type registration and usage
                 </revision>
+ <revision id="20080417_1855CET" major="0" minor="1" micro="3" author="m_ch">
+ - Added an elaborate example on class registration and usage
+ - Done major modifications to multiple sources
+ </revision>
         </revisions>
 </library>

Added: sandbox/mirror/libs/examples/registering/classes.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/examples/registering/classes.cpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,405 @@
+/**
+ * \file examples/registering/classes.cpp
+ * Example of class registering and reflection with
+ * the mirror library.
+ *
+ * NOTE: if You are not familiar with namespace and type
+ * registration and reflection, You should probably
+ * see examples/registering/namespaces.cpp and
+ * examples/registering/types.cpp first.
+ *
+ * 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)
+ */
+#include <assert.h>
+
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/at.hpp>
+
+#include <boost/char_type_switch/iostream.hpp>
+
+#include <boost/mirror/meta_namespace.hpp>
+#include <boost/mirror/meta_type.hpp>
+#include <boost/mirror/meta_class.hpp>
+
+#include <boost/mirror/utils/name_to_stream.hpp>
+
+#include <boost/mirror/reflects_global_scope.hpp>
+#include <boost/mirror/reflects_namespace.hpp>
+#include <boost/mirror/reflects_class.hpp>
+#include <boost/mirror/reflects_type.hpp>
+
+
+/** First declare some namespaces and classes
+ */
+
+namespace test {
+namespace feature {
+namespace detail {
+
+struct foo_base { };
+struct foo_base2 { };
+struct foo_base3 { };
+
+// declare a struct with multiple base classes
+struct foo : foo_base, public foo_base2, virtual protected foo_base3
+{
+};
+
+} // namespace detail
+} // namespace feature
+
+namespace stuff {
+namespace detail {
+
+struct bar_base
+{
+ // This line allows mirror to access non-public
+ // class members
+ BOOST_MIRROR_FRIENDLY_CLASS(bar_base)
+ int an_int;
+ long a_long;
+};
+
+
+class bar : protected bar_base
+{
+ BOOST_MIRROR_FRIENDLY_CLASS(bar)
+ //
+ float a_float;
+ //
+ double a_double;
+ //
+ // This is a getter and a setter for two 'virtual' attributes.
+ // There are no members to store the actual values,
+ // the first member attrib is read-only
+ // and the second is write-only
+ int get_ro_val(void) const {return 1; /* or generate value */}
+ //
+ void set_wo_val(int a_val){ /* do something with a_val */}
+ //
+ // This is a member with a setter function
+ // Not too clever, the value can be read directly,
+ // but must be stored by the setter function.
+ // Anyway, mirror supports this
+ //
+ ::boost::bstring a_string;
+ void set_string(const ::boost::bstring& a_str)
+ {
+ a_string = a_str;
+ ::boost::bcout << a_string << ::std::endl;
+ }
+ //
+public:
+ // A little weird getter/setter pair
+ // Note that the getter is not const
+ bool get_bool(void) {return a_string.empty();}
+ void set_bool(bool b){if(!b) a_string.clear();}
+ //
+ // An 'embedded' class
+ struct bar_part
+ {
+ char a_char;
+ bool a_bool;
+ };
+};
+
+} // namespace detail
+} // namespace stuff
+
+} // namespace test
+
+
+namespace boost {
+namespace mirror {
+
+/** Register the namespaces
+ */
+BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(test)
+BOOST_MIRROR_REG_META_NAMESPACE(_test, feature)
+BOOST_MIRROR_REG_META_NAMESPACE(_test_feature, detail)
+BOOST_MIRROR_REG_META_NAMESPACE(_test, stuff)
+BOOST_MIRROR_REG_META_NAMESPACE(_test_stuff, detail)
+//
+/** Register the types
+ */
+BOOST_MIRROR_REG_META_TYPE(_test_feature_detail, ::test::feature::detail, foo_base)
+BOOST_MIRROR_REG_META_TYPE(_test_feature_detail, ::test::feature::detail, foo_base2)
+BOOST_MIRROR_REG_META_TYPE(_test_feature_detail, ::test::feature::detail, foo_base3)
+BOOST_MIRROR_REG_META_TYPE(_test_feature_detail, ::test::feature::detail, foo)
+BOOST_MIRROR_REG_META_TYPE(_test_stuff_detail, ::test::stuff::detail, bar_base)
+BOOST_MIRROR_REG_META_TYPE(_test_stuff_detail, ::test::stuff::detail, bar)
+// register the embedded type that is declared inside of the bar class
+BOOST_MIRROR_REG_META_TYPE_EMBEDDED(::test::stuff::detail::bar, bar_part)
+
+
+/** Register the base classes of foo
+ */
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::test::feature::detail::foo)
+ // a simple base (not virtual, nor explicitly public/protected/private)
+ BOOST_MIRROR_REG_BASE_CLASS_SIMPLE(0, ::test::feature::detail::foo_base)
+ // a public non-virtual base
+ BOOST_MIRROR_REG_BASE_CLASS(1, public, ::test::feature::detail::foo_base2)
+ // a virtual protected base
+ BOOST_MIRROR_REG_BASE_CLASS_VIRTUAL(2, protected, ::test::feature::detail::foo_base3)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+
+// since bar has only one base we can register it this way more quickly
+BOOST_MIRROR_REG_SINGLE_BASE_CLASS(
+ ::test::stuff::detail::bar,
+ public, ::test::stuff::detail::bar_base
+)
+
+/** Class attributes
+ */
+// register the attributes of bar_base
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::stuff::detail::bar_base)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, int, an_int)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(1, long, a_long)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+// register the attributes of bar, this is little more tricky
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::stuff::detail::bar)
+ // these two are simple
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, float, a_float)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(1, double, a_double)
+ //
+ // this 'virtual' attribute has only a getter (cannot be set)
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_ONLY(2, int, a_ro_val, get_ro_val)
+ // this 'virtual' attribute has only a setter (cannot be queried)
+ BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_ONLY(3, int, a_wo_val, set_wo_val)
+ //
+ // this is an attrib that has no getter but has a setter function
+ // Also note that macros with the _TD suffix allow to register
+ // attributes with typedef'd types
+ BOOST_MIRROR_REG_CLASS_ATTRIB_SETTER_TD(4, _boost, ::boost, bstring, a_string, set_string)
+ //
+ // and the last one is accessed by the means of a pair of getter/setter functions
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER(5, bool, a_bool, get_bool, set_bool)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+/** This is a pretty printer template that prints
+ * some info about the given meta_object into
+ * a stream.
+ */
+template <class meta_object>
+struct pretty_printer
+{
+ typedef meta_object meta_object;
+ //
+ // prints some info about the meta-object t
+ // to the given stream
+ template <class out_stream>
+ out_stream& print(out_stream& s) const
+ {
+ typedef pretty_printer<meta_object> prn_type;
+ typedef prn_type::meta_object meta_object;
+ //
+ using namespace ::std;
+ //
+ // check the kind of meta object
+ // and print the kind of the object it reflects
+ if(reflects_class<meta_object>::value)
+ s << "The class '";
+ else if(reflects_type<meta_object>::value)
+ s << "The type '";
+ else return s << "Unknown meta object";
+ //
+ // print out it's name
+ s << name_to_stream<meta_object>() << "' " << endl;
+ //
+ // print info about the scope where the meta-object
+ // is defined
+ s << "is defined ";
+ // if the scope is the global scope
+ if(reflects_global_scope<meta_object::scope>::value)
+ s << "on the global scope";
+ // if it's a class
+ else if(reflects_class<meta_object::scope>::value)
+ s << "inside of the '" << name_to_stream<meta_object::scope>() << "' class";
+ // otherwise
+ else s << "in the '" << name_to_stream<meta_object::scope>() << "' namespace";
+ s << "." << endl;
+ //
+ // print the base classes if any
+ print_base_classes(s, (meta_object*)0);
+ // print the attributes if any
+ print_attribs(s, (meta_object*)0);
+ //
+ return s;
+ }
+ //
+ // does not print anything for other meta-objects
+ // than meta_classes
+ template <class out_stream, class meta_object>
+ out_stream& print_base_classes(out_stream& s, meta_object*) const {return s;}
+ //
+ // a function object that gets called by mpl::for_each
+ // for every base class of the given class
+ template <class out_stream>
+ struct base_class_printer
+ {
+ out_stream& s;
+ base_class_printer(out_stream& _s):s(_s){ }
+ //
+ template <class meta_inheritance>
+ void operator()(meta_inheritance) const
+ {
+ // the argument is a specialization of the
+ // meta_inheritance<> template
+ // it's base_class typedef is the type
+ // of the base class
+ using namespace ::std;
+ s << endl << " - " <<
+ name_to_stream<BOOST_MIRROR_REFLECT_CLASS(meta_inheritance::base_class)>();
+ }
+ };
+ //
+ // prints info about base classes
+ template <class out_stream, class base_class>
+ out_stream& print_base_classes(out_stream& s, meta_class<base_class>*) const
+ {
+ using namespace ::std;
+ //
+ // print out the count of (registered) base classes that
+ // the inspected class has
+ s << "It has ";
+ if(mpl::size<meta_object::base_classes::list>::value == 1)
+ s << "this one base class:";
+ else if(mpl::size<meta_object::base_classes::list>::value > 1)
+ s << "these " << mpl::size<meta_object::base_classes::list>::value << " base classes:";
+ else s << "no base classes.";
+ //
+ // execute the printer on the list of base classes
+ mpl::for_each<meta_object::base_classes::list>(base_class_printer<out_stream>(s));
+ //
+ return s << endl;
+ }
+ //
+ // does not print anything for non meta_class meta-objects
+ template <class out_stream, class meta_object>
+ out_stream& print_attribs(out_stream& s, meta_object*) const {return s;}
+ //
+ //
+ // a functor that gets called for every meta_attribute
+ // of the given meta_class
+ template <class out_stream>
+ struct attrib_printer
+ {
+ out_stream& s;
+ // the constructor takes reference to the output stream
+ attrib_printer(out_stream& _s):s(_s){ }
+ //
+ // function call operator
+ template <class meta_class, class iterator, class attrib_type>
+ void operator()(meta_class*, iterator pos, attrib_type*) const
+ {
+ // the first argument is a undefined pointer to the
+ // meta_class which we are inspecting (it only conveys
+ // the information about the meta_class<> specialization
+ //
+ // the second argument is the position that can be used
+ // to access base_name of the i-th attribute. Basically
+ // this is a mpl::int_<>
+ //
+ // the third attribute is an undefined pointer used to
+ // pass the info about the i-th member attrib type
+ //
+ // NOTE: the pointers may be replaced by mpl::identity<>
+ // or some other type in the future
+ using namespace ::std;
+ s << endl << " - " <<
+ name_to_stream<BOOST_MIRROR_REFLECT_TYPE(attrib_type)>() <<
+ " " <<
+ meta_class::attributes::base_name(pos);
+ }
+ };
+ //
+ // this overload prints the list of attributes of the given class
+ template <class out_stream, class base_class>
+ out_stream& print_attribs(out_stream& s, meta_class<base_class>*) const
+ {
+ //
+ // print the number of the registered attributes
+ s << "It has ";
+ if(mpl::size<meta_object::attributes::type_list>::value == 1)
+ s << "this one member attribute:";
+ else if(mpl::size<meta_object::attributes::type_list>::value > 1)
+ s << "these " << mpl::size<meta_object::attributes::type_list>::value << " member attributes:";
+ else s << "no member attributes.";
+ //
+ // execute the printer on the list of member attributes
+ // note that the type of functor and the implementation
+ // of for_each is likely subject to changes
+ meta_object::attributes::for_each(attrib_printer<out_stream>(s));
+ return s << ::std::endl;
+ }
+
+};
+
+// now some easy stuff, overload the << operator
+// for our pretty_printer
+template <class meta_object, class out_stream>
+out_stream& operator << (out_stream& s, const pretty_printer<meta_object>& prn)
+{
+ return prn.print(s) << ::std::endl << "----------------------";
+}
+
+} // namespace mirror
+} // namespace boost
+
+
+
+
+
+int main(void)
+{
+ using namespace ::std;
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ using ::test::feature::detail::foo;
+ using ::test::stuff::detail::bar;
+ using ::test::stuff::detail::bar_base;
+ //
+ // use the pretty printer to print out into about the given types
+ // pointer to native type
+ bcout << "|01| " << endl << pretty_printer<BOOST_MIRROR_REFLECT_TYPE(double*)>() << endl;
+ // a class defined in a namespace
+ bcout << "|02| " << endl << pretty_printer<BOOST_MIRROR_REFLECT_CLASS(foo)>() << endl;
+ bcout << "|03| " << endl << pretty_printer<BOOST_MIRROR_REFLECT_CLASS(bar)>() << endl;
+ // an embedded class
+ bcout << "|04| " << endl << pretty_printer<BOOST_MIRROR_REFLECT_CLASS(bar::bar_part)>() << endl;
+ // typedef'd type
+ bcout << "|05| " << endl << pretty_printer<BOOST_MIRROR_REFLECT_TYPEDEFD(_boost, bchar)>() << endl;
+ // type of an expression
+ bcout << "|06| " << endl << pretty_printer<BOOST_MIRROR_REFLECT_TYPEOF("foo")>() << endl;
+ //
+ //
+ bar_base x = {123, 456L};
+ bar_base y = {234, 567L};
+ //
+ // the meta-attributes can be used to examine
+ // values of the members too
+ assert(BOOST_MIRROR_REFLECT_CLASS(BOOST_TYPEOF(x))::attributes::get(x, mpl::int_<0>()) == x.an_int);
+ assert(BOOST_MIRROR_REFLECT_CLASS(BOOST_TYPEOF(x))::attributes::get(x, mpl::int_<1>()) == x.a_long);
+ // and also to set them
+ BOOST_MIRROR_REFLECT_CLASS(BOOST_TYPEOF(x))::attributes::set(
+ x, mpl::int_<0>(),
+ BOOST_MIRROR_REFLECT_CLASS(BOOST_TYPEOF(y))::attributes::get(y, mpl::int_<0>())
+ );
+ BOOST_MIRROR_REFLECT_CLASS(BOOST_TYPEOF(x))::attributes::set(
+ x, mpl::int_<1>(),
+ BOOST_MIRROR_REFLECT_CLASS(BOOST_TYPEOF(y))::attributes::get(y, mpl::int_<1>())
+ );
+ //
+ assert(x.an_int == y.an_int);
+ assert(x.a_long == y.a_long);
+ //
+ bcout << "Finished" << endl;
+ //
+ return 0;
+}
+

Modified: sandbox/mirror/libs/examples/registering/namespaces.cpp
==============================================================================
--- sandbox/mirror/libs/examples/registering/namespaces.cpp (original)
+++ sandbox/mirror/libs/examples/registering/namespaces.cpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -1,5 +1,5 @@
 /**
- * \file examples/registering/namespaces.hpp
+ * \file examples/registering/namespaces.cpp
  * Example of namespace registering and reflection with
  * the mirror library
  *
@@ -77,41 +77,41 @@
         // of the namespace
         //
         // print the base name of the namespace
- bcout << meta_ns_test_stuff_detail::base_name() << endl;
+ bcout << "|01| " <<meta_ns_test_stuff_detail::base_name() << endl;
         //
         // the 'parent' type is the meta_namespace<> for the parent
         // namespace of the given namespace
         //
         // print the base name of the parent namespace
- bcout << meta_ns_test_stuff_detail::parent::base_name() << endl;
- bcout << meta_ns_test_stuff_detail::parent::parent::base_name() << endl;
+ bcout << "|02| " <<meta_ns_test_stuff_detail::parent::base_name() << endl;
+ bcout << "|03| " <<meta_ns_test_stuff_detail::parent::parent::base_name() << endl;
         //
         // the 'scope' member is a mpl::vector containing the whole
         // list of ancestor namespaces
         //
         // find out and print the 'depth' of the namespace
- bcout << mpl::size<meta_ns_global_scope::scope>::value << endl;
- bcout << mpl::size<meta_ns_test::scope>::value << endl;
- bcout << mpl::size<meta_ns_test_stuff_detail::scope>::value << endl;
+ bcout << "|04| " <<mpl::size<meta_ns_global_scope::scope>::value << endl;
+ bcout << "|05| " <<mpl::size<meta_ns_test::scope>::value << endl;
+ bcout << "|06| " <<mpl::size<meta_ns_test_stuff_detail::scope>::value << endl;
         //
         // the name_to_stream<meta_object> class allows to put the full name
         // (including the scope) into a stream
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff_detail) >() << endl;
+ bcout << "|07| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_) >() << endl;
+ bcout << "|08| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test) >() << endl;
+ bcout << "|09| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff) >() << endl;
+ bcout << "|10| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff_detail) >() << endl;
         // in this case the :: is prepended to the full name
         // thus test::stuff -> ::test::stuff
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_) >(true) << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test) >(true) << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff) >(true) << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff_detail) >(true) << endl;
+ bcout << "|11| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_) >(true) << endl;
+ bcout << "|12| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test) >(true) << endl;
+ bcout << "|13| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff) >(true) << endl;
+ bcout << "|14| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff_detail) >(true) << endl;
         //
         // there are few namespace registered by default
         // including (::std, ::boost, ::boost::mirror)
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_std) >(true) << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_boost) >(true) << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_boost_mirror) >(true) << endl;
+ bcout << "|15| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_std) >(true) << endl;
+ bcout << "|16| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_boost) >(true) << endl;
+ bcout << "|17| " <<name_to_stream< BOOST_MIRROR_REFLECT_NAMESPACE(_boost_mirror) >(true) << endl;
         return 0;
 }
 

Modified: sandbox/mirror/libs/examples/registering/types.cpp
==============================================================================
--- sandbox/mirror/libs/examples/registering/types.cpp (original)
+++ sandbox/mirror/libs/examples/registering/types.cpp 2008-04-17 12:58:53 EDT (Thu, 17 Apr 2008)
@@ -1,5 +1,5 @@
 /**
- * \file examples/registering/types.hpp
+ * \file examples/registering/types.cpp
  * Example of type registering and reflection with
  * the mirror library
  *
@@ -13,6 +13,8 @@
 
 #include <boost/mirror/meta_namespace.hpp>
 #include <boost/mirror/meta_type.hpp>
+//
+#include <boost/mirror/reflects_global_scope.hpp>
 // utility that allows to put the name of the type to a given stream
 #include <boost/mirror/utils/name_to_stream/type.hpp>
 //
@@ -27,6 +29,7 @@
 
 struct foo { };
 struct bar { };
+typedef double foobar;
 
 } // namespace detail
 } // namespace feature
@@ -48,6 +51,9 @@
 // register the types
 BOOST_MIRROR_REG_META_TYPE(_test_feature_detail, ::test::feature::detail, foo)
 BOOST_MIRROR_REG_META_TYPE(_test_feature_detail, ::test::feature::detail, bar)
+// register a typedef'd class this allows to distinguish it from
+// the 'source' type in some situations
+BOOST_MIRROR_REG_META_TYPEDEFD(_test_feature_detail, ::test::feature::detail, foobar)
 
 } // namespace mirror
 } // namespace boost
@@ -61,59 +67,62 @@
         //
         using ::test::feature::detail::foo;
         using ::test::feature::detail::bar;
+ using ::test::feature::detail::foobar;
         //
         // The BOOST_MIRROR_REFLECT_TYPE(TYPE) macro expands into the meta_type<>
         // specialization for the given type
- // The result is a type name
         //
         typedef BOOST_MIRROR_REFLECT_TYPE(foo) meta_foo;
         typedef BOOST_MIRROR_REFLECT_TYPE(bar) meta_bar;
         //
         // put the full name of the type to the output stream
         //
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(foo) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bar) >() << endl;
+ bcout << "|01| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(foo) >() << endl;
+ bcout << "|02| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bar) >() << endl;
         //
- // do the same thing with the typedef'd type
+ // Do the same thing with the typedef'd type
         // actually, nearly the same .. the true argument given to the
- // constructor makes the name_to_stream<> template output the
- // leading :: too.
- bcout << name_to_stream< meta_foo >(true) << endl;
- bcout << name_to_stream< meta_bar >(true) << endl;
+ // constructor makes the name_to_stream<> template, output the
+ // leading "::" too.
+ bcout << "|03| " << name_to_stream< meta_foo >(true) << endl;
+ bcout << "|04| " << name_to_stream< meta_bar >(true) << endl;
         //
         // this works too...
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(foo*) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bar&) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(foo***) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bar**&) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const foo**) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(volatile bar*&) >() << endl;
+ bcout << "|05| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(foo*) >() << endl;
+ bcout << "|06| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bar&) >() << endl;
+ bcout << "|07| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(foo***) >() << endl;
+ bcout << "|08| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bar**&) >() << endl;
+ bcout << "|09| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const foo**) >() << endl;
+ bcout << "|10| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(volatile bar*&) >() << endl;
         //
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const volatile foo) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const volatile bar*) >() << endl;
+ bcout << "|11| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const volatile foo) >() << endl;
+ bcout << "|12| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const volatile bar*) >() << endl;
         //
         // native c++ types are registered by default
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(volatile short int) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const char*) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(wchar_t*) >() << endl;
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bool) >() << endl;
+ bcout << "|13| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(volatile short int) >() << endl;
+ bcout << "|14| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const char*) >() << endl;
+ bcout << "|15| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(wchar_t*) >() << endl;
+ bcout << "|16| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bool) >() << endl;
         //
         // use with Boost.Typeof
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(BOOST_TYPEOF(1+1)) >() << endl;
+ bcout << "|17| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(BOOST_TYPEOF(1+1)) >() << endl;
         // ... and maybe more conveniently
- bcout << name_to_stream< BOOST_MIRROR_REFLECT_TYPEOF(1.0/2.0) >() << endl;
+ bcout << "|18| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPEOF(1.0/2.0) >() << endl;
         //
         // sometimes it is useful to distinguish between a typedef'd type
         // and the 'source' type.
         //
- // this reflects bchar as char or wchar_t defined
+ // this reflects bchar as char or wchar_t based
         // on compilation configuration
         typedef BOOST_MIRROR_REFLECT_TYPE(bchar) meta_bchar;
- // this returns a meta-type that allows to query the typedef'd name
+ // this reflects a meta-type that allows to query the typedef'd name
         typedef BOOST_MIRROR_REFLECT_TYPEDEFD(_boost, bchar) meta_bchar_td;
+ // this reflects the meta-type for the typedef type foobar
+ typedef BOOST_MIRROR_REFLECT_TYPEDEFD(_test_feature_detail, foobar) meta_foobar_td;
         //
- bcout << name_to_stream< meta_bchar >() << endl;
- bcout << name_to_stream< meta_bchar_td >() << endl;
+ bcout << "|19| " << name_to_stream< meta_bchar >() << endl;
+ bcout << "|20| " << name_to_stream< meta_bchar_td >() << endl;
+ bcout << "|21| " << name_to_stream< meta_foobar_td >() << endl;
         //
         // unfortunately BOOST_MIRROR_REFLECT_TYPEDEFD(...) works only if
         // the typedefined name is explicitly given
@@ -121,6 +130,17 @@
         // However, the next line for example would fail to compile
         //typedef BOOST_MIRROR_REFLECT_TYPEDEFD(_boost, BOOST_TYPEOF(L'x')) meta_bchar_td;
         //
+ // check whether the type is defined on the global scope
+ if(!reflects_global_scope<meta_bchar_td::scope>::value)
+ bcout << "|22| " << "bchar NOT defined on global scope" << endl;
+ if(!reflects_global_scope<meta_foo::scope>::value)
+ bcout << "|23| " << "foo NOT defined on global scope" << endl;
+ // use with typeof
+ if(reflects_global_scope< BOOST_MIRROR_REFLECT_TYPEOF(1+2) ::scope>::value)
+ bcout << "|24| " << "type of (1+2) defined on global scope" << endl;
+ //
+ if(reflects_global_scope< BOOST_MIRROR_REFLECT_TYPEOF("foo") ::scope>::value)
+ bcout << "|25| " << "type of \"foo\" defined on global scope" << endl;
         //
         return 0;
 }


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