mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
Merge branch 'revgraphics'
Conflicts: src/framework/CMakeLists.txt src/framework/application.cpp src/framework/graphics/graphics.cpp
This commit is contained in:
69
src/framework/util/databuffer.h
Normal file
69
src/framework/util/databuffer.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef DATABUFFER_H
|
||||
#define DATABUFFER_H
|
||||
|
||||
template<class T>
|
||||
class DataBuffer
|
||||
{
|
||||
public:
|
||||
DataBuffer(int res = 64) {
|
||||
m_capacity = res;
|
||||
m_buffer = new T[m_capacity];
|
||||
m_size = 0;
|
||||
}
|
||||
~DataBuffer() { delete[] m_buffer; }
|
||||
|
||||
inline void reset() { m_size = 0; }
|
||||
inline bool isEmpty() const { return m_size == 0; }
|
||||
|
||||
inline int size() const { return m_size; }
|
||||
inline T *data() const { return m_buffer; }
|
||||
|
||||
inline const T& at(int i) const { return m_buffer[i]; }
|
||||
inline const T& last() const { return m_buffer[m_size-1]; }
|
||||
inline const T& first() const { return m_buffer[0]; }
|
||||
inline const T& operator[](int i) const { return m_buffer[i]; }
|
||||
inline T& operator[](int i) { return m_buffer[i]; }
|
||||
|
||||
inline void add(const T &t) {
|
||||
if(m_size >= m_capacity) {
|
||||
m_capacity *= 2;
|
||||
T *buffer = new T[m_capacity];
|
||||
for(int i=0;i<m_size;++i)
|
||||
buffer[i] = m_buffer[i];
|
||||
delete[] m_buffer;
|
||||
m_buffer = buffer;
|
||||
}
|
||||
m_buffer[m_size++] = t;
|
||||
}
|
||||
|
||||
inline DataBuffer &operator<<(const T &t) { add(t); return *this; }
|
||||
|
||||
private:
|
||||
int m_size;
|
||||
int m_capacity;
|
||||
T *m_buffer;
|
||||
};
|
||||
|
||||
#endif
|
@@ -78,8 +78,8 @@ public:
|
||||
void setBottomLeft(const TPoint<T> &p) { x1 = p.x; y2 = p.y; }
|
||||
void setWidth(T width) { x2 = x1 + width - 1; }
|
||||
void setHeight(T height) { y2 = y1 + height- 1; }
|
||||
void setSize(T width, T height) { x2 = x1 + width - 1; y2 = y1 + height - 1; }
|
||||
void setSize(const TSize<T>& size) { x2 = x1 + size.width() - 1; y2 = y1 + size.height() - 1; }
|
||||
void resize(T width, T height) { x2 = x1 + width - 1; y2 = y1 + height - 1; }
|
||||
void resize(const TSize<T>& size) { x2 = x1 + size.width() - 1; y2 = y1 + size.height() - 1; }
|
||||
void setRect(T x, T y, T width, T height) { x1 = x; y1 = y; x2 = (x + width - 1); y2 = (y + height - 1); }
|
||||
void setCoords(int left, int top, int right, int bottom) { x1 = left; y1 = top; x2 = right; y2 = bottom; }
|
||||
|
||||
|
@@ -43,7 +43,7 @@ public:
|
||||
int width() const { return wd; }
|
||||
int height() const { return ht; }
|
||||
|
||||
void setSize(T w, T h) { wd = w; ht = h; }
|
||||
void resize(T w, T h) { wd = w; ht = h; }
|
||||
void setWidth(T w) { wd = w; }
|
||||
void setHeight(T h) { ht = h; }
|
||||
|
||||
@@ -115,7 +115,7 @@ std::istream& operator>>(std::istream& in, TSize<T>& size)
|
||||
{
|
||||
T w, h;
|
||||
in >> w >> h;
|
||||
size.setSize(w, h);
|
||||
size.resize(w, h);
|
||||
return in;
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,8 @@
|
||||
#include <sstream>
|
||||
#include <exception>
|
||||
#include <cxxabi.h>
|
||||
#include <vector>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "types.h"
|
||||
#include "exception.h"
|
||||
|
||||
@@ -258,6 +260,16 @@ inline std::string ip2str(uint32 ip) {
|
||||
return std::string(host);
|
||||
}
|
||||
|
||||
template<typename T = std::string>
|
||||
std::vector<T> split(const std::string& str, const std::string& separators = " ") {
|
||||
std::vector<std::string> splitted;
|
||||
boost::split(splitted, str, boost::is_any_of(std::string(separators)));
|
||||
std::vector<T> results(splitted.size());
|
||||
for(uint i=0;i<splitted.size();++i)
|
||||
results[i] = Fw::safeCast<T>(splitted[i]);
|
||||
return results;
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
void throwException(const T&... args) {
|
||||
throw Exception(Fw::mkstr(args...));
|
||||
|
Reference in New Issue
Block a user