Classes | Namespaces | Defines | Typedefs | Functions

CheckedInt.h File Reference

#include "prtypes.h"
#include <climits>
Include dependency graph for CheckedInt.h:

Classes

struct  mozilla::CheckedInt_internal::unsupported_type
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< T >
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< PRInt8 >
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< PRUint8 >
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< PRInt16 >
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< PRUint16 >
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< PRInt32 >
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< PRUint32 >
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< PRInt64 >
struct  mozilla::CheckedInt_internal::integer_type_manually_recorded_info< PRUint64 >
struct  mozilla::CheckedInt_internal::is_unsupported_type< T >
struct  mozilla::CheckedInt_internal::is_unsupported_type< unsupported_type >
struct  mozilla::CheckedInt_internal::integer_traits< T >
struct  mozilla::CheckedInt_internal::is_in_range_impl< T, U, is_T_signed, is_U_signed >
struct  mozilla::CheckedInt_internal::is_in_range_impl< T, U, true, true >
struct  mozilla::CheckedInt_internal::is_in_range_impl< T, U, false, false >
struct  mozilla::CheckedInt_internal::is_in_range_impl< T, U, true, false >
struct  mozilla::CheckedInt_internal::is_in_range_impl< T, U, false, true >
struct  mozilla::CheckedInt_internal::is_mul_valid_impl< T, is_signed, twice_bigger_type_is_supported >
struct  mozilla::CheckedInt_internal::is_mul_valid_impl< T, is_signed, true >
struct  mozilla::CheckedInt_internal::is_mul_valid_impl< T, true, false >
struct  mozilla::CheckedInt_internal::is_mul_valid_impl< T, false, false >
struct  mozilla::CheckedInt_internal::opposite_if_signed_impl< T, is_signed >
struct  mozilla::CheckedInt_internal::opposite_if_signed_impl< T, false >
class  mozilla::CheckedInt< T >
 Integer wrapper class checking for integer overflow and other errors. More...
struct  mozilla::cast_to_CheckedInt_impl< T, U >
struct  mozilla::cast_to_CheckedInt_impl< T, CheckedInt< T > >

Namespaces

namespace  mozilla
 

This is the base class for all link classes.


namespace  mozilla::CheckedInt_internal

Defines

#define CHECKEDINT_REGISTER_SUPPORTED_TYPE(T, _twice_bigger_type, _unsigned_type)
#define CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP)
#define CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP)
#define CHECKEDINT_MAKE_TYPEDEF(Type)   typedef CheckedInt<PR##Type> Checked##Type;

Typedefs

typedef CheckedInt< PRInt8 > mozilla::CheckedInt8
typedef CheckedInt< PRUint8 > mozilla::CheckedUint8
typedef CheckedInt< PRInt16 > mozilla::CheckedInt16
typedef CheckedInt< PRUint16 > mozilla::CheckedUint16
typedef CheckedInt< PRInt32 > mozilla::CheckedInt32
typedef CheckedInt< PRUint32 > mozilla::CheckedUint32
typedef CheckedInt< PRInt64mozilla::CheckedInt64
typedef CheckedInt< PRUint64mozilla::CheckedUint64

Functions

