From 47561d83506a8414ea44fbe6d81bc5198543d8e2 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 7 Sep 2013 13:37:35 +0900 Subject: [PATCH] Unified two equivalent enums 'Endianness' and 'ByteOrder'. --- taglib/riff/rifffile.cpp | 8 +++---- taglib/riff/rifffile.h | 6 ++--- taglib/toolkit/taglib.h | 6 +++++ taglib/toolkit/tbytevector.cpp | 40 +++++++++++++++++----------------- taglib/toolkit/tstring.cpp | 2 +- taglib/toolkit/tutils.h | 6 ----- 6 files changed, 33 insertions(+), 35 deletions(-) diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index cd18a2b0..78335690 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -50,9 +50,9 @@ public: endianness(BigEndian), size(0) { - } - Endianness endianness; + + ByteOrder endianness; ByteVector type; TagLib::uint size; ByteVector format; @@ -73,7 +73,7 @@ RIFF::File::~File() // protected members //////////////////////////////////////////////////////////////////////////////// -RIFF::File::File(FileName file, Endianness endianness) : TagLib::File(file) +RIFF::File::File(FileName file, ByteOrder endianness) : TagLib::File(file) { d = new FilePrivate; d->endianness = endianness; @@ -82,7 +82,7 @@ RIFF::File::File(FileName file, Endianness endianness) : TagLib::File(file) read(); } -RIFF::File::File(IOStream *stream, Endianness endianness) : TagLib::File(stream) +RIFF::File::File(IOStream *stream, ByteOrder endianness) : TagLib::File(stream) { d = new FilePrivate; d->endianness = endianness; diff --git a/taglib/riff/rifffile.h b/taglib/riff/rifffile.h index 9197196d..6c2a9357 100644 --- a/taglib/riff/rifffile.h +++ b/taglib/riff/rifffile.h @@ -53,10 +53,8 @@ namespace TagLib { protected: - enum Endianness { BigEndian, LittleEndian }; - - File(FileName file, Endianness endianness); - File(IOStream *stream, Endianness endianness); + File(FileName file, ByteOrder endianness); + File(IOStream *stream, ByteOrder endianness); /*! * \return The size of the main RIFF chunk. diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index b460b568..703007a2 100644 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -79,6 +79,12 @@ namespace TagLib #else typedef off_t offset_t; #endif + + enum ByteOrder + { + LittleEndian, + BigEndian + }; } /*! diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 889afaea..796cf6da 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -188,7 +188,7 @@ size_t findVector( return ByteVector::npos; } -template +template inline T toNumber(const ByteVector &v, size_t offset) { static const bool swap = (ENDIAN != Utils::SystemByteOrder); @@ -222,7 +222,7 @@ inline T toNumber(const ByteVector &v, size_t offset) } } -template +template inline ByteVector fromNumber(T value) { static const bool swap = (ENDIAN != Utils::SystemByteOrder); @@ -299,32 +299,32 @@ ByteVector ByteVector::fromCString(const char *s, size_t length) ByteVector ByteVector::fromUInt16LE(size_t value) { - return fromNumber(static_cast(value)); + return fromNumber(static_cast(value)); } ByteVector ByteVector::fromUInt16BE(size_t value) { - return fromNumber(static_cast(value)); + return fromNumber(static_cast(value)); } ByteVector ByteVector::fromUInt32LE(size_t value) { - return fromNumber(static_cast(value)); + return fromNumber(static_cast(value)); } ByteVector ByteVector::fromUInt32BE(size_t value) { - return fromNumber(static_cast(value)); + return fromNumber(static_cast(value)); } ByteVector ByteVector::fromUInt64LE(ulonglong value) { - return fromNumber(value); + return fromNumber(value); } ByteVector ByteVector::fromUInt64BE(ulonglong value) { - return fromNumber(value); + return fromNumber(value); } //////////////////////////////////////////////////////////////////////////////// @@ -647,52 +647,52 @@ TagLib::uint ByteVector::checksum() const short ByteVector::toInt16LE(size_t offset) const { - return static_cast(toNumber(*this, offset)); + return static_cast(toNumber(*this, offset)); } short ByteVector::toInt16BE(size_t offset) const { - return static_cast(toNumber(*this, offset)); + return static_cast(toNumber(*this, offset)); } ushort ByteVector::toUInt16LE(size_t offset) const { - return toNumber(*this, offset); + return toNumber(*this, offset); } ushort ByteVector::toUInt16BE(size_t offset) const { - return toNumber(*this, offset); + return toNumber(*this, offset); } uint ByteVector::toUInt24LE(size_t offset) const { - return toNumber(*this, offset); + return toNumber(*this, offset); } uint ByteVector::toUInt24BE(size_t offset) const { - return toNumber(*this, offset); + return toNumber(*this, offset); } uint ByteVector::toUInt32LE(size_t offset) const { - return toNumber(*this, offset); + return toNumber(*this, offset); } uint ByteVector::toUInt32BE(size_t offset) const { - return toNumber(*this, offset); + return toNumber(*this, offset); } long long ByteVector::toInt64LE(size_t offset) const { - return static_cast(toNumber(*this, offset)); + return static_cast(toNumber(*this, offset)); } long long ByteVector::toInt64BE(size_t offset) const { - return static_cast(toNumber(*this, offset)); + return static_cast(toNumber(*this, offset)); } float ByteVector::toFloat32BE(size_t offset) const @@ -714,7 +714,7 @@ float ByteVector::toFloat32BE(size_t offset) const } tmp; ::memcpy(&tmp, data() + offset, 4); - if(Utils::SystemByteOrder == Utils::LittleEndian) + if(Utils::SystemByteOrder == LittleEndian) tmp.i = Utils::byteSwap(tmp.i); return tmp.f; @@ -774,7 +774,7 @@ double ByteVector::toFloat64BE(size_t offset) const } tmp; ::memcpy(&tmp, data() + offset, 8); - if(Utils::SystemByteOrder == Utils::LittleEndian) + if(Utils::SystemByteOrder == LittleEndian) tmp.i = Utils::byteSwap(tmp.i); return tmp.f; diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 2887c09f..ceb6e9da 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -822,7 +822,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 == BigEndian) ? String::UTF16BE : String::UTF16LE; //////////////////////////////////////////////////////////////////////////////// // related functions diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h index 4a398d26..e6660065 100644 --- a/taglib/toolkit/tutils.h +++ b/taglib/toolkit/tutils.h @@ -145,12 +145,6 @@ namespace TagLib #endif } - enum ByteOrder - { - LittleEndian, - BigEndian - }; - #ifdef SYSTEM_BYTEORDER # if SYSTEM_BYTEORDER == 1