Boost logo

Boost-Commit :

From: chochlik_at_[hidden]
Date: 2008-04-25 12:01:49


Author: matus.chochlik
Date: 2008-04-25 12:01:48 EDT (Fri, 25 Apr 2008)
New Revision: 44765
URL: http://svn.boost.org/trac/boost/changeset/44765

Log:
Added support for getting fully qualified names of namespaces/types/etc.
Updated several examples to show full_name getting
NOTE: full_name getter not available yet for all meta_types
NOTE: tested only with MSVC++ 2008 EE

Text files modified:
   sandbox/mirror/boost/char_type_switch/string.hpp | 11 +++++++++++
   sandbox/mirror/boost/mirror/detail/template_name.hpp | 2 +-
   sandbox/mirror/boost/mirror/meta_namespace.hpp | 29 +++++++++++++++++++++++++++--
   sandbox/mirror/boost/mirror/meta_type.hpp | 40 ++++++++++++++++++++++++++++++++++++----
   sandbox/mirror/boost/mirror/meta_types/std_pair.hpp | 2 +-
   sandbox/mirror/libs/doc/xml/mirror/_library.xml | 6 ++++++
   sandbox/mirror/libs/examples/registering/classes.cpp | 2 ++
   sandbox/mirror/libs/examples/registering/namespaces.cpp | 10 ++++++++++
   sandbox/mirror/libs/examples/registering/types.cpp | 5 +++++
   9 files changed, 99 insertions(+), 8 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-04-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -89,6 +89,17 @@
 #endif
 }
 
+/** string copy
+ */
+inline bchar* bstrncpy(bchar* dst, const bchar* src, size_t count)
+{
+#ifdef BOOST_USE_WIDE_CHARS
+ return ::std::wcsncpy(dst, src, count);
+#else
+ return ::std::strncpy(dst, src, count);
+#endif
+}
+
 // enable the deprecated function warnings on msvc
 #pragma warning(pop)
 

Modified: sandbox/mirror/boost/mirror/detail/template_name.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/detail/template_name.hpp (original)
+++ sandbox/mirror/boost/mirror/detail/template_name.hpp 2008-04-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -103,7 +103,7 @@
                 bchar* cur_pos = the_base_name;
                 //
                 // copy the name of the template
- bstrcpy(cur_pos, meta_type::template_name());
+ bstrcpy(cur_pos, meta_type::template_base_name());
                 cur_pos += template_name_length;
                 //
                 // append the leading "< "

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-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -38,8 +38,12 @@
 {
         typedef void parent;
         typedef mpl::vector0<> scope;
- static const bchar* base_name (void) {return BOOST_STR_LIT("");}
+
+ static const bchar* base_name(void) {return BOOST_STR_LIT("");}
         BOOST_MIRROR_CONST_MEMBER_ATTRIB(size_t, base_name_length, 0)
+
+ static const bchar* full_name(void) {return BOOST_STR_LIT("");}
+ BOOST_MIRROR_CONST_MEMBER_ATTRIB(size_t, full_name_length, 0)
 };
 
 
