/Src/Dependencies/Boost/boost/spirit/home/support/nonterminal/extract_param.hpp

http://hadesmem.googlecode.com/ · C++ Header · 123 lines · 93 code · 14 blank · 16 comment · 0 complexity · 8b35a81c867726a7bf5d64c81d0944e9 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Copyright (c) 2009 Francois Barel
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #if !defined(BOOST_SPIRIT_EXTRACT_PARAM_AUGUST_08_2009_0848AM)
  9. #define BOOST_SPIRIT_EXTRACT_PARAM_AUGUST_08_2009_0848AM
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/spirit/home/support/meta_compiler.hpp>
  14. #include <boost/spirit/home/support/nonterminal/locals.hpp>
  15. #include <boost/spirit/home/support/unused.hpp>
  16. #include <boost/spirit/home/support/common_terminals.hpp>
  17. #include <boost/function_types/is_function.hpp>
  18. #include <boost/function_types/parameter_types.hpp>
  19. #include <boost/function_types/result_type.hpp>
  20. #include <boost/fusion/include/as_list.hpp>
  21. #include <boost/fusion/include/as_vector.hpp>
  22. #include <boost/mpl/deref.hpp>
  23. #include <boost/mpl/end.hpp>
  24. #include <boost/mpl/eval_if.hpp>
  25. #include <boost/mpl/find_if.hpp>
  26. #include <boost/mpl/identity.hpp>
  27. #include <boost/mpl/if.hpp>
  28. #include <boost/mpl/placeholders.hpp>
  29. #include <boost/type_traits/is_same.hpp>
  30. namespace boost { namespace spirit { namespace detail
  31. {
  32. ///////////////////////////////////////////////////////////////////////////
  33. // Helpers to extract params (locals, attributes, ...) from nonterminal
  34. // template arguments
  35. ///////////////////////////////////////////////////////////////////////////
  36. template <typename Types, typename Pred, typename Default>
  37. struct extract_param
  38. {
  39. typedef typename mpl::find_if<Types, Pred>::type pos;
  40. typedef typename
  41. mpl::eval_if<
  42. is_same<pos, typename mpl::end<Types>::type>
  43. , mpl::identity<Default>
  44. , mpl::deref<pos>
  45. >::type
  46. type;
  47. };
  48. ///////////////////////////////////////////////////////////////////////////
  49. template <typename Types>
  50. struct extract_locals
  51. : fusion::result_of::as_vector<
  52. typename extract_param<
  53. Types
  54. , is_locals<mpl::_>
  55. , locals<>
  56. >::type
  57. >
  58. {};
  59. ///////////////////////////////////////////////////////////////////////////
  60. template <typename Domain, typename Types>
  61. struct extract_component
  62. : spirit::result_of::compile<
  63. Domain
  64. , typename extract_param<
  65. Types
  66. , traits::matches<Domain, mpl::_>
  67. , unused_type
  68. >::type
  69. >
  70. {};
  71. ///////////////////////////////////////////////////////////////////////////
  72. template <typename Types>
  73. struct extract_sig
  74. : extract_param<
  75. Types
  76. , function_types::is_function<mpl::_>
  77. , void()
  78. >
  79. {};
  80. template <typename Sig>
  81. struct attr_from_sig
  82. {
  83. typedef typename function_types::result_type<Sig>::type attr;
  84. typedef typename
  85. mpl::if_<
  86. is_same<attr, void>
  87. , unused_type
  88. , attr
  89. >::type
  90. type;
  91. };
  92. template <typename Sig>
  93. struct params_from_sig
  94. {
  95. typedef typename function_types::parameter_types<Sig>::type params;
  96. typedef typename fusion::result_of::as_list<params>::type type;
  97. };
  98. ///////////////////////////////////////////////////////////////////////////
  99. template <typename Types>
  100. struct extract_encoding
  101. : extract_param<
  102. Types
  103. , is_char_encoding<mpl::_>
  104. , unused_type
  105. >
  106. {};
  107. }}}
  108. #endif