mirror of
https://github.com/edubart/otclient.git
synced 2025-10-20 06:23:26 +02:00
Tidy up the source code
* Replaced push_back calls with emplace_back where applicable. * Replaced size() == 0 and size() != 0 with empty() and !empty(). * Replaced C style loops for range for loops where applicable. * Fixed mismatching arg names between function declarations and definitions. * Replaced NULL and 0 (in the context of pointers) with nullptr. * Remove unnecessary calls to string::c_str() where applicable. * Replaced deprecated C headers with proper C++ headers. * Removed unnecessary null pointer checks when deleting pointers (deleting a null pointer has no effect). * Fixed a potential memory leak in apngloader.cpp file. * Replaced unsafe strcpy with strncpy in the demangle_name function.
This commit is contained in:
@@ -38,7 +38,7 @@ void AsyncDispatcher::terminate()
|
||||
void AsyncDispatcher::spawn_thread()
|
||||
{
|
||||
m_running = true;
|
||||
m_threads.push_back(std::thread(std::bind(&AsyncDispatcher::exec_loop, this)));
|
||||
m_threads.emplace_back(std::bind(&AsyncDispatcher::exec_loop, this));
|
||||
}
|
||||
|
||||
void AsyncDispatcher::stop()
|
||||
@@ -55,7 +55,7 @@ void AsyncDispatcher::stop()
|
||||
void AsyncDispatcher::exec_loop() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
while(true) {
|
||||
while(m_tasks.size() == 0 && m_running)
|
||||
while(m_tasks.empty() && m_running)
|
||||
m_condition.wait(lock);
|
||||
|
||||
if(!m_running)
|
||||
|
@@ -74,7 +74,7 @@ void Config::clear()
|
||||
|
||||
void Config::setValue(const std::string& key, const std::string& value)
|
||||
{
|
||||
if(value == "") {
|
||||
if(value.empty()) {
|
||||
remove(key);
|
||||
return;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ void Config::setList(const std::string& key, const std::vector<std::string>& lis
|
||||
{
|
||||
remove(key);
|
||||
|
||||
if(list.size() == 0)
|
||||
if(list.empty())
|
||||
return;
|
||||
|
||||
OTMLNodePtr child = OTMLNode::create(key, true);
|
||||
|
@@ -320,7 +320,7 @@ std::string FileStream::getString()
|
||||
} else {
|
||||
if(m_pos+len > m_data.size()) {
|
||||
throwError("read failed");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
str = std::string((char*)&m_data[m_pos], len);
|
||||
|
@@ -74,8 +74,8 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
|
||||
m_outFile.flush();
|
||||
}
|
||||
|
||||
std::size_t now = std::time(NULL);
|
||||
m_logMessages.push_back(LogMessage(level, outmsg, now));
|
||||
std::size_t now = std::time(nullptr);
|
||||
m_logMessages.emplace_back(level, outmsg, now);
|
||||
if(m_logMessages.size() > MAX_LOG_HISTORY)
|
||||
m_logMessages.pop_front();
|
||||
|
||||
@@ -133,7 +133,7 @@ void Logger::setLogFile(const std::string& file)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
|
||||
m_outFile.open(stdext::utf8_to_latin1(file.c_str()).c_str(), std::ios::out | std::ios::app);
|
||||
m_outFile.open(stdext::utf8_to_latin1(file).c_str(), std::ios::out | std::ios::app);
|
||||
if(!m_outFile.is_open() || !m_outFile.good()) {
|
||||
g_logger.error(stdext::format("Unable to save log to '%s'", file));
|
||||
return;
|
||||
|
@@ -264,8 +264,8 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
|
||||
std::list<std::string> files;
|
||||
auto rc = PHYSFS_enumerateFiles(resolvePath(directoryPath).c_str());
|
||||
|
||||
for(int i = 0; rc[i] != NULL; i++)
|
||||
files.push_back(rc[i]);
|
||||
for(int i = 0; rc[i] != nullptr; i++)
|
||||
files.emplace_back(rc[i]);
|
||||
|
||||
PHYSFS_freeList(rc);
|
||||
return files;
|
||||
|
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
bool addSearchPath(const std::string& path, bool pushFront = false);
|
||||
bool removeSearchPath(const std::string& path);
|
||||
void searchAndAddPackages(const std::string& packagesDir, const std::string& packagesExt);
|
||||
void searchAndAddPackages(const std::string& packagesDir, const std::string& packageExt);
|
||||
|
||||
bool fileExists(const std::string& fileName);
|
||||
bool directoryExists(const std::string& directoryName);
|
||||
|
@@ -30,8 +30,8 @@ AnimatedTexture::AnimatedTexture(const Size& size, std::vector<ImagePtr> frames,
|
||||
if(!setupSize(size, buildMipmaps))
|
||||
return;
|
||||
|
||||
for(uint i=0;i<frames.size();++i) {
|
||||
m_frames.push_back(new Texture(frames[i], buildMipmaps, compress));
|
||||
for(const auto &frame: frames) {
|
||||
m_frames.push_back(new Texture(frame, buildMipmaps, compress));
|
||||
}
|
||||
|
||||
m_framesDelay = framesDelay;
|
||||
|
@@ -23,14 +23,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <zlib.h>
|
||||
#include "apngloader.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||
#define swap16(data) _byteswap_ushort(data)
|
||||
@@ -169,7 +171,7 @@ void unpack(z_stream& zstream, unsigned char * dst, unsigned int dst_size, unsig
|
||||
{
|
||||
unsigned int j;
|
||||
unsigned char * row = dst;
|
||||
unsigned char * prev_row = NULL;
|
||||
unsigned char * prev_row = nullptr;
|
||||
|
||||
zstream.next_out = dst;
|
||||
zstream.avail_out = dst_size;
|
||||
@@ -609,7 +611,7 @@ int load_apng(std::stringstream& file, struct apng_data *apng)
|
||||
pData=(unsigned char *)malloc(zbuf_size);
|
||||
pImg1=pOut1;
|
||||
pImg2=pOut2;
|
||||
frames_delay = NULL;
|
||||
frames_delay = nullptr;
|
||||
|
||||
/* apng decoding - begin */
|
||||
memset(pOut1, 0, outimg1);
|
||||
@@ -677,7 +679,7 @@ int load_apng(std::stringstream& file, struct apng_data *apng)
|
||||
frames = read32(file);
|
||||
if(frames_delay)
|
||||
free(frames_delay);
|
||||
frames_delay = (unsigned short*)malloc(frames*sizeof(int));
|
||||
frames_delay = (unsigned short*)malloc(frames*sizeof(unsigned short));
|
||||
loops = read32(file);
|
||||
/*crc = */read32(file);
|
||||
if (pOut1)
|
||||
@@ -871,7 +873,7 @@ void write_chunk(std::ostream& f, const char* name, unsigned char* data, unsigne
|
||||
f.write(name, 4);
|
||||
crc = crc32(crc, (const Bytef*)name, 4);
|
||||
|
||||
if(data != NULL && length > 0) {
|
||||
if(data != nullptr && length > 0) {
|
||||
f.write((char*)data, length);
|
||||
crc = crc32(crc, data, length);
|
||||
}
|
||||
@@ -955,8 +957,17 @@ void save_png(std::stringstream& f, unsigned int width, unsigned int height, int
|
||||
unsigned char* zbuf1 = (unsigned char*)malloc(zbuf_size);
|
||||
unsigned char* zbuf2 = (unsigned char*)malloc(zbuf_size);
|
||||
|
||||
if(!row_buf || !sub_row || !up_row || !avg_row || !paeth_row || !zbuf1 || !zbuf2)
|
||||
if(!row_buf || !sub_row || !up_row || !avg_row || !paeth_row || !zbuf1 || !zbuf2) {
|
||||
free(row_buf);
|
||||
free(sub_row);
|
||||
free(up_row);
|
||||
free(avg_row);
|
||||
free(paeth_row);
|
||||
free(zbuf1);
|
||||
free(zbuf2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
row_buf[0] = 0;
|
||||
sub_row[0] = 1;
|
||||
@@ -994,7 +1005,7 @@ void save_png(std::stringstream& f, unsigned int width, unsigned int height, int
|
||||
zstream2.next_out = zbuf2;
|
||||
zstream2.avail_out = zbuf_size;
|
||||
|
||||
prev = NULL;
|
||||
prev = nullptr;
|
||||
row = pixels;
|
||||
|
||||
for(j = 0; j < (unsigned int)height; j++) {
|
||||
@@ -1122,7 +1133,7 @@ void save_png(std::stringstream& f, unsigned int width, unsigned int height, int
|
||||
deflateReset(&zstream2);
|
||||
zstream2.data_type = Z_BINARY;
|
||||
|
||||
write_chunk(f, "IEND", 0, 0);
|
||||
write_chunk(f, "IEND", nullptr, 0);
|
||||
|
||||
deflateEnd(&zstream1);
|
||||
deflateEnd(&zstream2);
|
||||
|
@@ -298,8 +298,7 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
||||
std::vector<std::string> wordsSplit = stdext::split(text);
|
||||
|
||||
// break huge words into small ones
|
||||
for(uint i=0;i<wordsSplit.size();++i) {
|
||||
const std::string& word = wordsSplit[i];
|
||||
for(const auto &word: wordsSplit) {
|
||||
int wordWidth = calculateTextRectSize(word).width();
|
||||
if(wordWidth > maxWidth) {
|
||||
std::string newWord;
|
||||
@@ -324,8 +323,8 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
||||
}
|
||||
|
||||
// compose lines
|
||||
for(uint i=0;i<words.size();++i) {
|
||||
std::string candidate = line + words[i];
|
||||
for(const auto &word: words) {
|
||||
std::string candidate = line + word;
|
||||
int candidateWidth = calculateTextRectSize(candidate).width();
|
||||
|
||||
if(candidateWidth > maxWidth) {
|
||||
@@ -334,7 +333,7 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
||||
line = "";
|
||||
}
|
||||
|
||||
line += words[i] + " ";
|
||||
line += word + " ";
|
||||
}
|
||||
|
||||
outText += line;
|
||||
|
@@ -48,7 +48,7 @@ public:
|
||||
/// Calculate glyphs positions to use on render, also calculates textBoxSize if wanted
|
||||
const std::vector<Point>& calculateGlyphsPositions(const std::string& text,
|
||||
Fw::AlignmentFlag align = Fw::AlignTopLeft,
|
||||
Size* textBoxSize = NULL);
|
||||
Size* textBoxSize = nullptr);
|
||||
|
||||
/// Simulate render and calculate text size
|
||||
Size calculateTextRectSize(const std::string& text);
|
||||
|
@@ -34,10 +34,8 @@ CoordsBuffer::CoordsBuffer()
|
||||
|
||||
CoordsBuffer::~CoordsBuffer()
|
||||
{
|
||||
if(m_hardwareVertexArray)
|
||||
delete m_hardwareVertexArray;
|
||||
if(m_hardwareTextureCoordArray)
|
||||
delete m_hardwareTextureCoordArray;
|
||||
delete m_hardwareVertexArray;
|
||||
delete m_hardwareTextureCoordArray;
|
||||
}
|
||||
|
||||
void CoordsBuffer::addBoudingRect(const Rect& dest, int innerLineWidth)
|
||||
|
@@ -60,7 +60,7 @@ public:
|
||||
void drawBoundingRect(const Rect& dest, int innerLineWidth);
|
||||
|
||||
void setMatrixMode(MatrixMode matrixMode);
|
||||
void setTransformMatrix(const Matrix3& projectionMatrix);
|
||||
void setTransformMatrix(const Matrix3& transformMatrix);
|
||||
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
||||
void setTextureMatrix(const Matrix3& textureMatrix);
|
||||
void setColor(const Color& color);
|
||||
|
@@ -165,7 +165,7 @@ void PainterShaderProgram::addMultiTexture(const std::string& file)
|
||||
|
||||
void PainterShaderProgram::bindMultiTextures()
|
||||
{
|
||||
if(m_multiTextures.size() == 0)
|
||||
if(m_multiTextures.empty())
|
||||
return;
|
||||
|
||||
int i=1;
|
||||
|
@@ -54,8 +54,8 @@ void ParticleEffect::load(const ParticleEffectTypePtr& effectType)
|
||||
|
||||
void ParticleEffect::render()
|
||||
{
|
||||
for(auto it = m_systems.begin(), end = m_systems.end(); it != end; ++it)
|
||||
(*it)->render();
|
||||
for(auto &system: m_systems)
|
||||
system->render();
|
||||
}
|
||||
|
||||
void ParticleEffect::update()
|
||||
|
@@ -51,7 +51,7 @@ public:
|
||||
ParticleEffect() {}
|
||||
|
||||
void load(const ParticleEffectTypePtr& effectType);
|
||||
bool hasFinished() { return m_systems.size() == 0; }
|
||||
bool hasFinished() { return m_systems.empty(); }
|
||||
void render();
|
||||
void update();
|
||||
|
||||
|
@@ -61,8 +61,8 @@ void ParticleSystem::addParticle(const ParticlePtr& particle)
|
||||
|
||||
void ParticleSystem::render()
|
||||
{
|
||||
for(auto it = m_particles.begin(), end = m_particles.end(); it != end; ++it)
|
||||
(*it)->render();
|
||||
for(auto &particle: m_particles)
|
||||
particle->render();
|
||||
g_painter->resetCompositionMode();
|
||||
}
|
||||
|
||||
|
@@ -142,7 +142,7 @@ void ParticleType::load(const OTMLNodePtr& node)
|
||||
}
|
||||
|
||||
if(pColors.empty())
|
||||
pColors.push_back(Color(255, 255, 255, 128));
|
||||
pColors.emplace_back(255, 255, 255, 128);
|
||||
if(pColorsStops.empty())
|
||||
pColorsStops.push_back(0);
|
||||
|
||||
|
@@ -69,7 +69,7 @@ bool Shader::compileSourceCode(const std::string& sourceCode)
|
||||
std::string code = qualifierDefines;
|
||||
code.append(sourceCode);
|
||||
const char *c_source = code.c_str();
|
||||
glShaderSource(m_shaderId, 1, &c_source, NULL);
|
||||
glShaderSource(m_shaderId, 1, &c_source, nullptr);
|
||||
glCompileShader(m_shaderId);
|
||||
|
||||
int res = GL_FALSE;
|
||||
@@ -95,7 +95,7 @@ std::string Shader::log()
|
||||
glGetShaderiv(m_shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if(infoLogLength > 1) {
|
||||
std::vector<char> buf(infoLogLength);
|
||||
glGetShaderInfoLog(m_shaderId, infoLogLength-1, NULL, &buf[0]);
|
||||
glGetShaderInfoLog(m_shaderId, infoLogLength-1, nullptr, &buf[0]);
|
||||
infoLog = &buf[0];
|
||||
}
|
||||
return infoLog;
|
||||
|
@@ -129,7 +129,7 @@ std::string ShaderProgram::log()
|
||||
glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if(infoLogLength > 1) {
|
||||
std::vector<char> buf(infoLogLength);
|
||||
glGetShaderInfoLog(m_programId, infoLogLength-1, NULL, &buf[0]);
|
||||
glGetShaderInfoLog(m_programId, infoLogLength-1, nullptr, &buf[0]);
|
||||
infoLog = &buf[0];
|
||||
}
|
||||
return infoLog;
|
||||
|
@@ -75,7 +75,7 @@ bool Mouse::pushCursor(const std::string& name)
|
||||
|
||||
void Mouse::popCursor(const std::string& name)
|
||||
{
|
||||
if(m_cursorStack.size() == 0)
|
||||
if(m_cursorStack.empty())
|
||||
return;
|
||||
|
||||
if(name.empty() || m_cursors.find(name) == m_cursors.end())
|
||||
@@ -93,7 +93,7 @@ void Mouse::popCursor(const std::string& name)
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_cursorStack.size() > 0)
|
||||
if(!m_cursorStack.empty())
|
||||
g_window.setMouseCursor(m_cursorStack.back());
|
||||
else
|
||||
g_window.restoreMouseCursor();
|
||||
@@ -101,7 +101,7 @@ void Mouse::popCursor(const std::string& name)
|
||||
|
||||
bool Mouse::isCursorChanged()
|
||||
{
|
||||
return m_cursorStack.size() > 0;
|
||||
return !m_cursorStack.empty();
|
||||
}
|
||||
|
||||
bool Mouse::isPressed(Fw::MouseButton mouseButton)
|
||||
|
@@ -122,7 +122,7 @@ union luai_Cast2 { double l_d; LUAI_INT32 l_p[2]; };
|
||||
#if !defined(lua_number2unsigned) /* { */
|
||||
/* the following definition assures proper modulo behavior */
|
||||
#if defined(LUA_NUMBER_DOUBLE)
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
|
||||
#define lua_number2unsigned(i,n) \
|
||||
((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
|
||||
@@ -365,7 +365,7 @@ static const luaL_Reg bitlib[] = {
|
||||
{"replace", b_replace},
|
||||
{"rrotate", b_rrot},
|
||||
{"rshift", b_rshift},
|
||||
{NULL, NULL}
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
int luaopen_bit32 (lua_State *L) {
|
||||
|
@@ -707,7 +707,7 @@ void LuaInterface::closeLuaState()
|
||||
if(L) {
|
||||
// close lua, it also collects
|
||||
lua_close(L);
|
||||
L = NULL;
|
||||
L = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -785,7 +785,7 @@ int LuaInterface::weakRef()
|
||||
|
||||
void LuaInterface::unref(int ref)
|
||||
{
|
||||
if(ref >= 0 && L != NULL)
|
||||
if(ref >= 0 && L != nullptr)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,9 @@
|
||||
|
||||
#include <framework/core/application.h>
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <memory>
|
||||
|
||||
asio::io_service g_ioService;
|
||||
std::list<std::shared_ptr<asio::streambuf>> Connection::m_outputStreams;
|
||||
@@ -123,7 +125,7 @@ void Connection::write(uint8* buffer, size_t size)
|
||||
m_outputStream = m_outputStreams.front();
|
||||
m_outputStreams.pop_front();
|
||||
} else
|
||||
m_outputStream = std::shared_ptr<asio::streambuf>(new asio::streambuf);
|
||||
m_outputStream = std::make_shared<asio::streambuf>();
|
||||
|
||||
m_delayedWriteTimer.cancel();
|
||||
m_delayedWriteTimer.expires_from_now(boost::posix_time::milliseconds(0));
|
||||
@@ -177,7 +179,7 @@ void Connection::read_until(const std::string& what, const RecvCallback& callbac
|
||||
|
||||
asio::async_read_until(m_socket,
|
||||
m_inputStream,
|
||||
what.c_str(),
|
||||
what,
|
||||
std::bind(&Connection::onRecv, asConnection(), std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
m_readTimer.cancel();
|
||||
|
@@ -144,7 +144,7 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size)
|
||||
|
||||
void Protocol::generateXteaKey()
|
||||
{
|
||||
std::mt19937 eng(std::time(NULL));
|
||||
std::mt19937 eng(std::time(nullptr));
|
||||
std::uniform_int_distribution<uint32> unif(0, 0xFFFFFFFF);
|
||||
m_xteaKey[0] = unif(eng);
|
||||
m_xteaKey[1] = unif(eng);
|
||||
|
@@ -27,7 +27,7 @@
|
||||
|
||||
OTMLParser::OTMLParser(OTMLDocumentPtr doc, std::istream& in) :
|
||||
currentDepth(0), currentLine(0),
|
||||
doc(doc), currentParent(doc), previousNode(0),
|
||||
doc(doc), currentParent(doc), previousNode(nullptr),
|
||||
in(in)
|
||||
{
|
||||
}
|
||||
|
@@ -150,8 +150,8 @@ void PlatformWindow::releaseAllKeys()
|
||||
|
||||
m_inputEvent.keyboardModifiers = 0;
|
||||
|
||||
for(int i=0;i<4;++i)
|
||||
m_mouseButtonStates[i] = false;
|
||||
for(auto &mouseButtonState: m_mouseButtonStates)
|
||||
mouseButtonState = false;
|
||||
}
|
||||
|
||||
void PlatformWindow::fireKeysPress()
|
||||
|
@@ -30,9 +30,9 @@
|
||||
#define __USE_GNU
|
||||
#endif
|
||||
|
||||
#include <csignal>
|
||||
#include <execinfo.h>
|
||||
#include <ucontext.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define MAX_BACKTRACE_DEPTH 128
|
||||
#define DEMANGLE_BACKTRACE_SYMBOLS
|
||||
@@ -129,10 +129,10 @@ void installCrashHandler()
|
||||
sigemptyset (&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
|
||||
sigaction(SIGILL, &sa, NULL); // illegal instruction
|
||||
sigaction(SIGSEGV, &sa, NULL); // segmentation fault
|
||||
sigaction(SIGFPE, &sa, NULL); // floating-point exception
|
||||
sigaction(SIGABRT, &sa, NULL); // process aborted (asserts)
|
||||
sigaction(SIGILL, &sa, nullptr); // illegal instruction
|
||||
sigaction(SIGSEGV, &sa, nullptr); // segmentation fault
|
||||
sigaction(SIGFPE, &sa, nullptr); // floating-point exception
|
||||
sigaction(SIGABRT, &sa, nullptr); // process aborted (asserts)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -23,9 +23,9 @@
|
||||
#ifndef WIN32
|
||||
|
||||
#include "platform.h"
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <framework/stdext/stdext.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
@@ -51,7 +51,7 @@ bool Platform::spawnProcess(std::string process, const std::vector<std::string>&
|
||||
cargs[0] = (char*)process.c_str();
|
||||
for(uint i=1;i<=args.size();++i)
|
||||
cargs[i] = (char*)args[i-1].c_str();
|
||||
cargs[args.size()+1] = 0;
|
||||
cargs[args.size()+1] = nullptr;
|
||||
|
||||
if(execv(process.c_str(), cargs) == -1)
|
||||
_exit(EXIT_FAILURE);
|
||||
@@ -84,7 +84,7 @@ std::string Platform::getCurrentDir()
|
||||
{
|
||||
std::string res;
|
||||
char cwd[2048];
|
||||
if(getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
if(getcwd(cwd, sizeof(cwd)) != nullptr) {
|
||||
res = cwd;
|
||||
res += "/";
|
||||
}
|
||||
|
@@ -31,15 +31,15 @@
|
||||
|
||||
X11Window::X11Window()
|
||||
{
|
||||
m_display = 0;
|
||||
m_visual = 0;
|
||||
m_display = nullptr;
|
||||
m_visual = nullptr;
|
||||
m_window = 0;
|
||||
m_rootWindow = 0;
|
||||
m_colormap = 0;
|
||||
m_cursor = 0;
|
||||
m_hiddenCursor = 0;
|
||||
m_xim = 0;
|
||||
m_xic = 0;
|
||||
m_xim = nullptr;
|
||||
m_xic = nullptr;
|
||||
m_screen = 0;
|
||||
m_wmDelete = 0;
|
||||
m_minimumSize = Size(600,480);
|
||||
@@ -51,8 +51,8 @@ X11Window::X11Window()
|
||||
m_eglDisplay = 0;
|
||||
m_eglSurface = 0;
|
||||
#else
|
||||
m_fbConfig = 0;
|
||||
m_glxContext = 0;
|
||||
m_fbConfig = nullptr;
|
||||
m_glxContext = nullptr;
|
||||
#endif
|
||||
|
||||
m_keyMap[XK_Escape] = Fw::KeyEscape;
|
||||
@@ -247,22 +247,22 @@ void X11Window::terminate()
|
||||
|
||||
if(m_visual) {
|
||||
XFree(m_visual);
|
||||
m_visual = 0;
|
||||
m_visual = nullptr;
|
||||
}
|
||||
|
||||
if(m_xic) {
|
||||
XDestroyIC(m_xic);
|
||||
m_xic = 0;
|
||||
m_xic = nullptr;
|
||||
}
|
||||
|
||||
if(m_xim) {
|
||||
XCloseIM(m_xim);
|
||||
m_xim = 0;
|
||||
m_xim = nullptr;
|
||||
}
|
||||
|
||||
if(m_display) {
|
||||
XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
m_display = nullptr;
|
||||
}
|
||||
|
||||
m_visible = false;
|
||||
@@ -270,7 +270,7 @@ void X11Window::terminate()
|
||||
|
||||
void X11Window::internalOpenDisplay()
|
||||
{
|
||||
m_display = XOpenDisplay(NULL);
|
||||
m_display = XOpenDisplay(nullptr);
|
||||
if(!m_display)
|
||||
g_logger.fatal("Unable to open X11 display");
|
||||
m_screen = DefaultScreen(m_display);
|
||||
@@ -343,7 +343,7 @@ bool X11Window::internalSetupWindowInput()
|
||||
}
|
||||
|
||||
XSetLocaleModifiers("");
|
||||
m_xim = XOpenIM(m_display, NULL, NULL, NULL);
|
||||
m_xim = XOpenIM(m_display, nullptr, nullptr, nullptr);
|
||||
if(!m_xim) {
|
||||
g_logger.error("XOpenIM failed");
|
||||
return false;
|
||||
@@ -368,7 +368,7 @@ void X11Window::internalCheckGL()
|
||||
if(!eglInitialize(m_eglDisplay, NULL, NULL))
|
||||
g_logger.fatal("Unable to initialize EGL");
|
||||
#else
|
||||
if(!glXQueryExtension(m_display, NULL, NULL))
|
||||
if(!glXQueryExtension(m_display, nullptr, nullptr))
|
||||
g_logger.fatal("GLX not supported");
|
||||
#endif
|
||||
}
|
||||
@@ -450,7 +450,7 @@ void X11Window::internalCreateGLContext()
|
||||
if(m_eglContext == EGL_NO_CONTEXT )
|
||||
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
|
||||
#else
|
||||
m_glxContext = glXCreateContext(m_display, m_visual, NULL, True);
|
||||
m_glxContext = glXCreateContext(m_display, m_visual, nullptr, True);
|
||||
|
||||
if(!m_glxContext)
|
||||
g_logger.fatal("Unable to create GLX context");
|
||||
@@ -477,9 +477,9 @@ void X11Window::internalDestroyGLContext()
|
||||
}
|
||||
#else
|
||||
if(m_glxContext) {
|
||||
glXMakeCurrent(m_display, None, NULL);
|
||||
glXMakeCurrent(m_display, None, nullptr);
|
||||
glXDestroyContext(m_display, m_glxContext);
|
||||
m_glxContext = 0;
|
||||
m_glxContext = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -606,7 +606,7 @@ void X11Window::poll()
|
||||
// lookup keysym and translate it
|
||||
KeySym keysym;
|
||||
char buf[32];
|
||||
XLookupString(&xkey, buf, sizeof(buf), &keysym, 0);
|
||||
XLookupString(&xkey, buf, sizeof(buf), &keysym, nullptr);
|
||||
Fw::Key keyCode = Fw::KeyUnknown;
|
||||
|
||||
if(m_keyMap.find(keysym) != m_keyMap.end())
|
||||
@@ -651,7 +651,7 @@ void X11Window::poll()
|
||||
Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
|
||||
Atom actualType;
|
||||
ulong i, numItems, bytesAfter;
|
||||
uchar *propertyValue = NULL;
|
||||
uchar *propertyValue = nullptr;
|
||||
int actualFormat;
|
||||
|
||||
if(XGetWindowProperty(m_display, m_window, wmState,
|
||||
@@ -740,7 +740,7 @@ void X11Window::poll()
|
||||
Status status;
|
||||
len = XmbLookupString(m_xic, &event.xkey, buf, sizeof(buf), &keysym, &status);
|
||||
} else { // otherwise use XLookupString, but often it doesn't work right with dead keys
|
||||
static XComposeStatus compose = {NULL, 0};
|
||||
static XComposeStatus compose = {nullptr, 0};
|
||||
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, &compose);
|
||||
}
|
||||
|
||||
@@ -972,7 +972,7 @@ void X11Window::setVerticalSync(bool enable)
|
||||
//TODO
|
||||
#else
|
||||
typedef GLint (*glSwapIntervalProc)(GLint);
|
||||
glSwapIntervalProc glSwapInterval = NULL;
|
||||
glSwapIntervalProc glSwapInterval = nullptr;
|
||||
|
||||
if(isExtensionSupported("GLX_MESA_swap_control"))
|
||||
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA");
|
||||
|
@@ -35,7 +35,7 @@ OggSoundFile::~OggSoundFile()
|
||||
bool OggSoundFile::prepareOgg()
|
||||
{
|
||||
ov_callbacks callbacks = { cb_read, cb_seek, cb_close, cb_tell };
|
||||
ov_open_callbacks(m_file.get(), &m_vorbisFile, 0, 0, callbacks);
|
||||
ov_open_callbacks(m_file.get(), &m_vorbisFile, nullptr, 0, callbacks);
|
||||
|
||||
vorbis_info* vi = ov_info(&m_vorbisFile, -1);
|
||||
if(!vi) {
|
||||
|
@@ -37,13 +37,13 @@ SoundManager g_sounds;
|
||||
|
||||
void SoundManager::init()
|
||||
{
|
||||
m_device = alcOpenDevice(NULL);
|
||||
m_device = alcOpenDevice(nullptr);
|
||||
if(!m_device) {
|
||||
g_logger.error("unable to open audio device");
|
||||
return;
|
||||
}
|
||||
|
||||
m_context = alcCreateContext(m_device, NULL);
|
||||
m_context = alcCreateContext(m_device, nullptr);
|
||||
if(!m_context) {
|
||||
g_logger.error(stdext::format("unable to create audio context: %s", alcGetString(m_device, alcGetError(m_device))));
|
||||
return;
|
||||
@@ -59,8 +59,8 @@ void SoundManager::terminate()
|
||||
{
|
||||
ensureContext();
|
||||
|
||||
for(auto it = m_streamFiles.begin(); it != m_streamFiles.end();++it) {
|
||||
auto& future = it->second;
|
||||
for(auto &streamFile: m_streamFiles) {
|
||||
auto& future = streamFile.second;
|
||||
future.wait();
|
||||
}
|
||||
m_streamFiles.clear();
|
||||
|
@@ -52,7 +52,7 @@ public:
|
||||
any() : content(nullptr) { }
|
||||
any(const any& other) : content(other.content ? other.content->clone() : nullptr) { }
|
||||
template<typename T> any(const T& value) : content(new holder<T>(value)) { }
|
||||
~any() { if(content) delete content; }
|
||||
~any() { delete content; }
|
||||
|
||||
any& swap(any& rhs) { std::swap(content, rhs.content); return *this; }
|
||||
|
||||
|
@@ -44,20 +44,21 @@ namespace stdext {
|
||||
|
||||
const char* demangle_name(const char* name)
|
||||
{
|
||||
static const unsigned BufferSize = 1024;
|
||||
static char Buffer[1024] = {};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static char buffer[1024];
|
||||
UnDecorateSymbolName(name, buffer, sizeof(buffer), UNDNAME_COMPLETE);
|
||||
return buffer;
|
||||
UnDecorateSymbolName(name, Buffer, BufferSize, UNDNAME_COMPLETE);
|
||||
return Buffer;
|
||||
#else
|
||||
size_t len;
|
||||
int status;
|
||||
static char buffer[1024];
|
||||
char* demangled = abi::__cxa_demangle(name, 0, &len, &status);
|
||||
char* demangled = abi::__cxa_demangle(name, nullptr, &len, &status);
|
||||
if(demangled) {
|
||||
strcpy(buffer, demangled);
|
||||
strncpy(Buffer, demangled, BufferSize);
|
||||
free(demangled);
|
||||
}
|
||||
return buffer;
|
||||
return Buffer;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -66,4 +66,4 @@ double round(double r)
|
||||
return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ class packed_storage {
|
||||
|
||||
public:
|
||||
packed_storage() : m_values(nullptr), m_size(0) { }
|
||||
~packed_storage() { if(m_values) delete[] m_values; }
|
||||
~packed_storage() { delete[] m_values; }
|
||||
|
||||
template<typename T>
|
||||
void set(Key id, const T& value) {
|
||||
|
@@ -46,7 +46,7 @@ public:
|
||||
template <class InputIterator>
|
||||
packed_vector(InputIterator first, InputIterator last) : m_size(last - first), m_data(new T[m_size]) { std::copy(first, last, m_data); }
|
||||
packed_vector(const packed_vector<T>& other) : m_size(other.m_size), m_data(new T[other.m_size]) { std::copy(other.begin(), other.end(), m_data); }
|
||||
~packed_vector() { if(m_data) delete[] m_data; }
|
||||
~packed_vector() { delete[] m_data; }
|
||||
|
||||
packed_vector<T,U>& operator=(packed_vector<T,U> other) { other.swap(*this); return *this; }
|
||||
|
||||
|
@@ -23,22 +23,22 @@
|
||||
#ifndef STDEXT_H
|
||||
#define STDEXT_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "dumper.h"
|
||||
#include "types.h"
|
||||
#include "exception.h"
|
||||
#include "demangle.h"
|
||||
#include "any.h"
|
||||
#include "boolean.h"
|
||||
#include "cast.h"
|
||||
#include "compiler.h"
|
||||
#include "demangle.h"
|
||||
#include "dumper.h"
|
||||
#include "dynamic_storage.h"
|
||||
#include "exception.h"
|
||||
#include "format.h"
|
||||
#include "math.h"
|
||||
#include "packed_any.h"
|
||||
#include "packed_storage.h"
|
||||
#include "packed_vector.h"
|
||||
#include "shared_object.h"
|
||||
#include "string.h"
|
||||
#include "time.h"
|
||||
#include "boolean.h"
|
||||
#include "shared_object.h"
|
||||
#include "any.h"
|
||||
#include "packed_any.h"
|
||||
#include "dynamic_storage.h"
|
||||
#include "packed_storage.h"
|
||||
#include "format.h"
|
||||
#include "packed_vector.h"
|
||||
#include "types.h"
|
||||
|
||||
#endif
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include "string.h"
|
||||
#include "format.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <ctype.h>
|
||||
#include <cctype>
|
||||
#include <physfs.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "time.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <thread>
|
||||
@@ -30,7 +31,7 @@ namespace stdext {
|
||||
const static auto startup_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
ticks_t time() {
|
||||
return std::time(NULL);
|
||||
return std::time(nullptr);
|
||||
}
|
||||
|
||||
ticks_t millis()
|
||||
|
@@ -50,8 +50,8 @@ void UIParticles::drawSelf(Fw::DrawPane drawPane)
|
||||
else
|
||||
g_painter->translate(m_rect.x() + m_referencePos.x * m_rect.width(), m_rect.y() + m_referencePos.y * m_rect.height());
|
||||
|
||||
for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it)
|
||||
(*it)->render();
|
||||
for(auto &effect: m_effects)
|
||||
effect->render();
|
||||
g_painter->restoreSavedState();
|
||||
}
|
||||
}
|
||||
|
@@ -397,9 +397,9 @@ void UITextEdit::appendText(std::string text)
|
||||
return;
|
||||
|
||||
// only ignore text append if it contains invalid characters
|
||||
if(m_validCharacters.size() > 0) {
|
||||
for(uint i = 0; i < text.size(); ++i) {
|
||||
if(m_validCharacters.find(text[i]) == std::string::npos)
|
||||
if(!m_validCharacters.empty()) {
|
||||
for(char i: text) {
|
||||
if(m_validCharacters.find(i) == std::string::npos)
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -424,7 +424,7 @@ void UITextEdit::appendCharacter(char c)
|
||||
if(m_maxLength > 0 && m_text.length() + 1 > m_maxLength)
|
||||
return;
|
||||
|
||||
if(m_validCharacters.size() > 0 && m_validCharacters.find(c) == std::string::npos)
|
||||
if(!m_validCharacters.empty() && m_validCharacters.find(c) == std::string::npos)
|
||||
return;
|
||||
|
||||
std::string tmp;
|
||||
|
@@ -103,7 +103,7 @@ protected:
|
||||
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
||||
virtual bool onDoubleClick(const Point& mousePos);
|
||||
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& virtualSize, const Size& totalSize);
|
||||
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& visibleSize, const Size& totalSize);
|
||||
|
||||
private:
|
||||
void disableUpdates() { m_updatesEnabled = false; }
|
||||
|
@@ -70,7 +70,7 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
|
||||
|
||||
drawSelf(drawPane);
|
||||
|
||||
if(m_children.size() > 0) {
|
||||
if(!m_children.empty()) {
|
||||
if(m_clipping)
|
||||
g_painter->setClipRect(visibleRect.intersection(getPaddingRect()));
|
||||
|
||||
@@ -488,7 +488,7 @@ void UIWidget::unlockChild(const UIWidgetPtr& child)
|
||||
|
||||
// find new child to lock
|
||||
UIWidgetPtr lockedChild;
|
||||
if(m_lockedChildren.size() > 0) {
|
||||
if(!m_lockedChildren.empty()) {
|
||||
lockedChild = m_lockedChildren.front();
|
||||
assert(hasChild(lockedChild));
|
||||
}
|
||||
@@ -1043,8 +1043,8 @@ bool UIWidget::hasChild(const UIWidgetPtr& child)
|
||||
int UIWidget::getChildIndex(const UIWidgetPtr& child)
|
||||
{
|
||||
int index = 1;
|
||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||
if(*it == child)
|
||||
for(auto &it: m_children) {
|
||||
if(it == child)
|
||||
return index;
|
||||
++index;
|
||||
}
|
||||
@@ -1713,8 +1713,7 @@ bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widget
|
||||
bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved, UIWidgetList& widgetList)
|
||||
{
|
||||
if(containsPaddingPoint(mousePos)) {
|
||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||
const UIWidgetPtr& child = *it;
|
||||
for(auto &child: m_children) {
|
||||
if(child->isExplicitlyVisible() && child->isExplicitlyEnabled() && child->containsPoint(mousePos))
|
||||
child->propagateOnMouseMove(mousePos, mouseMoved, widgetList);
|
||||
|
||||
|
@@ -246,7 +246,7 @@ public:
|
||||
bool isClipping() { return m_clipping; }
|
||||
bool isDestroyed() { return m_destroyed; }
|
||||
|
||||
bool hasChildren() { return m_children.size() > 0; }
|
||||
bool hasChildren() { return !m_children.empty(); }
|
||||
bool containsMarginPoint(const Point& point) { return getMarginRect().contains(point); }
|
||||
bool containsPaddingPoint(const Point& point) { return getPaddingRect().contains(point); }
|
||||
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
||||
|
@@ -32,8 +32,7 @@ public:
|
||||
m_capacity(res),
|
||||
m_buffer(new T[m_capacity]) { }
|
||||
~DataBuffer() {
|
||||
if(m_buffer)
|
||||
delete[] m_buffer;
|
||||
delete[] m_buffer;
|
||||
}
|
||||
|
||||
inline void reset() { m_size = 0; }
|
||||
@@ -59,8 +58,8 @@ public:
|
||||
T *buffer = new T[n];
|
||||
for(uint i=0;i<m_size;++i)
|
||||
buffer[i] = m_buffer[i];
|
||||
if(m_buffer)
|
||||
delete[] m_buffer;
|
||||
|
||||
delete[] m_buffer;
|
||||
m_buffer = buffer;
|
||||
m_capacity = n;
|
||||
}
|
||||
|
Reference in New Issue
Block a user