PageRenderTime 28ms CodeModel.GetById 10ms app.highlight 12ms RepoModel.GetById 3ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/spirit/home/support/char_set/range_functions.hpp

http://hadesmem.googlecode.com/
C++ Header | 98 lines | 68 code | 17 blank | 13 comment | 7 complexity | 3dd94f715797b40c4c9fb4285c33abd0 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2001-2011 Joel de Guzman
 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#if !defined(BOOST_SPIRIT_RANGE_FUNCTIONS_MAY_16_2006_0720_PM)
 8#define BOOST_SPIRIT_RANGE_FUNCTIONS_MAY_16_2006_0720_PM
 9
10#if defined(_MSC_VER)
11#pragma once
12#endif
13
14#include <boost/integer_traits.hpp>
15
16namespace boost { namespace spirit { namespace support { namespace detail
17{
18    template <typename Range>
19    inline bool
20    is_valid(Range const& range)
21    {
22        // test for valid ranges
23        return range.first <= range.last;
24    }
25
26    template <typename Range>
27    inline bool
28    includes(Range const& range, Range const& other)
29    {
30        // see if two ranges intersect
31        return (range.first <= other.first) && (range.last >= other.last);
32    }
33
34    template <typename Range>
35    inline bool
36    includes(Range const& range, typename Range::value_type val)
37    {
38        // see if val is in range
39        return (range.first <= val) && (range.last >= val);
40    }
41
42    template <typename Range>
43    inline bool
44    can_merge(Range const& range, Range const& other)
45    {
46        // see if a 'range' overlaps, or is adjacent to
47        // another range 'other', so we can merge them
48
49        typedef typename Range::value_type value_type;
50        typedef integer_traits<value_type> integer_traits;
51
52        value_type decr_first =
53            range.first == integer_traits::const_min
54            ? range.first : range.first-1;
55
56        value_type incr_last =
57            range.last == integer_traits::const_max
58            ? range.last : range.last+1;
59
60        return (decr_first <= other.last) && (incr_last >= other.first);
61    }
62
63    template <typename Range>
64    inline void
65    merge(Range& result, Range const& other)
66    {
67        // merge two ranges
68        if (result.first > other.first)
69            result.first = other.first;
70        if (result.last < other.last)
71            result.last = other.last;
72    }
73
74    template <typename Range>
75    struct range_compare
76    {
77        // compare functor with a value or another range
78
79        typedef typename Range::value_type value_type;
80
81        bool operator()(Range const& x, const value_type y) const
82        {
83            return x.first < y;
84        }
85
86        bool operator()(value_type const x, Range const& y) const
87        {
88            return x < y.first;
89        }
90
91        bool operator()(Range const& x, Range const& y) const
92        {
93            return x.first < y.first;
94        }
95    };
96}}}}
97
98#endif