get_encoding.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(BOOST_SPIRIT_GET_ENCODING_JANUARY_13_2009_1255PM)
  7. #define BOOST_SPIRIT_GET_ENCODING_JANUARY_13_2009_1255PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/mpl/identity.hpp>
  12. #include <boost/type_traits/is_same.hpp>
  13. namespace boost { namespace spirit { namespace detail
  14. {
  15. template <typename Modifiers, typename Encoding>
  16. struct get_implicit_encoding
  17. {
  18. // Extract the implicit encoding from the Modifiers
  19. // If one is not found, Encoding is used. The explicit
  20. // encoding is the first viable encoding that can be
  21. // extracted from the Modifiers (there can be more than one).
  22. typedef typename
  23. mpl::find_if<
  24. char_encodings,
  25. has_modifier<Modifiers, tag::char_encoding_base<mpl::_1> >
  26. >::type
  27. iter;
  28. typedef typename
  29. mpl::eval_if<
  30. is_same<iter, typename mpl::end<char_encodings>::type>,
  31. mpl::identity<Encoding>,
  32. mpl::deref<iter>
  33. >::type
  34. type;
  35. };
  36. template <typename Modifiers, typename Encoding>
  37. struct get_encoding
  38. {
  39. // Extract the explicit encoding from the Modifiers
  40. // If one is not found, get implicit encoding (see above).
  41. // Explicit encoding is the encoding explicitly declared
  42. // using the encoding[c] directive.
  43. typedef typename
  44. mpl::find_if<
  45. char_encodings,
  46. has_modifier<Modifiers, tag::char_code<tag::encoding, mpl::_1> >
  47. >::type
  48. iter;
  49. typedef typename
  50. mpl::eval_if<
  51. is_same<iter, typename mpl::end<char_encodings>::type>,
  52. get_implicit_encoding<Modifiers, Encoding>,
  53. mpl::deref<iter>
  54. >::type
  55. type;
  56. };
  57. template <typename Modifiers, typename Encoding, bool case_modifier = false>
  58. struct get_encoding_with_case : mpl::identity<Encoding> {};
  59. template <typename Modifiers, typename Encoding>
  60. struct get_encoding_with_case<Modifiers, Encoding, true>
  61. : get_encoding<Modifiers, Encoding> {};
  62. }}}
  63. #endif