OpenTTD
Public Member Functions | Private Attributes
OverflowSafeInt< T, T_MAX, T_MIN > Class Template Reference

Overflow safe template for integers, i.e. More...

#include <overflowsafe_type.hpp>

Public Member Functions

 OverflowSafeInt (const OverflowSafeInt &other)
 
 OverflowSafeInt (const int64 int_)
 
OverflowSafeIntoperator= (const OverflowSafeInt &other)
 
OverflowSafeInt operator- () const
 
OverflowSafeIntoperator+= (const OverflowSafeInt &other)
 Safe implementation of addition. More...
 
OverflowSafeInt operator+ (const OverflowSafeInt &other) const
 
OverflowSafeInt operator+ (const int other) const
 
OverflowSafeInt operator+ (const uint other) const
 
OverflowSafeIntoperator-= (const OverflowSafeInt &other)
 
OverflowSafeInt operator- (const OverflowSafeInt &other) const
 
OverflowSafeInt operator- (const int other) const
 
OverflowSafeInt operator- (const uint other) const
 
OverflowSafeIntoperator++ ()
 
OverflowSafeIntoperator-- ()
 
OverflowSafeInt operator++ (int)
 
OverflowSafeInt operator-- (int)
 
OverflowSafeIntoperator*= (const int factor)
 Safe implementation of multiplication. More...
 
OverflowSafeInt operator* (const int64 factor) const
 
OverflowSafeInt operator* (const int factor) const
 
OverflowSafeInt operator* (const uint factor) const
 
OverflowSafeInt operator* (const uint16 factor) const
 
OverflowSafeInt operator* (const byte factor) const
 
OverflowSafeIntoperator/= (const int64 divisor)
 
OverflowSafeInt operator/ (const OverflowSafeInt &divisor) const
 
OverflowSafeInt operator/ (const int divisor) const
 
OverflowSafeInt operator/ (const uint divisor) const
 
OverflowSafeIntoperator%= (const int divisor)
 
OverflowSafeInt operator% (const int divisor) const
 
OverflowSafeIntoperator<<= (const int shift)
 
OverflowSafeInt operator<< (const int shift) const
 
OverflowSafeIntoperator>>= (const int shift)
 
OverflowSafeInt operator>> (const int shift) const
 
bool operator== (const OverflowSafeInt &other) const
 
bool operator!= (const OverflowSafeInt &other) const
 
bool operator> (const OverflowSafeInt &other) const
 
bool operator>= (const OverflowSafeInt &other) const
 
bool operator< (const OverflowSafeInt &other) const
 
bool operator<= (const OverflowSafeInt &other) const
 
bool operator== (const int other) const
 
bool operator!= (const int other) const
 
bool operator> (const int other) const
 
bool operator>= (const int other) const
 
bool operator< (const int other) const
 
bool operator<= (const int other) const
 
 operator int64 () const
 

Private Attributes

m_value
 The non-overflow safe backend to store the value in. More...
 

Detailed Description

template<class T, T T_MAX, T T_MIN>
class OverflowSafeInt< T, T_MAX, T_MIN >

Overflow safe template for integers, i.e.

integers that will never overflow you multiply the maximum value with 2, or add 2, or subtract something from the minimum value, etc.

Parameters
Tthe type these integers are stored with.
T_MAXthe maximum value for the integers.
T_MINthe minimum value for the integers.

Definition at line 26 of file overflowsafe_type.hpp.

Member Function Documentation

◆ operator*=()

template<class T, T T_MAX, T T_MIN>
OverflowSafeInt& OverflowSafeInt< T, T_MAX, T_MIN >::operator*= ( const int  factor)
inline

Safe implementation of multiplication.

Parameters
factorthe factor to multiply this with.
Note
when the multiplication would yield more than T_MAX (or less than T_MIN), it will be T_MAX (respectively T_MIN).

Definition at line 78 of file overflowsafe_type.hpp.

◆ operator+=()

template<class T, T T_MAX, T T_MIN>
OverflowSafeInt& OverflowSafeInt< T, T_MAX, T_MIN >::operator+= ( const OverflowSafeInt< T, T_MAX, T_MIN > &  other)
inline

Safe implementation of addition.

Parameters
otherthe amount to add
Note
when the addition would yield more than T_MAX (or less than T_MIN), it will be T_MAX (respectively T_MIN).

Definition at line 47 of file overflowsafe_type.hpp.

Field Documentation

◆ m_value

template<class T, T T_MAX, T T_MIN>
T OverflowSafeInt< T, T_MAX, T_MIN >::m_value
private

The non-overflow safe backend to store the value in.

Definition at line 30 of file overflowsafe_type.hpp.

Referenced by OverflowSafeInt< int64, INT64_MAX, INT64_MIN >::operator+=().


The documentation for this class was generated from the following file: