[12062] Cleanup MaNGOS sources

This commit is contained in:
Schmoozerd 2012-07-19 22:03:32 +02:00
parent a4cbed3199
commit aeff8f9d1a
46 changed files with 1982 additions and 1864 deletions

View file

@ -35,7 +35,7 @@ class ByteBufferException
void PrintPosError() const
{
sLog.outError("Attempted to %s in ByteBuffer (pos: " SIZEFMTD " size: "SIZEFMTD") value with size: " SIZEFMTD,
(add ? "put" : "get"), pos, size, esize);
(add ? "put" : "get"), pos, size, esize);
}
private:
bool add;
@ -68,7 +68,7 @@ class ByteBuffer
}
// copy constructor
ByteBuffer(const ByteBuffer &buf): _rpos(buf._rpos), _wpos(buf._wpos), _storage(buf._storage) { }
ByteBuffer(const ByteBuffer& buf): _rpos(buf._rpos), _wpos(buf._wpos), _storage(buf._storage) { }
void clear()
{
@ -79,153 +79,153 @@ class ByteBuffer
template <typename T> void put(size_t pos,T value)
{
EndianConvert(value);
put(pos,(uint8 *)&value,sizeof(value));
put(pos,(uint8*)&value,sizeof(value));
}
ByteBuffer &operator<<(uint8 value)
ByteBuffer& operator<<(uint8 value)
{
append<uint8>(value);
return *this;
}
ByteBuffer &operator<<(uint16 value)
ByteBuffer& operator<<(uint16 value)
{
append<uint16>(value);
return *this;
}
ByteBuffer &operator<<(uint32 value)
ByteBuffer& operator<<(uint32 value)
{
append<uint32>(value);
return *this;
}
ByteBuffer &operator<<(uint64 value)
ByteBuffer& operator<<(uint64 value)
{
append<uint64>(value);
return *this;
}
// signed as in 2e complement
ByteBuffer &operator<<(int8 value)
ByteBuffer& operator<<(int8 value)
{
append<int8>(value);
return *this;
}
ByteBuffer &operator<<(int16 value)
ByteBuffer& operator<<(int16 value)
{
append<int16>(value);
return *this;
}
ByteBuffer &operator<<(int32 value)
ByteBuffer& operator<<(int32 value)
{
append<int32>(value);
return *this;
}
ByteBuffer &operator<<(int64 value)
ByteBuffer& operator<<(int64 value)
{
append<int64>(value);
return *this;
}
// floating points
ByteBuffer &operator<<(float value)
ByteBuffer& operator<<(float value)
{
append<float>(value);
return *this;
}
ByteBuffer &operator<<(double value)
ByteBuffer& operator<<(double value)
{
append<double>(value);
return *this;
}
ByteBuffer &operator<<(const std::string &value)
ByteBuffer& operator<<(const std::string& value)
{
append((uint8 const *)value.c_str(), value.length());
append((uint8 const*)value.c_str(), value.length());
append((uint8)0);
return *this;
}
ByteBuffer &operator<<(const char *str)
ByteBuffer& operator<<(const char* str)
{
append((uint8 const *)str, str ? strlen(str) : 0);
append((uint8 const*)str, str ? strlen(str) : 0);
append((uint8)0);
return *this;
}
ByteBuffer &operator>>(bool &value)
ByteBuffer& operator>>(bool& value)
{
value = read<char>() > 0 ? true : false;
return *this;
}
ByteBuffer &operator>>(uint8 &value)
ByteBuffer& operator>>(uint8& value)
{
value = read<uint8>();
return *this;
}
ByteBuffer &operator>>(uint16 &value)
ByteBuffer& operator>>(uint16& value)
{
value = read<uint16>();
return *this;
}
ByteBuffer &operator>>(uint32 &value)
ByteBuffer& operator>>(uint32& value)
{
value = read<uint32>();
return *this;
}
ByteBuffer &operator>>(uint64 &value)
ByteBuffer& operator>>(uint64& value)
{
value = read<uint64>();
return *this;
}
//signed as in 2e complement
ByteBuffer &operator>>(int8 &value)
ByteBuffer& operator>>(int8& value)
{
value = read<int8>();
return *this;
}
ByteBuffer &operator>>(int16 &value)
ByteBuffer& operator>>(int16& value)
{
value = read<int16>();
return *this;
}
ByteBuffer &operator>>(int32 &value)
ByteBuffer& operator>>(int32& value)
{
value = read<int32>();
return *this;
}
ByteBuffer &operator>>(int64 &value)
ByteBuffer& operator>>(int64& value)
{
value = read<int64>();
return *this;
}
ByteBuffer &operator>>(float &value)
ByteBuffer& operator>>(float& value)
{
value = read<float>();
return *this;
}
ByteBuffer &operator>>(double &value)
ByteBuffer& operator>>(double& value)
{
value = read<double>();
return *this;
}
ByteBuffer &operator>>(std::string& value)
ByteBuffer& operator>>(std::string& value)
{
value.clear();
while (rpos() < size()) // prevent crash at wrong string format in packet
@ -239,7 +239,7 @@ class ByteBuffer
}
template<class T>
ByteBuffer &operator>>(Unused<T> const&)
ByteBuffer& operator>>(Unused<T> const&)
{
read_skip<T>();
return *this;
@ -272,7 +272,7 @@ class ByteBuffer
void read_skip(size_t skip)
{
if(_rpos + skip > size())
if (_rpos + skip > size())
throw ByteBufferException(false, _rpos, skip, size());
_rpos += skip;
}
@ -286,16 +286,16 @@ class ByteBuffer
template <typename T> T read(size_t pos) const
{
if(pos + sizeof(T) > size())
if (pos + sizeof(T) > size())
throw ByteBufferException(false, pos, sizeof(T), size());
T val = *((T const*)&_storage[pos]);
EndianConvert(val);
return val;
}
void read(uint8 *dest, size_t len)
void read(uint8* dest, size_t len)
{
if(_rpos + len > size())
if (_rpos + len > size())
throw ByteBufferException(false, _rpos, len, size());
memcpy(dest, &_storage[_rpos], len);
_rpos += len;
@ -307,9 +307,9 @@ class ByteBuffer
uint8 guidmark = 0;
(*this) >> guidmark;
for(int i = 0; i < 8; ++i)
for (int i = 0; i < 8; ++i)
{
if(guidmark & (uint8(1) << i))
if (guidmark & (uint8(1) << i))
{
uint8 bit;
(*this) >> bit;
@ -320,7 +320,7 @@ class ByteBuffer
return guid;
}
const uint8 *contents() const { return &_storage[0]; }
const uint8* contents() const { return &_storage[0]; }
size_t size() const { return _storage.size(); }
bool empty() const { return _storage.empty(); }
@ -343,17 +343,17 @@ class ByteBuffer
append((uint8 const*)str.c_str(), str.size() + 1);
}
void append(const char *src, size_t cnt)
void append(const char* src, size_t cnt)
{
return append((const uint8 *)src, cnt);
return append((const uint8*)src, cnt);
}
template<class T> void append(const T *src, size_t cnt)
template<class T> void append(const T* src, size_t cnt)
{
return append((const uint8 *)src, cnt * sizeof(T));
return append((const uint8*)src, cnt * sizeof(T));
}
void append(const uint8 *src, size_t cnt)
void append(const uint8* src, size_t cnt)
{
if (!cnt)
return;
@ -368,7 +368,7 @@ class ByteBuffer
void append(const ByteBuffer& buffer)
{
if(buffer.wpos())
if (buffer.wpos())
append(buffer.contents(), buffer.wpos());
}
@ -402,9 +402,9 @@ class ByteBuffer
append(packGUID, size);
}
void put(size_t pos, const uint8 *src, size_t cnt)
void put(size_t pos, const uint8* src, size_t cnt)
{
if(pos + cnt > size())
if (pos + cnt > size())
throw ByteBufferException(true, pos, cnt, size());
memcpy(&_storage[pos], src, cnt);
}
@ -487,7 +487,7 @@ class ByteBuffer
template <typename T> void append(T value)
{
EndianConvert(value);
append((uint8 *)&value, sizeof(value));
append((uint8*)&value, sizeof(value));
}
protected:
@ -496,7 +496,7 @@ class ByteBuffer
};
template <typename T>
inline ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> const& v)
inline ByteBuffer& operator<<(ByteBuffer& b, std::vector<T> const& v)
{
b << (uint32)v.size();
for (typename std::vector<T>::iterator i = v.begin(); i != v.end(); ++i)
@ -507,12 +507,12 @@ inline ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> const& v)
}
template <typename T>
inline ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v)
inline ByteBuffer& operator>>(ByteBuffer& b, std::vector<T>& v)
{
uint32 vsize;
b >> vsize;
v.clear();
while(vsize--)
while (vsize--)
{
T t;
b >> t;
@ -522,7 +522,7 @@ inline ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v)
}
template <typename T>
inline ByteBuffer &operator<<(ByteBuffer &b, std::list<T> const& v)
inline ByteBuffer& operator<<(ByteBuffer& b, std::list<T> const& v)
{
b << (uint32)v.size();
for (typename std::list<T>::iterator i = v.begin(); i != v.end(); ++i)
@ -533,12 +533,12 @@ inline ByteBuffer &operator<<(ByteBuffer &b, std::list<T> const& v)
}
template <typename T>
inline ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v)
inline ByteBuffer& operator>>(ByteBuffer& b, std::list<T>& v)
{
uint32 vsize;
b >> vsize;
v.clear();
while(vsize--)
while (vsize--)
{
T t;
b >> t;
@ -548,7 +548,7 @@ inline ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v)
}
template <typename K, typename V>
inline ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m)
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)
@ -559,12 +559,12 @@ inline ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m)
}
template <typename K, typename V>
inline ByteBuffer &operator>>(ByteBuffer &b, std::map<K, V> &m)
inline ByteBuffer& operator>>(ByteBuffer& b, std::map<K, V>& m)
{
uint32 msize;
b >> msize;
m.clear();
while(msize--)
while (msize--)
{
K k;
V v;