Inline functions had better have internal linkages.

This also removes useless inline specifiers.
This commit is contained in:
Tsuda Kageyu 2016-02-15 20:53:27 +09:00
parent 455e827e1e
commit 46eacaeba4
12 changed files with 263 additions and 253 deletions

View File

@ -50,7 +50,7 @@ namespace
bool unicodeStrings = true;
bool stringManagementEnabled = true;
inline char *stringToCharArray(const String &s)
char *stringToCharArray(const String &s)
{
const std::string str = s.to8Bit(unicodeStrings);
@ -65,7 +65,7 @@ namespace
#endif
}
inline String charArrayToString(const char *s)
String charArrayToString(const char *s)
{
return String(s, unicodeStrings ? String::UTF8 : String::Latin1);
}

View File

@ -133,7 +133,7 @@ unsigned int APE::Properties::sampleFrames() const
namespace
{
inline int headerVersion(const ByteVector &header)
int headerVersion(const ByteVector &header)
{
if(header.size() < 6 || !header.startsWith("MAC "))
return -1;

View File

@ -47,7 +47,7 @@ using namespace APE;
namespace
{
inline bool isKeyValid(const char *key, size_t length)
bool isKeyValid(const char *key, size_t length)
{
const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", 0 };

View File

@ -34,65 +34,68 @@ namespace TagLib
{
namespace ASF
{
inline unsigned short readWORD(File *file, bool *ok = 0)
namespace
{
const ByteVector v = file->readBlock(2);
if(v.size() != 2) {
if(ok) *ok = false;
return 0;
}
if(ok) *ok = true;
return v.toUShort(false);
}
inline unsigned int readDWORD(File *file, bool *ok = 0)
{
const ByteVector v = file->readBlock(4);
if(v.size() != 4) {
if(ok) *ok = false;
return 0;
}
if(ok) *ok = true;
return v.toUInt(false);
}
inline long long readQWORD(File *file, bool *ok = 0)
{
const ByteVector v = file->readBlock(8);
if(v.size() != 8) {
if(ok) *ok = false;
return 0;
}
if(ok) *ok = true;
return v.toLongLong(false);
}
inline String readString(File *file, int length)
{
ByteVector data = file->readBlock(length);
unsigned int size = data.size();
while (size >= 2) {
if(data[size - 1] != '\0' || data[size - 2] != '\0') {
break;
inline unsigned short readWORD(File *file, bool *ok = 0)
{
const ByteVector v = file->readBlock(2);
if(v.size() != 2) {
if(ok) *ok = false;
return 0;
}
size -= 2;
if(ok) *ok = true;
return v.toUShort(false);
}
if(size != data.size()) {
data.resize(size);
}
return String(data, String::UTF16LE);
}
inline ByteVector renderString(const String &str, bool includeLength = false)
{
ByteVector data = str.data(String::UTF16LE) + ByteVector::fromShort(0, false);
if(includeLength) {
data = ByteVector::fromShort(data.size(), false) + data;
inline unsigned int readDWORD(File *file, bool *ok = 0)
{
const ByteVector v = file->readBlock(4);
if(v.size() != 4) {
if(ok) *ok = false;
return 0;
}
if(ok) *ok = true;
return v.toUInt(false);
}
return data;
}
inline long long readQWORD(File *file, bool *ok = 0)
{
const ByteVector v = file->readBlock(8);
if(v.size() != 8) {
if(ok) *ok = false;
return 0;
}
if(ok) *ok = true;
return v.toLongLong(false);
}
inline String readString(File *file, int length)
{
ByteVector data = file->readBlock(length);
unsigned int size = data.size();
while (size >= 2) {
if(data[size - 1] != '\0' || data[size - 2] != '\0') {
break;
}
size -= 2;
}
if(size != data.size()) {
data.resize(size);
}
return String(data, String::UTF16LE);
}
inline ByteVector renderString(const String &str, bool includeLength = false)
{
ByteVector data = str.data(String::UTF16LE) + ByteVector::fromShort(0, false);
if(includeLength) {
data = ByteVector::fromShort(data.size(), false) + data;
}
return data;
}
}
}
}

View File

@ -62,42 +62,42 @@ namespace
// Templatized internal functions. T should be String or IOStream*.
template <typename T>
inline FileName toFileName(T arg)
FileName toFileName(T arg)
{
debug("FileRef::toFileName<T>(): This version should never be called.");
return FileName(L"");
}
template <>
inline FileName toFileName<IOStream *>(IOStream *arg)
FileName toFileName<IOStream *>(IOStream *arg)
{
return arg->name();
}
template <>
inline FileName toFileName<FileName>(FileName arg)
FileName toFileName<FileName>(FileName arg)
{
return arg;
}
template <typename T>
inline File *resolveFileType(T arg, bool readProperties,
AudioProperties::ReadStyle style)
File *resolveFileType(T arg, bool readProperties,
AudioProperties::ReadStyle style)
{
debug("FileRef::resolveFileType<T>(): This version should never be called.");
return 0;
}
template <>
inline File *resolveFileType<IOStream *>(IOStream *arg, bool readProperties,
AudioProperties::ReadStyle style)
File *resolveFileType<IOStream *>(IOStream *arg, bool readProperties,
AudioProperties::ReadStyle style)
{
return 0;
}
template <>
inline File *resolveFileType<FileName>(FileName arg, bool readProperties,
AudioProperties::ReadStyle style)
File *resolveFileType<FileName>(FileName arg, bool readProperties,
AudioProperties::ReadStyle style)
{
ResolverList::ConstIterator it = fileTypeResolvers.begin();
for(; it != fileTypeResolvers.end(); ++it) {

View File

@ -34,7 +34,7 @@ using namespace TagLib;
namespace
{
inline bool checkValid(const MP4::AtomList &list)
bool checkValid(const MP4::AtomList &list)
{
for(MP4::AtomList::ConstIterator it = list.begin(); it != list.end(); ++it) {

View File

@ -34,25 +34,27 @@ namespace TagLib
{
namespace MPEG
{
/*!
* MPEG frames can be recognized by the bit pattern 11111111 111, so the
* first byte is easy to check for, however checking to see if the second byte
* starts with \e 111 is a bit more tricky, hence these functions.
*/
inline bool firstSyncByte(unsigned char byte)
namespace
{
return (byte == 0xFF);
/*!
* MPEG frames can be recognized by the bit pattern 11111111 111, so the
* first byte is easy to check for, however checking to see if the second byte
* starts with \e 111 is a bit more tricky, hence these functions.
*/
inline bool firstSyncByte(unsigned char byte)
{
return (byte == 0xFF);
}
inline bool secondSynchByte(unsigned char byte)
{
// 0xFF is possible in theory, but it's very unlikely be a header.
return (byte != 0xFF && ((byte & 0xE0) == 0xE0));
}
}
inline bool secondSynchByte(unsigned char byte)
{
// 0xFF is possible in theory, but it's very unlikely be a header.
return (byte != 0xFF && ((byte & 0xE0) == 0xE0));
}
}
}

View File

@ -37,7 +37,7 @@ using namespace TagLib;
namespace
{
// Returns the first packet index of the right next page to the given one.
inline unsigned int nextPacketIndex(const Ogg::Page *page)
unsigned int nextPacketIndex(const Ogg::Page *page)
{
if(page->header()->lastPacketCompleted())
return page->firstPacketIndex() + page->packetCount();

View File

@ -34,18 +34,23 @@ namespace TagLib
{
namespace RIFF
{
inline bool isValidChunkName(const ByteVector &name)
namespace
{
if(name.size() != 4)
return false;
for(ByteVector::ConstIterator it = name.begin(); it != name.end(); ++it) {
const int c = static_cast<unsigned char>(*it);
if(c < 32 || 127 < c)
inline bool isValidChunkName(const ByteVector &name)
{
if(name.size() != 4)
return false;
for(ByteVector::ConstIterator it = name.begin(); it != name.end(); ++it) {
const int c = static_cast<unsigned char>(*it);
if(c < 32 || 127 < c)
return false;
}
return true;
}
return true;
}
}
}

View File

@ -47,7 +47,7 @@ namespace
const FileHandle InvalidFileHandle = INVALID_HANDLE_VALUE;
inline FileHandle openFile(const FileName &path, bool readOnly)
FileHandle openFile(const FileName &path, bool readOnly)
{
const DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
@ -59,12 +59,12 @@ namespace
return InvalidFileHandle;
}
inline void closeFile(FileHandle file)
void closeFile(FileHandle file)
{
CloseHandle(file);
}
inline size_t readFile(FileHandle file, ByteVector &buffer)
size_t readFile(FileHandle file, ByteVector &buffer)
{
DWORD length;
if(ReadFile(file, buffer.data(), static_cast<DWORD>(buffer.size()), &length, NULL))
@ -73,7 +73,7 @@ namespace
return 0;
}
inline size_t writeFile(FileHandle file, const ByteVector &buffer)
size_t writeFile(FileHandle file, const ByteVector &buffer)
{
DWORD length;
if(WriteFile(file, buffer.data(), static_cast<DWORD>(buffer.size()), &length, NULL))
@ -94,22 +94,22 @@ namespace
const FileHandle InvalidFileHandle = 0;
inline FileHandle openFile(const FileName &path, bool readOnly)
FileHandle openFile(const FileName &path, bool readOnly)
{
return fopen(path, readOnly ? "rb" : "rb+");
}
inline void closeFile(FileHandle file)
void closeFile(FileHandle file)
{
fclose(file);
}
inline size_t readFile(FileHandle file, ByteVector &buffer)
size_t readFile(FileHandle file, ByteVector &buffer)
{
return fread(buffer.data(), sizeof(char), buffer.size(), file);
}
inline size_t writeFile(FileHandle file, const ByteVector &buffer)
size_t writeFile(FileHandle file, const ByteVector &buffer)
{
return fwrite(buffer.data(), sizeof(char), buffer.size(), file);
}

View File

@ -29,12 +29,6 @@
# include <config.h>
#endif
#include "tstring.h"
#include "tdebug.h"
#include "tstringlist.h"
#include "trefcounter.h"
#include "tutils.h"
#include <iostream>
#include <cerrno>
#include <climits>
@ -47,12 +41,17 @@
# include "unicode.h"
#endif
#include <tstring.h>
#include <tdebug.h>
#include <tstringlist.h>
#include <trefcounter.h>
#include <tutils.h>
namespace
{
using namespace TagLib;
inline size_t UTF16toUTF8(
const wchar_t *src, size_t srcLength, char *dst, size_t dstLength)
size_t UTF16toUTF8(const wchar_t *src, size_t srcLength, char *dst, size_t dstLength)
{
size_t len = 0;
@ -84,8 +83,7 @@ namespace
return len;
}
inline size_t UTF8toUTF16(
const char *src, size_t srcLength, wchar_t *dst, size_t dstLength)
size_t UTF8toUTF16(const char *src, size_t srcLength, wchar_t *dst, size_t dstLength)
{
size_t len = 0;
@ -118,7 +116,7 @@ namespace
}
// Returns the native format of std::wstring.
inline String::Type wcharByteOrder()
String::Type wcharByteOrder()
{
if(Utils::systemByteOrder() == Utils::LittleEndian)
return String::UTF16LE;
@ -128,7 +126,7 @@ namespace
// Converts a Latin-1 string into UTF-16(without BOM/CPU byte order)
// and copies it to the internal buffer.
inline void copyFromLatin1(std::wstring &data, const char *s, size_t length)
void copyFromLatin1(std::wstring &data, const char *s, size_t length)
{
data.resize(length);
@ -138,7 +136,7 @@ namespace
// Converts a UTF-8 string into UTF-16(without BOM/CPU byte order)
// and copies it to the internal buffer.
inline void copyFromUTF8(std::wstring &data, const char *s, size_t length)
void copyFromUTF8(std::wstring &data, const char *s, size_t length)
{
data.resize(length);
@ -150,7 +148,7 @@ namespace
// Converts a UTF-16 (with BOM), UTF-16LE or UTF16-BE string into
// UTF-16(without BOM/CPU byte order) and copies it to the internal buffer.
inline void copyFromUTF16(std::wstring &data, const wchar_t *s, size_t length, String::Type t)
void copyFromUTF16(std::wstring &data, const wchar_t *s, size_t length, String::Type t)
{
bool swap;
if(t == String::UTF16) {
@ -184,7 +182,7 @@ namespace
// Converts a UTF-16 (with BOM), UTF-16LE or UTF16-BE string into
// UTF-16(without BOM/CPU byte order) and copies it to the internal buffer.
inline void copyFromUTF16(std::wstring &data, const char *s, size_t length, String::Type t)
void copyFromUTF16(std::wstring &data, const char *s, size_t length, String::Type t)
{
bool swap;
if(t == String::UTF16) {

View File

@ -55,235 +55,237 @@ namespace TagLib
{
namespace Utils
{
/*!
* Reverses the order of bytes in an 16-bit integer.
*/
inline unsigned short byteSwap(unsigned short x)
namespace
{
/*!
* Reverses the order of bytes in an 16-bit integer.
*/
inline unsigned short byteSwap(unsigned short x)
{
#if defined(HAVE_BOOST_BYTESWAP)
return boost::endian::endian_reverse(x);
return boost::endian::endian_reverse(x);
#elif defined(HAVE_GCC_BYTESWAP)
return __builtin_bswap16(x);
return __builtin_bswap16(x);
#elif defined(HAVE_MSC_BYTESWAP)
return _byteswap_ushort(x);
return _byteswap_ushort(x);
#elif defined(HAVE_GLIBC_BYTESWAP)
return __bswap_16(x);
return __bswap_16(x);
#elif defined(HAVE_MAC_BYTESWAP)
return OSSwapInt16(x);
return OSSwapInt16(x);
#elif defined(HAVE_OPENBSD_BYTESWAP)
return swap16(x);
return swap16(x);
#else
return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
#endif
}
}
/*!
* Reverses the order of bytes in an 32-bit integer.
*/
inline unsigned int byteSwap(unsigned int x)
{
/*!
* Reverses the order of bytes in an 32-bit integer.
*/
inline unsigned int byteSwap(unsigned int x)
{
#if defined(HAVE_BOOST_BYTESWAP)
return boost::endian::endian_reverse(x);
return boost::endian::endian_reverse(x);
#elif defined(HAVE_GCC_BYTESWAP)
return __builtin_bswap32(x);
return __builtin_bswap32(x);
#elif defined(HAVE_MSC_BYTESWAP)
return _byteswap_ulong(x);
return _byteswap_ulong(x);
#elif defined(HAVE_GLIBC_BYTESWAP)
return __bswap_32(x);
return __bswap_32(x);
#elif defined(HAVE_MAC_BYTESWAP)
return OSSwapInt32(x);
return OSSwapInt32(x);
#elif defined(HAVE_OPENBSD_BYTESWAP)
return swap32(x);
return swap32(x);
#else
return ((x & 0xff000000u) >> 24)
| ((x & 0x00ff0000u) >> 8)
| ((x & 0x0000ff00u) << 8)
| ((x & 0x000000ffu) << 24);
return ((x & 0xff000000u) >> 24)
| ((x & 0x00ff0000u) >> 8)
| ((x & 0x0000ff00u) << 8)
| ((x & 0x000000ffu) << 24);
#endif
}
}
/*!
* Reverses the order of bytes in an 64-bit integer.
*/
inline unsigned long long byteSwap(unsigned long long x)
{
/*!
* Reverses the order of bytes in an 64-bit integer.
*/
inline unsigned long long byteSwap(unsigned long long x)
{
#if defined(HAVE_BOOST_BYTESWAP)
return boost::endian::endian_reverse(x);
return boost::endian::endian_reverse(x);
#elif defined(HAVE_GCC_BYTESWAP)
return __builtin_bswap64(x);
return __builtin_bswap64(x);
#elif defined(HAVE_MSC_BYTESWAP)
return _byteswap_uint64(x);
return _byteswap_uint64(x);
#elif defined(HAVE_GLIBC_BYTESWAP)
return __bswap_64(x);
return __bswap_64(x);
#elif defined(HAVE_MAC_BYTESWAP)
return OSSwapInt64(x);
return OSSwapInt64(x);
#elif defined(HAVE_OPENBSD_BYTESWAP)
return swap64(x);
return swap64(x);
#else
return ((x & 0xff00000000000000ull) >> 56)
| ((x & 0x00ff000000000000ull) >> 40)
| ((x & 0x0000ff0000000000ull) >> 24)
| ((x & 0x000000ff00000000ull) >> 8)
| ((x & 0x00000000ff000000ull) << 8)
| ((x & 0x0000000000ff0000ull) << 24)
| ((x & 0x000000000000ff00ull) << 40)
| ((x & 0x00000000000000ffull) << 56);
return ((x & 0xff00000000000000ull) >> 56)
| ((x & 0x00ff000000000000ull) >> 40)
| ((x & 0x0000ff0000000000ull) >> 24)
| ((x & 0x000000ff00000000ull) >> 8)
| ((x & 0x00000000ff000000ull) << 8)
| ((x & 0x0000000000ff0000ull) << 24)
| ((x & 0x000000000000ff00ull) << 40)
| ((x & 0x00000000000000ffull) << 56);
#endif
}
}
/*!
* Returns a formatted string just like standard sprintf(), but makes use of
* safer functions such as snprintf() if available.
*/
inline String formatString(const char *format, ...)
{
// Sufficient buffer size for the current internal uses.
// Consider changing this value when you use this function.
/*!
* Returns a formatted string just like standard sprintf(), but makes use of
* safer functions such as snprintf() if available.
*/
inline String formatString(const char *format, ...)
{
// Sufficient buffer size for the current internal uses.
// Consider changing this value when you use this function.
static const size_t BufferSize = 128;
static const size_t BufferSize = 128;
va_list args;
va_start(args, format);
va_list args;
va_start(args, format);
char buf[BufferSize];
int length;
char buf[BufferSize];
int length;
#if defined(HAVE_VSNPRINTF)
length = vsnprintf(buf, BufferSize, format, args);
length = vsnprintf(buf, BufferSize, format, args);
#elif defined(HAVE_VSPRINTF_S)
length = vsprintf_s(buf, format, args);
length = vsprintf_s(buf, format, args);
#else
// The last resort. May cause a buffer overflow.
// The last resort. May cause a buffer overflow.
length = vsprintf(buf, format, args);
if(length >= BufferSize) {
debug("Utils::formatString() - Buffer overflow! Returning an empty string.");
length = -1;
}
length = vsprintf(buf, format, args);
if(length >= BufferSize) {
debug("Utils::formatString() - Buffer overflow! Returning an empty string.");
length = -1;
}
#endif
va_end(args);
va_end(args);
if(length > 0)
return String(buf);
else
return String();
}
/*!
* Returns whether the two strings s1 and s2 are equal, ignoring the case of
* the characters.
*
* We took the trouble to define this one here, since there are some
* incompatible variations of case insensitive strcmp().
*/
inline bool equalsIgnoreCase(const char *s1, const char *s2)
{
while(*s1 != '\0' && *s2 != '\0' && ::tolower(*s1) == ::tolower(*s2)) {
s1++;
s2++;
if(length > 0)
return String(buf);
else
return String();
}
return (*s1 == '\0' && *s2 == '\0');
/*!
* Returns whether the two strings s1 and s2 are equal, ignoring the case of
* the characters.
*
* We took the trouble to define this one here, since there are some
* incompatible variations of case insensitive strcmp().
*/
inline bool equalsIgnoreCase(const char *s1, const char *s2)
{
while(*s1 != '\0' && *s2 != '\0' && ::tolower(*s1) == ::tolower(*s2)) {
s1++;
s2++;
}
return (*s1 == '\0' && *s2 == '\0');
}
/*!
* The types of byte order of the running system.
*/
enum ByteOrder
{
//! Little endian systems.
LittleEndian,
//! Big endian systems.
BigEndian
};
/*!
* Returns the integer byte order of the system.
*/
inline ByteOrder systemByteOrder()
{
union {
int i;
char c;
} u;
u.i = 1;
if(u.c == 1)
return LittleEndian;
else
return BigEndian;
}
/*!
* Returns the IEEE754 byte order of the system.
*/
inline ByteOrder floatByteOrder()
{
union {
double d;
char c;
} u;
// 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;
}
}
/*!
* The types of byte order of the running system.
*/
enum ByteOrder
{
//! Little endian systems.
LittleEndian,
//! Big endian systems.
BigEndian
};
/*!
* Returns the integer byte order of the system.
*/
inline ByteOrder systemByteOrder()
{
union {
int i;
char c;
} u;
u.i = 1;
if(u.c == 1)
return LittleEndian;
else
return BigEndian;
}
/*!
* Returns the IEEE754 byte order of the system.
*/
inline ByteOrder floatByteOrder()
{
union {
double d;
char c;
} u;
// 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;
}
}
}