bool_policies.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Hartmut Kaiser
  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. ==============================================================================*/
  6. #if !defined(SPIRIT_QI_BOOL_POLICIES_SEP_29_2009_0710AM)
  7. #define SPIRIT_QI_BOOL_POLICIES_SEP_29_2009_0710AM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/detail/string_parse.hpp>
  12. #include <boost/spirit/home/qi/detail/assign_to.hpp>
  13. namespace boost { namespace spirit { namespace qi
  14. {
  15. ///////////////////////////////////////////////////////////////////////////
  16. // Default boolean policies
  17. ///////////////////////////////////////////////////////////////////////////
  18. template <typename T = bool>
  19. struct bool_policies
  20. {
  21. template <typename Iterator, typename Attribute>
  22. static bool
  23. parse_true(Iterator& first, Iterator const& last, Attribute& attr_)
  24. {
  25. if (detail::string_parse("true", first, last, unused))
  26. {
  27. spirit::traits::assign_to(T(true), attr_); // result is true
  28. return true;
  29. }
  30. return false;
  31. }
  32. template <typename Iterator, typename Attribute>
  33. static bool
  34. parse_false(Iterator& first, Iterator const& last, Attribute& attr_)
  35. {
  36. if (detail::string_parse("false", first, last, unused))
  37. {
  38. spirit::traits::assign_to(T(false), attr_); // result is false
  39. return true;
  40. }
  41. return false;
  42. }
  43. };
  44. ///////////////////////////////////////////////////////////////////////////
  45. template <typename T = bool>
  46. struct no_case_bool_policies
  47. {
  48. template <typename Iterator, typename Attribute>
  49. static bool
  50. parse_true(Iterator& first, Iterator const& last, Attribute& attr_)
  51. {
  52. if (detail::string_parse("true", "TRUE", first, last, unused))
  53. {
  54. spirit::traits::assign_to(T(true), attr_); // result is true
  55. return true;
  56. }
  57. return false;
  58. }
  59. template <typename Iterator, typename Attribute>
  60. static bool
  61. parse_false(Iterator& first, Iterator const& last, Attribute& attr_)
  62. {
  63. if (detail::string_parse("false", "FALSE", first, last, unused))
  64. {
  65. spirit::traits::assign_to(T(false), attr_); // result is false
  66. return true;
  67. }
  68. return false;
  69. }
  70. };
  71. }}}
  72. #endif