Core: header cleanup, split realmlist, boost compatibility, cotire, remove stormlib/zlib and stormlib/bzip2 and instead use dep sources
This commit is contained in:
1 parent
7fff6c424f
commit
5ff847159c
1243 files changed
+29780
-36517
No files matched your search
@@ -17,10 +17,13 @@
|
||||
*/
|
||||
|
||||
#include "ByteBuffer.h"
|
||||
#include "Errors.h"
|
||||
#include "MessageBuffer.h"
|
||||
#include "Common.h"
|
||||
#include "Log.h"
|
||||
#include "Util.h"
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
|
||||
ByteBuffer::ByteBuffer(MessageBuffer&& buffer) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0), _storage(buffer.Move())
|
||||
{
|
||||
@@ -44,12 +47,86 @@ ByteBufferSourceException::ByteBufferSourceException(size_t pos, size_t size,
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << "Attempted to put a "
|
||||
<< (valueSize > 0 ? "NULL-pointer" : "zero-sized value")
|
||||
<< (valueSize > 0 ? "nullptr-pointer" : "zero-sized value")
|
||||
<< " in ByteBuffer (pos: " << pos << " size: " << size << ")";
|
||||
|
||||
message().assign(ss.str());
|
||||
}
|
||||
|
||||
ByteBuffer& ByteBuffer::operator>>(float& value)
|
||||
{
|
||||
value = read<float>();
|
||||
if (!std::isfinite(value))
|
||||
throw ByteBufferException();
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteBuffer& ByteBuffer::operator>>(double& value)
|
||||
{
|
||||
value = read<double>();
|
||||
if (!std::isfinite(value))
|
||||
throw ByteBufferException();
|
||||
return *this;
|
||||
}
|
||||
|
||||
uint32 ByteBuffer::ReadPackedTime()
|
||||
{
|
||||
uint32 packedDate = read<uint32>();
|
||||
tm lt = tm();
|
||||
|
||||
lt.tm_min = packedDate & 0x3F;
|
||||
lt.tm_hour = (packedDate >> 6) & 0x1F;
|
||||
//lt.tm_wday = (packedDate >> 11) & 7;
|
||||
lt.tm_mday = ((packedDate >> 14) & 0x3F) + 1;
|
||||
lt.tm_mon = (packedDate >> 20) & 0xF;
|
||||
lt.tm_year = ((packedDate >> 24) & 0x1F) + 100;
|
||||
|
||||
return uint32(mktime(<));
|
||||
}
|
||||
|
||||
void ByteBuffer::append(uint8 const* src, size_t cnt)
|
||||
{
|
||||
ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", _wpos, size());
|
||||
ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", _wpos, size());
|
||||
ASSERT(size() < 10000000);
|
||||
|
||||
FlushBits();
|
||||
|
||||
size_t const newSize = _wpos + cnt;
|
||||
if (_storage.capacity() < newSize) // custom memory allocation rules
|
||||
{
|
||||
if (newSize < 100)
|
||||
_storage.reserve(300);
|
||||
else if (newSize < 750)
|
||||
_storage.reserve(2500);
|
||||
else if (newSize < 6000)
|
||||
_storage.reserve(10000);
|
||||
else
|
||||
_storage.reserve(400000);
|
||||
}
|
||||
|
||||
if (_storage.size() < newSize)
|
||||
_storage.resize(newSize);
|
||||
std::memcpy(&_storage[_wpos], src, cnt);
|
||||
_wpos = newSize;
|
||||
}
|
||||
|
||||
void ByteBuffer::AppendPackedTime(time_t time)
|
||||
{
|
||||
tm lt;
|
||||
localtime_r(&time, <);
|
||||
append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min);
|
||||
}
|
||||
|
||||
void ByteBuffer::put(size_t pos, uint8 const* src, size_t cnt)
|
||||
{
|
||||
ASSERT(pos + cnt <= size(), "Attempted to put value with size: " SZFMTD " in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", cnt, pos, size());
|
||||
ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", pos, size());
|
||||
ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", pos, size());
|
||||
|
||||
std::memcpy(&_storage[pos], src, cnt);
|
||||
}
|
||||
|
||||
void ByteBuffer::print_storage() const
|
||||
{
|
||||
if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output
|
||||
|
||||
@@ -20,10 +20,9 @@
|
||||
#define _BYTEBUFFER_H
|
||||
|
||||
#include "Define.h"
|
||||
#include "Errors.h"
|
||||
#include "ByteConverter.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
class MessageBuffer;
|
||||
@@ -181,7 +180,8 @@ class TC_SHARED_API ByteBuffer
|
||||
append<uint8>(b ^ 1);
|
||||
}
|
||||
|
||||
template <typename T> void put(size_t pos, T value)
|
||||
template <typename T>
|
||||
void put(std::size_t pos, T value)
|
||||
{
|
||||
static_assert(std::is_fundamental<T>::value, "append(compound)");
|
||||
EndianConvert(value);
|
||||
@@ -352,21 +352,8 @@ class TC_SHARED_API ByteBuffer
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteBuffer &operator>>(float &value)
|
||||
{
|
||||
value = read<float>();
|
||||
if (!std::isfinite(value))
|
||||
throw ByteBufferException();
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteBuffer &operator>>(double &value)
|
||||
{
|
||||
value = read<double>();
|
||||
if (!std::isfinite(value))
|
||||
throw ByteBufferException();
|
||||
return *this;
|
||||
}
|
||||
ByteBuffer& operator>>(float& value);
|
||||
ByteBuffer& operator>>(double& value);
|
||||
|
||||
ByteBuffer &operator>>(std::string& value)
|
||||
{
|
||||
@@ -503,20 +490,7 @@ class TC_SHARED_API ByteBuffer
|
||||
append(str.c_str(), len);
|
||||
}
|
||||
|
||||
uint32 ReadPackedTime()
|
||||
{
|
||||
uint32 packedDate = read<uint32>();
|
||||
tm lt = tm();
|
||||
|
||||
lt.tm_min = packedDate & 0x3F;
|
||||
lt.tm_hour = (packedDate >> 6) & 0x1F;
|
||||
//lt.tm_wday = (packedDate >> 11) & 7;
|
||||
lt.tm_mday = ((packedDate >> 14) & 0x3F) + 1;
|
||||
lt.tm_mon = (packedDate >> 20) & 0xF;
|
||||
lt.tm_year = ((packedDate >> 24) & 0x1F) + 100;
|
||||
|
||||
return uint32(mktime(<));
|
||||
}
|
||||
uint32 ReadPackedTime();
|
||||
|
||||
ByteBuffer& ReadPackedTime(uint32& time)
|
||||
{
|
||||
@@ -564,36 +538,7 @@ class TC_SHARED_API ByteBuffer
|
||||
return append((const uint8 *)src, cnt * sizeof(T));
|
||||
}
|
||||
|
||||
void append(const uint8 *src, size_t cnt)
|
||||
{
|
||||
if (!cnt)
|
||||
throw ByteBufferSourceException(_wpos, size(), cnt);
|
||||
|
||||
if (!src)
|
||||
throw ByteBufferSourceException(_wpos, size(), cnt);
|
||||
|
||||
ASSERT(size() < 10000000);
|
||||
|
||||
FlushBits();
|
||||
|
||||
size_t const newSize = _wpos + cnt;
|
||||
if (_storage.capacity() < newSize) // custom memory allocation rules
|
||||
{
|
||||
if (newSize < 100)
|
||||
_storage.reserve(300);
|
||||
else if (newSize < 750)
|
||||
_storage.reserve(2500);
|
||||
else if (newSize < 6000)
|
||||
_storage.reserve(10000);
|
||||
else
|
||||
_storage.reserve(400000);
|
||||
}
|
||||
|
||||
if (_storage.size() < newSize)
|
||||
_storage.resize(newSize);
|
||||
std::memcpy(&_storage[_wpos], src, cnt);
|
||||
_wpos = newSize;
|
||||
}
|
||||
void append(uint8 const* src, size_t cnt);
|
||||
|
||||
void append(const ByteBuffer& buffer)
|
||||
{
|
||||
@@ -630,23 +575,9 @@ class TC_SHARED_API ByteBuffer
|
||||
append(packGUID, size);
|
||||
}
|
||||
|
||||
void AppendPackedTime(time_t time)
|
||||
{
|
||||
tm lt;
|
||||
localtime_r(&time, <);
|
||||
append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min);
|
||||
}
|
||||
void AppendPackedTime(time_t time);
|
||||
|
||||
void put(size_t pos, const uint8 *src, size_t cnt)
|
||||
{
|
||||
if (pos + cnt > size())
|
||||
throw ByteBufferPositionException(true, pos, cnt, size());
|
||||
|
||||
if (!src)
|
||||
throw ByteBufferSourceException(_wpos, size(), cnt);
|
||||
|
||||
std::memcpy(&_storage[pos], src, cnt);
|
||||
}
|
||||
void put(size_t pos, uint8 const* src, size_t cnt);
|
||||
|
||||
void print_storage() const;
|
||||
|
||||
@@ -660,85 +591,6 @@ class TC_SHARED_API ByteBuffer
|
||||
std::vector<uint8> _storage;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v)
|
||||
{
|
||||
b << (uint32)v.size();
|
||||
for (typename std::vector<T>::iterator i = v.begin(); i != v.end(); ++i)
|
||||
{
|
||||
b << *i;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v)
|
||||
{
|
||||
uint32 vsize;
|
||||
b >> vsize;
|
||||
v.clear();
|
||||
while (vsize--)
|
||||
{
|
||||
T t;
|
||||
b >> t;
|
||||
v.push_back(t);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v)
|
||||
{
|
||||
b << (uint32)v.size();
|
||||
for (typename std::list<T>::iterator i = v.begin(); i != v.end(); ++i)
|
||||
{
|
||||
b << *i;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v)
|
||||
{
|
||||
uint32 vsize;
|
||||
b >> vsize;
|
||||
v.clear();
|
||||
while (vsize--)
|
||||
{
|
||||
T t;
|
||||
b >> t;
|
||||
v.push_back(t);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m)
|
||||
{
|
||||
b << (uint32)m.size();
|
||||
for (typename std::map<K, V>::iterator i = m.begin(); i != m.end(); ++i)
|
||||
{
|
||||
b << i->first << i->second;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline ByteBuffer &operator>>(ByteBuffer &b, std::map<K, V> &m)
|
||||
{
|
||||
uint32 msize;
|
||||
b >> msize;
|
||||
m.clear();
|
||||
while (msize--)
|
||||
{
|
||||
K k;
|
||||
V v;
|
||||
b >> k >> v;
|
||||
m.insert(make_pair(k, v));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/// @todo Make a ByteBuffer.cpp and move all this inlining to it.
|
||||
template<> inline std::string ByteBuffer::read<std::string>()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user