summaryrefslogtreecommitdiff
path: root/boost/spirit/home/qi/numeric/bool_policies.hpp
blob: 62641a60360affc52162fb31cf118d803b964b0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*=============================================================================
    Copyright (c) 2001-2011 Hartmut Kaiser

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(SPIRIT_QI_BOOL_POLICIES_SEP_29_2009_0710AM)
#define SPIRIT_QI_BOOL_POLICIES_SEP_29_2009_0710AM

#if defined(_MSC_VER)
#pragma once
#endif

#include <boost/spirit/home/qi/detail/string_parse.hpp>
#include <boost/spirit/home/qi/detail/assign_to.hpp>

namespace boost { namespace spirit { namespace qi
{
    ///////////////////////////////////////////////////////////////////////////
    //  Default boolean policies
    ///////////////////////////////////////////////////////////////////////////
    template <typename T = bool>
    struct bool_policies
    {
        template <typename Iterator, typename Attribute>
        static bool
        parse_true(Iterator& first, Iterator const& last, Attribute& attr_)
        {
            if (detail::string_parse("true", first, last, unused))
            {
                spirit::traits::assign_to(T(true), attr_);    // result is true
                return true;
            }
            return false;
        }

        template <typename Iterator, typename Attribute>
        static bool
        parse_false(Iterator& first, Iterator const& last, Attribute& attr_)
        {
            if (detail::string_parse("false", first, last, unused))
            {
                spirit::traits::assign_to(T(false), attr_);   // result is false
                return true;
            }
            return false;
        }
    };

    ///////////////////////////////////////////////////////////////////////////
    template <typename T = bool>
    struct no_case_bool_policies
    {
        template <typename Iterator, typename Attribute>
        static bool
        parse_true(Iterator& first, Iterator const& last, Attribute& attr_)
        {
            if (detail::string_parse("true", "TRUE", first, last, unused))
            {
                spirit::traits::assign_to(T(true), attr_);    // result is true
                return true;
            }
            return false;
        }

        template <typename Iterator, typename Attribute>
        static bool
        parse_false(Iterator& first, Iterator const& last, Attribute& attr_)
        {
            if (detail::string_parse("false", "FALSE", first, last, unused))
            {
                spirit::traits::assign_to(T(false), attr_);   // result is false
                return true;
            }
            return false;
        }
    };

}}}

#endif