PageRenderTime 20ms CodeModel.GetById 9ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost-1.52.0/boost/xpressive/detail/utility/width.hpp

https://gitlab.com/tylerluo/pythonocc
C++ Header | 94 lines | 67 code | 18 blank | 9 comment | 6 complexity | 849e95ddec391dd9424a33c55f9f2a60 MD5 | raw file
 1///////////////////////////////////////////////////////////////////////////////
 2// width.hpp
 3//
 4//  Copyright 2008 Eric Niebler. Distributed under the Boost
 5//  Software License, Version 1.0. (See accompanying file
 6//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 7
 8#ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_WIDTH_HPP_EAN_04_07_2006
 9#define BOOST_XPRESSIVE_DETAIL_UTILITY_WIDTH_HPP_EAN_04_07_2006
10
11// MS compatible compilers support #pragma once
12#if defined(_MSC_VER) && (_MSC_VER >= 1020)
13# pragma once
14#endif
15
16#include <climits> // for INT_MAX
17#include <boost/mpl/size_t.hpp>
18
19namespace boost { namespace xpressive { namespace detail
20{
21
22typedef mpl::size_t<INT_MAX / 2 - 1> unknown_width;
23struct width;
24bool is_unknown(width const &that);
25
26///////////////////////////////////////////////////////////////////////////////
27// width
28struct width
29{
30    width(std::size_t val = 0)
31      : value_(val)
32    {
33    }
34
35    bool operator !() const
36    {
37        return !this->value_;
38    }
39
40    width &operator +=(width const &that)
41    {
42        this->value_ =
43            !is_unknown(*this) && !is_unknown(that)
44          ? this->value_ + that.value_
45          : unknown_width();
46        return *this;
47    }
48
49    width &operator |=(width const &that)
50    {
51        this->value_ =
52            this->value_ == that.value_
53          ? this->value_
54          : unknown_width();
55        return *this;
56    }
57
58    std::size_t value() const
59    {
60        return this->value_;
61    }
62
63private:
64    std::size_t value_;
65};
66
67inline bool is_unknown(width const &that)
68{
69    return unknown_width::value == that.value();
70}
71
72inline bool operator ==(width const &left, width const &right)
73{
74    return left.value() == right.value();
75}
76
77inline bool operator !=(width const &left, width const &right)
78{
79    return left.value() != right.value();
80}
81
82inline width operator +(width left, width const &right)
83{
84    return left += right;
85}
86
87inline width operator |(width left, width const &right)
88{
89    return left |= right;
90}
91
92}}} // namespace boost::xpressive::detail
93
94#endif