extended_type_info.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_HPP
  2. #define BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // extended_type_info.hpp: interface for portable version of type_info
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. // for now, extended type info is part of the serialization libraries
  15. // this could change in the future.
  16. #include <cstdarg>
  17. #include <boost/assert.hpp>
  18. #include <cstddef> // NULL
  19. #include <boost/config.hpp>
  20. #include <boost/noncopyable.hpp>
  21. #include <boost/mpl/bool.hpp>
  22. #include <boost/serialization/config.hpp>
  23. #include <boost/config/abi_prefix.hpp> // must be the last header
  24. #ifdef BOOST_MSVC
  25. # pragma warning(push)
  26. # pragma warning(disable : 4251 4231 4660 4275)
  27. #endif
  28. #define BOOST_SERIALIZATION_MAX_KEY_SIZE 128
  29. namespace boost {
  30. namespace serialization {
  31. namespace void_cast_detail{
  32. class void_caster;
  33. }
  34. class BOOST_SYMBOL_VISIBLE extended_type_info :
  35. private boost::noncopyable
  36. {
  37. private:
  38. friend class boost::serialization::void_cast_detail::void_caster;
  39. // used to uniquely identify the type of class derived from this one
  40. // so that different derivations of this class can be simultaneously
  41. // included in implementation of sets and maps.
  42. const unsigned int m_type_info_key;
  43. virtual bool is_less_than(const extended_type_info & /*rhs*/) const = 0;
  44. virtual bool is_equal(const extended_type_info & /*rhs*/) const = 0;
  45. const char * m_key;
  46. protected:
  47. BOOST_SERIALIZATION_DECL void key_unregister() const;
  48. BOOST_SERIALIZATION_DECL void key_register() const;
  49. // this class can't be used as is. It's just the
  50. // common functionality for all type_info replacement
  51. // systems. Hence, make these protected
  52. BOOST_SERIALIZATION_DECL extended_type_info(
  53. const unsigned int type_info_key,
  54. const char * key
  55. );
  56. virtual BOOST_SERIALIZATION_DECL ~extended_type_info();
  57. public:
  58. const char * get_key() const {
  59. return m_key;
  60. }
  61. virtual const char * get_debug_info() const = 0;
  62. BOOST_SERIALIZATION_DECL bool operator<(const extended_type_info &rhs) const;
  63. BOOST_SERIALIZATION_DECL bool operator==(const extended_type_info &rhs) const;
  64. bool operator!=(const extended_type_info &rhs) const {
  65. return !(operator==(rhs));
  66. }
  67. // note explicit "export" of static function to work around
  68. // gcc 4.5 mingw error
  69. static BOOST_SERIALIZATION_DECL const extended_type_info *
  70. find(const char *key);
  71. // for plugins
  72. virtual void * construct(unsigned int /*count*/ = 0, ...) const = 0;
  73. virtual void destroy(void const * const /*p*/) const = 0;
  74. };
  75. template<class T>
  76. struct guid_defined : boost::mpl::false_ {};
  77. namespace ext {
  78. template <typename T>
  79. struct guid_impl
  80. {
  81. static inline const char * call()
  82. {
  83. return NULL;
  84. }
  85. };
  86. }
  87. template<class T>
  88. inline const char * guid(){
  89. return ext::guid_impl<T>::call();
  90. }
  91. } // namespace serialization
  92. } // namespace boost
  93. #ifdef BOOST_MSVC
  94. #pragma warning(pop)
  95. #endif
  96. #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  97. #endif // BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_HPP