Boost logo

Boost-Commit :

From: chochlik_at_[hidden]
Date: 2008-04-17 05:49:54


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

Log:
Made major changes to namespace registration and type registration.
Some changes to name_to_stream templates
Added an example of type registration and meta-type usage
Updated the example of namespace registration and meta-namespace usage
Updated documentation
Added:
   sandbox/mirror/boost/mirror/reflects_global_scope.hpp (contents, props changed)
   sandbox/mirror/boost/mirror/utils/name_to_stream/class.hpp (contents, props changed)
   sandbox/mirror/boost/mirror/utils/name_to_stream/type.hpp (contents, props changed)
   sandbox/mirror/libs/examples/registering/types.cpp (contents, props changed)
Removed:
   sandbox/mirror/boost/mirror/utils/name_to_stream/name_to_stream.hpp
Text files modified:
   sandbox/mirror/boost/mirror/meta_namespace.hpp | 63 ++++++---------
   sandbox/mirror/boost/mirror/meta_type.hpp | 69 ++++++++++++++-
   sandbox/mirror/boost/mirror/utils/name_to_stream.hpp | 165 +--------------------------------------
   sandbox/mirror/boost/mirror/utils/name_to_stream/namespace.hpp | 33 +++----
   sandbox/mirror/libs/doc/xml/css/mirror.css | 6 +
   sandbox/mirror/libs/doc/xml/mirror/_library.xml | 9 ++
   sandbox/mirror/libs/doc/xml/mirror/sections/char_type.xml | 2
   sandbox/mirror/libs/examples/registering/namespaces.cpp | 15 ++-
   8 files changed, 129 insertions(+), 233 deletions(-)

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 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -10,12 +10,8 @@
 #ifndef BOOST_MIRROR_META_NAMESPACE_HPP
 #define BOOST_MIRROR_META_NAMESPACE_HPP
 
-// true type/false type for trait templates
-#include <boost/type_traits/integral_constant.hpp>
 // for various typelists
 #include <boost/mpl/vector.hpp>
-// for "compile time strings"
-#include <boost/mpl/vector_c.hpp>
 // common mpl algoritgms
 #include <boost/mpl/push_back.hpp>
 //
@@ -30,69 +26,60 @@
 
 /** meta-namespace template definition
  */
-template<class parent_meta_ns, class namespace_name>
+template<class namespace_alias>
 struct meta_namespace;
 
+/** defines an alias (_) for the meta-namespace for the global scope
+ */
+namespace namespaces { struct _{ }; }
+
 /** meta-namespace for the global scope
  */
-template<> struct meta_namespace<void, mpl::vector_c<char> >
+template<> struct meta_namespace< namespaces::_ >
 {
         typedef void parent;
         typedef mpl::vector0<> scope;
         static const bchar* base_name (void) {return BOOST_STR_LIT("");}
 };
-/** defines an alias (_) for the meta-namespace for the global scope
- */
-namespace namespaces {
-typedef meta_namespace<void, mpl::vector_c<char> > _;
-}
-
-/** Is-global-scope trait template for namespaces
- */
-template <class meta_namespace>
-struct is_global_scope : public false_type{ };
-
-/** Is-global-scope trait specialization for global scope meta_namespace
- */
-template <>
-struct is_global_scope<namespaces::_> : public true_type{ };
 
 /** Helper macro for registering new general namespaces (top level or nested)
  */
