bool.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Hartmut Kaiser
  3. Copyright (c) 2011 Bryce Lelbach
  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_TEST_QI_BOOL)
  8. #define BOOST_SPIRIT_TEST_QI_BOOL
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/spirit/include/support_argument.hpp>
  11. #include <boost/spirit/include/qi_char.hpp>
  12. #include <boost/spirit/include/qi_numeric.hpp>
  13. #include <boost/spirit/include/qi_directive.hpp>
  14. #include <boost/cstdint.hpp>
  15. #include "test.hpp"
  16. ///////////////////////////////////////////////////////////////////////////////
  17. struct backwards_bool_policies : boost::spirit::qi::bool_policies<>
  18. {
  19. // we want to interpret a 'true' spelled backwards as 'false'
  20. template <typename Iterator, typename Attribute>
  21. static bool
  22. parse_false(Iterator& first, Iterator const& last, Attribute& attr)
  23. {
  24. namespace spirit = boost::spirit;
  25. namespace qi = boost::spirit::qi;
  26. if (qi::detail::string_parse("eurt", first, last, qi::unused))
  27. {
  28. spirit::traits::assign_to(false, attr); // result is false
  29. return true;
  30. }
  31. return false;
  32. }
  33. };
  34. ///////////////////////////////////////////////////////////////////////////////
  35. struct test_bool_type
  36. {
  37. test_bool_type(bool b) : b(b) {} // provide conversion
  38. bool b;
  39. };
  40. #endif