/Src/Dependencies/Boost/boost/spirit/home/karma/detail/attributes.hpp

http://hadesmem.googlecode.com/ · C++ Header · 108 lines · 79 code · 18 blank · 11 comment · 0 complexity · 698ceb5035c24487b498b0d8b639b87b MD5 · raw file

  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. // Copyright (c) 2001-2011 Joel de Guzman
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #if !defined(SPIRIT_KARMA_DETAIL_ATTRIBUTES_APR_18_2010_0453PM)
  7. #define SPIRIT_KARMA_DETAIL_ATTRIBUTES_APR_18_2010_0453PM
  8. #include <boost/spirit/home/karma/domain.hpp>
  9. #include <boost/spirit/home/support/attributes_fwd.hpp>
  10. #include <boost/spirit/home/support/attributes.hpp>
  11. ///////////////////////////////////////////////////////////////////////////////
  12. namespace boost { namespace spirit { namespace karma
  13. {
  14. template <typename Exposed, typename Transformed, typename Enable = void>
  15. struct transform_attribute
  16. {
  17. typedef Transformed type;
  18. static Transformed pre(Exposed& val)
  19. {
  20. return Transformed(traits::extract_from<Transformed>(val, unused));
  21. }
  22. // Karma only, no post() and no fail() required
  23. };
  24. template <typename Exposed, typename Transformed>
  25. struct transform_attribute<boost::optional<Exposed> const, Transformed
  26. , typename disable_if<is_same<boost::optional<Exposed>, Transformed> >::type>
  27. {
  28. typedef Transformed const& type;
  29. static Transformed const& pre(boost::optional<Exposed> const& val)
  30. {
  31. return boost::get<Transformed>(val);
  32. }
  33. };
  34. template <typename Attribute>
  35. struct transform_attribute<Attribute const, Attribute>
  36. {
  37. typedef Attribute const& type;
  38. static Attribute const& pre(Attribute const& val) { return val; }
  39. // Karma only, no post() and no fail() required
  40. };
  41. // reference types need special handling
  42. template <typename Exposed, typename Transformed>
  43. struct transform_attribute<Exposed&, Transformed>
  44. : transform_attribute<Exposed, Transformed>
  45. {};
  46. template <typename Exposed, typename Transformed>
  47. struct transform_attribute<Exposed const&, Transformed>
  48. : transform_attribute<Exposed const, Transformed>
  49. {};
  50. template <typename Attribute>
  51. struct transform_attribute<Attribute const&, Attribute>
  52. : transform_attribute<Attribute const, Attribute>
  53. {};
  54. // unused_type needs some special handling as well
  55. template <>
  56. struct transform_attribute<unused_type, unused_type>
  57. {
  58. typedef unused_type type;
  59. static unused_type pre(unused_type) { return unused; }
  60. };
  61. template <>
  62. struct transform_attribute<unused_type const, unused_type>
  63. : transform_attribute<unused_type, unused_type>
  64. {};
  65. template <typename Attribute>
  66. struct transform_attribute<unused_type, Attribute>
  67. : transform_attribute<unused_type, unused_type>
  68. {};
  69. template <typename Attribute>
  70. struct transform_attribute<unused_type const, Attribute>
  71. : transform_attribute<unused_type, unused_type>
  72. {};
  73. template <typename Attribute>
  74. struct transform_attribute<Attribute, unused_type>
  75. : transform_attribute<unused_type, unused_type>
  76. {};
  77. template <typename Attribute>
  78. struct transform_attribute<Attribute const, unused_type>
  79. : transform_attribute<unused_type, unused_type>
  80. {};
  81. }}}
  82. ///////////////////////////////////////////////////////////////////////////////
  83. namespace boost { namespace spirit { namespace traits
  84. {
  85. template <typename Exposed, typename Transformed>
  86. struct transform_attribute<Exposed, Transformed, karma::domain>
  87. : karma::transform_attribute<Exposed, Transformed>
  88. {};
  89. }}}
  90. #endif