template<typename T >
mozilla::CheckedInt_internal::has_sign_bit (T x)
template<typename T >
mozilla::CheckedInt_internal::binary_complement (T x)
template<typename T , typename U >
mozilla::CheckedInt_internal::is_in_range (U x)
template<typename T >
mozilla::CheckedInt_internal::is_add_valid (T x, T y, T result)
template<typename T >
mozilla::CheckedInt_internal::is_sub_valid (T x, T y, T result)
template<typename T >
mozilla::CheckedInt_internal::is_mul_valid (T x, T y, T)
template<typename T >
mozilla::CheckedInt_internal::is_div_valid (T x, T y)
template<typename T >
mozilla::CheckedInt_internal::opposite_if_signed (T x)
template<typename T >
CheckedInt< T > mozilla::operator+ (const CheckedInt< T > &lhs, const CheckedInt< T > &rhs)
template<typename T >
CheckedInt< T > mozilla::operator- (const CheckedInt< T > &lhs, const CheckedInt< T > &rhs)
template<typename T >
CheckedInt< T > mozilla::operator* (const CheckedInt< T > &lhs, const CheckedInt< T > &rhs)
template<typename T >
CheckedInt< T > mozilla::operator/ (const CheckedInt< T > &lhs, const CheckedInt< T > &rhs)
template<typename T , typename U >
cast_to_CheckedInt_impl< T, U >
::return_type 
mozilla::cast_to_CheckedInt (U u)
template<typename T , typename U >
CheckedInt< T > mozilla::operator+ (const CheckedInt< T > &lhs, U rhs)
template<typename T , typename U >
CheckedInt< T > mozilla::operator+ (U lhs, const CheckedInt< T > &rhs)
template<typename T , typename U >
CheckedInt< T > mozilla::operator* (const CheckedInt< T > &lhs, U rhs)
template<typename T , typename U >
CheckedInt< T > mozilla::operator* (U lhs, const CheckedInt< T > &rhs)
template<typename T , typename U >
CheckedInt< T > mozilla::operator- (const CheckedInt< T > &lhs, U rhs)
template<typename T , typename U >
CheckedInt< T > mozilla::operator- (U lhs, const CheckedInt< T > &rhs)
template<typename T , typename U >
CheckedInt< T > mozilla::operator/ (const CheckedInt< T > &lhs, U rhs)
template<typename T , typename U >
CheckedInt< T > mozilla::operator/ (U lhs, const CheckedInt< T > &rhs)
template<typename T , typename U >
PRBool mozilla::operator== (const CheckedInt< T > &lhs, U rhs)
template<typename T , typename U >
PRBool mozilla::operator== (U lhs, const CheckedInt< T > &rhs)

Define Documentation

#define CHECKEDINT_BASIC_BINARY_OPERATOR (   NAME,
  OP 
)
Value:
template<typename T>                                          \
inline CheckedInt<T> operator OP(const CheckedInt<T> &lhs, const CheckedInt<T> &rhs) \
{                                                                     \
    T x = lhs.mValue;                                                \
    T y = rhs.mValue;                                                \
    T result = x OP y;                                                \
    T is_op_valid                                                     \
        = CheckedInt_internal::is_##NAME##_valid(x, y, result);       \
    /* give the compiler a good chance to perform RVO */              \
    return CheckedInt<T>(result,                                      \
                         lhs.mIsValid & rhs.mIsValid & is_op_valid);  \
}
#define CHECKEDINT_CONVENIENCE_BINARY_OPERATORS (   OP,
  COMPOUND_OP 
)
Value:
template<typename T>                                          \
template<typename U>                                          \
CheckedInt<T>& CheckedInt<T>::operator COMPOUND_OP(U rhs)    \
{                                                             \
    *this = *this OP cast_to_CheckedInt<T>(rhs);                 \
    return *this;                                             \
}                                                             \
template<typename T, typename U>                              \
inline CheckedInt<T> operator OP(const CheckedInt<T> &lhs, U rhs) \
{                                                             \
    return lhs OP cast_to_CheckedInt<T>(rhs);                    \
}                                                             \
template<typename T, typename U>                              \
inline CheckedInt<T> operator OP(U lhs, const CheckedInt<T> &rhs) \
{                                                             \
    return cast_to_CheckedInt<T>(lhs) OP rhs;                    \
}
#define CHECKEDINT_MAKE_TYPEDEF (   Type  )     typedef CheckedInt<PR##Type> Checked##Type;
#define CHECKEDINT_REGISTER_SUPPORTED_TYPE (   T,
  _twice_bigger_type,
  _unsigned_type 
)
Value:
template<> struct integer_type_manually_recorded_info<T>       \
{                                                              \
    enum { is_supported = 1 };                                 \
    typedef _twice_bigger_type twice_bigger_type;              \
    typedef _unsigned_type unsigned_type;                      \
    static void TYPE_NOT_SUPPORTED_BY_CheckedInt() {}          \
};