[857] | 1 | // Copyright David Abrahams 2002.
|
---|
| 2 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
| 3 | // accompanying file LICENSE_1_0.txt or copy at
|
---|
| 4 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
| 5 | #ifndef DECORATED_TYPE_ID_DWA2002517_HPP
|
---|
| 6 | # define DECORATED_TYPE_ID_DWA2002517_HPP
|
---|
| 7 |
|
---|
| 8 | # include <boost/python/type_id.hpp>
|
---|
| 9 | # include <boost/python/detail/indirect_traits.hpp>
|
---|
| 10 | # include <boost/type_traits/cv_traits.hpp>
|
---|
| 11 |
|
---|
| 12 | namespace boost { namespace python { namespace detail {
|
---|
| 13 |
|
---|
| 14 | struct decorated_type_info : totally_ordered<decorated_type_info>
|
---|
| 15 | {
|
---|
| 16 | enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 };
|
---|
| 17 |
|
---|
| 18 | decorated_type_info(type_info, decoration = decoration());
|
---|
| 19 |
|
---|
| 20 | inline bool operator<(decorated_type_info const& rhs) const;
|
---|
| 21 | inline bool operator==(decorated_type_info const& rhs) const;
|
---|
| 22 |
|
---|
| 23 | friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&);
|
---|
| 24 |
|
---|
| 25 | operator type_info const&() const;
|
---|
| 26 | private: // type
|
---|
| 27 | typedef type_info base_id_t;
|
---|
| 28 |
|
---|
| 29 | private: // data members
|
---|
| 30 | decoration m_decoration;
|
---|
| 31 | base_id_t m_base_type;
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 | template <class T>
|
---|
| 35 | inline decorated_type_info decorated_type_id(boost::type<T>* = 0)
|
---|
| 36 | {
|
---|
| 37 | return decorated_type_info(
|
---|
| 38 | type_id<T>()
|
---|
| 39 | , decorated_type_info::decoration(
|
---|
| 40 | (is_const<T>::value || indirect_traits::is_reference_to_const<T>::value
|
---|
| 41 | ? decorated_type_info::const_ : 0)
|
---|
| 42 | | (is_volatile<T>::value || indirect_traits::is_reference_to_volatile<T>::value
|
---|
| 43 | ? decorated_type_info::volatile_ : 0)
|
---|
| 44 | | (is_reference<T>::value ? decorated_type_info::reference : 0)
|
---|
| 45 | )
|
---|
| 46 | );
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | inline decorated_type_info::decorated_type_info(type_info base_t, decoration decoration)
|
---|
| 50 | : m_decoration(decoration)
|
---|
| 51 | , m_base_type(base_t)
|
---|
| 52 | {
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | inline bool decorated_type_info::operator<(decorated_type_info const& rhs) const
|
---|
| 56 | {
|
---|
| 57 | return m_decoration < rhs.m_decoration
|
---|
| 58 | || m_decoration == rhs.m_decoration
|
---|
| 59 | && m_base_type < rhs.m_base_type;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | inline bool decorated_type_info::operator==(decorated_type_info const& rhs) const
|
---|
| 63 | {
|
---|
| 64 | return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | inline decorated_type_info::operator type_info const&() const
|
---|
| 68 | {
|
---|
| 69 | return m_base_type;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&);
|
---|
| 73 |
|
---|
| 74 | }}} // namespace boost::python::detail
|
---|
| 75 |
|
---|
| 76 | #endif // DECORATED_TYPE_ID_DWA2002517_HPP
|
---|