From 3d03ca3d10268ddf08b87a49770b712de2bb7e91 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sun, 20 Jan 2002 23:50:52 +0000 Subject: [PATCH] made it possible to initialize from type_info [SVN r12383] --- include/boost/python/converter/type_id.hpp | 67 +++++++++++++++------- src/converter/type_id.cpp | 6 +- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/include/boost/python/converter/type_id.hpp b/include/boost/python/converter/type_id.hpp index 2c0c1a26..fd731f83 100644 --- a/include/boost/python/converter/type_id.hpp +++ b/include/boost/python/converter/type_id.hpp @@ -37,24 +37,25 @@ namespace detail // which works across shared libraries. struct undecorated_type_id_t : totally_ordered { + undecorated_type_id_t(std::type_info const&); + + // default constructor needed to build arrays, etc. + undecorated_type_id_t(); + + bool operator<(undecorated_type_id_t const& rhs) const; + bool operator==(undecorated_type_id_t const& rhs) const; + + char const* name() const; + friend BOOST_PYTHON_DECL std::ostream& operator<<( + std::ostream&, undecorated_type_id_t const&); + + private: // data members # ifdef BOOST_PYTHON_TYPE_ID_NAME typedef char const* base_id_t; # else typedef std::type_info const* base_id_t; # endif - undecorated_type_id_t(base_id_t); - - // default constructor for use in BGL graph internal properties - undecorated_type_id_t() {} - - bool operator<(undecorated_type_id_t const& rhs) const; - bool operator==(undecorated_type_id_t const& rhs) const; - - friend BOOST_PYTHON_DECL std::ostream& operator<<( - std::ostream&, undecorated_type_id_t const&); - - private: // data members base_id_t m_base_type; }; @@ -66,8 +67,10 @@ struct type_id_t : totally_ordered bool operator<(type_id_t const& rhs) const; bool operator==(type_id_t const& rhs) const; + friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_id_t const&); - + + operator undecorated_type_id_t const&() const; private: // type typedef undecorated_type_id_t base_id_t; @@ -153,13 +156,7 @@ struct is_reference_to_volatile template inline undecorated_type_id_t undecorated_type_id(detail::dummy* = 0) { - return undecorated_type_id_t( -# ifdef BOOST_PYTHON_TYPE_ID_NAME - typeid(T).name() -# else - &typeid(T) -# endif - ); + return undecorated_type_id_t(typeid(T)); } template @@ -177,8 +174,19 @@ inline type_id_t type_id(detail::dummy* = 0) ); } -inline undecorated_type_id_t::undecorated_type_id_t(base_id_t base_t) - : m_base_type(base_t) +inline undecorated_type_id_t::undecorated_type_id_t(std::type_info const& id) + : m_base_type( +# ifdef BOOST_PYTHON_TYPE_ID_NAME + id.name() +# else + &id +# endif + ) +{ +} + +inline undecorated_type_id_t::undecorated_type_id_t() + : m_base_type() { } @@ -218,6 +226,21 @@ inline bool type_id_t::operator==(type_id_t const& rhs) const return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type; } +inline type_id_t::operator undecorated_type_id_t const&() const +{ + return m_base_type; +} + +inline char const* undecorated_type_id_t::name() const +{ +# ifdef BOOST_PYTHON_TYPE_ID_NAME + return m_base_type; +# else + return m_base_type->name(); +# endif +} + + BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, undecorated_type_id_t const&); BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_id_t const&); diff --git a/src/converter/type_id.cpp b/src/converter/type_id.cpp index 421cc5cf..688dd2bc 100644 --- a/src/converter/type_id.cpp +++ b/src/converter/type_id.cpp @@ -15,11 +15,7 @@ namespace boost { namespace python { namespace converter { BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream& os, undecorated_type_id_t const& x) { -# ifdef BOOST_PYTHON_TYPE_ID_NAME - return os << x.m_base_type; -# else - return os << x.m_base_type->name(); -# endif + return os << x.name(); } BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream& os, type_id_t const& x)