2012-08-23 01:33:52 +04:00
|
|
|
#ifndef units_hh_INCLUDED
|
|
|
|
#define units_hh_INCLUDED
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename RealType, typename ValueType = int>
|
|
|
|
class StronglyTypedInteger
|
|
|
|
{
|
|
|
|
public:
|
2012-09-05 01:54:10 +04:00
|
|
|
explicit constexpr StronglyTypedInteger(ValueType value)
|
2012-08-23 01:33:52 +04:00
|
|
|
: m_value(value) {}
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr RealType operator+(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return RealType(m_value + other.m_value); }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr RealType operator-(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return RealType(m_value - other.m_value); }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr RealType operator*(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return RealType(m_value * other.m_value); }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr RealType operator/(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return RealType(m_value / other.m_value); }
|
|
|
|
|
|
|
|
RealType& operator+=(const RealType& other)
|
|
|
|
{ m_value += other.m_value; return static_cast<RealType&>(*this); }
|
|
|
|
|
|
|
|
RealType& operator-=(const RealType& other)
|
|
|
|
{ m_value -= other.m_value; return static_cast<RealType&>(*this); }
|
|
|
|
|
|
|
|
RealType& operator*=(const RealType& other)
|
|
|
|
{ m_value *= other.m_value; return static_cast<RealType&>(*this); }
|
|
|
|
|
|
|
|
RealType& operator/=(const RealType& other)
|
|
|
|
{ m_value /= other.m_value; return static_cast<RealType&>(*this); }
|
|
|
|
|
|
|
|
RealType& operator++()
|
|
|
|
{ ++m_value; return static_cast<RealType&>(*this); }
|
|
|
|
|
|
|
|
RealType& operator--()
|
|
|
|
{ --m_value; return static_cast<RealType&>(*this); }
|
|
|
|
|
|
|
|
RealType operator++(int)
|
2012-10-02 16:19:45 +04:00
|
|
|
{ RealType backup(static_cast<RealType&>(*this)); ++m_value; return backup; }
|
2012-08-23 01:33:52 +04:00
|
|
|
|
|
|
|
RealType operator--(int)
|
2012-10-02 16:19:45 +04:00
|
|
|
{ RealType backup(static_cast<RealType&>(*this)); --m_value; return backup; }
|
2012-08-23 01:33:52 +04:00
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr RealType operator-() { return RealType(-m_value); }
|
2012-08-23 01:33:52 +04:00
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr bool operator==(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return m_value == other.m_value; }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr bool operator!=(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return m_value != other.m_value; }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr bool operator<(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return m_value < other.m_value; }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr bool operator<=(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return m_value <= other.m_value; }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr bool operator>(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return m_value > other.m_value; }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr bool operator>=(const RealType& other) const
|
2012-08-23 01:33:52 +04:00
|
|
|
{ return m_value >= other.m_value; }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr bool operator!() const
|
2012-08-24 01:56:35 +04:00
|
|
|
{ return !m_value; }
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
explicit constexpr operator ValueType() const { return m_value; }
|
2012-10-02 16:18:34 +04:00
|
|
|
explicit constexpr operator bool() const { return m_value; }
|
2012-08-23 01:33:52 +04:00
|
|
|
private:
|
|
|
|
ValueType m_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LineCount : public StronglyTypedInteger<LineCount, int>
|
|
|
|
{
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr LineCount(int value) : StronglyTypedInteger<LineCount>(value) {}
|
2012-08-23 01:33:52 +04:00
|
|
|
};
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
inline constexpr LineCount operator"" _line(unsigned long long int value)
|
2012-08-23 01:33:52 +04:00
|
|
|
{
|
|
|
|
return LineCount(value);
|
|
|
|
}
|
|
|
|
|
2012-08-24 01:56:35 +04:00
|
|
|
struct CharCount : public StronglyTypedInteger<CharCount, int>
|
|
|
|
{
|
2012-09-05 01:54:10 +04:00
|
|
|
constexpr CharCount(int value) : StronglyTypedInteger<CharCount>(value) {}
|
2012-08-24 01:56:35 +04:00
|
|
|
};
|
|
|
|
|
2012-09-05 01:54:10 +04:00
|
|
|
inline constexpr CharCount operator"" _char(unsigned long long int value)
|
2012-08-24 01:56:35 +04:00
|
|
|
{
|
|
|
|
return CharCount(value);
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:33:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // units_hh_INCLUDED
|
|
|
|
|