Boost logo

Boost-Commit :

From: boost_at_[hidden]
Date: 2008-05-26 15:48:24


Author: matthiasschabel
Date: 2008-05-26 15:48:23 EDT (Mon, 26 May 2008)
New Revision: 45787
URL: http://svn.boost.org/trac/boost/changeset/45787

Log:
fix type name demangling and replace boost regex with boost string_algo
Text files modified:
   sandbox/units/boost/units/detail/utility.hpp | 34 ++++++++++++++--------------------
   sandbox/units/libs/units/example/composite_output.cpp | 4 ++++
   2 files changed, 18 insertions(+), 20 deletions(-)

Modified: sandbox/units/boost/units/detail/utility.hpp
==============================================================================
--- sandbox/units/boost/units/detail/utility.hpp (original)
+++ sandbox/units/boost/units/detail/utility.hpp 2008-05-26 15:48:23 EDT (Mon, 26 May 2008)
@@ -21,19 +21,18 @@
 #include <boost/cstdint.hpp>
 #include <boost/limits.hpp>
 
-#ifdef MCS_USE_BOOST_REGEX_DEMANGLING
-#include <boost/regex.hpp>
-#ifdef __GNUC__
-#define MCS_USE_DEMANGLING
+#if (__GNUC__ && __cplusplus && __GNUC__ >= 3)
+#define BOOST_UNITS_USE_DEMANGLING
 #endif // __GNUC__
-#endif // MCS_USE_BOOST_REGEX_DEMANGLING
 
-#ifdef MCS_USE_DEMANGLING
+#ifdef BOOST_UNITS_USE_DEMANGLING
 
-#ifdef __GNUC__
+#if (__GNUC__ && __cplusplus && __GNUC__ >= 3)
 #include <cxxabi.h>
 #endif // __GNUC__
 
+#include <boost/algorithm/string/replace.hpp>
+
 namespace boost {
 
 namespace units {
@@ -44,7 +43,7 @@
 std::string
 demangle(const char* name)
 {
- #ifdef __GNUC__
+ #if (__GNUC__ && __cplusplus && __GNUC__ >= 3)
     // need to demangle C++ symbols
     char* realname;
     std::size_t len;
@@ -54,9 +53,12 @@
     
     if (realname != NULL)
     {
- const std::string out(realname);
+ std::string out(realname);
+
         std::free(realname);
         
+ boost::replace_all(out,"boost::units::","");
+
         return out;
     }
     
@@ -72,23 +74,15 @@
 std::string simplify_typename(const L& /*source*/)
 {
     const std::string demangled = detail::demangle(typeid(L).name());
-
- #ifdef MCS_USE_BOOST_REGEX_DEMANGLING
- boost::regex ns_regex("boost::units::detail::|boost::units::");
-
- const std::string tmp(boost::regex_replace(demangled,ns_regex,""));
-
- return tmp;
- #else // MCS_USE_BOOST_REGEX_DEMANGLING
+
     return demangled;
- #endif // MCS_USE_BOOST_REGEX_DEMANGLING
 }
 
 } // namespace units
 
 } // namespace boost
 
-#else // MCS_USE_DEMANGLING
+#else // BOOST_UNITS_USE_DEMANGLING
 
 namespace boost {
 
@@ -118,6 +112,6 @@
 // To get system-specific predefined macros:
 // gcc -arch ppc -dM -E - < /dev/null | sort
 
-#endif // MCS_USE_DEMANGLING
+#endif // BOOST_UNITS_USE_DEMANGLING
 
 #endif // BOOST_UNITS_UTILITY_HPP

Modified: sandbox/units/libs/units/example/composite_output.cpp
==============================================================================
--- sandbox/units/libs/units/example/composite_output.cpp (original)
+++ sandbox/units/libs/units/example/composite_output.cpp 2008-05-26 15:48:23 EDT (Mon, 26 May 2008)
@@ -13,6 +13,8 @@
 #include <boost/units/io.hpp>
 #include <boost/units/scale.hpp>
 
+#include <boost/units/detail/utility.hpp>
+
 #include <boost/units/systems/si/capacitance.hpp>
 #include <boost/units/systems/si/io.hpp>
 #include <boost/units/systems/si/prefixes.hpp>
@@ -73,6 +75,8 @@
         std::cout << name_string(scale<10,static_rational<-9> >()) << std::endl;
 
         // wrong! - should output "n" and "nano", respectively
+ std::cout << simplify_typename(si::nano) << std::endl;
+
         std::cout << symbol_string(si::nano) << std::endl;
         std::cout << name_string(si::nano) << std::endl;
         


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