File indexing completed on 2025-01-18 09:53:52
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_WIDTH_HPP_EAN_04_07_2006
0009 #define BOOST_XPRESSIVE_DETAIL_UTILITY_WIDTH_HPP_EAN_04_07_2006
0010
0011
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015
0016 #include <climits> // for INT_MAX
0017 #include <boost/mpl/size_t.hpp>
0018
0019 namespace boost { namespace xpressive { namespace detail
0020 {
0021
0022 typedef mpl::size_t<INT_MAX / 2 - 1> unknown_width;
0023 struct width;
0024 bool is_unknown(width const &that);
0025
0026
0027
0028 struct width
0029 {
0030 width(std::size_t val = 0)
0031 : value_(val)
0032 {
0033 }
0034
0035 bool operator !() const
0036 {
0037 return !this->value_;
0038 }
0039
0040 width &operator +=(width const &that)
0041 {
0042 this->value_ =
0043 !is_unknown(*this) && !is_unknown(that)
0044 ? this->value_ + that.value_
0045 : unknown_width();
0046 return *this;
0047 }
0048
0049 width &operator |=(width const &that)
0050 {
0051 this->value_ =
0052 this->value_ == that.value_
0053 ? this->value_
0054 : unknown_width();
0055 return *this;
0056 }
0057
0058 std::size_t value() const
0059 {
0060 return this->value_;
0061 }
0062
0063 private:
0064 std::size_t value_;
0065 };
0066
0067 inline bool is_unknown(width const &that)
0068 {
0069 return unknown_width::value == that.value();
0070 }
0071
0072 inline bool operator ==(width const &left, width const &right)
0073 {
0074 return left.value() == right.value();
0075 }
0076
0077 inline bool operator !=(width const &left, width const &right)
0078 {
0079 return left.value() != right.value();
0080 }
0081
0082 inline width operator +(width left, width const &right)
0083 {
0084 return left += right;
0085 }
0086
0087 inline width operator |(width left, width const &right)
0088 {
0089 return left |= right;
0090 }
0091
0092 }}}
0093
0094 #endif