|
Boost-Commit : |
From: chochlik_at_[hidden]
Date: 2008-07-04 08:42:06
Author: matus.chochlik
Date: 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
New Revision: 47072
URL: http://svn.boost.org/trac/boost/changeset/47072
Log:
- This is the start of a new branch (0.2.x)
- Several features previosly implemented by the means of the preprocessor were rewritten using templates
- Fully qualified name composing has been rewritten using standard C++ strings
- Complete rewrite of namespace registering and reflection
- The macro MIRROR_REG_NAMESPACE(NAME_SEQ) can now be used for registering both top-level and nested namespaces. Both registering and reflection have been fairly simplified
- Replaced the MIRROR_REFLECT_NAMESPACE with MIRRORED_NAMESPACE macro that takes the full namespace name instead of a namespace alias MIRROR_REFLECT_NAMESPACE(_boost_mirror) is now MIRRORED_NAMESPACE(::boost::mirror).
- Added MIRRORED_GLOBAL_SCOPE() to reflect global scope namespace which is equivalent but preferred to MIRRORED_NAMESPACE(::__)
- Complete rewrite of type registering and reflection
- WARNING: this revision will probably not compile
Added:
sandbox/mirror/boost/mirror/detail/full_name_builder.hpp (contents, props changed)
Text files modified:
sandbox/mirror/boost/char_type_switch/string.hpp | 13 ++
sandbox/mirror/boost/mirror/meta_data_fwd.hpp | 11 +
sandbox/mirror/boost/mirror/meta_namespace.hpp | 206 ++++++++++++++++++++++++---------------
sandbox/mirror/boost/mirror/meta_type.hpp | 78 ++++++++++----
sandbox/mirror/boost/mirror/traits/reflects_global_scope.hpp | 6
sandbox/mirror/boost/mirror/utils/name_to_stream/namespace.hpp | 10
sandbox/mirror/libs/mirror/doc/xml/mirror/_library.xml | 15 ++
sandbox/mirror/libs/mirror/example/registering/namespaces.cpp | 74 ++++++-------
sandbox/mirror/libs/mirror/example/registering/types.cpp | 78 +++++++-------
9 files changed, 296 insertions(+), 195 deletions(-)
Modified: sandbox/mirror/boost/char_type_switch/string.hpp
==============================================================================
--- sandbox/mirror/boost/char_type_switch/string.hpp (original)
+++ sandbox/mirror/boost/char_type_switch/string.hpp 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -10,6 +10,7 @@
#ifndef BOOST_CHAR_WIDTH_SWITCH_STRING
#define BOOST_CHAR_WIDTH_SWITCH_STRING
+
#include <boost/char_type_switch/choice.hpp>
#include <boost/config.hpp>
// Needed for ::std::string / ::std::wstring
@@ -22,6 +23,9 @@
#ifdef BOOST_USE_WIDE_CHARS
+
+#include <boost/preprocessor/wstringize.hpp>
+
// If wide characters were chosen
//
// define character type
@@ -30,7 +34,12 @@
typedef ::std::wstring bstring;
// define macro for string literal type selection
# define BOOST_STR_LIT(STR) L##STR
+ // stringization
+# define BOOST_CTS_STRINGIZE(TO_TEXT) BOOST_PP_WSTRINGIZE(TO_TEXT)
#else // NOT BOOST_USE_WIDE_CHARS
+
+#include <boost/preprocessor/stringize.hpp>
+
// if narrow characters were chosen
//
// define character type
@@ -39,9 +48,11 @@
typedef ::std::string bstring;
// define macro for string literal type selection
# define BOOST_STR_LIT(STR) STR
+ // stringization
+# define BOOST_CTS_STRINGIZE(TO_TEXT) BOOST_PP_STRINGIZE(TO_TEXT)
#endif // NOT BOOST_USE_WIDE_CHARS
-// define macro expanding into a compile time const lenght
+// define macro expanding into a compile time const length
// of the given string literal
#define BOOST_STR_LIT_LENGTH(STR) ((sizeof(STR)/sizeof(char))-1)
Added: sandbox/mirror/boost/mirror/detail/full_name_builder.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/detail/full_name_builder.hpp 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -0,0 +1,69 @@
+/**
+ * \file boost/mirror/detail/full_name_builder.hpp
+ *
+ * Helper template that decorates classes having base_name function and
+ * a scope meta-object with full_name function and full_name_length
+ * constant
+ *
+ * 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_DETAIL_FULL_NAME_BUILDER_HPP
+#define BOOST_MIRROR_META_DETAIL_FULL_NAME_BUILDER_HPP
+
+// template meta programming
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/plus.hpp>
+
+// forward declarations and common mirror defs
+#include <boost/mirror/common_defs.hpp>
+#include <boost/mirror/meta_data_fwd.hpp>
+
+// char-type related
+#include <boost/char_type_switch/string.hpp>
+
+namespace boost {
+namespace mirror {
+
+namespace detail {
+
+ /** Helper template that builds the fully qualified names
+ * from base names
+ */
+ template <class Scope, class BaseMetaObject>
+ struct full_name_builder : public BaseMetaObject
+ {
+ private:
+ // initializes the full names
+ inline static bstring init_full_name(void)
+ {
+ bstring res(Scope::full_name());
+ res.append(bstring(BOOST_STR_LIT("::")));
+ res.append(bstring(BaseMetaObject::base_name()));
+ return res;
+ }
+ public:
+ // full name getter
+ inline static const bchar* full_name(void)
+ {
+ static bstring s_full_name(init_full_name());
+ return s_full_name.c_str();
+ }
+
+ // the full name length
+ typedef typename ::boost::mpl::plus<
+ typename Scope::full_name_length,
+ typename ::boost::mpl::int_<2>::type,
+ typename BaseMetaObject::base_name_length
+ >::type full_name_length;
+ };
+
+
+} // namespace detail
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Modified: sandbox/mirror/boost/mirror/meta_data_fwd.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_data_fwd.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_data_fwd.hpp 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -15,14 +15,17 @@
/** Meta-namespace forward template declaration
*/
-template<class NamespaceAlias>
+template<class NamespacePlaceholder>
struct meta_namespace;
/** Macro that expands into the meta_namespace for the
- * namespace with the given alias.
+ * passed namespace.
*/
-#define BOOST_MIRROR_REFLECT_NAMESPACE(NAMESPACE_ALIAS) \
- ::boost::mirror::meta_namespace<namespaces::NAMESPACE_ALIAS>
+#define BOOST_MIRRORED_NAMESPACE(FULL_NAMESPACE_NAME) \
+ mirror::meta_namespace< namespace_ ## FULL_NAMESPACE_NAME ## ::_ >
+
+#define BOOST_MIRRORED_GLOBAL_SCOPE() \
+ mirror::meta_namespace< namespace_ ## ::_ >
Modified: sandbox/mirror/boost/mirror/meta_namespace.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_namespace.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_namespace.hpp 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -7,103 +7,147 @@
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
-#ifndef BOOST_MIRROR_META_NAMESPACE_HPP
-#define BOOST_MIRROR_META_NAMESPACE_HPP
+#ifndef BOOST_MIRROR_META_NAMESPACE
+#define BOOST_MIRROR_META_NAMESPACE
-// for various typelists
+// preprocessor related things
+#include <boost/preprocessor/seq/for_each.hpp>
+#include <boost/preprocessor/seq/reverse.hpp>
+#include <boost/preprocessor/seq/pop_back.hpp>
+#include <boost/preprocessor/seq/seq.hpp>
+
+// template meta programming
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/plus.hpp>
#include <boost/mpl/vector.hpp>
-// common mpl algoritgms
#include <boost/mpl/push_back.hpp>
-//
-// for bulk declarations
-#include <boost/preprocessor.hpp>
-// mirror uses switchable character type
-#include <boost/char_type_switch/string.hpp>
-// forward declarations
-#include <boost/mirror/meta_data_fwd.hpp>
-// implementation helpers
+// forward declarations and common mirror defs
#include <boost/mirror/common_defs.hpp>
+#include <boost/mirror/meta_data_fwd.hpp>
+
+// char-type related
+#include <boost/char_type_switch/string.hpp>
+// full name builder
+#include <boost/mirror/detail/full_name_builder.hpp>
+
namespace boost {
namespace mirror {
-/** defines an alias (_) for the meta-namespace for the global scope
- */
-namespace namespaces { struct _{ }; }
-
-/** meta-namespace for the global scope
+/** Meta data about namespaces
*/
-template<> struct meta_namespace< namespaces::_ >
+template <class NamespacePlaceholder>
+struct meta_namespace
+: detail::full_name_builder<
+ meta_namespace<typename NamespacePlaceholder::parent_placeholder>,
+ NamespacePlaceholder
+>
{
- typedef void parent;
- typedef mpl::vector0<> scope;
-
- static const bchar* base_name(void) {return BOOST_STR_LIT("");}
- BOOST_STATIC_CONSTANT(int, base_name_length = 0);
-
- static const bchar* full_name(void) {return BOOST_STR_LIT("");}
- BOOST_STATIC_CONSTANT(int, full_name_length = 0);
+ // the parent meta_namespace
+ typedef meta_namespace<
+ typename NamespacePlaceholder::parent_placeholder
+ > scope;
+
+ //
+ typedef typename ::boost::mpl::push_back<
+ typename scope::ancestors,
+ scope
+ >::type ancestors;
};
-
-/** Helper macro for registering new general namespaces (top level or nested)
+/** The declaration of the namespace placeholder for the
+ * global scope
*/
-#define BOOST_MIRROR_REG_NAMESPACE_HELPER(PARENT_NS_ALIAS, NAMESPACE_NAME) \
-{ \
- typedef meta_namespace< namespaces :: PARENT_NS_ALIAS > parent; \
- typedef mpl::push_back<parent::scope, parent>::type scope; \
- BOOST_STATIC_CONSTANT(\
- int, \
- base_name_length = \
- BOOST_STR_LIT_LENGTH(#NAMESPACE_NAME)\
- ); \
- static const bchar* base_name(void) {return BOOST_STR_LIT(#NAMESPACE_NAME);} \
- BOOST_STATIC_CONSTANT(\
- int, \
- full_name_length = \
- parent::full_name_length + 2 + \
- base_name_length \
- ); \
- static const bchar* full_name(void)\
- {\
- static bchar the_full_name[full_name_length] = \
- BOOST_STR_LIT(""); \
- if(!the_full_name[0]) \
- { \
- bchar * pos = the_full_name; \
- bstrncpy(pos, parent::full_name(), parent::full_name_length);\
- pos += parent::full_name_length; \
- bstrncpy(pos, BOOST_STR_LIT("::"), 2);\
- pos += 2; \
- bstrncpy(pos, base_name(), base_name_length);\
- } \
- return the_full_name; \
- } \
-};
-
-
-/** Macro for registering new general namespaces (top level or nested)
- */
-#define BOOST_MIRROR_REG_NAMESPACE(PARENT_NS_ALIAS, NAMESPACE_NAME) \
- namespace namespaces {struct PARENT_NS_ALIAS##_##NAMESPACE_NAME { }; }\
- template<> struct meta_namespace< namespaces :: PARENT_NS_ALIAS##_##NAMESPACE_NAME > \
- BOOST_MIRROR_REG_NAMESPACE_HELPER(PARENT_NS_ALIAS, NAMESPACE_NAME)
+namespace namespace_ {
+ struct _
+ {
+ // the base name of the namespace
+ inline static const bchar* base_name(void){return BOOST_STR_LIT("");}
+
+ // length of the basename:number of characters w/o the terminating '\0'
+ typedef ::boost::mpl::int_<0>::type base_name_length;
+
+ // the base name of the namespace
+ inline static const bchar* full_name(void){return base_name();}
+
+ // the length of the full name without the terminating null
+ typedef base_name_length full_name_length;
+ };
+
+ // this is necessary for MIRORRED_NAMESPACE() to work with
+ // the global scope
+ namespace __ {
+ typedef struct namespace_::_ _;
+ } // namespace __
+} // namespace namespace_
+
+// meta_namespace specialization for the global scope
+template < >
+struct meta_namespace< namespace_ :: _ > : namespace_ :: _
+{
+ typedef mpl::vector0<> ancestors;
+};
-/** Macro for registering of top-level namespaces
- */
-#define BOOST_MIRROR_REG_NAMESPACE_TOP_LEVEL(NAMESPACE_NAME) \
- namespace namespaces {struct _##NAMESPACE_NAME { }; }\
- template<> struct meta_namespace< namespaces :: _##NAMESPACE_NAME > \
- BOOST_MIRROR_REG_NAMESPACE_HELPER(_, NAMESPACE_NAME)
-
-// Registration of the ::std namespace
-BOOST_MIRROR_REG_NAMESPACE_TOP_LEVEL(std)
-// Registration of the ::boost namespace
-BOOST_MIRROR_REG_NAMESPACE_TOP_LEVEL(boost)
-// Registration of the ::boost::mirror namespace
-BOOST_MIRROR_REG_NAMESPACE(_boost, mirror)
+// helper macro expanded multiple times during the namespace registration
+#define BOOST_MIRROR_REG_NAMESPACE_PROLOGUE_HELPER(R, DATA, NAMESPACE_NAME) \
+ namespace NAMESPACE_NAME {
+
+// helper macro expanded multiple times during the namespace registration
+#define BOOST_MIRROR_REG_NAMESPACE_EPILOGUE_HELPER(R, DATA, NAMESPACE_NAME) \
+ } // namespace NAMESPACE_NAME
+
+// helper macro expanded multiple times during the namespace registration
+#define BOOST_MIRROR_REG_NAMESPACE_ENUM_HELPER(R, DATA, NAMESPACE_NAME) \
+ :: NAMESPACE_NAME
+
+
+/** Macro that does the registering of a namespace.
+ * The argument must be a BOOST_PP sequence containing the
+ * names of the parent namspaces and the registered namespace.
+ *
+ * The sequence needed to register namespace ::test is (test)
+ * To register ::test::foo::bar::baz use (test)(foo)(bar)(baz)
+ */
+#define BOOST_MIRROR_REG_NAMESPACE(NAME_SEQUENCE) \
+ namespace namespace_ { \
+ BOOST_PP_SEQ_FOR_EACH(BOOST_MIRROR_REG_NAMESPACE_PROLOGUE_HELPER, _, NAME_SEQUENCE) \
+ struct _ \
+ { \
+ typedef namespace_ \
+ BOOST_PP_SEQ_FOR_EACH( \
+ BOOST_MIRROR_REG_NAMESPACE_ENUM_HELPER, \
+ _, \
+ BOOST_PP_SEQ_POP_BACK(NAME_SEQUENCE) \
+ ) :: _ parent_placeholder; \
+ static const bchar* base_name(void) \
+ { \
+ return BOOST_CTS_STRINGIZE( \
+ BOOST_PP_SEQ_HEAD( \
+ BOOST_PP_SEQ_REVERSE(NAME_SEQUENCE) \
+ ) \
+ ); \
+ } \
+ typedef ::boost::mpl::int_< \
+ BOOST_STR_LIT_LENGTH( \
+ BOOST_CTS_STRINGIZE( \
+ BOOST_PP_SEQ_HEAD( \
+ BOOST_PP_SEQ_REVERSE(NAME_SEQUENCE) \
+ ) \
+ ) \
+ ) \
+ >::type base_name_length; \
+ }; \
+ BOOST_PP_SEQ_FOR_EACH(BOOST_MIRROR_REG_NAMESPACE_EPILOGUE_HELPER, _, NAME_SEQUENCE) \
+ }
+
+
+/** Register some of the common namespaces
+ */
+BOOST_MIRROR_REG_NAMESPACE((std))
+BOOST_MIRROR_REG_NAMESPACE((boost))
+BOOST_MIRROR_REG_NAMESPACE((boost)(mirror))
} // 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-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -10,13 +10,8 @@
#ifndef BOOST_MIRROR_META_TYPE_HPP
#define BOOST_MIRROR_META_TYPE_HPP
-// meta namespaces (includes boost/char_type_switch/string.hpp)
+// meta namespaces
#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>
-//
//
#include <boost/mirror/detail/const_type_name.hpp>
#include <boost/mirror/detail/volatile_type_name.hpp>
@@ -29,6 +24,53 @@
namespace boost {
namespace mirror {
+namespace detail {
+ template <typename Type>
+ struct defined_type_info;
+} // namespace detail
+
+
+/** Meta-data describing types
+ */
+template <typename Type>
+struct meta_type
+: public detail::full_name_builder<
+ typename defined_type_info<Type>::scope,
+ defined_type_info<Type>
+>{ };
+
+/** Macro for declaration of meta-types
+ */
+#define BOOST_MIRROR_REG_TYPE(NAMESPACE, BASE_NAME) \
+ namespace detail { \
+ template <> struct defined_type_info< NAMESPACE::BASE_NAME > \
+ { \
+ typedef BOOST_MIRRORED_NAMESPACE(NAMESPACE) scope; \
+ typedef NAMESPACE::BASE_NAME reflected_type; \
+ static const bchar* base_name(void) {return BOOST_STR_LIT(#BASE_NAME);} \
+ typedef typename ::boost::mpl::int_< \
+ BOOST_STR_LIT_LENGTH(#BASE_NAME) \
+ >::type base_name_length; \
+ }; \
+ } // namespace detail
+
+/** Macro for declaration of meta-types
+ */
+#define BOOST_MIRROR_REG_TYPE_GLOBAL_SCOPE(BASE_NAME) \
+ namespace detail { \
+ template <> struct defined_type_info< BASE_NAME > \
+ { \
+ typedef BOOST_MIRRORED_GLOBAL_SCOPE() scope; \
+ typedef BASE_NAME reflected_type; \
+ static const bchar* base_name(void) {return BOOST_STR_LIT(#BASE_NAME);} \
+ typedef typename ::boost::mpl::int_< \
+ BOOST_STR_LIT_LENGTH(#BASE_NAME) \
+ >::type base_name_length; \
+ }; \
+ } // namespace detail
+
+
+#ifdef NEVER_COMPILE_THIS
namespace detail {
@@ -75,21 +117,6 @@
}
-/** Macro for declaration of meta-types
- */
-#define BOOST_MIRROR_REG_TYPE(NAMESPACE_ALIAS, NAMESPACE, BASE_NAME) \
- template <> struct meta_type< NAMESPACE::BASE_NAME > \
- { \
- typedef BOOST_MIRROR_REFLECT_NAMESPACE(NAMESPACE_ALIAS) scope; \
- typedef NAMESPACE::BASE_NAME reflected_type; \
- static const bchar* base_name(void) {return BOOST_STR_LIT(#BASE_NAME);}\
- BOOST_STATIC_CONSTANT( \
- int, \
- base_name_length = \
- BOOST_STR_LIT_LENGTH(#BASE_NAME)\
- ); \
- BOOST_MIRROR_TMP_DECLARE_META_TYPE_FULL_NAME() \
- };
/** Macro for declaration of meta-types for typedefined types
*/
@@ -145,6 +172,7 @@
BOOST_MIRROR_TMP_DECLARE_META_TYPE_FULL_NAME() \
};
+#endif // NEVER_COMPILE_THIS
/** Helper macro used for batch registering of the meta-types for
* the C++ native types
@@ -179,12 +207,12 @@
/** Register std string and wstring
*/
-BOOST_MIRROR_REG_TYPE(_std, ::std, string)
-BOOST_MIRROR_REG_TYPE(_std, ::std, wstring)
+BOOST_MIRROR_REG_TYPE(::std, string)
+BOOST_MIRROR_REG_TYPE(::std, wstring)
/** Now register the bchar and bstring too
*/
-BOOST_MIRROR_REG_TYPEDEFD(_boost, ::boost, bchar)
-BOOST_MIRROR_REG_TYPEDEFD(_boost, ::boost, bstring)
+BOOST_MIRROR_REG_TYPEDEFD(::boost, bchar)
+BOOST_MIRROR_REG_TYPEDEFD(::boost, bstring)
/** Meta-types for pointers
Modified: sandbox/mirror/boost/mirror/traits/reflects_global_scope.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/traits/reflects_global_scope.hpp (original)
+++ sandbox/mirror/boost/mirror/traits/reflects_global_scope.hpp 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -21,12 +21,14 @@
/** Reflects-global-scope trait template for other meta-namespaces
*/
template <class MetaNamespace>
-struct reflects_global_scope : public false_type{ };
+struct reflects_global_scope
+: public false_type{ };
/** Reflects-global-scope trait specialization for global scope meta_namespace
*/
template <>
-struct reflects_global_scope<BOOST_MIRROR_REFLECT_NAMESPACE(_)> : public true_type{ };
+struct reflects_global_scope< BOOST_MIRRORED_GLOBAL_SCOPE() >
+: public true_type{ };
} // namespace mirror
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-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -22,7 +22,7 @@
/** Specialization of name_to_stream_helper for the global scope meta-namespace
*/
template <>
-struct name_to_stream_helper< BOOST_MIRROR_REFLECT_NAMESPACE(_) >
+struct name_to_stream_helper< BOOST_MIRRORED_GLOBAL_SCOPE() >
{
template <class OutStream>
static OutStream& put(OutStream& s, bool ldng_dbl_cln)
@@ -33,14 +33,14 @@
/** Specialization of name_to_stream_helper for the top level namespaces
*/
-template <class NamespaceAlias>
-struct name_to_stream_helper<meta_namespace<NamespaceAlias> >
+template <class NamespacePlaceholder>
+struct name_to_stream_helper<meta_namespace<NamespacePlaceholder> >
{
- typedef meta_namespace<NamespaceAlias> meta_ns;
+ typedef meta_namespace<NamespacePlaceholder> meta_ns;
template <class OutStream>
static OutStream& put(OutStream& s, bool ldng_dbl_cln)
{
- typedef typename meta_ns::parent parent_ns;
+ typedef typename meta_ns::scope parent_ns;
// let the printer print out the base name of the parent namespace
name_to_stream<parent_ns>::put(s, ldng_dbl_cln);
// if the parent is not the global scope
Modified: sandbox/mirror/libs/mirror/doc/xml/mirror/_library.xml
==============================================================================
--- sandbox/mirror/libs/mirror/doc/xml/mirror/_library.xml (original)
+++ sandbox/mirror/libs/mirror/doc/xml/mirror/_library.xml 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -229,5 +229,20 @@
- Tested with gcc 4.3.0 on SuSE
- Tested with intel 10.1 on SuSE
</revision>
+ <revision id="20080704" major="0" minor="2" micro="0" author="m_ch">
+ - New branch
+ - Several features implemented by the means of the preprocessor were rewritten using templates
+ - Fully qualified name composing has been rewritten using standard C++ strings
+ - Complete rewrite of namespace registering and reflection
+ - The macro MIRROR_REG_NAMESPACE(NAME_SEQ) can now be used for registering both top-level and nested namespaces
+ Both registering and reflection have been fairly simplified
+ - Replaced the MIRROR_REFLECT_NAMESPACE with MIRRORED_NAMESPACE macro that takes the full namespace name instead
+ of a namespace alias MIRROR_REFLECT_NAMESPACE(_boost_mirror) is now MIRRORED_NAMESPACE(::boost::mirror).
+ - Added MIRRORED_GLOBAL_SCOPE() to reflect global scope namespace which is equivalent but preffered to
+ MIRRORED_NAMESPACE(::__)
+ - Complete rewrite of type registering and reflection
+
+ - Tested with MSVC++ 2008 EE On Vista
+ </revision>
</revisions>
</library>
Modified: sandbox/mirror/libs/mirror/example/registering/namespaces.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/registering/namespaces.cpp (original)
+++ sandbox/mirror/libs/mirror/example/registering/namespaces.cpp 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -39,16 +39,12 @@
// register the namespaces
//
-// the namespace 'test' in the global scope
-BOOST_MIRROR_REG_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_NAMESPACE(_test, feature)
-BOOST_MIRROR_REG_NAMESPACE(_test_feature, detail)
+BOOST_MIRROR_REG_NAMESPACE((test))
+BOOST_MIRROR_REG_NAMESPACE((test)(feature))
+BOOST_MIRROR_REG_NAMESPACE((test)(feature)(detail))
//
-BOOST_MIRROR_REG_NAMESPACE(_test, stuff)
-BOOST_MIRROR_REG_NAMESPACE(_test_stuff, detail)
+BOOST_MIRROR_REG_NAMESPACE((test)(stuff))
+BOOST_MIRROR_REG_NAMESPACE((test)(stuff)(detail))
} // namespace mirror
} // namespace boost
@@ -63,14 +59,16 @@
// ~ wcout when using wide chars
// it's typedef'd in the boost namespace
//
- // the BOOST_MIRROR_REFLECT_NAMESPACE(NAMESPACE_ALIAS) returns the
- // meta_namespace<> specialization for the given namespace alias
+ // the BOOST_MIRRORED_NAMESPACE(FULL_NAMESPACE_NAME) returns the
+ // meta_namespace<> specialization for the given namespace
//
- // define an alternative name for the global scope meta-data
- typedef BOOST_MIRROR_REFLECT_NAMESPACE(_) meta_ns_global_scope;
+ // define an alternative name for the global scope meta-namespace
+ // BOOST_MIRRORED_NAMESPACE(::__) is equivalent to this
+ typedef BOOST_MIRRORED_GLOBAL_SCOPE() meta_ns_global_scope;
+
// define an alternative name for the ::test namespace meta-data
- typedef BOOST_MIRROR_REFLECT_NAMESPACE(_test) meta_ns_test;
- typedef BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff_detail) meta_ns_test_stuff_detail;
+ typedef BOOST_MIRRORED_NAMESPACE(::test) meta_ns_test;
+ typedef BOOST_MIRRORED_NAMESPACE(::test::stuff::detail) meta_ns_test_stuff_detail;
//
//
// the base name function allows to get the base name
@@ -83,45 +81,45 @@
// namespace of the given namespace
//
// print the base name of the parent namespace
- bcout << "|02| " <<meta_ns_test_stuff_detail::parent::base_name() << endl;
- bcout << "|03| " <<meta_ns_test_stuff_detail::parent::parent::base_name() << endl;
+ bcout << "|02| " <<meta_ns_test_stuff_detail::scope::base_name() << endl;
+ bcout << "|03| " <<meta_ns_test_stuff_detail::scope::scope::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 << "|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;
+ bcout << "|04| " <<mpl::size<meta_ns_global_scope::ancestors>::value << endl;
+ bcout << "|05| " <<mpl::size<meta_ns_test::ancestors>::value << endl;
+ bcout << "|06| " <<mpl::size<meta_ns_test_stuff_detail::ancestors>::value << endl;
//
// the name_to_stream<meta_object> class allows to put the full name
// (including the scope) into a stream
- 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;
+ bcout << "|07| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::__) >() << endl;
+ bcout << "|08| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::test) >() << endl;
+ bcout << "|09| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::test::stuff) >() << endl;
+ bcout << "|10| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::test::stuff::detail) >() << endl;
// in this case the :: is prepended to the full name
// thus test::stuff -> ::test::stuff
- 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;
+ bcout << "|11| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::__) >(true) << endl;
+ bcout << "|12| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::test) >(true) << endl;
+ bcout << "|13| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::test::stuff) >(true) << endl;
+ bcout << "|14| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::test::stuff::detail) >(true) << endl;
//
// there are few namespace registered by default
// including (::std, ::boost, ::boost::mirror)
- 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;
+ bcout << "|15| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::std) >(true) << endl;
+ bcout << "|16| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::boost) >(true) << endl;
+ bcout << "|17| " <<name_to_stream< BOOST_MIRRORED_NAMESPACE(::boost::mirror) >(true) << endl;
//
// printing out the full namespace names directly without the name_to_stream
// printer template
- bcout << "|18| " << BOOST_MIRROR_REFLECT_NAMESPACE(_) ::full_name() << endl;
- bcout << "|19| " << BOOST_MIRROR_REFLECT_NAMESPACE(_std) ::full_name() << endl;
- bcout << "|20| " << BOOST_MIRROR_REFLECT_NAMESPACE(_boost) ::full_name() << endl;
- bcout << "|21| " << BOOST_MIRROR_REFLECT_NAMESPACE(_boost_mirror) ::full_name() << endl;
- bcout << "|22| " << BOOST_MIRROR_REFLECT_NAMESPACE(_test) ::full_name() << endl;
- bcout << "|23| " << BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff) ::full_name() << endl;
- bcout << "|24| " << BOOST_MIRROR_REFLECT_NAMESPACE(_test_stuff_detail) ::full_name() << endl;
+ bcout << "|18| " << BOOST_MIRRORED_NAMESPACE(::__) ::full_name() << endl;
+ bcout << "|19| " << BOOST_MIRRORED_NAMESPACE(::std) ::full_name() << endl;
+ bcout << "|20| " << BOOST_MIRRORED_NAMESPACE(::boost) ::full_name() << endl;
+ bcout << "|21| " << BOOST_MIRRORED_NAMESPACE(::boost::mirror) ::full_name() << endl;
+ bcout << "|22| " << BOOST_MIRRORED_NAMESPACE(::test) ::full_name() << endl;
+ bcout << "|23| " << BOOST_MIRRORED_NAMESPACE(::test::stuff) ::full_name() << endl;
+ bcout << "|24| " << BOOST_MIRRORED_NAMESPACE(::test::stuff::detail) ::full_name() << endl;
return 0;
}
Modified: sandbox/mirror/libs/mirror/example/registering/types.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/registering/types.cpp (original)
+++ sandbox/mirror/libs/mirror/example/registering/types.cpp 2008-07-04 08:42:05 EDT (Fri, 04 Jul 2008)
@@ -44,16 +44,16 @@
// NOTE: if You are not familiar with namespace registration and usage
// see the examples/registering/namespaces.cpp source file
//
-BOOST_MIRROR_REG_NAMESPACE_TOP_LEVEL(test)
-BOOST_MIRROR_REG_NAMESPACE(_test, feature)
-BOOST_MIRROR_REG_NAMESPACE(_test_feature, detail)
+BOOST_MIRROR_REG_NAMESPACE((test))
+BOOST_MIRROR_REG_NAMESPACE((test)(feature))
+BOOST_MIRROR_REG_NAMESPACE((test)(feature)(detail))
//
// register the types
-BOOST_MIRROR_REG_TYPE(_test_feature_detail, ::test::feature::detail, foo)
-BOOST_MIRROR_REG_TYPE(_test_feature_detail, ::test::feature::detail, bar)
+BOOST_MIRROR_REG_TYPE(::test::feature::detail, foo)
+BOOST_MIRROR_REG_TYPE(::test::feature::detail, bar)
// register a typedef'd class this allows to distinguish it from
// the 'source' type in some situations
-BOOST_MIRROR_REG_TYPEDEFD(_test_feature_detail, ::test::feature::detail, foobar)
+BOOST_MIRROR_REG_TYPEDEFD(::test::feature::detail, foobar)
} // namespace mirror
} // namespace boost
@@ -69,16 +69,16 @@
using ::test::feature::detail::bar;
using ::test::feature::detail::foobar;
//
- // The BOOST_MIRROR_REFLECT_TYPE(TYPE) macro expands into the meta_type<>
+ // The BOOST_MIRRORED_TYPE(TYPE) macro expands into the meta_type<>
// specialization for the given type
//
- typedef BOOST_MIRROR_REFLECT_TYPE(foo) meta_foo;
- typedef BOOST_MIRROR_REFLECT_TYPE(bar) meta_bar;
+ typedef BOOST_MIRRORED_TYPE(foo) meta_foo;
+ typedef BOOST_MIRRORED_TYPE(bar) meta_bar;
//
// put the full name of the type to the output stream
//
- bcout << "|01| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(foo) >() << endl;
- bcout << "|02| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(bar) >() << endl;
+ bcout << "|01| " << name_to_stream< BOOST_MIRRORED_TYPE(foo) >() << endl;
+ bcout << "|02| " << name_to_stream< BOOST_MIRRORED_TYPE(bar) >() << endl;
//
// Do the same thing with the typedef'd type
// actually, nearly the same .. the true argument given to the
@@ -88,47 +88,47 @@
bcout << "|04| " << name_to_stream< meta_bar >(true) << endl;
//
// this works too...
- 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 << "|05| " << name_to_stream< BOOST_MIRRORED_TYPE(foo*) >() << endl;
+ bcout << "|06| " << name_to_stream< BOOST_MIRRORED_TYPE(bar&) >() << endl;
+ bcout << "|07| " << name_to_stream< BOOST_MIRRORED_TYPE(foo***) >() << endl;
+ bcout << "|08| " << name_to_stream< BOOST_MIRRORED_TYPE(bar**&) >() << endl;
+ bcout << "|09| " << name_to_stream< BOOST_MIRRORED_TYPE(const foo**) >() << endl;
+ bcout << "|10| " << name_to_stream< BOOST_MIRRORED_TYPE(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;
+ bcout << "|11| " << name_to_stream< BOOST_MIRRORED_TYPE(const volatile foo) >() << endl;
+ bcout << "|12| " << name_to_stream< BOOST_MIRRORED_TYPE(const volatile bar*) >() << endl;
//
// native c++ types are registered by default
- 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;
+ bcout << "|13| " << name_to_stream< BOOST_MIRRORED_TYPE(volatile short int) >() << endl;
+ bcout << "|14| " << name_to_stream< BOOST_MIRRORED_TYPE(const char*) >() << endl;
+ bcout << "|15| " << name_to_stream< BOOST_MIRRORED_TYPE(wchar_t*) >() << endl;
+ bcout << "|16| " << name_to_stream< BOOST_MIRRORED_TYPE(bool) >() << endl;
//
// use with Boost.Typeof
- bcout << "|17| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPE(BOOST_TYPEOF(1+1)) >() << endl;
+ bcout << "|17| " << name_to_stream< BOOST_MIRRORED_TYPE(BOOST_TYPEOF(1+1)) >() << endl;
// ... and maybe more conveniently
- bcout << "|18| " << name_to_stream< BOOST_MIRROR_REFLECT_TYPEOF(1.0/2.0) >() << endl;
+ bcout << "|18| " << name_to_stream< BOOST_MIRRORED_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 based
// on compilation configuration
- typedef BOOST_MIRROR_REFLECT_TYPE(bchar) meta_bchar;
+ typedef BOOST_MIRRORED_TYPE(bchar) meta_bchar;
// this reflects a meta-type that allows to query the typedef'd name
- typedef BOOST_MIRROR_REFLECT_TYPEDEFD(_boost, bchar) meta_bchar_td;
+ typedef BOOST_MIRRORED_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;
+ typedef BOOST_MIRRORED_TYPEDEFD(_test_feature_detail, foobar) meta_foobar_td;
//
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
+ // unfortunately BOOST_MIRRORED_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;
+ //typedef BOOST_MIRRORED_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)
@@ -136,19 +136,19 @@
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)
+ if(reflects_global_scope< BOOST_MIRRORED_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)
+ if(reflects_global_scope< BOOST_MIRRORED_TYPEOF("foo") ::scope>::value)
bcout << "|25| " << "type of \"foo\" defined on global scope" << endl;
//
- bcout << "|26| " << BOOST_MIRROR_REFLECT_TYPE(bool) ::full_name() << endl;
- bcout << "|27| " << BOOST_MIRROR_REFLECT_TYPE(bchar) ::full_name() << endl;
- bcout << "|28| " << BOOST_MIRROR_REFLECT_TYPEDEFD(_boost, bchar) ::full_name() << endl;
- bcout << "|29| " << BOOST_MIRROR_REFLECT_TYPEDEFD(_boost, bstring) ::full_name() << endl;
- bcout << "|30| " << BOOST_MIRROR_REFLECT_TYPE(int const * const volatile) ::full_name() << endl;
- bcout << "|31| " << BOOST_MIRROR_REFLECT_TYPE(int volatile * const * volatile) ::full_name() << endl;
- bcout << "|32| " << BOOST_MIRROR_REFLECT_TYPE(int const * const [321]) ::full_name() << endl;
+ bcout << "|26| " << BOOST_MIRRORED_TYPE(bool) ::full_name() << endl;
+ bcout << "|27| " << BOOST_MIRRORED_TYPE(bchar) ::full_name() << endl;
+ bcout << "|28| " << BOOST_MIRRORED_TYPEDEFD(_boost, bchar) ::full_name() << endl;
+ bcout << "|29| " << BOOST_MIRRORED_TYPEDEFD(_boost, bstring) ::full_name() << endl;
+ bcout << "|30| " << BOOST_MIRRORED_TYPE(int const * const volatile) ::full_name() << endl;
+ bcout << "|31| " << BOOST_MIRRORED_TYPE(int volatile * const * volatile) ::full_name() << endl;
+ bcout << "|32| " << BOOST_MIRRORED_TYPE(int const * const [321]) ::full_name() << 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