-#define BOOST_MIRROR_REG_META_NAMESPACE_HELPER(PARENT_META_NS, PREFIX, NAMESPACE, SPELLED_NAME) \
-template<> struct meta_namespace<PARENT_META_NS, mpl::vector_c<char, SPELLED_NAME> > \
+#define BOOST_MIRROR_REG_META_NAMESPACE_HELPER(PARENT_NS_ALIAS, PREFIX, NAMESPACE_NAME) \
+namespace namespaces {struct PREFIX##_##NAMESPACE_NAME { }; }\
+template<> struct meta_namespace< namespaces :: PREFIX##_##NAMESPACE_NAME > \
 { \
- typedef PARENT_META_NS parent; \
- typedef mpl::push_back<typedef PARENT_META_NS::scope, PARENT_META_NS>::type scope; \
- static const bchar* base_name (void) {return BOOST_STR_LIT(#NAMESPACE);} \
+ typedef meta_namespace< namespaces :: PARENT_NS_ALIAS > parent; \
+ typedef mpl::push_back<typedef parent::scope, parent>::type scope; \
+ static const bchar* base_name (void) {return BOOST_STR_LIT(#NAMESPACE_NAME);} \
 }; \
-namespace namespaces { \
- typedef meta_namespace<PARENT_META_NS, mpl::vector_c<char, SPELLED_NAME> > PREFIX##_##NAMESPACE; \
-}
+
 
 /** Macro for registering new general namespaces (top level or nested)
  */
-#define BOOST_MIRROR_REG_META_NAMESPACE(PARENT_META_NS_ALIAS, NAMESPACE, SPELLED_NAME) \
- BOOST_MIRROR_REG_META_NAMESPACE_HELPER(namespaces::PARENT_META_NS_ALIAS, PARENT_META_NS_ALIAS, NAMESPACE, SPELLED_NAME)
-
+#define BOOST_MIRROR_REG_META_NAMESPACE(PARENT_NS_ALIAS, NAMESPACE_NAME) \
+ BOOST_MIRROR_REG_META_NAMESPACE_HELPER(PARENT_NS_ALIAS, PARENT_NS_ALIAS, NAMESPACE_NAME)
 
 /** Macro for registering of top-level namespaces
  */
-#define BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(NAMESPACE, SPELLED_NAME) \
- BOOST_MIRROR_REG_META_NAMESPACE_HELPER(namespaces::_, BOOST_PP_EMPTY(), NAMESPACE, SPELLED_NAME)
+#define BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(NAMESPACE_NAME) \
+ BOOST_MIRROR_REG_META_NAMESPACE_HELPER(\
+ _, \
+ BOOST_PP_EMPTY(), \
+ NAMESPACE_NAME \
+ )
 
 // Registration of the ::std namespace
-BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(std, BOOST_PP_TUPLE_REM_CTOR(3,('s','t','d')));
+BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(std)
 // Registration of the ::boost namespace
-BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(boost, BOOST_PP_TUPLE_REM_CTOR(5,('b','o','o','s','t')));
+BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(boost)
 // Registration of the ::boost::mirror namespace
-BOOST_MIRROR_REG_META_NAMESPACE(_boost, mirror, BOOST_PP_TUPLE_REM_CTOR(6,('m','i','r','r','o','r')));
+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::namespaces::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 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -10,8 +10,6 @@
 #ifndef BOOST_MIRROR_META_TYPE_HPP
 #define BOOST_MIRROR_META_TYPE_HPP
 
-// true type/false type for trait templates
-#include <boost/type_traits/integral_constant.hpp>
 // meta namespaces (includes boost/char_type_switch/string.hpp)
 #include <boost/mirror/meta_namespace.hpp>
 // for declarations of meta-types for groups of types
@@ -25,23 +23,49 @@
 template <class base_type>
 struct meta_type;
 
+namespace detail {
+
+template <class type_identifier, typename base_type>
+struct typedefd_type_selector;
+
+} // namespace detail
+
+template <class type_identifier, typename base_type>
+struct meta_type< detail::typedefd_type_selector<
+ type_identifier, base_type
+> > : meta_type<base_type>{ };
+
 
 /** Macro for declaration of meta-types
  */
-#define BOOST_MIRROR_REG_META_TYPE(META_NAMESPACE_ALIAS, NAMESPACE, BASE_NAME) \
+#define BOOST_MIRROR_REG_META_TYPE(NAMESPACE_ALIAS, NAMESPACE, BASE_NAME) \
         template <> struct meta_type< NAMESPACE::BASE_NAME > \
         { \
- typedef namespaces::META_NAMESPACE_ALIAS scope; \
+ typedef BOOST_MIRROR_REFLECT_NAMESPACE(NAMESPACE_ALIAS) scope; \
                 typedef NAMESPACE::BASE_NAME base_type; \
                 static const bchar* base_name (void) {return BOOST_STR_LIT(#BASE_NAME);}\
         };
 
+/** Macro for declaration of meta-types for typedefined types
+ */
+#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, \
+ NAMESPACE::TYPEDEFD_NAME \
+ > > \
+ { \
+ typedef BOOST_MIRROR_REFLECT_NAMESPACE(NAMESPACE_ALIAS) scope; \
+ typedef NAMESPACE::TYPEDEFD_NAME base_type; \
+ static const bchar* base_name (void) {return BOOST_STR_LIT(#TYPEDEFD_NAME);}\
+ };
+
 /** Declaration of meta types for types in the global scope
  */
 #define BOOST_MIRROR_REG_META_TYPE_GLOBAL_SCOPE(BASE_TYPE) \
         template <> struct meta_type< BASE_TYPE > \
         { \
- typedef namespaces::_ scope; \
+ typedef BOOST_MIRROR_REFLECT_NAMESPACE(_) scope; \
                 typedef BASE_TYPE base_type; \
                 static const bchar* base_name (void) {return BOOST_STR_LIT(#BASE_TYPE);}\
         };
@@ -70,9 +94,9 @@
                 ( \
                         bool, \
                         char, signed char, unsigned char, wchar_t, \
- unsigned short, short, \
- int, unsigned, \
- long, unsigned long, \
+ unsigned short int, short, \
+ int, unsigned int, \
+ long, unsigned long int, \
                         float, \
                         double, long double \
                 ) \
@@ -87,6 +111,11 @@
  */
 #undef BOOST_MIRROR_REG_ITH_META_TYPE_NATIVE
 
+/** Now register the bchar and bstring too
+ */
+BOOST_MIRROR_REG_META_TYPEDEFD(_boost, ::boost, bchar)
+BOOST_MIRROR_REG_META_TYPEDEFD(_boost, ::boost, bstring)
+
 
 /** Meta-types for pointers
  */
@@ -134,6 +163,30 @@
 };
 
 
+/** 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_global_scope.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/reflects_global_scope.hpp 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,35 @@
+/**
+ * \file boost/mirror/reflects_global_scope.hpp
+ * Meta function that returns true if the given meta_namespace
+ * reflects the global scope
+ *
+ * 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_GLOBAL_SCOPE_HPP
+#define BOOST_MIRROR_META_REFLECTS_GLOBAL_SCOPE_HPP
+
+// true type/false type for trait templates
+#include <boost/type_traits/integral_constant.hpp>
+
+namespace boost {
+namespace mirror {
+
+/** Is-global-scope trait template for meta-namespaces
+ */
+template <class meta_namespace>
+struct reflects_global_scope : public false_type{ };
+
+/** Is-global-scope trait specialization for global scope meta_namespace
+ */
+template <>
+struct reflects_global_scope<BOOST_MIRROR_REFLECT_NAMESPACE(_)> : public true_type{ };
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/boost/mirror/utils/name_to_stream.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/utils/name_to_stream.hpp (original)
+++ sandbox/mirror/boost/mirror/utils/name_to_stream.hpp 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -7,171 +7,16 @@
  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  */
 
-#ifndef BOOST_MIRROR_UTILS_NAME_TO_STREAM
-#define BOOST_MIRROR_UTILS_NAME_TO_STREAM
+#ifndef BOOST_MIRROR_UTILS_NAME_TO_STREAM_HPP
+#define BOOST_MIRROR_UTILS_NAME_TO_STREAM_HPP
 
-// meta namespaces (includes boost/char_type_switch/string.hpp)
-#include <boost/mirror/meta_namespace.hpp>
-// meta types
-#include <boost/mirror/meta_type.hpp>
+#include <boost/mirror/utils/name_to_stream/namespace.hpp>
+#include <boost/mirror/utils/name_to_stream/type.hpp>
+#include <boost/mirror/utils/name_to_stream/class.hpp>
 
 namespace boost {
 namespace mirror {
 
-/** name_to_stream_helper function object
- */
-template <class meta_object>
-struct name_to_stream_helper;
-
-/** Specialization for the global scope meta-namespace
- */
-template <class namespace_name>
-struct name_to_stream_helper<meta_namespace<void, namespace_name> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return ldng_dbl_cln? s << BOOST_STR_LIT("::") : s;
- }
-};
-
-/** Specialization for the top level namespaces
- */
-template <class namespace_name>
-struct name_to_stream_helper<meta_namespace<namespaces::_, namespace_name> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return (ldng_dbl_cln? s << BOOST_STR_LIT("::") : s) <<
- meta_namespace<namespaces::_, namespace_name>::base_name();
- }
-};
-
-/** Specialization of meta_namespace for nested namespaces
- */
-template <class parent_meta_ns, class namespace_name>
-struct name_to_stream_helper<meta_namespace<parent_meta_ns, namespace_name> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return name_to_stream<parent_meta_ns>::put(s, ldng_dbl_cln) <<
- BOOST_STR_LIT("::") <<
- meta_namespace<parent_meta_ns, namespace_name>::base_name();
- }
-};
-
-/** Specialization for meta-types
- */
-template <typename base_type>
-struct name_to_stream_helper<meta_type<base_type> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- if(!is_global_scope<typename meta_type<base_type>::scope>::value)
- name_to_stream<meta_type<base_type>::scope>::put(s, ldng_dbl_cln) << BOOST_STR_LIT("::");
- else if(ldng_dbl_cln) s << BOOST_STR_LIT("::");
- return s << meta_type<base_type>::base_name();
- }
-};
-
-/** Specialization for meta-types for pointers
- */
-template <typename pointee_type>
-struct name_to_stream_helper<meta_type<pointee_type*> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return name_to_stream_helper<meta_type<pointee_type> >::put(s,ldng_dbl_cln) << BOOST_STR_LIT("*");
- }
-};
-
-/** Specialization for meta-types for references
- */
-template <typename refered_to_type>
-struct name_to_stream_helper<meta_type<refered_to_type&> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return name_to_stream_helper<meta_type<refered_to_type> >::put(s,ldng_dbl_cln) << BOOST_STR_LIT("&");
- }
-};
-
-/** Specialization for meta-types for const types
- */
-template <typename non_const_type>
-struct name_to_stream_helper<meta_type<const non_const_type> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- s << BOOST_STR_LIT("const ");
- return name_to_stream_helper<meta_type<non_const_type> >::put(s,ldng_dbl_cln);
- }
-};
-
-/** Specialization for meta-types for volatile types
- */
-template <typename non_volatile_type>
-struct name_to_stream_helper<meta_type<volatile non_volatile_type> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- s << BOOST_STR_LIT("volatile ");
- return name_to_stream_helper<meta_type<non_volatile_type> >::put(s,ldng_dbl_cln);
- }
-};
-
-/** Specialization for meta-types for volatile types
- */
-template <typename non_cv_type>
-struct name_to_stream_helper<meta_type<const volatile non_cv_type> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- s << BOOST_STR_LIT("const volatile ");
- return name_to_stream_helper<meta_type<non_cv_type> >::put(s,ldng_dbl_cln);
- }
-};
-
-
-/** Specialization for meta-classes
- */
-template <typename base_type>
-struct name_to_stream_helper<meta_class<base_type> > :
-public name_to_stream_helper<meta_type<base_type> > { };
-
-/** name_to_stream function object
- * Puts the whole name of the meta object into the given stream.
- * There are three ways how to use this function object
- * 1) invocation of static member function put(...)
- * name_to_stream<meta_object>::put(stream);
- * 2) construction with a stream as argument
- * name_to_stream<meta_object> nts(stream);
- * 3) construction and calling of the function call operator
- * name_to_stream<meta_object>()(stream); or
- * name_to_stream<meta_object> nts; nts();
- */
-template <typename meta_object>
-struct name_to_stream : public name_to_stream_helper<meta_object>
-{
- // default constructor
- name_to_stream(void){ }
- // this constructor invokes the put operation on the given stream
- template <class out_stream>
- name_to_stream(out_stream& s, bool ldng_dbl_cln = false){put(s, ldng_dbl_cln);}
- // function call operator
- template <class out_stream>
- out_stream& operator()(out_stream& s, bool ldng_dbl_cln = false){return put(s, ldng_dbl_cln);}
-};
-
-
 } // namespace mirror
 } // namespace boost
 

