/src/contrib/boost/spirit/home/support/adapt_class_attributes.hpp

http://pythonocc.googlecode.com/ · C++ Header · 128 lines · 101 code · 15 blank · 12 comment · 0 complexity · f966cc47886b1a55dfda05e4f8c6f2cb MD5 · raw file

  1. // Copyright (c) 2001-2010 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(BOOST_SPIRIT_ADAPT_CLASS_ATTRIBUTES_JAN_27_2010_1219PM)
  6. #define BOOST_SPIRIT_ADAPT_CLASS_ATTRIBUTES_JAN_27_2010_1219PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/support/attributes.hpp>
  11. #include <boost/spirit/home/support/container.hpp>
  12. #include <boost/fusion/include/adapt_class.hpp>
  13. #include <boost/utility/enable_if.hpp>
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // forward declaration only
  16. namespace boost { namespace fusion { namespace extension
  17. {
  18. template <typename T, int N> struct class_member_proxy;
  19. }}}
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // customization points allowing to use adapted classes with spirit
  22. namespace boost { namespace spirit { namespace traits
  23. {
  24. ///////////////////////////////////////////////////////////////////////////
  25. template <typename T, int N>
  26. struct is_container<fusion::extension::class_member_proxy<T, N> >
  27. : is_container<typename fusion::extension::class_member_proxy<T, N>::type>
  28. {};
  29. template <typename T, int N>
  30. struct container_value<fusion::extension::class_member_proxy<T, N> >
  31. : container_value<typename fusion::extension::class_member_proxy<T, N>::type>
  32. {};
  33. template <typename T, int N, typename Val>
  34. struct push_back_container<fusion::extension::class_member_proxy<T, N>, Val
  35. , typename enable_if<
  36. is_reference<typename fusion::extension::class_member_proxy<T, N>::type>
  37. >::type>
  38. {
  39. static bool call(fusion::extension::class_member_proxy<T, N>& p, Val const& val)
  40. {
  41. typedef typename fusion::extension::class_member_proxy<T, N>::type type;
  42. return push_back((type)p, val);
  43. }
  44. };
  45. template <typename T, int N>
  46. struct container_iterator<fusion::extension::class_member_proxy<T, N> >
  47. : container_iterator<typename fusion::extension::class_member_proxy<T, N>::type>
  48. {};
  49. ///////////////////////////////////////////////////////////////////////////
  50. template <typename T, int N, typename Val>
  51. struct assign_to_attribute_from_value<
  52. fusion::extension::class_member_proxy<T, N>, Val>
  53. {
  54. static void
  55. call(Val const& val, fusion::extension::class_member_proxy<T, N>& attr)
  56. {
  57. attr = val;
  58. }
  59. };
  60. ///////////////////////////////////////////////////////////////////////////
  61. template <typename T, int N>
  62. struct attribute_type<fusion::extension::class_member_proxy<T, N> >
  63. : fusion::extension::class_member_proxy<T, N>
  64. {};
  65. ///////////////////////////////////////////////////////////////////////////
  66. template <typename T, int N, typename Attribute>
  67. struct transform_attribute<
  68. fusion::extension::class_member_proxy<T, N>, Attribute
  69. , typename disable_if<
  70. is_reference<typename fusion::extension::class_member_proxy<T, N>::lvalue>
  71. >::type>
  72. {
  73. typedef Attribute type;
  74. static Attribute
  75. pre(fusion::extension::class_member_proxy<T, N>& val)
  76. {
  77. return val;
  78. }
  79. static void
  80. post(fusion::extension::class_member_proxy<T, N>& val
  81. , Attribute const& attr)
  82. {
  83. val = attr;
  84. }
  85. static void
  86. fail(fusion::extension::class_member_proxy<T, N>&)
  87. {
  88. }
  89. };
  90. template <typename T, int N, typename Attribute>
  91. struct transform_attribute<
  92. fusion::extension::class_member_proxy<T, N>, Attribute
  93. , typename enable_if<
  94. is_reference<typename fusion::extension::class_member_proxy<T, N>::lvalue>
  95. >::type>
  96. {
  97. typedef Attribute& type;
  98. static Attribute&
  99. pre(fusion::extension::class_member_proxy<T, N>& val)
  100. {
  101. return val;
  102. }
  103. static void
  104. post(fusion::extension::class_member_proxy<T, N>&, Attribute const&)
  105. {
  106. }
  107. static void
  108. fail(fusion::extension::class_member_proxy<T, N>&)
  109. {
  110. }
  111. };
  112. }}}
  113. #endif