224 #if !defined (_SAFEINT_DEFAULT_ERROR_POLICY)
225 #define _SAFEINT_DEFAULT_ERROR_POLICY SafeIntErrorPolicy_SafeIntException
228 #if !defined (_SAFEINT_SHIFT_ASSERT)
229 #define _SAFEINT_SHIFT_ASSERT(x) _ASSERTE(x)
232 #if !defined (_SAFEINT_BINARY_ASSERT)
233 #define _SAFEINT_BINARY_ASSERT(x) _ASSERTE(x)
236 #if !defined (_SAFEINT_EXCEPTION_ASSERT)
237 #define _SAFEINT_EXCEPTION_ASSERT()
243 #if !defined (_SAFEINT_UNSIGNED_NEGATION_BEHAVIOR)
244 #define _SAFEINT_UNSIGNED_NEGATION_BEHAVIOR()
249 #if !defined (_SAFEINT_USE_ANSI_CONVERSIONS)
250 #define _SAFEINT_USE_ANSI_CONVERSIONS 0
253 #pragma pack(push, _CRT_PACKING)
325 template <
typename T,
typename U >
326 inline bool SafeCast(
const T From, U& To )
throw()
332 template <
typename T,
typename U >
338 template <
typename T,
typename U >
344 template <
typename T,
typename U >
350 template <
typename T,
typename U >
356 template <
typename T,
typename U >
362 template <
typename T,
typename U >
368 template <
typename T,
typename U >
369 inline bool SafeModulus(
const T& t,
const U& u, T& result )
throw()
374 template <
typename T,
typename U >
381 template <
typename T,
typename U >
388 template <
typename T,
typename U >
389 inline bool SafeAdd( T t, U u, T& result )
throw()
395 template <
typename T,
typename U >
403 template <
typename T,
typename E = _SAFEINT_DEFAULT_ERROR_POLICY >
430 template <
typename U >
437 template <
typename U >
449 template <
typename U >
466 template <
typename U >
507 operator __int16()
const
514 operator unsigned __int16()
const
516 unsigned __int16 val;
521 operator __int32()
const
528 operator unsigned __int32()
const
530 unsigned __int32 val;
551 operator __int64()
const
558 operator unsigned __int64()
const
560 unsigned __int64 val;
565 #ifdef _NATIVE_WCHAR_T_DEFINED
568 unsigned __int16 val;
608 E::SafeIntOnOverflow();
619 E::SafeIntOnOverflow();
635 E::SafeIntOnOverflow();
647 E::SafeIntOnOverflow();
697 template <
typename U >
713 template <
typename U >
720 template <
typename U >
728 template <
typename U >
750 template <
typename U >
757 template <
typename U >
765 template <
typename U >
809 template <
typename U >
824 template <
typename U >
831 template <
typename U >
839 template <
typename U >
861 template <
typename U >
868 template <
typename U >
880 template <
typename U >
886 bool operator <( SafeInt< T, E > rhs )
const throw()
888 return m_int < (T)rhs;
892 template <
typename U >
900 return m_int >= (T)rhs;
904 template <
typename U >
912 return m_int > (T)rhs;
916 template <
typename U >
922 bool operator <=( SafeInt< T, E > rhs )
const throw()
924 return m_int <= (T)rhs;
928 template <
typename U >
937 return (
m_int == 0 ?
false :
true ) == rhs;
943 template <
typename U >
951 return (
m_int == 0 ?
false :
true ) != b;
964 template <
typename U >
973 template <
typename U >
984 template <
typename U >
994 template <
typename U >
1005 template <
typename U >
1014 template <
typename U >
1024 template <
typename U >
1034 template <
typename U >
1054 template <
typename U >
1079 template <
typename U >
1086 template <
typename U >
1099 template <
typename U >
1116 template <
typename U >
1123 template <
typename U >
1136 template <
typename U >
1149 template <
typename U >
1156 template <
typename U >
1173 return tmp > upper ? upper : tmp;
1183 template <
int bits >
1199 const T AlignValue = ( (T)1 << bits ) - 1;
1201 m_int = (
m_int + AlignValue ) & ~AlignValue;
1204 E::SafeIntOnOverflow();
1222 template <
typename T,
typename U,
typename E >
1223 bool operator <( U lhs, SafeInt< T, E > rhs )
throw()
1228 template <
typename T,
typename U,
typename E >
1235 template <
typename T,
typename U,
typename E >
1241 template <
typename T,
typename U,
typename E >
1248 template <
typename T,
typename U,
typename E >
1254 template <
typename T,
typename U,
typename E >
1261 template <
typename T,
typename U,
typename E >
1262 bool operator <=( U lhs, SafeInt< T, E > rhs )
throw()
1267 template <
typename T,
typename U,
typename E >
1275 template <
typename T,
typename E >
1278 return lhs == ( (T)rhs == 0 ?
false :
true );
1281 template <
typename T,
typename U,
typename E >
1287 template <
typename T,
typename U,
typename E >
1294 template <
typename T,
typename U,
typename E >
1300 template <
typename T,
typename E >
1303 return ( (T)rhs == 0 ?
false :
true ) != lhs;
1306 template <
typename T,
typename U,
typename E >
1313 template <
typename T,
typename U,
typename E >
1322 #pragma warning(suppress:4127 6326)
1333 E::SafeIntOnDivZero();
1340 template <
typename T,
typename U,
typename E >
1351 #pragma warning(push)
1352 #pragma warning(disable: 4127 4146 4307 4310 6326)
1362 if(
sizeof( U ) >= 4 &&
sizeof( T ) <=
sizeof( U ) )
1368 if(
sizeof(T) == 4 )
1369 tmp = lhs/(U)(
unsigned __int32)( -(T)rhs );
1371 tmp = lhs/(U)( -(T)rhs );
1383 E::SafeIntOnOverflow();
1389 E::SafeIntOnDivZero();
1399 if(
sizeof( U ) <
sizeof( T ) )
1405 E::SafeIntOnOverflow();
1413 #pragma warning(pop)
1417 template <
typename T,
typename U,
typename E >
1426 template <
typename T,
typename U,
typename E >
1438 template <
typename T,
typename U,
typename E >
1447 template <
typename T,
typename U,
typename E >
1456 template <
typename T,
typename U,
typename E >
1465 template <
typename T,
typename U,
typename E >
1474 template <
typename T,
typename U,
typename E >
1483 template <
typename T,
typename U,
typename E >
1490 template <
typename T,
typename U,
typename E >
1497 template <
typename T,
typename U,
typename E >
1504 template <
typename T,
typename U,
typename E >
1505 T& operator <<=( T& lhs, SafeInt< U, E > rhs )
throw()
1511 template <
typename T,
typename U,
typename E >
1522 template <
typename T,
typename U,
typename E >
1535 template <
typename T,
typename U,
typename E >
1545 template <
typename T,
typename U,
typename E >
1552 template <
typename T,
typename U,
typename E >
1559 template <
typename T,
typename U,
typename E >
1566 template <
typename T,
typename U,
typename E >
1573 template <
typename T,
typename U,
typename E >
1580 template <
typename T,
typename U,
typename E >
1587 template <
typename T,
typename U,
typename E >
1588 T*& operator <<=( T* lhs, SafeInt< U, E > rhs )
1594 template <
typename T,
typename U,
typename E >
1605 template <
typename T,
typename U,
typename E >
1615 template <
typename T,
typename U,
typename E >
1629 template <
typename T,
typename U,
typename E >
1636 template <
typename T,
typename U,
typename E >
1643 template <
typename T,
typename U,
typename E >
const SafeInt< T, E > & Align()
Definition: safeint.h:1184
SafeIntException()
Definition: safeint.h:283
const T & Ref() const
Definition: safeint.h:580
const T * Ptr() const
Definition: safeint.h:579
T & operator^=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1491
T & operator/=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1466
SafeInt()
Definition: safeint.h:407
SafeInt< T, E > & operator/=(SafeInt< T, E > i)
Definition: safeint.h:781
bool operator>=(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1249
SafeInt< T, E > operator&(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1630
Definition: safeint_internal.h:780
static __declspec(noreturn) void SafeIntOnOverflow()
Definition: safeint.h:308
Definition: safeint_internal.h:585
bool operator<(U rhs) const
Definition: safeint.h:881
SafeInt< T, E > operator>>(U bits) const
Definition: safeint.h:1006
SafeInt(bool b)
Definition: safeint.h:424
Definition: safeint.h:264
bool SafeEquals(const T t, const U u)
Definition: safeint.h:333
SafeInt< T, E > & operator-=(SafeInt< T, E > rhs)
Definition: safeint.h:855
static __declspec(noreturn) void SafeIntOnOverflow()
Definition: safeint.h:293
Definition: safeint.h:255
bool operator>(U rhs) const
Definition: safeint.h:905
static __declspec(noreturn) void SafeIntOnDivZero()
Definition: safeint.h:299
SafeInt< T, E > & operator*=(SafeInt< T, E > rhs)
Definition: safeint.h:744
Definition: safeint_internal.h:531
bool SafeLessThanEquals(const T t, const U u)
Definition: safeint.h:363
const SafeInt< T, E > & Align16()
Definition: safeint.h:1213
_In_ long
Definition: corecrt_wstdlib.h:88
Definition: safeint.h:404
bool operator!=(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1295
T * Ptr()
Definition: safeint.h:578
SafeInt< T, E > operator~() const
Definition: safeint.h:653
Definition: safeint_internal.h:479
bool operator>=(U rhs) const
Definition: safeint.h:893
Definition: safeint_internal.h:57
bool SafeGreaterThan(const T t, const U u)
Definition: safeint.h:345
bool SafeCast(const T From, U &To)
Definition: safeint.h:326
bool operator!=(U rhs) const
Definition: safeint.h:944
bool SafeLessThan(const T t, const U u)
Definition: safeint.h:357
SafeInt< T, E > operator%(U rhs) const
Definition: safeint.h:698
bool SafeNotEquals(const T t, const U u)
Definition: safeint.h:339
Definition: safeint_internal.h:31
int ptrdiff_t
Definition: vcruntime.h:199
SafeInt< T, E > Max(SafeInt< T, E > test, SafeInt< T, E > upper=SafeInt< T, E >(details::IntTraits< T >::maxInt)) const
Definition: safeint.h:1170
T & operator+=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1439
SafeInt(const T &i)
Definition: safeint.h:416
SafeInt(const SafeInt< U, E > &u)
Definition: safeint.h:431
Definition: safeint.h:280
SafeInt< T, E > operator-(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1427
SafeInt< T, E > operator/(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1349
T & operator>>=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1512
bool operator<=(U rhs) const
Definition: safeint.h:917
bool SafeGreaterThanEquals(const T t, const U u)
Definition: safeint.h:351
#define _CRT_SECURE_INVALID_PARAMETER(expr)
Definition: corecrt.h:274
const SafeInt< T, E > & Align64()
Definition: safeint.h:1215
T & operator&=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1484
unsigned int uintptr_t
Definition: vadefs.h:30
const SafeInt< T, E > & Align2()
Definition: safeint.h:1210
bool operator==(U rhs) const
Definition: safeint.h:929
SafeInt< T, E > operator|(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1644
int i[4]
Definition: dvec.h:68
SafeInt< T, E > & operator^=(SafeInt< T, E > rhs)
Definition: safeint.h:1110
Definition: safeint.h:265
T & operator*=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1457
bool SafeMultiply(T t, U u, T &result)
Definition: safeint.h:375
SafeInt< T, E > operator-() const
Definition: safeint.h:591
#define _SAFEINT_EXCEPTION_ASSERT()
Definition: safeint.h:237
Definition: safeint_internal.h:2768
SafeInt< T, E > operator+(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1418
Definition: safeint.h:306
#define bool
Definition: stdbool.h:15
SafeInt< T, E > & operator>>=(U bits)
Definition: safeint.h:1025
Definition: safeint_internal.h:104
SafeInt< T, E > operator*(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1341
SafeInt< T, E > operator&(SafeInt< T, E > rhs) const
Definition: safeint.h:1049
SafeIntError m_code
Definition: safeint.h:288
SafeInt< T, E > operator/(U rhs) const
Definition: safeint.h:766
bool operator>(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1236
SafeInt< T, E > & operator=(const U &rhs)
Definition: safeint.h:450
unsigned char
Definition: mbstring.h:107
_CRT_BEGIN_C_HEADER typedef void(__CRTDECL *terminate_handler)()
Definition: safeint_internal.h:1515
SafeInt< T, E > operator<<(U bits) const
Definition: safeint.h:965
T & operator%=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1475
T & operator|=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1498
SafeInt< T, E > & operator+=(SafeInt< T, E > rhs)
Definition: safeint.h:818
const SafeInt< T, E > & Align32()
Definition: safeint.h:1214
Definition: safeint_internal.h:1531
SafeIntError
Definition: safeint.h:261
SafeInt< T, E > & operator|=(SafeInt< T, E > rhs)
Definition: safeint.h:1143
SafeInt< T, E > operator^(SafeInt< T, E > rhs) const
Definition: safeint.h:1094
Definition: safeint_internal.h:1734
Definition: safeint_internal.h:93
Definition: safeint.h:263
bool SafeSubtract(T t, U u, T &result)
Definition: safeint.h:396
unsigned short wchar_t
Definition: sourceannotations.h:25
SafeInt< U, E > operator>>(U lhs, SafeInt< T, E > bits)
Definition: safeint.h:1616
Definition: safeint.h:291
Definition: safeint_internal.h:2809
SafeIntException(SafeIntError code)
Definition: safeint.h:284
Definition: safeint_internal.h:33
SafeInt(const U &i)
Definition: safeint.h:438
T m_int
Definition: safeint.h:1218
SafeInt< T, E > operator%(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1314
const SafeInt< T, E > & Align4()
Definition: safeint.h:1211
SafeInt< T, E > & operator++()
Definition: safeint.h:601
bool SafeDivide(T t, U u, T &result)
Definition: safeint.h:382
float floor(float _X) __GPU_ONLY
Calculates the floor of the argument
Definition: amp_math.h:527
const SafeInt< T, E > & operator+() const
Definition: safeint.h:588
SafeInt< T, E > Min(SafeInt< T, E > test, SafeInt< T, E > floor=SafeInt< T, E >(details::IntTraits< T >::minInt)) const
Definition: safeint.h:1164
SafeInt< T, E > operator|(SafeInt< T, E > rhs) const
Definition: safeint.h:1131
Definition: safeint_internal.h:331
SafeInt< T, E > & operator<<=(U bits)
Definition: safeint.h:985
void Swap(SafeInt< T, E > &with)
Definition: safeint.h:1176
Definition: safeint_internal.h:248
bool operator==(bool lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1276
Definition: safeint_internal.h:2179
bool operator!() const
Definition: safeint.h:583
SafeInt< T, E > & operator&=(SafeInt< T, E > rhs)
Definition: safeint.h:1073
SafeInt< T, E > operator*(U rhs) const
Definition: safeint.h:729
Definition: safeint_internal.h:1508
bool SafeAdd(T t, U u, T &result)
Definition: safeint.h:389
#define _SAFEINT_SHIFT_ASSERT(x)
Definition: safeint.h:229
SafeInt< T, E > operator^(U lhs, SafeInt< T, E > rhs)
Definition: safeint.h:1637
Definition: safeint_internal.h:2850
bool SafeModulus(const T &t, const U &u, T &result)
Definition: safeint.h:369
static __declspec(noreturn) void SafeIntOnDivZero()
Definition: safeint.h:314
T & operator-=(T &lhs, SafeInt< U, E > rhs)
Definition: safeint.h:1448
SafeInt< T, E > & operator%=(U rhs)
Definition: safeint.h:714
SafeInt< T, E > & operator--()
Definition: safeint.h:612
const SafeInt< T, E > & Align8()
Definition: safeint.h:1212