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