Added: sandbox/mirror/boost/mirror/utils/name_to_stream/class.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/utils/name_to_stream/class.hpp 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,33 @@
+/**
+ * \file boost/mirror/utils/name_to_stream/class.hpp
+ * Putting names of reflected classes to streams
+ *
+ * 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_UTILS_NAME_TO_STREAM_CLASS_HPP
+#define BOOST_MIRROR_UTILS_NAME_TO_STREAM_CLASS_HPP
+
+// helpers for type name
+#include <boost/mirror/utils/name_to_stream/type.hpp>
+// meta classes
+#include <boost/mirror/meta_class.hpp>
+
+namespace boost {
+namespace mirror {
+
+
+/** Specialization for meta-classes
+ */
+template <typename base_type>
+struct name_to_stream_helper<meta_class<base_type> > :
+public name_to_stream_helper<meta_type<base_type> > { };
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Deleted: sandbox/mirror/boost/mirror/utils/name_to_stream/name_to_stream.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/utils/name_to_stream/name_to_stream.hpp 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
+++ (empty file)
@@ -1,179 +0,0 @@
-/**
- * \file boost/mirror/utils/name_to_stream.hpp
- * Putting names of reflected nammespaces, classes, etc. to streams
- *
- * 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_UTILS_NAME_TO_STREAM
-#define BOOST_MIRROR_UTILS_NAME_TO_STREAM
-
-// 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 {
-
-/** name_to_stream_helper function object
- */
-template <class meta_object>
-struct name_to_stream_helper;
-
-/** Specialization for the global scope meta-namespace
- */
-template <class namespace_name>
-struct name_to_stream_helper<meta_namespace<void, namespace_name> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return ldng_dbl_cln? s << BOOST_STR_LIT("::") : s;
- }
-};
-
-/** Specialization for the top level namespaces
- */
-template <class namespace_name>
-struct name_to_stream_helper<meta_namespace<namespaces::_, namespace_name> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return (ldng_dbl_cln? s << BOOST_STR_LIT("::") : s) <<
- meta_namespace<namespaces::_, namespace_name>::base_name();
- }
-};
-
-/** Specialization of meta_namespace for nested namespaces
- */
-template <class parent_meta_ns, class namespace_name>
-struct name_to_stream_helper<meta_namespace<parent_meta_ns, namespace_name> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return name_to_stream<parent_meta_ns>::put(s, ldng_dbl_cln) <<
- BOOST_STR_LIT("::") <<
- meta_namespace<parent_meta_ns, namespace_name>::base_name();
- }
-};
-
-/** Specialization for meta-types
- */
-template <typename base_type>
-struct name_to_stream_helper<meta_type<base_type> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- if(!is_global_scope<typename meta_type<base_type>::scope>::value)
- name_to_stream<meta_type<base_type>::scope>::put(s, ldng_dbl_cln) << BOOST_STR_LIT("::");
- else if(ldng_dbl_cln) s << BOOST_STR_LIT("::");
- return s << meta_type<base_type>::base_name();
- }
-};
-
-/** Specialization for meta-types for pointers
- */
-template <typename pointee_type>
-struct name_to_stream_helper<meta_type<pointee_type*> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return name_to_stream_helper<meta_type<pointee_type> >::put(s,ldng_dbl_cln) << BOOST_STR_LIT("*");
- }
-};
-
-/** Specialization for meta-types for references
- */
-template <typename refered_to_type>
-struct name_to_stream_helper<meta_type<refered_to_type&> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- return name_to_stream_helper<meta_type<refered_to_type> >::put(s,ldng_dbl_cln) << BOOST_STR_LIT("&");
- }
-};
-
-/** Specialization for meta-types for const types
- */
-template <typename non_const_type>
-struct name_to_stream_helper<meta_type<const non_const_type> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- s << BOOST_STR_LIT("const ");
- return name_to_stream_helper<meta_type<non_const_type> >::put(s,ldng_dbl_cln);
- }
-};
-
-/** Specialization for meta-types for volatile types
- */
-template <typename non_volatile_type>
-struct name_to_stream_helper<meta_type<volatile non_volatile_type> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- s << BOOST_STR_LIT("volatile ");
- return name_to_stream_helper<meta_type<non_volatile_type> >::put(s,ldng_dbl_cln);
- }
-};
-
-/** Specialization for meta-types for volatile types
- */
-template <typename non_cv_type>
-struct name_to_stream_helper<meta_type<const volatile non_cv_type> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln = false)
- {
- s << BOOST_STR_LIT("const volatile ");
- return name_to_stream_helper<meta_type<non_cv_type> >::put(s,ldng_dbl_cln);
- }
-};
-
-
-/** Specialization for meta-classes
- */
-template <typename base_type>
-struct name_to_stream_helper<meta_class<base_type> > :
-public name_to_stream_helper<meta_type<base_type> > { };
-
-/** name_to_stream function object
- * Puts the whole name of the meta object into the given stream.
- * There are three ways how to use this function object
- * 1) invocation of static member function put(...)
- * name_to_stream<meta_object>::put(stream);
- * 2) construction with a stream as argument
- * name_to_stream<meta_object> nts(stream);
- * 3) construction and calling of the function call operator
- * name_to_stream<meta_object>()(stream); or
- * name_to_stream<meta_object> nts; nts();
- */
-template <typename meta_object>
-struct name_to_stream : public name_to_stream_helper<meta_object>
-{
- // default constructor
- name_to_stream(void){ }
- // this constructor invokes the put operation on the given stream
- template <class out_stream>
- name_to_stream(out_stream& s, bool ldng_dbl_cln = false){put(s, ldng_dbl_cln);}
- // function call operator
- template <class out_stream>
- out_stream& operator()(out_stream& s, bool ldng_dbl_cln = false){return put(s, ldng_dbl_cln);}
-};
-
-
-} // namespace mirror
-} // namespace boost
-
-#endif //include guard
-

