BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
fc::safe< T > Struct Template Reference

#include <safe.hpp>

Inheritance diagram for fc::safe< T >:
fc::safe_base< T >

Public Member Functions

 safe ()=default
 
template<typename V >
 safe (V v)
 
template<typename V >
safeoperator= (V v)
 
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true>
safe operator- () const
 
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true>
safe operator- () const
 
safeoperator+= (const safe &b)
 
safeoperator-= (const safe &b)
 
safeoperator*= (const safe &b)
 
safeoperator/= (const safe &b)
 
safeoperator%= (const safe &b)
 
safeoperator++ ()
 
safe operator++ (int)
 
safeoperator-- ()
 
safe operator-- (int)
 

Static Public Member Functions

template<typename V , typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true, std::enable_if_t< std::is_integral< V >::value, bool > = true, std::enable_if_t< std::is_signed< V >::value, bool > = true>
static T check (V v)
 
template<typename V , typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true, std::enable_if_t< std::is_integral< V >::value, bool > = true, std::enable_if_t< std::is_unsigned< V >::value, bool > = true>
static T check (V v)
 
template<typename V , typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true, std::enable_if_t< std::is_integral< V >::value, bool > = true, std::enable_if_t< std::is_signed< V >::value, bool > = true>
static T check (V v)
 
template<typename V , typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true, std::enable_if_t< std::is_integral< V >::value, bool > = true, std::enable_if_t< std::is_unsigned< V >::value, bool > = true>
static T check (V v)
 
static constexpr safe min ()
 
static constexpr safe max ()
 

Public Attributes

value = 0
 

Friends

safe operator+ (const safe &a, const safe &b)
 
safe operator- (const safe &a, const safe &b)
 
safe operator* (const safe &a, const safe &b)
 
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true>
safe operator/ (const safe &a, const safe &b)
 
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true>
safe operator/ (const safe &a, const safe &b)
 
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true>
safe operator% (const safe &a, const safe &b)
 
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true>
safe operator% (const safe &a, const safe &b)
 
bool operator== (const safe &a, const safe &b)
 
bool operator== (const safe &a, T b)
 
bool operator== (T a, const safe &b)
 
bool operator< (const safe &a, const safe &b)
 
bool operator< (const safe &a, T b)
 
bool operator< (T a, const safe &b)
 
bool operator> (const safe &a, const safe &b)
 
bool operator> (const safe &a, T b)
 
bool operator> (T a, const safe &b)
 
bool operator!= (const safe &a, const safe &b)
 
bool operator!= (const safe &a, T b)
 
bool operator!= (T a, const safe &b)
 
bool operator<= (const safe &a, const safe &b)
 
bool operator<= (const safe &a, T b)
 
bool operator<= (T a, const safe &b)
 
bool operator>= (const safe &a, const safe &b)
 
bool operator>= (const safe &a, T b)
 
bool operator>= (T a, const safe &b)
 

Detailed Description

template<typename T>
struct fc::safe< T >

This type is designed to provide automatic checks for integer overflow and default initialization. It will throw an exception on overflow conditions.

It can only be used on built-in types.

Implemented using spec from: https://www.securecoding.cert.org/confluence/display/c/INT32-C.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow

Definition at line 26 of file safe.hpp.

Constructor & Destructor Documentation

◆ safe() [1/2]

template<typename T >
fc::safe< T >::safe ( )
default

◆ safe() [2/2]

template<typename T >
template<typename V >
fc::safe< T >::safe ( v)
inline

Definition at line 89 of file safe.hpp.

Member Function Documentation

◆ check() [1/4]

template<typename T >
template<typename V , typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true, std::enable_if_t< std::is_integral< V >::value, bool > = true, std::enable_if_t< std::is_signed< V >::value, bool > = true>
static T fc::safe< T >::check ( v)
inlinestatic

Definition at line 37 of file safe.hpp.

◆ check() [2/4]

template<typename T >
template<typename V , typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true, std::enable_if_t< std::is_integral< V >::value, bool > = true, std::enable_if_t< std::is_unsigned< V >::value, bool > = true>
static T fc::safe< T >::check ( v)
inlinestatic

Definition at line 52 of file safe.hpp.

◆ check() [3/4]

template<typename T >
template<typename V , typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true, std::enable_if_t< std::is_integral< V >::value, bool > = true, std::enable_if_t< std::is_signed< V >::value, bool > = true>
static T fc::safe< T >::check ( v)
inlinestatic

Definition at line 65 of file safe.hpp.

◆ check() [4/4]

template<typename T >
template<typename V , typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true, std::enable_if_t< std::is_integral< V >::value, bool > = true, std::enable_if_t< std::is_unsigned< V >::value, bool > = true>
static T fc::safe< T >::check ( v)
inlinestatic

Definition at line 80 of file safe.hpp.

◆ max()

template<typename T >
static constexpr safe fc::safe< T >::max ( )
inlinestaticconstexpr

Definition at line 105 of file safe.hpp.

◆ min()

template<typename T >
static constexpr safe fc::safe< T >::min ( )
inlinestaticconstexpr

Definition at line 101 of file safe.hpp.

◆ operator%=()

template<typename T >
safe& fc::safe< T >::operator%= ( const safe< T > &  b)
inline

Definition at line 240 of file safe.hpp.

◆ operator*=()

