From: <man...@us...> - 2013-04-12 13:49:58
|
Revision: 1855 http://sourceforge.net/p/modplug/code/1855 Author: manxorist Date: 2013-04-12 13:49:50 +0000 (Fri, 12 Apr 2013) Log Message: ----------- [Ref] Remove Util::NumericTraits. Remove all global variables that made use of the compile-time values of Util::NumericTraits. Replace usages of these variables with std::numeric_limits. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/common/serialization_utils.cpp trunk/OpenMPT/common/serialization_utils.h trunk/OpenMPT/mptrack/test/test.cpp Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-04-12 13:39:35 UTC (rev 1854) +++ trunk/OpenMPT/common/misc_util.h 2013-04-12 13:49:50 UTC (rev 1855) @@ -245,20 +245,7 @@ namespace Util { - // Numeric traits provide compile time values for integer min, max limits. - template <class T> struct NumericTraits {}; - template <> struct NumericTraits<int8> {static const int8 maxValue = int8_max; static const int8 minValue = int8_min;}; - template <> struct NumericTraits<int16> {static const int16 maxValue = int16_max; static const int16 minValue = int16_min;}; - template <> struct NumericTraits<int32> {static const int32 maxValue = int32_max; static const int32 minValue = int32_min;}; - template <> struct NumericTraits<int64> {static const int64 maxValue = int64_max; static const int64 minValue = int64_min;}; - template <> struct NumericTraits<long> {static const long maxValue = LONG_MAX; static const long minValue = LONG_MIN;}; - template <> struct NumericTraits<uint8> {static const uint8 maxValue = uint8_max; static const uint8 minValue = 0;}; - template <> struct NumericTraits<uint16> {static const uint16 maxValue = uint16_max; static const uint16 minValue = 0;}; - template <> struct NumericTraits<uint32> {static const uint32 maxValue = uint32_max; static const uint32 minValue = 0;}; - template <> struct NumericTraits<uint64> {static const uint64 maxValue = uint64_max; static const uint64 minValue = 0;}; - template <> struct NumericTraits<unsigned long> {static const unsigned long maxValue = ULONG_MAX; static const unsigned long minValue = 0;}; - // Minimum of 3 values template <class T> inline const T& Min(const T& a, const T& b, const T& c) {return std::min(std::min(a, b), c);} Modified: trunk/OpenMPT/common/serialization_utils.cpp =================================================================== --- trunk/OpenMPT/common/serialization_utils.cpp 2013-04-12 13:39:35 UTC (rev 1854) +++ trunk/OpenMPT/common/serialization_utils.cpp 2013-04-12 13:49:50 UTC (rev 1855) @@ -553,7 +553,7 @@ { const Offtype nRawEntrySize = m_pOstrm->tellp() - posBeforeWrite; - if (nRawEntrySize > DataSize_max) + if (nRawEntrySize > std::numeric_limits<DataSize>::max()) { AddWriteNote(SNW_INSUFFICIENT_DATASIZETYPE); return; } DataSize nEntrySize = static_cast<DataSize>(nRawEntrySize); @@ -727,13 +727,13 @@ if (GetFlag(RwfRwHasMap)) { ReadAdaptive1248(iStrm, tempU64); - if(tempU64 > Offtype_max) + if(tempU64 > std::numeric_limits<Offtype>::max()) { AddReadNote(SNR_INSUFFICIENT_STREAM_OFFTYPE); return; } } const Offtype rawEndOfHdrData = iStrm.tellg() - m_posStart; - if (rawEndOfHdrData < 0 || rawEndOfHdrData > RposType_max) + if (rawEndOfHdrData < 0 || rawEndOfHdrData > std::numeric_limits<RposType>::max()) { AddReadNote(SNR_INSUFFICIENT_RPOSTYPE); return; } m_rposEndofHdrData = static_cast<RposType>(rawEndOfHdrData); @@ -787,7 +787,7 @@ { uint64 tempU64; ReadAdaptive1248(iStrm, tempU64); - if(tempU64 > Offtype_max) + if(tempU64 > std::numeric_limits<Offtype>::max()) { AddReadNote(SNR_INSUFFICIENT_STREAM_OFFTYPE); return; } mapData[i].rposStart = static_cast<RposType>(tempU64); } @@ -799,7 +799,7 @@ { uint64 tempU64; ReadAdaptive1248(iStrm, tempU64); - if(tempU64 > Offtype_max) + if(tempU64 > std::numeric_limits<Offtype>::max()) { AddReadNote(SNR_INSUFFICIENT_STREAM_OFFTYPE); return; } mapData[i].nSize = static_cast<DataSize>(tempU64); } Modified: trunk/OpenMPT/common/serialization_utils.h =================================================================== --- trunk/OpenMPT/common/serialization_utils.h 2013-04-12 13:39:35 UTC (rev 1854) +++ trunk/OpenMPT/common/serialization_utils.h 2013-04-12 13:49:50 UTC (rev 1855) @@ -34,19 +34,11 @@ typedef Offtype Postype; typedef std::streamsize Streamsize; -//typedef uintptr_t DataSize; // Data size type. -//typedef uintptr_t RposType; // Relative position type. -//typedef uintptr_t NumType; // Entry count type. typedef uintptr_t DataSize; // Data size type. typedef uintptr_t RposType; // Relative position type. typedef uintptr_t NumType; // Entry count type. -const DataSize DataSize_max = Util::NumericTraits<DataSize>::maxValue; -const RposType RposType_max = Util::NumericTraits<RposType>::maxValue; -const NumType NumType_max = Util::NumericTraits<NumType>::maxValue; -const DataSize invalidDatasize = DataSize_max; -const Offtype Offtype_min = Util::NumericTraits<Offtype>::minValue; -const Offtype Offtype_max = Util::NumericTraits<Offtype>::maxValue; +const DataSize invalidDatasize = DataSize(-1); typedef std::basic_string<TCHAR> String; Modified: trunk/OpenMPT/mptrack/test/test.cpp =================================================================== --- trunk/OpenMPT/mptrack/test/test.cpp 2013-04-12 13:39:35 UTC (rev 1854) +++ trunk/OpenMPT/mptrack/test/test.cpp 2013-04-12 13:49:50 UTC (rev 1855) @@ -199,11 +199,6 @@ VERIFY_EQUAL(int64_min, (std::numeric_limits<int64>::min)()); VERIFY_EQUAL(int64_max, (std::numeric_limits<int64>::max)()); VERIFY_EQUAL(uint64_max, (std::numeric_limits<uint64>::max)()); - - VERIFY_EQUAL(Util::NumericTraits<long>::minValue, (std::numeric_limits<long>::min)()); - VERIFY_EQUAL(Util::NumericTraits<long>::maxValue, (std::numeric_limits<long>::max)()); - VERIFY_EQUAL(Util::NumericTraits<unsigned long>::minValue, (std::numeric_limits<unsigned long>::min)()); - VERIFY_EQUAL(Util::NumericTraits<unsigned long>::maxValue, (std::numeric_limits<unsigned long>::max)()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |