From: Mikko Rasa Date: Wed, 1 Aug 2012 14:30:58 +0000 (+0300) Subject: Prefer inttypes.h to doing the #ifdef dance everywhere X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=95bd04e16acacde19fcfdcc722baf72b06dcdfee Prefer inttypes.h to doing the #ifdef dance everywhere --- diff --git a/source/core/hash.cpp b/source/core/hash.cpp index 26e6059..fe5e339 100644 --- a/source/core/hash.cpp +++ b/source/core/hash.cpp @@ -10,7 +10,7 @@ http://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function http://www.isthe.com/chongo/tech/comp/fnv/index.html */ -unsigned hash32(const void *data, unsigned size, unsigned bits) +UInt32 hash32(const void *data, unsigned size, unsigned bits) { if(bits==0 || bits>32) throw invalid_argument("hash32"); @@ -28,15 +28,15 @@ unsigned hash32(const void *data, unsigned size, unsigned bits) return result; } -HashValue64 hash64(const void *data, unsigned size, unsigned bits) +UInt64 hash64(const void *data, unsigned size, unsigned bits) { if(bits==0 || bits>64) throw invalid_argument("hash64"); - static const HashValue64 prime = 1099511628211ULL; - static const HashValue64 offset = 14695981039346656037ULL; + static const UInt64 prime = 1099511628211ULL; + static const UInt64 offset = 14695981039346656037ULL; - HashValue64 result = offset; + UInt64 result = offset; for(unsigned i=0; i(data)+i))*prime; diff --git a/source/core/hash.h b/source/core/hash.h index bb3de05..75aba09 100644 --- a/source/core/hash.h +++ b/source/core/hash.h @@ -2,21 +2,16 @@ #define MSP_CORE_HASH_H_ #include +#include "inttypes.h" namespace Msp { -#ifdef MSVC -typedef __uint64 HashValue64; -#else -typedef unsigned long long HashValue64; -#endif - /** Computes a 32-bit Fowler-Noll-Vo (FNV-1a) hash. The number of bits can be limited to less than 32, in which case XOR-folding is used to reduce the hash size. */ -unsigned hash32(const void *, unsigned, unsigned = 32); +UInt32 hash32(const void *, unsigned, unsigned = 32); /** Convenience function to compute a 32-bit hash of a string. @@ -28,12 +23,12 @@ inline unsigned hash32(const std::string &s, unsigned b = 32) Computes a 64-bit Fowler-Noll-Vo (FNV-1a) hash. Note that even if bits is limited to 32 or less, this does not produce the same result as hash32. */ -HashValue64 hash64(const void *, unsigned, unsigned = 64); +UInt64 hash64(const void *, unsigned, unsigned = 64); /** Convenience function to compute a 64-bit hash of a string. */ -inline HashValue64 hash64(const std::string &s, unsigned b = 64) +inline UInt64 hash64(const std::string &s, unsigned b = 64) { return hash64(s.data(), s.size(), b); } } // namespace Msp diff --git a/source/io/seekable.h b/source/io/seekable.h index 9522311..1fc3f89 100644 --- a/source/io/seekable.h +++ b/source/io/seekable.h @@ -1,6 +1,7 @@ #ifndef MSP_IO_SEEKABLE_H_ #define MSP_IO_SEEKABLE_H_ +#include #include "base.h" namespace Msp { @@ -8,11 +9,7 @@ namespace IO { class Handle; -#ifdef MSVC -typedef __int64 SeekOffset; -#else -typedef long long SeekOffset; -#endif +typedef Int64 SeekOffset; enum SeekType { diff --git a/source/strings/lexicalcast.cpp b/source/strings/lexicalcast.cpp index 782f4a8..71e346b 100644 --- a/source/strings/lexicalcast.cpp +++ b/source/strings/lexicalcast.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "format.h" #include "lexicalcast.h" @@ -20,11 +21,7 @@ struct Temporary template struct Temporary { -#ifdef WIN32 - typedef __int64 Type; -#else - typedef unsigned long long Type; -#endif + typedef UInt64 Type; }; /* Helper to avoid warnings about an unsigned type never being < 0 */ diff --git a/source/time/rawtime.h b/source/time/rawtime.h index 7652450..1af7956 100644 --- a/source/time/rawtime.h +++ b/source/time/rawtime.h @@ -1,14 +1,12 @@ #ifndef MSP_TIME_RAWTIME_H_ #define MSP_TIME_RAWTIME_H_ +#include + namespace Msp { namespace Time { -#ifdef MSVC -typedef __int64 RawTime; -#else -typedef long long RawTime; -#endif +typedef Int64 RawTime; } // namespace Time } // namespace Msp