bool_policies.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*=============================================================================
  2. Copyright (c) 2009 Hartmut Kaiser
  3. Copyright (c) 2014 Joel de Guzman
  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. ==============================================================================*/
  7. #if !defined(BOOST_SPIRIT_X3_BOOL_POLICIES_SEP_29_2009_0710AM)
  8. #define BOOST_SPIRIT_X3_BOOL_POLICIES_SEP_29_2009_0710AM
  9. #include <boost/spirit/home/x3/string/detail/string_parse.hpp>
  10. #include <boost/spirit/home/x3/support/traits/move_to.hpp>
  11. namespace boost { namespace spirit { namespace x3
  12. {
  13. ///////////////////////////////////////////////////////////////////////////
  14. // Default boolean policies
  15. ///////////////////////////////////////////////////////////////////////////
  16. template <typename T = bool>
  17. struct bool_policies
  18. {
  19. template <typename Iterator, typename Attribute, typename CaseCompare>
  20. static bool
  21. parse_true(Iterator& first, Iterator const& last, Attribute& attr_, CaseCompare const& case_compare)
  22. {
  23. if (detail::string_parse("true", first, last, unused, case_compare))
  24. {
  25. traits::move_to(T(true), attr_); // result is true
  26. return true;
  27. }
  28. return false;
  29. }
  30. template <typename Iterator, typename Attribute, typename CaseCompare>
  31. static bool
  32. parse_false(Iterator& first, Iterator const& last, Attribute& attr_, CaseCompare const& case_compare)
  33. {
  34. if (detail::string_parse("false", first, last, unused, case_compare))
  35. {
  36. traits::move_to(T(false), attr_); // result is false
  37. return true;
  38. }
  39. return false;
  40. }
  41. };
  42. }}}
  43. #endif