Modified: sandbox/mirror/boost/mirror/utils/name_to_stream/namespace.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/utils/name_to_stream/namespace.hpp (original)
+++ sandbox/mirror/boost/mirror/utils/name_to_stream/namespace.hpp 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -14,14 +14,15 @@
 #include <boost/mirror/utils/name_to_stream/common.hpp>
 // meta namespaces (includes boost/char_type_switch/string.hpp)
 #include <boost/mirror/meta_namespace.hpp>
+#include <boost/mirror/reflects_global_scope.hpp>
 
 namespace boost {
 namespace mirror {
 
 /** Specialization of name_to_stream_helper for the global scope meta-namespace
  */
-template <class namespace_name>
-struct name_to_stream_helper<meta_namespace<void, namespace_name> >
+template <>
+struct name_to_stream_helper< BOOST_MIRROR_REFLECT_NAMESPACE(_) >
 {
         template <class out_stream>
         static out_stream& put(out_stream& s, bool ldng_dbl_cln)
@@ -32,28 +33,20 @@
 
 /** Specialization of name_to_stream_helper for the top level namespaces
  */
-template <class namespace_name>
-struct name_to_stream_helper<meta_namespace<namespaces::_, namespace_name> >
+template <class namespace_alias>
+struct name_to_stream_helper<meta_namespace<namespace_alias> >
 {
+ typedef meta_namespace<namespace_alias> meta_ns;
         template <class out_stream>
         static out_stream& put(out_stream& s, bool ldng_dbl_cln)
         {
- return (ldng_dbl_cln? s << BOOST_STR_LIT("::") : s) <<
- meta_namespace<namespaces::_, namespace_name>::base_name();
- }
-};
-
-/** Specialization of name_to_stream_helper for nested namespaces
- */
-template <class parent_meta_ns, class namespace_name>
-struct name_to_stream_helper<meta_namespace<parent_meta_ns, namespace_name> >
-{
- template <class out_stream>
- static out_stream& put(out_stream& s, bool ldng_dbl_cln)
- {
- return name_to_stream<parent_meta_ns>::put(s, ldng_dbl_cln) <<
- BOOST_STR_LIT("::") <<
- meta_namespace<parent_meta_ns, namespace_name>::base_name();
+ // let the printer print out the base name of the parent namespace
+ name_to_stream<meta_ns::parent>::put(s, ldng_dbl_cln);
+ // if the parent is not the global scope
+ if(!reflects_global_scope<meta_ns::parent>::value)
+ s << BOOST_STR_LIT("::");
+ // let the printer print out the base name of the parent namespace
+ return s << meta_ns::base_name();
         }
 };
 

Added: sandbox/mirror/boost/mirror/utils/name_to_stream/type.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/utils/name_to_stream/type.hpp 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,104 @@
+/**
+ * \file boost/mirror/utils/name_to_stream/type.hpp
+ * Putting names of reflected type to streams
+ *
+ * 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_UTILS_NAME_TO_STREAM_TYPE_HPP
+#define BOOST_MIRROR_UTILS_NAME_TO_STREAM_TYPE_HPP
+
+// include the name to stream helpers for namespaces
+#include <boost/mirror/utils/name_to_stream/namespace.hpp>
+// meta types
+#include <boost/mirror/meta_type.hpp>
+
+namespace boost {
+namespace mirror {
+
+/** Specialization for meta-types
+ */
+template <typename base_type>
+struct name_to_stream_helper<meta_type<base_type> >
+{
+ template <class out_stream>
+ static out_stream& put(out_stream& s, bool ldng_dbl_cln)
+ {
+ if(!reflects_global_scope<typename meta_type<base_type>::scope>::value)
+ name_to_stream<meta_type<base_type>::scope>::put(s, ldng_dbl_cln) << BOOST_STR_LIT("::");
+ else if(ldng_dbl_cln) s << BOOST_STR_LIT("::");
+ return s << meta_type<base_type>::base_name();
+ }
+};
+
+/** Specialization for meta-types for pointers
+ */
+template <typename pointee_type>
+struct name_to_stream_helper<meta_type<pointee_type*> >
+{
+ template <class out_stream>
+ static out_stream& put(out_stream& s, bool ldng_dbl_cln)
+ {
+ return name_to_stream_helper<meta_type<pointee_type> >::put(s,ldng_dbl_cln) << BOOST_STR_LIT("*");
+ }
+};
+
+/** Specialization for meta-types for references
+ */
+template <typename refered_to_type>
+struct name_to_stream_helper<meta_type<refered_to_type&> >
+{
+ template <class out_stream>
+ static out_stream& put(out_stream& s, bool ldng_dbl_cln)
+ {
+ return name_to_stream_helper<meta_type<refered_to_type> >::put(s,ldng_dbl_cln) << BOOST_STR_LIT("&");
+ }
+};
+
+/** Specialization for meta-types for const types
+ */
+template <typename non_const_type>
+struct name_to_stream_helper<meta_type<const non_const_type> >
+{
+ 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<non_const_type> >::put(s,ldng_dbl_cln);
+ }
+};
+
+/** Specialization for meta-types for volatile types
+ */
+template <typename non_volatile_type>
+struct name_to_stream_helper<meta_type<volatile non_volatile_type> >
+{
+ template <class out_stream>
+ static out_stream& put(out_stream& s, bool ldng_dbl_cln)
+ {
+ s << BOOST_STR_LIT("volatile ");
+ return name_to_stream_helper<meta_type<non_volatile_type> >::put(s,ldng_dbl_cln);
+ }
+};
+
+/** Specialization for meta-types for const volatile types
+ */
+template <typename non_cv_type>
+struct name_to_stream_helper<meta_type<const volatile non_cv_type> >
+{
+ template <class out_stream>
+ static out_stream& put(out_stream& s, bool ldng_dbl_cln)
+ {
+ s << BOOST_STR_LIT("const volatile ");
+ return name_to_stream_helper<meta_type<non_cv_type> >::put(s,ldng_dbl_cln);
+ }
+};
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/libs/doc/xml/css/mirror.css
==============================================================================
--- sandbox/mirror/libs/doc/xml/css/mirror.css (original)
+++ sandbox/mirror/libs/doc/xml/css/mirror.css 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -25,6 +25,8 @@
 
 DIV.section {
         padding-left: 2.5em;
+ padding-right: 0.5em;
+ border: 1px solid #C0F0C0;
 }
 
 DIV.licensing-notice, DIV.copyright-notice, DIV.revision-notice {
@@ -48,12 +50,16 @@
         border: 1px solid #A0C0A0;
         background-color: #E0FFE0;
         padding: 0.5em;
+ margin-top: 1em;
+ margin-bottom: 0.5em;
 }
 
 P.note {
         border: 1px solid #C0A0A0;
         background-color: #FFE0E0;
         padding: 0.5em;
+ margin-left: 1em;
+ width: 90%;
 }
 
 

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 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -21,5 +21,14 @@
                 <revision id="20080416" major="0" minor="1" micro="1" author="m_ch">
                         Updated documentation and added several examples.
                 </revision>
+ <revision id="20080417_1146CET" major="0" minor="1" micro="2" author="m_ch">
+ - Modified the REG_NAMESPACE*(...) macros to make them much more simple
+ - Modified the name_to_stream templates and split the sources into
+ separate files
+ - Added BOOST_MIRROR_REFLECT_NAMESPACE and BOOST_MIRROR_REFLECT_TYPE*
+ macros that expand to the approrpiate meta-object type
+ - Updated documentation
+ - Added example on type registration and usage
+ </revision>
         </revisions>
 </library>

Modified: sandbox/mirror/libs/doc/xml/mirror/sections/char_type.xml
==============================================================================
--- sandbox/mirror/libs/doc/xml/mirror/sections/char_type.xml (original)
+++ sandbox/mirror/libs/doc/xml/mirror/sections/char_type.xml 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -3,7 +3,7 @@
         <paragraph>
                 The <lib_name_ref/> library defines and uses <cpp_expr>::boost::bchar</cpp_expr> (or <cpp_expr>bchar</cpp_expr>) character type and several other types like <cpp_expr>bstring</cpp_expr>, <cpp_expr>bcin</cpp_expr>, <cpp_expr>bcout</cpp_expr>, <cpp_expr>bcerr</cpp_expr>, etc. defined in the <cpp_expr>boost</cpp_expr> namespace. These types are defined as <cpp_expr>char</cpp_expr> (and <cpp_expr>::std::string</cpp_expr>, <cpp_expr>::std::cin</cpp_expr>, <cpp_expr>::std::cout</cpp_expr>, <cpp_expr>::std::cerr</cpp_expr>, respectively) when the preprocessor symbol <cpp_expr>BOOST_USE_WIDE_CHARS</cpp_expr> is <emph>not</emph> defined (this is the default) and defined as <cpp_expr>wchar_t</cpp_expr> (and <cpp_expr>::std::wstring</cpp_expr>, <cpp_expr>::std::wcin</cpp_expr>, <cpp_expr>::std::wcout</cpp_expr>, <cpp_expr>::std::wcerr</cpp_expr>, respectively) otherwise.
         <paragraph>
- There is also a macro named <cpp_expr>BOOST_STR_LIT(STRING_LITERAL)</cpp_expr> that expands either to <cpp_expr>STRING_LITERAL</cpp_expr> or to <cpp_expr>L##STRING_LITERAL</cpp_expr> based on the <cpp_expr>BOOST_USE_WIDE_CHARS</cpp_expr> being defined.
+ There is also a macro named <cpp_expr>BOOST_STR_LIT(STRING_LITERAL)</cpp_expr> that expands either to <cpp_expr>STRING_LITERAL</cpp_expr> or to <cpp_expr>L##STRING_LITERAL</cpp_expr> based on the <cpp_expr>BOOST_USE_WIDE_CHARS</cpp_expr> not being or being defined.
 
         </paragraph>
         </paragraph>

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 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -1,11 +1,13 @@
 /**
  * \file examples/registering/namespaces.hpp
- * Example of namespace registering and reflection
+ * Example of namespace registering and reflection with
+ * the mirror library
  *
  * 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)
  */
+
 // narrow/wide char stream
 #include <boost/char_type_switch/iostream.hpp>
 // namespace registering
@@ -38,14 +40,15 @@
 // register the namespaces
 //
 // the namespace 'test' in the global scope
-BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(test, BOOST_PP_TUPLE_REM_CTOR(4,('t','e','s','t')))
+BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(test)
 // namespace feature in namespace ::test
 // the _test is a "namespace alias" for namespace ::test
 // _ is the namespace alias for the global scope
-BOOST_MIRROR_REG_META_NAMESPACE(_test, feature, BOOST_PP_TUPLE_REM_CTOR(7,('f','e','a','t','u','r','e')))
-BOOST_MIRROR_REG_META_NAMESPACE(_test_feature, detail, BOOST_PP_TUPLE_REM_CTOR(6,('d','e','t','a','i','l')))
-BOOST_MIRROR_REG_META_NAMESPACE(_test, stuff, BOOST_PP_TUPLE_REM_CTOR(5,('s','t','u','f','f')))
-BOOST_MIRROR_REG_META_NAMESPACE(_test_stuff, detail, BOOST_PP_TUPLE_REM_CTOR(6,('d','e','t','a','i','l')))
+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)
 
 } // namespace mirror
 } // namespace boost