template<typename T >
safe& fc::safe< T >::operator*= ( const safe< T > &  b)
inline

Definition at line 230 of file safe.hpp.

◆ operator++() [1/2]

template<typename T >
safe& fc::safe< T >::operator++ ( )
inline

Definition at line 246 of file safe.hpp.

◆ operator++() [2/2]

template<typename T >
safe fc::safe< T >::operator++ ( int  )
inline

Definition at line 251 of file safe.hpp.

◆ operator+=()

template<typename T >
safe& fc::safe< T >::operator+= ( const safe< T > &  b)
inline

Definition at line 220 of file safe.hpp.

◆ operator-() [1/2]

template<typename T >
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true>
safe fc::safe< T >::operator- ( ) const
inline

Definition at line 204 of file safe.hpp.

◆ operator-() [2/2]

template<typename T >
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true>
safe fc::safe< T >::operator- ( ) const
inline

Definition at line 213 of file safe.hpp.

◆ operator--() [1/2]

template<typename T >
safe& fc::safe< T >::operator-- ( )
inline

Definition at line 258 of file safe.hpp.

◆ operator--() [2/2]

template<typename T >
safe fc::safe< T >::operator-- ( int  )
inline

Definition at line 263 of file safe.hpp.

◆ operator-=()

template<typename T >
safe& fc::safe< T >::operator-= ( const safe< T > &  b)
inline

Definition at line 225 of file safe.hpp.

◆ operator/=()

template<typename T >
safe& fc::safe< T >::operator/= ( const safe< T > &  b)
inline

Definition at line 235 of file safe.hpp.

◆ operator=()

template<typename T >
template<typename V >
safe& fc::safe< T >::operator= ( v)
inline

Definition at line 95 of file safe.hpp.

Friends And Related Function Documentation

◆ operator!= [1/3]

template<typename T >
bool operator!= ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 309 of file safe.hpp.

◆ operator!= [2/3]

template<typename T >
bool operator!= ( const safe< T > &  a,
b 
)
friend

Definition at line 313 of file safe.hpp.

◆ operator!= [3/3]

template<typename T >
bool operator!= ( a,
const safe< T > &  b 
)
friend

Definition at line 317 of file safe.hpp.

◆ operator% [1/2]

template<typename T >
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true>
safe operator% ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 183 of file safe.hpp.

◆ operator% [2/2]

template<typename T >
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true>
safe operator% ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 194 of file safe.hpp.

◆ operator*

template<typename T >
safe operator* ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 127 of file safe.hpp.

◆ operator+

template<typename T >
safe operator+ ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 110 of file safe.hpp.

◆ operator-

template<typename T >
safe operator- ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 118 of file safe.hpp.

◆ operator/ [1/2]

template<typename T >
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_signed< X >::value, bool > = true>
safe operator/ ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 162 of file safe.hpp.

◆ operator/ [2/2]

template<typename T >
template<typename... Dummy, typename X = T, std::enable_if_t< std::is_unsigned< X >::value, bool > = true>
safe operator/ ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 173 of file safe.hpp.

◆ operator< [1/3]

template<typename T >
bool operator< ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 283 of file safe.hpp.

◆ operator< [2/3]

template<typename T >
bool operator< ( const safe< T > &  a,
b 
)
friend

Definition at line 287 of file safe.hpp.

◆ operator< [3/3]

template<typename T >
bool operator< ( a,
const safe< T > &  b 
)
friend

Definition at line 291 of file safe.hpp.

◆ operator<= [1/3]

template<typename T >
bool operator<= ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 322 of file safe.hpp.

◆ operator<= [2/3]

template<typename T >
bool operator<= ( const safe< T > &  a,
b 
)
friend

Definition at line 326 of file safe.hpp.

◆ operator<= [3/3]

template<typename T >
bool operator<= ( a,
const safe< T > &  b 
)
friend

Definition at line 330 of file safe.hpp.

◆ operator== [1/3]

template<typename T >
bool operator== ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 270 of file safe.hpp.

◆ operator== [2/3]

template<typename T >
bool operator== ( const safe< T > &  a,
b 
)
friend

Definition at line 274 of file safe.hpp.

◆ operator== [3/3]

template<typename T >
bool operator== ( a,
const safe< T > &  b 
)
friend

Definition at line 278 of file safe.hpp.

◆ operator> [1/3]

template<typename T >
bool operator> ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 296 of file safe.hpp.

◆ operator> [2/3]

template<typename T >
bool operator> ( const safe< T > &  a,
b 
)
friend

Definition at line 300 of file safe.hpp.

◆ operator> [3/3]

template<typename T >
bool operator> ( a,
const safe< T > &  b 
)
friend

Definition at line 304 of file safe.hpp.

◆ operator>= [1/3]

template<typename T >
bool operator>= ( const safe< T > &  a,
const safe< T > &  b 
)
friend

Definition at line 335 of file safe.hpp.

◆ operator>= [2/3]

template<typename T >
bool operator>= ( const safe< T > &  a,
b 
)
friend

Definition at line 339 of file safe.hpp.

◆ operator>= [3/3]

template<typename T >
bool operator>= ( a,
const safe< T > &  b 
)
friend

Definition at line 343 of file safe.hpp.

Member Data Documentation

◆ value

template<typename T >
T fc::safe< T >::value = 0

Definition at line 28 of file safe.hpp.


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