@@ -49,12 +53,33 @@
 { \
         typedef meta_namespace< namespaces :: PARENT_NS_ALIAS > parent; \
         typedef mpl::push_back<parent::scope, parent>::type scope; \
- static const bchar* base_name (void) {return BOOST_STR_LIT(#NAMESPACE_NAME);} \
         BOOST_MIRROR_CONST_MEMBER_ATTRIB(\
                 size_t, \
                 base_name_length, \
                 BOOST_STR_LIT_LENGTH(#NAMESPACE_NAME)\
         ) \
+ static const bchar* base_name(void) {return BOOST_STR_LIT(#NAMESPACE_NAME);} \
+ BOOST_MIRROR_CONST_MEMBER_ATTRIB(\
+ size_t, \
+ 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; \
+ } \
 };
 
 

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-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -46,6 +46,32 @@
         type_identifier, base_type
> > : meta_type<base_type>{ };
 
+/** Helper macro that declared the full_name-related stuff
+ */
+#define BOOST_MIRROR_TMP_DECLARE_META_TYPE_FULL_NAME() \
+ BOOST_MIRROR_CONST_MEMBER_ATTRIB(\
+ size_t, \
+ full_name_length, \
+ scope::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, scope::full_name(), scope::full_name_length);\
+ pos += scope::full_name_length; \
+ bstrncpy(pos, BOOST_STR_LIT("::"), 2);\
+ pos += 2; \
+ bstrncpy(pos, base_name(), base_name_length);\
+ } \
+ return the_full_name; \
+ }
+
+
 /** Macro for declaration of meta-types
  */
 #define BOOST_MIRROR_REG_META_TYPE(NAMESPACE_ALIAS, NAMESPACE, BASE_NAME) \
@@ -53,12 +79,13 @@
         { \
                 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);}\
+ static const bchar* base_name(void) {return BOOST_STR_LIT(#BASE_NAME);}\
                 BOOST_MIRROR_CONST_MEMBER_ATTRIB( \
                         size_t, \
                         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
@@ -72,12 +99,13 @@
         { \
                 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);}\
+ static const bchar* base_name(void) {return BOOST_STR_LIT(#TYPEDEFD_NAME);}\
                 BOOST_MIRROR_CONST_MEMBER_ATTRIB( \
                         size_t, \
                         base_name_length, \
                         BOOST_STR_LIT_LENGTH(#TYPEDEFD_NAME)\
                 ) \
+ BOOST_MIRROR_TMP_DECLARE_META_TYPE_FULL_NAME() \
         };
 
 /** Declaration of meta types for types in the global scope
@@ -87,12 +115,14 @@
         { \
                 typedef BOOST_MIRROR_REFLECT_NAMESPACE(_) scope; \
                 typedef BASE_NAME base_type; \
- static const bchar* base_name (void) {return BOOST_STR_LIT(#BASE_NAME);}\
+ static const bchar* base_name(void) {return BOOST_STR_LIT(#BASE_NAME);}\
                 BOOST_MIRROR_CONST_MEMBER_ATTRIB( \
                         size_t, \
                         base_name_length, \
                         BOOST_STR_LIT_LENGTH( #BASE_NAME ) \
                 ) \
+ static const bchar* full_name(void) {return base_name();}\
+ BOOST_MIRROR_CONST_MEMBER_ATTRIB(size_t, full_name_length, base_name_length) \
         };
 
 /** Declaration of meta types for types in declared inside
@@ -103,12 +133,13 @@
         { \
                 typedef meta_class< WRAPPER > scope; \
                 typedef WRAPPER::BASE_NAME base_type; \
- static const bchar* base_name (void) {return BOOST_STR_LIT(#BASE_NAME);}\
+ static const bchar* base_name(void) {return BOOST_STR_LIT(#BASE_NAME);}\
                 BOOST_MIRROR_CONST_MEMBER_ATTRIB( \
                         size_t, \
                         base_name_length, \
                         BOOST_STR_LIT_LENGTH(#BASE_NAME)\
                 ) \
+ BOOST_MIRROR_TMP_DECLARE_META_TYPE_FULL_NAME() \
         };
 
 
@@ -141,6 +172,7 @@
  */
 #undef BOOST_MIRROR_REG_ITH_META_TYPE_NATIVE
 
+
 /** Register std string and wstring
  */
 BOOST_MIRROR_REG_META_TYPE(_std, ::std, string)

Modified: sandbox/mirror/boost/mirror/meta_types/std_pair.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_types/std_pair.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_types/std_pair.hpp 2008-04-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -28,7 +28,7 @@
 {
         typedef BOOST_MIRROR_REFLECT_NAMESPACE(_std) scope;
         typedef ::std::pair<first_type, second_type> base_type;
- static const bchar* template_name(void){return BOOST_STR_LIT("pair");}
+ static const bchar* template_base_name(void){return BOOST_STR_LIT("pair");}
 };
 
 

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-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -60,5 +60,11 @@
                         - Added the index to the base name of static arrays
                         - NOTE: tested only with MSVC++ 2008 EE
                 </revision>
+ <revision id="20080425_1758CET" major="0" minor="1" micro="10" author="m_ch">
+ - Added support for getting fully qualified names of namespaces/types/etc.
+ - Updated several examples to show full_name getting
+ - NOTE: full_name getter not available yet for all meta_types
+ - NOTE: tested only with MSVC++ 2008 EE
+ </revision>
         </revisions>
 </library>

Modified: sandbox/mirror/libs/examples/registering/classes.cpp
==============================================================================
--- sandbox/mirror/libs/examples/registering/classes.cpp (original)
+++ sandbox/mirror/libs/examples/registering/classes.cpp 2008-04-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -386,6 +386,8 @@
         // type of an expression
         bcout << "|06| " << endl << pretty_printer<BOOST_MIRROR_REFLECT_TYPEOF("foo")>() << endl;
         //
+ // full typenames
+ //bcout << "|07| " << BOOST_MIRROR_REFLECT_TYPEOF("foo") ::full_name() << endl;
         //
         bar_base x = {123, 456L};
         bar_base y = {234, 567L};

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-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -112,6 +112,16 @@
         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;
+ //
+ // 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;
         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-25 12:01:48 EDT (Fri, 25 Apr 2008)
@@ -142,6 +142,11 @@
         if(reflects_global_scope< BOOST_MIRROR_REFLECT_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;
+ //
         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