Added: sandbox/mirror/libs/examples/registering/types.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/examples/registering/types.cpp 2008-04-17 05:49:53 EDT (Thu, 17 Apr 2008)
@@ -0,0 +1,127 @@
+/**
+ * \file examples/registering/types.hpp
+ * Example of type registering and reflection with
+ * the mirror library
+ *
+ * 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)
+ */
+
+// narrow/wide char stream
+#include <boost/char_type_switch/iostream.hpp>
+
+#include <boost/mirror/meta_namespace.hpp>
+#include <boost/mirror/meta_type.hpp>
+// utility that allows to put the name of the type to a given stream
+#include <boost/mirror/utils/name_to_stream/type.hpp>
+//
+//
+#include <boost/typeof/typeof.hpp>
+
+
+
+namespace test {
+namespace feature {
+namespace detail {
+
+struct foo { };
+struct bar { };
+
+} // namespace detail
+} // namespace feature
+} // namespace test
+
+
+namespace boost {
+namespace mirror {
+
+// register the namespaces
+//
+// NOTE: if You are not familiar with namespace registration and usage
+// see the examples/registering/namespaces.cpp source file
+//
+BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(test)
+BOOST_MIRROR_REG_META_NAMESPACE(_test, feature)
+BOOST_MIRROR_REG_META_NAMESPACE(_test_feature, detail)
+//
+// 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)
+
+} // namespace mirror
+} // namespace boost
+
+
+int main(void)
+{
+ using namespace ::std;
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ using ::test::feature::detail::foo;
+ using ::test::feature::detail::bar;
+ //
+ // 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;
+ //
+ // 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;
+ //
+ // 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 << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(const volatile foo) >() << endl;
+ bcout << 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;
+ //
+ // use with Boost.Typeof
+ bcout << 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;
+ //
+ // sometimes it is useful to distinguish between a typedef'd type
+ // and the 'source' type.
+ //
+ // this reflects bchar as char or wchar_t defined
+ // on compilation configuration
+ typedef BOOST_MIRROR_REFLECT_TYPE(bchar) meta_bchar;
+ // this returns a meta-type that allows to query the typedef'd name
+ typedef BOOST_MIRROR_REFLECT_TYPEDEFD(_boost, bchar) meta_bchar_td;
+ //
+ bcout << name_to_stream< meta_bchar >() << endl;
+ bcout << name_to_stream< meta_bchar_td >() << endl;
+ //
+ // unfortunately BOOST_MIRROR_REFLECT_TYPEDEFD(...) works only if
+ // the typedefined name is explicitly given
+ // still it can be useful in certin situations.
+ // However, the next line for example would fail to compile
+ //typedef BOOST_MIRROR_REFLECT_TYPEDEFD(_boost, BOOST_TYPEOF(L'x')) meta_bchar_td;
+ //
+ //
+ 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