annotate DEPENDENCIES/generic/include/boost/xpressive/detail/utility/width.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////////////////////
Chris@16 2 // width.hpp
Chris@16 3 //
Chris@16 4 // Copyright 2008 Eric Niebler. Distributed under the Boost
Chris@16 5 // Software License, Version 1.0. (See accompanying file
Chris@16 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_WIDTH_HPP_EAN_04_07_2006
Chris@16 9 #define BOOST_XPRESSIVE_DETAIL_UTILITY_WIDTH_HPP_EAN_04_07_2006
Chris@16 10
Chris@16 11 // MS compatible compilers support #pragma once
Chris@101 12 #if defined(_MSC_VER)
Chris@16 13 # pragma once
Chris@16 14 #endif
Chris@16 15
Chris@16 16 #include <climits> // for INT_MAX
Chris@16 17 #include <boost/mpl/size_t.hpp>
Chris@16 18
Chris@16 19 namespace boost { namespace xpressive { namespace detail
Chris@16 20 {
Chris@16 21
Chris@16 22 typedef mpl::size_t<INT_MAX / 2 - 1> unknown_width;
Chris@16 23 struct width;
Chris@16 24 bool is_unknown(width const &that);
Chris@16 25
Chris@16 26 ///////////////////////////////////////////////////////////////////////////////
Chris@16 27 // width
Chris@16 28 struct width
Chris@16 29 {
Chris@16 30 width(std::size_t val = 0)
Chris@16 31 : value_(val)
Chris@16 32 {
Chris@16 33 }
Chris@16 34
Chris@16 35 bool operator !() const
Chris@16 36 {
Chris@16 37 return !this->value_;
Chris@16 38 }
Chris@16 39
Chris@16 40 width &operator +=(width const &that)
Chris@16 41 {
Chris@16 42 this->value_ =
Chris@16 43 !is_unknown(*this) && !is_unknown(that)
Chris@16 44 ? this->value_ + that.value_
Chris@16 45 : unknown_width();
Chris@16 46 return *this;
Chris@16 47 }
Chris@16 48
Chris@16 49 width &operator |=(width const &that)
Chris@16 50 {
Chris@16 51 this->value_ =
Chris@16 52 this->value_ == that.value_
Chris@16 53 ? this->value_
Chris@16 54 : unknown_width();
Chris@16 55 return *this;
Chris@16 56 }
Chris@16 57
Chris@16 58 std::size_t value() const
Chris@16 59 {
Chris@16 60 return this->value_;
Chris@16 61 }
Chris@16 62
Chris@16 63 private:
Chris@16 64 std::size_t value_;
Chris@16 65 };
Chris@16 66
Chris@16 67 inline bool is_unknown(width const &that)
Chris@16 68 {
Chris@16 69 return unknown_width::value == that.value();
Chris@16 70 }
Chris@16 71
Chris@16 72 inline bool operator ==(width const &left, width const &right)
Chris@16 73 {
Chris@16 74 return left.value() == right.value();
Chris@16 75 }
Chris@16 76
Chris@16 77 inline bool operator !=(width const &left, width const &right)
Chris@16 78 {
Chris@16 79 return left.value() != right.value();
Chris@16 80 }
Chris@16 81
Chris@16 82 inline width operator +(width left, width const &right)
Chris@16 83 {
Chris@16 84 return left += right;
Chris@16 85 }
Chris@16 86
Chris@16 87 inline width operator |(width left, width const &right)
Chris@16 88 {
Chris@16 89 return left |= right;
Chris@16 90 }
Chris@16 91
Chris@16 92 }}} // namespace boost::xpressive::detail
Chris@16 93
Chris@16 94 #endif