Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Hartmut Kaiser
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 ==============================================================================*/
|
Chris@16
|
7 #if !defined(SPIRIT_QI_BOOL_POLICIES_SEP_29_2009_0710AM)
|
Chris@16
|
8 #define SPIRIT_QI_BOOL_POLICIES_SEP_29_2009_0710AM
|
Chris@16
|
9
|
Chris@16
|
10 #if defined(_MSC_VER)
|
Chris@16
|
11 #pragma once
|
Chris@16
|
12 #endif
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/spirit/home/qi/detail/string_parse.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/qi/detail/assign_to.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost { namespace spirit { namespace qi
|
Chris@16
|
18 {
|
Chris@16
|
19 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
20 // Default boolean policies
|
Chris@16
|
21 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
22 template <typename T = bool>
|
Chris@16
|
23 struct bool_policies
|
Chris@16
|
24 {
|
Chris@16
|
25 template <typename Iterator, typename Attribute>
|
Chris@16
|
26 static bool
|
Chris@16
|
27 parse_true(Iterator& first, Iterator const& last, Attribute& attr_)
|
Chris@16
|
28 {
|
Chris@16
|
29 if (detail::string_parse("true", first, last, unused))
|
Chris@16
|
30 {
|
Chris@16
|
31 spirit::traits::assign_to(T(true), attr_); // result is true
|
Chris@16
|
32 return true;
|
Chris@16
|
33 }
|
Chris@16
|
34 return false;
|
Chris@16
|
35 }
|
Chris@16
|
36
|
Chris@16
|
37 template <typename Iterator, typename Attribute>
|
Chris@16
|
38 static bool
|
Chris@16
|
39 parse_false(Iterator& first, Iterator const& last, Attribute& attr_)
|
Chris@16
|
40 {
|
Chris@16
|
41 if (detail::string_parse("false", first, last, unused))
|
Chris@16
|
42 {
|
Chris@16
|
43 spirit::traits::assign_to(T(false), attr_); // result is false
|
Chris@16
|
44 return true;
|
Chris@16
|
45 }
|
Chris@16
|
46 return false;
|
Chris@16
|
47 }
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
51 template <typename T = bool>
|
Chris@16
|
52 struct no_case_bool_policies
|
Chris@16
|
53 {
|
Chris@16
|
54 template <typename Iterator, typename Attribute>
|
Chris@16
|
55 static bool
|
Chris@16
|
56 parse_true(Iterator& first, Iterator const& last, Attribute& attr_)
|
Chris@16
|
57 {
|
Chris@16
|
58 if (detail::string_parse("true", "TRUE", first, last, unused))
|
Chris@16
|
59 {
|
Chris@16
|
60 spirit::traits::assign_to(T(true), attr_); // result is true
|
Chris@16
|
61 return true;
|
Chris@16
|
62 }
|
Chris@16
|
63 return false;
|
Chris@16
|
64 }
|
Chris@16
|
65
|
Chris@16
|
66 template <typename Iterator, typename Attribute>
|
Chris@16
|
67 static bool
|
Chris@16
|
68 parse_false(Iterator& first, Iterator const& last, Attribute& attr_)
|
Chris@16
|
69 {
|
Chris@16
|
70 if (detail::string_parse("false", "FALSE", first, last, unused))
|
Chris@16
|
71 {
|
Chris@16
|
72 spirit::traits::assign_to(T(false), attr_); // result is false
|
Chris@16
|
73 return true;
|
Chris@16
|
74 }
|
Chris@16
|
75 return false;
|
Chris@16
|
76 }
|
Chris@16
|
77 };
|
Chris@16
|
78
|
Chris@16
|
79 }}}
|
Chris@16
|
80
|
Chris@16
|
81 #endif
|