Merge pull request #639 from TsudaKageyu/remove-cmake-check-float

Run-time check for byte order rather than CMake check.
This commit is contained in:
Tsuda Kageyu
2015-08-07 01:17:27 +09:00
7 changed files with 23 additions and 158 deletions

View File

@ -209,7 +209,7 @@ T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignifica
template <class T>
T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst)
{
static const bool isBigEndian = (Utils::SystemByteOrder == Utils::BigEndian);
const bool isBigEndian = (Utils::systemByteOrder() == Utils::BigEndian);
const bool swap = (mostSignificantByteFirst != isBigEndian);
if(offset + sizeof(T) > v.size())
@ -228,7 +228,7 @@ T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst)
template <class T>
ByteVector fromNumber(T value, bool mostSignificantByteFirst)
{
static const bool isBigEndian = (Utils::SystemByteOrder == Utils::BigEndian);
const bool isBigEndian = (Utils::systemByteOrder() == Utils::BigEndian);
const bool swap = (mostSignificantByteFirst != isBigEndian);
if(swap)
@ -251,7 +251,7 @@ TFloat toFloat(const ByteVector &v, size_t offset)
} tmp;
::memcpy(&tmp, v.data() + offset, sizeof(TInt));
if(ENDIAN != Utils::FloatByteOrder)
if(ENDIAN != Utils::floatByteOrder())
tmp.i = Utils::byteSwap(tmp.i);
return tmp.f;
@ -266,7 +266,7 @@ ByteVector fromFloat(TFloat value)
} tmp;
tmp.f = value;
if(ENDIAN != Utils::FloatByteOrder)
if(ENDIAN != Utils::floatByteOrder())
tmp.i = Utils::byteSwap(tmp.i);
return ByteVector(reinterpret_cast<char *>(&tmp), sizeof(TInt));

View File

@ -828,7 +828,7 @@ void String::copyFromUTF16(const char *s, size_t length, Type t)
}
const String::Type String::WCharByteOrder
= (Utils::SystemByteOrder == Utils::BigEndian) ? String::UTF16BE : String::UTF16LE;
= (Utils::systemByteOrder() == Utils::BigEndian) ? String::UTF16BE : String::UTF16LE;
}

View File

@ -216,20 +216,9 @@ namespace TagLib
BigEndian
};
#ifdef SYSTEM_BYTEORDER
# if SYSTEM_BYTEORDER == 1
const ByteOrder SystemByteOrder = LittleEndian;
# else
const ByteOrder SystemByteOrder = BigEndian;
# endif
#else
/*!
* Returns the integer byte order of the system.
*/
inline ByteOrder systemByteOrder()
{
union {
@ -244,41 +233,26 @@ namespace TagLib
return BigEndian;
}
const ByteOrder SystemByteOrder = systemByteOrder();
#endif
#ifdef FLOAT_BYTEORDER
# if FLOAT_BYTEORDER == 1
const ByteOrder FloatByteOrder = LittleEndian;
# else
const ByteOrder FloatByteOrder = BigEndian;
# endif
#else
/*!
* Returns the IEEE754 byte order of the system.
*/
inline ByteOrder floatByteOrder()
{
double bin[] = {
// "*TAGLIB*" encoded as a little-endian floating-point number
(double) 3.9865557444897601e-105, (double) 0.0
};
union {
double d;
char c;
} u;
char *str = (char*)&bin[0];
if(strncmp(&str[1], "TAGLIB", 6) == 0)
return LittleEndian;
else
return BigEndian;
// 1.0 is stored in memory like 0x3FF0000000000000 in canonical form.
// So the first byte is zero if little endian.
u.d = 1.0;
if(u.c == 0)
return LittleEndian;
else
return BigEndian;
}
const ByteOrder FloatByteOrder = floatByteOrder();
#endif
}
}