diff --git a/src/client/animator.cpp b/src/client/animator.cpp index 0382f291..c73abc8f 100644 --- a/src/client/animator.cpp +++ b/src/client/animator.cpp @@ -50,7 +50,7 @@ void Animator::unserialize(int animationPhases, const FileStreamPtr& fin) for(int i = 0; i < m_animationPhases; ++i) { int minimum = fin->getU32(); int maximum = fin->getU32(); - m_phaseDurations.push_back(std::make_tuple(minimum, maximum)); + m_phaseDurations.emplace_back(minimum, maximum); } m_phase = getStartPhase(); diff --git a/src/client/creatures.h b/src/client/creatures.h index 6a64f6a6..1ec05864 100644 --- a/src/client/creatures.h +++ b/src/client/creatures.h @@ -133,7 +133,7 @@ public: const std::vector& getCreatures() { return m_creatures; } protected: - void internalLoadCreatureBuffer(TiXmlElement* elem, const CreatureTypePtr& m); + void internalLoadCreatureBuffer(TiXmlElement* attrib, const CreatureTypePtr& m); private: std::vector m_creatures; diff --git a/src/client/game.cpp b/src/client/game.cpp index 8a9e8e1d..e1accc75 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -686,7 +686,7 @@ void Game::autoWalk(std::vector dirs) return; } - if(dirs.size() == 0) + if(dirs.empty()) return; // must cancel follow before any new walk @@ -1715,10 +1715,10 @@ std::string Game::formatCreatureName(const std::string& name) std::string formatedName = name; if(getFeature(Otc::GameFormatCreatureName) && name.length() > 0) { bool upnext = true; - for(uint i=0;i getGMActions() { return m_gmActions; } - bool isGM() { return m_gmActions.size() > 0; } + bool isGM() { return !m_gmActions.empty(); } Otc::Direction getLastWalkDir() { return m_lastWalkDir; } std::string formatCreatureName(const std::string &name); diff --git a/src/client/lightview.cpp b/src/client/lightview.cpp index 3a307b9e..510943c0 100644 --- a/src/client/lightview.cpp +++ b/src/client/lightview.cpp @@ -88,7 +88,7 @@ void LightView::addLightSource(const Point& center, float scaleFactor, const Lig color.setGreen(color.gF() * brightness); color.setBlue(color.bF() * brightness); - if(m_blendEquation == Painter::BlendEquation_Add && m_lightMap.size() > 0) { + if(m_blendEquation == Painter::BlendEquation_Add && !m_lightMap.empty()) { LightSource prevSource = m_lightMap.back(); if(prevSource.center == center && prevSource.color == color && prevSource.radius == radius) return; diff --git a/src/client/map.h b/src/client/map.h index 04f79f1a..0635fbe0 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -192,7 +192,7 @@ public: // tile zone related void setShowZone(tileflags_t zone, bool show); void setShowZones(bool show); - void setZoneColor(tileflags_t flag, const Color& color); + void setZoneColor(tileflags_t zone, const Color& color); void setZoneOpacity(float opacity) { m_zoneOpacity = opacity; } float getZoneOpacity() { return m_zoneOpacity; } diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index 0e92029f..2217f182 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -378,11 +378,11 @@ void MapView::updateVisibleTilesCache(int start) Rect(tpx, tpy + 1, 1, qs), }; - for(int i=0;i<4;++i) { - int sx = std::max(lines[i].left(), area.left()); - int ex = std::min(lines[i].right(), area.right()); - int sy = std::max(lines[i].top(), area.top()); - int ey = std::min(lines[i].bottom(), area.bottom()); + for(auto &line: lines) { + int sx = std::max(line.left(), area.left()); + int ex = std::min(line.right(), area.right()); + int sy = std::max(line.top(), area.top()); + int ey = std::min(line.bottom(), area.bottom()); for(int qx=sx;qx<=ex;++qx) for(int qy=sy;qy<=ey;++qy) m_spiral[count++] = Point(qx, qy); diff --git a/src/client/protocolgame.h b/src/client/protocolgame.h index fdfaf6ae..e65b5103 100644 --- a/src/client/protocolgame.h +++ b/src/client/protocolgame.h @@ -55,12 +55,12 @@ public: void sendTurnSouth(); void sendTurnWest(); void sendEquipItem(int itemId, int countOrSubType); - void sendMove(const Position& fromPos, int itemId, int stackpos, const Position& toPos, int count); + void sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count); void sendInspectNpcTrade(int itemId, int count); void sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack); void sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped); void sendCloseNpcTrade(); - void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId); + void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint creatureId); void sendInspectTrade(bool counterOffer, int index); void sendAcceptTrade(); void sendRejectTrade(); @@ -118,7 +118,7 @@ public: void sendRequestStoreOffers(const std::string& categoryName, int serviceType); void sendOpenStore(int serviceType, const std::string &category); void sendTransferCoins(const std::string& recipient, int amount); - void sendOpenTransactionHistory(int entiresPerPage); + void sendOpenTransactionHistory(int entriesPerPage); // otclient only void sendChangeMapAwareRange(int xrange, int yrange); diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index caf0fad5..50ee35ae 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -1000,7 +1000,7 @@ void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg) int weight = msg->getU32(); int buyPrice = msg->getU32(); int sellPrice = msg->getU32(); - items.push_back(std::make_tuple(item, name, weight, buyPrice, sellPrice)); + items.emplace_back(item, name, weight, buyPrice, sellPrice); } g_game.processOpenNpcTrade(items); @@ -1026,7 +1026,7 @@ void ProtocolGame::parsePlayerGoods(const InputMessagePtr& msg) else amount = msg->getU8(); - goods.push_back(std::make_tuple(Item::create(itemId), amount)); + goods.emplace_back(Item::create(itemId), amount); } g_game.processPlayerGoods(money, goods); @@ -1571,7 +1571,7 @@ void ProtocolGame::parseChannelList(const InputMessagePtr& msg) for(int i = 0; i < count; i++) { int id = msg->getU16(); std::string name = msg->getString(); - channelList.push_back(std::make_tuple(id, name)); + channelList.emplace_back(id, name); } g_game.processChannelList(channelList); @@ -1785,7 +1785,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) std::string outfitName = msg->getString(); int outfitAddons = msg->getU8(); - outfitList.push_back(std::make_tuple(outfitId, outfitName, outfitAddons)); + outfitList.emplace_back(outfitId, outfitName, outfitAddons); } } else { int outfitStart, outfitEnd; @@ -1798,7 +1798,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) } for(int i = outfitStart; i <= outfitEnd; i++) - outfitList.push_back(std::make_tuple(i, "", 0)); + outfitList.emplace_back(i, "", 0); } std::vector > mountList; @@ -1808,7 +1808,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) int mountId = msg->getU16(); // mount type std::string mountName = msg->getString(); // mount name - mountList.push_back(std::make_tuple(mountId, mountName)); + mountList.emplace_back(mountId, mountName); } } @@ -1881,7 +1881,7 @@ void ProtocolGame::parseQuestLog(const InputMessagePtr& msg) int id = msg->getU16(); std::string name = msg->getString(); bool completed = msg->getU8(); - questList.push_back(std::make_tuple(id, name, completed)); + questList.emplace_back(id, name, completed); } g_game.processQuestLog(questList); @@ -1895,7 +1895,7 @@ void ProtocolGame::parseQuestLine(const InputMessagePtr& msg) for(int i = 0; i < missionCount; i++) { std::string missionName = msg->getString(); std::string missionDescrition = msg->getString(); - questMissions.push_back(std::make_tuple(missionName, missionDescrition)); + questMissions.emplace_back(missionName, missionDescrition); } g_game.processQuestLine(questId, questMissions); @@ -1920,7 +1920,7 @@ void ProtocolGame::parseItemInfo(const InputMessagePtr& msg) item->setCountOrSubType(msg->getU8()); std::string desc = msg->getString(); - list.push_back(std::make_tuple(item, desc)); + list.emplace_back(item, desc); } g_lua.callGlobalField("g_game", "onItemInfo", list); @@ -1947,7 +1947,7 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg) for(int i = 0; i < sizeButtons; ++i) { std::string value = msg->getString(); int id = msg->getU8(); - buttonList.push_back(std::make_tuple(id, value)); + buttonList.emplace_back(id, value); } int sizeChoices = msg->getU8(); @@ -1955,7 +1955,7 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg) for(int i = 0; i < sizeChoices; ++i) { std::string value = msg->getString(); int id = msg->getU8(); - choiceList.push_back(std::make_tuple(id, value)); + choiceList.emplace_back(id, value); } int enterButton, escapeButton; diff --git a/src/client/statictext.cpp b/src/client/statictext.cpp index 2c254fa0..fea6b8c5 100644 --- a/src/client/statictext.cpp +++ b/src/client/statictext.cpp @@ -63,7 +63,7 @@ bool StaticText::addMessage(const std::string& name, Otc::MessageMode mode, cons { //TODO: this could be moved to lua // first message - if(m_messages.size() == 0) { + if(m_messages.empty()) { m_name = name; m_mode = mode; } @@ -82,7 +82,7 @@ bool StaticText::addMessage(const std::string& name, Otc::MessageMode mode, cons if(isYell()) delay *= 2; - m_messages.push_back(std::make_pair(text, g_clock.millis() + delay)); + m_messages.emplace_back(text, g_clock.millis() + delay); compose(); if(!m_updateEvent) diff --git a/src/client/thingtype.cpp b/src/client/thingtype.cpp index 28d6b3b6..0a3782a4 100644 --- a/src/client/thingtype.cpp +++ b/src/client/thingtype.cpp @@ -123,11 +123,11 @@ void ThingType::serialize(const FileStreamPtr& fin) } } - for(uint i = 0; i < m_spritesIndex.size(); i++) { + for(int i: m_spritesIndex) { if(g_game.getFeature(Otc::GameSpritesU32)) - fin->addU32(m_spritesIndex[i]); + fin->addU32(i); else - fin->addU16(m_spritesIndex[i]); + fin->addU16(i); } } @@ -328,7 +328,7 @@ void ThingType::exportImage(std::string fileName) if(m_null) stdext::throw_exception("cannot export null thingtype"); - if(m_spritesIndex.size() == 0) + if(m_spritesIndex.empty()) stdext::throw_exception("cannot export thingtype without sprites"); ImagePtr image(new Image(Size(32 * m_size.width() * m_layers * m_numPatternX, 32 * m_size.height() * m_animationPhases * m_numPatternY * m_numPatternZ))); @@ -571,4 +571,4 @@ void ThingType::setPathable(bool var) m_attribs.remove(ThingAttrNotPathable); else m_attribs.set(ThingAttrNotPathable, true); -} \ No newline at end of file +} diff --git a/src/client/thingtypemanager.cpp b/src/client/thingtypemanager.cpp index 7b6968b4..ce95f4e5 100644 --- a/src/client/thingtypemanager.cpp +++ b/src/client/thingtypemanager.cpp @@ -48,15 +48,15 @@ void ThingTypeManager::init() m_datLoaded = false; m_xmlLoaded = false; m_otbLoaded = false; - for(int i = 0; i < ThingLastCategory; ++i) - m_thingTypes[i].resize(1, m_nullThingType); + for(auto &m_thingType: m_thingTypes) + m_thingType.resize(1, m_nullThingType); m_itemTypes.resize(1, m_nullItemType); } void ThingTypeManager::terminate() { - for(int i = 0; i < ThingLastCategory; ++i) - m_thingTypes[i].clear(); + for(auto &m_thingType: m_thingTypes) + m_thingType.clear(); m_itemTypes.clear(); m_reverseItemTypes.clear(); m_nullThingType = nullptr; @@ -77,8 +77,8 @@ void ThingTypeManager::saveDat(std::string fileName) fin->addU32(m_datSignature); - for(int category = 0; category < ThingLastCategory; ++category) - fin->addU16(m_thingTypes[category].size() - 1); + for(auto &m_thingType: m_thingTypes) + fin->addU16(m_thingType.size() - 1); for(int category = 0; category < ThingLastCategory; ++category) { uint16 firstId = 1; @@ -110,10 +110,10 @@ bool ThingTypeManager::loadDat(std::string file) m_datSignature = fin->getU32(); m_contentRevision = static_cast(m_datSignature); - for(int category = 0; category < ThingLastCategory; ++category) { + for(auto &m_thingType: m_thingTypes) { int count = fin->getU16() + 1; - m_thingTypes[category].clear(); - m_thingTypes[category].resize(count, m_nullThingType); + m_thingType.clear(); + m_thingType.resize(count, m_nullThingType); } for(int category = 0; category < ThingLastCategory; ++category) { diff --git a/src/client/thingtypemanager.h b/src/client/thingtypemanager.h index 9ce8b51f..b60efb8b 100644 --- a/src/client/thingtypemanager.h +++ b/src/client/thingtypemanager.h @@ -47,7 +47,7 @@ public: const ItemTypePtr& findItemTypeByClientId(uint16 id); const ItemTypePtr& findItemTypeByName(std::string name); ItemTypeList findItemTypesByName(std::string name); - ItemTypeList findItemTypesByString(std::string str); + ItemTypeList findItemTypesByString(std::string name); const ThingTypePtr& getNullThingType() { return m_nullThingType; } const ItemTypePtr& getNullItemType() { return m_nullItemType; } diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 59a161dd..09074850 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -63,8 +63,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView * bool restore = false; if(g_map.showZones() && thing->isGround()) { - for(unsigned int i = 0; i < sizeof(flags) / sizeof(tileflags_t); ++i) { - tileflags_t flag = flags[i]; + for(auto flag: flags) { if(hasFlag(flag) && g_map.showZone(flag)) { g_painter->setOpacity(g_map.getZoneOpacity()); g_painter->setColor(g_map.getZoneColor(flag)); @@ -386,8 +385,7 @@ ThingPtr Tile::getTopLookThing() if(isEmpty()) return nullptr; - for(uint i = 0; i < m_things.size(); ++i) { - ThingPtr thing = m_things[i]; + for(auto thing: m_things) { if(!thing->isIgnoreLook() && (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())) return thing; } @@ -400,14 +398,12 @@ ThingPtr Tile::getTopUseThing() if(isEmpty()) return nullptr; - for(uint i = 0; i < m_things.size(); ++i) { - ThingPtr thing = m_things[i]; + for(auto thing: m_things) { if (thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature() && !thing->isSplash())) return thing; } - for(uint i = 0; i < m_things.size(); ++i) { - ThingPtr thing = m_things[i]; + for(auto thing: m_things) { if (!thing->isGround() && !thing->isGroundBorder() && !thing->isCreature() && !thing->isSplash()) return thing; } @@ -418,8 +414,7 @@ ThingPtr Tile::getTopUseThing() CreaturePtr Tile::getTopCreature() { CreaturePtr creature; - for(uint i = 0; i < m_things.size(); ++i) { - ThingPtr thing = m_things[i]; + for(auto thing: m_things) { if(thing->isLocalPlayer()) // return local player if there is no other creature creature = thing->static_self_cast(); else if(thing->isCreature() && !thing->isLocalPlayer()) @@ -480,8 +475,7 @@ ThingPtr Tile::getTopMultiUseThing() if(CreaturePtr topCreature = getTopCreature()) return topCreature; - for(uint i = 0; i < m_things.size(); ++i) { - ThingPtr thing = m_things[i]; + for(auto thing: m_things) { if(thing->isForceUse()) return thing; } @@ -495,8 +489,7 @@ ThingPtr Tile::getTopMultiUseThing() } } - for(uint i = 0; i < m_things.size(); ++i) { - ThingPtr thing = m_things[i]; + for(auto thing: m_things) { if(!thing->isGround() && !thing->isOnTop()) return thing; } diff --git a/src/framework/core/asyncdispatcher.cpp b/src/framework/core/asyncdispatcher.cpp index d1222b61..d71aa16d 100644 --- a/src/framework/core/asyncdispatcher.cpp +++ b/src/framework/core/asyncdispatcher.cpp @@ -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 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) diff --git a/src/framework/core/config.cpp b/src/framework/core/config.cpp index 060e1f2c..e6217cc3 100644 --- a/src/framework/core/config.cpp +++ b/src/framework/core/config.cpp @@ -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& lis { remove(key); - if(list.size() == 0) + if(list.empty()) return; OTMLNodePtr child = OTMLNode::create(key, true); diff --git a/src/framework/core/filestream.cpp b/src/framework/core/filestream.cpp index 85faed64..97e878b8 100644 --- a/src/framework/core/filestream.cpp +++ b/src/framework/core/filestream.cpp @@ -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); diff --git a/src/framework/core/logger.cpp b/src/framework/core/logger.cpp index d8905653..2258dcbb 100644 --- a/src/framework/core/logger.cpp +++ b/src/framework/core/logger.cpp @@ -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 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; diff --git a/src/framework/core/resourcemanager.cpp b/src/framework/core/resourcemanager.cpp index 5af5dcc1..6770b442 100644 --- a/src/framework/core/resourcemanager.cpp +++ b/src/framework/core/resourcemanager.cpp @@ -264,8 +264,8 @@ std::list ResourceManager::listDirectoryFiles(const std::string& di std::list 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; diff --git a/src/framework/core/resourcemanager.h b/src/framework/core/resourcemanager.h index f2476b8d..7ac0c7f6 100644 --- a/src/framework/core/resourcemanager.h +++ b/src/framework/core/resourcemanager.h @@ -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); diff --git a/src/framework/graphics/animatedtexture.cpp b/src/framework/graphics/animatedtexture.cpp index ed86c486..f3d3e47c 100644 --- a/src/framework/graphics/animatedtexture.cpp +++ b/src/framework/graphics/animatedtexture.cpp @@ -30,8 +30,8 @@ AnimatedTexture::AnimatedTexture(const Size& size, std::vector frames, if(!setupSize(size, buildMipmaps)) return; - for(uint i=0;i -#include -#include -#include #include "apngloader.h" -#include -#include +#include +#include +#include #include +#include +#include +#include + +#include #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); diff --git a/src/framework/graphics/bitmapfont.cpp b/src/framework/graphics/bitmapfont.cpp index a43af366..4685ff83 100644 --- a/src/framework/graphics/bitmapfont.cpp +++ b/src/framework/graphics/bitmapfont.cpp @@ -298,8 +298,7 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth) std::vector wordsSplit = stdext::split(text); // break huge words into small ones - for(uint i=0;i 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 maxWidth) { @@ -334,7 +333,7 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth) line = ""; } - line += words[i] + " "; + line += word + " "; } outText += line; diff --git a/src/framework/graphics/bitmapfont.h b/src/framework/graphics/bitmapfont.h index f086ccb1..3b53c73e 100644 --- a/src/framework/graphics/bitmapfont.h +++ b/src/framework/graphics/bitmapfont.h @@ -48,7 +48,7 @@ public: /// Calculate glyphs positions to use on render, also calculates textBoxSize if wanted const std::vector& 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); diff --git a/src/framework/graphics/coordsbuffer.cpp b/src/framework/graphics/coordsbuffer.cpp index 45260629..caa69ffe 100644 --- a/src/framework/graphics/coordsbuffer.cpp +++ b/src/framework/graphics/coordsbuffer.cpp @@ -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) diff --git a/src/framework/graphics/ogl/painterogl1.h b/src/framework/graphics/ogl/painterogl1.h index d7d1413a..abe6dfcc 100644 --- a/src/framework/graphics/ogl/painterogl1.h +++ b/src/framework/graphics/ogl/painterogl1.h @@ -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); diff --git a/src/framework/graphics/paintershaderprogram.cpp b/src/framework/graphics/paintershaderprogram.cpp index 949709f5..5f5848d1 100644 --- a/src/framework/graphics/paintershaderprogram.cpp +++ b/src/framework/graphics/paintershaderprogram.cpp @@ -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; diff --git a/src/framework/graphics/particleeffect.cpp b/src/framework/graphics/particleeffect.cpp index a18e613d..6868c481 100644 --- a/src/framework/graphics/particleeffect.cpp +++ b/src/framework/graphics/particleeffect.cpp @@ -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() diff --git a/src/framework/graphics/particleeffect.h b/src/framework/graphics/particleeffect.h index 00297418..f4e60573 100644 --- a/src/framework/graphics/particleeffect.h +++ b/src/framework/graphics/particleeffect.h @@ -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(); diff --git a/src/framework/graphics/particlesystem.cpp b/src/framework/graphics/particlesystem.cpp index c00ac981..a4d53bfb 100644 --- a/src/framework/graphics/particlesystem.cpp +++ b/src/framework/graphics/particlesystem.cpp @@ -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(); } diff --git a/src/framework/graphics/particletype.cpp b/src/framework/graphics/particletype.cpp index 32884df7..d19e0b33 100644 --- a/src/framework/graphics/particletype.cpp +++ b/src/framework/graphics/particletype.cpp @@ -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); diff --git a/src/framework/graphics/shader.cpp b/src/framework/graphics/shader.cpp index 14f8eb6d..223bb65b 100644 --- a/src/framework/graphics/shader.cpp +++ b/src/framework/graphics/shader.cpp @@ -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 buf(infoLogLength); - glGetShaderInfoLog(m_shaderId, infoLogLength-1, NULL, &buf[0]); + glGetShaderInfoLog(m_shaderId, infoLogLength-1, nullptr, &buf[0]); infoLog = &buf[0]; } return infoLog; diff --git a/src/framework/graphics/shaderprogram.cpp b/src/framework/graphics/shaderprogram.cpp index 0a421950..042124db 100644 --- a/src/framework/graphics/shaderprogram.cpp +++ b/src/framework/graphics/shaderprogram.cpp @@ -129,7 +129,7 @@ std::string ShaderProgram::log() glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength); if(infoLogLength > 1) { std::vector buf(infoLogLength); - glGetShaderInfoLog(m_programId, infoLogLength-1, NULL, &buf[0]); + glGetShaderInfoLog(m_programId, infoLogLength-1, nullptr, &buf[0]); infoLog = &buf[0]; } return infoLog; diff --git a/src/framework/input/mouse.cpp b/src/framework/input/mouse.cpp index d5060da2..3087e3ee 100644 --- a/src/framework/input/mouse.cpp +++ b/src/framework/input/mouse.cpp @@ -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) diff --git a/src/framework/luaengine/lbitlib.cpp b/src/framework/luaengine/lbitlib.cpp index 453eb95c..d688aea3 100644 --- a/src/framework/luaengine/lbitlib.cpp +++ b/src/framework/luaengine/lbitlib.cpp @@ -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 +#include #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) { diff --git a/src/framework/luaengine/luainterface.cpp b/src/framework/luaengine/luainterface.cpp index b2c90786..8184e7e0 100644 --- a/src/framework/luaengine/luainterface.cpp +++ b/src/framework/luaengine/luainterface.cpp @@ -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); } diff --git a/src/framework/net/connection.cpp b/src/framework/net/connection.cpp index 0df3cd37..db81fad8 100644 --- a/src/framework/net/connection.cpp +++ b/src/framework/net/connection.cpp @@ -24,7 +24,9 @@ #include #include + #include +#include asio::io_service g_ioService; std::list> 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(new asio::streambuf); + m_outputStream = std::make_shared(); 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(); diff --git a/src/framework/net/protocol.cpp b/src/framework/net/protocol.cpp index 10c29477..ead4519c 100644 --- a/src/framework/net/protocol.cpp +++ b/src/framework/net/protocol.cpp @@ -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 unif(0, 0xFFFFFFFF); m_xteaKey[0] = unif(eng); m_xteaKey[1] = unif(eng); diff --git a/src/framework/otml/otmlparser.cpp b/src/framework/otml/otmlparser.cpp index 256fb7d2..1da0f9ad 100644 --- a/src/framework/otml/otmlparser.cpp +++ b/src/framework/otml/otmlparser.cpp @@ -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) { } diff --git a/src/framework/platform/platformwindow.cpp b/src/framework/platform/platformwindow.cpp index 5053cb1c..ed8f36fd 100644 --- a/src/framework/platform/platformwindow.cpp +++ b/src/framework/platform/platformwindow.cpp @@ -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() diff --git a/src/framework/platform/unixcrashhandler.cpp b/src/framework/platform/unixcrashhandler.cpp index b27156a9..ab1c4e7d 100644 --- a/src/framework/platform/unixcrashhandler.cpp +++ b/src/framework/platform/unixcrashhandler.cpp @@ -30,9 +30,9 @@ #define __USE_GNU #endif +#include #include #include -#include #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 diff --git a/src/framework/platform/unixplatform.cpp b/src/framework/platform/unixplatform.cpp index cf77e02d..95f03a28 100644 --- a/src/framework/platform/unixplatform.cpp +++ b/src/framework/platform/unixplatform.cpp @@ -23,9 +23,9 @@ #ifndef WIN32 #include "platform.h" +#include #include #include -#include #include #include @@ -51,7 +51,7 @@ bool Platform::spawnProcess(std::string process, const std::vector& 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 += "/"; } diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index fb9d4236..34037eec 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -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"); diff --git a/src/framework/sound/oggsoundfile.cpp b/src/framework/sound/oggsoundfile.cpp index 0a5f1be5..cd7f6caa 100644 --- a/src/framework/sound/oggsoundfile.cpp +++ b/src/framework/sound/oggsoundfile.cpp @@ -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) { diff --git a/src/framework/sound/soundmanager.cpp b/src/framework/sound/soundmanager.cpp index 98f179fb..1b982dc4 100644 --- a/src/framework/sound/soundmanager.cpp +++ b/src/framework/sound/soundmanager.cpp @@ -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(); diff --git a/src/framework/stdext/any.h b/src/framework/stdext/any.h index 49280f91..cd7573f3 100644 --- a/src/framework/stdext/any.h +++ b/src/framework/stdext/any.h @@ -52,7 +52,7 @@ public: any() : content(nullptr) { } any(const any& other) : content(other.content ? other.content->clone() : nullptr) { } template any(const T& value) : content(new holder(value)) { } - ~any() { if(content) delete content; } + ~any() { delete content; } any& swap(any& rhs) { std::swap(content, rhs.content); return *this; } diff --git a/src/framework/stdext/demangle.cpp b/src/framework/stdext/demangle.cpp index 59def575..c1a997dc 100644 --- a/src/framework/stdext/demangle.cpp +++ b/src/framework/stdext/demangle.cpp @@ -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 } diff --git a/src/framework/stdext/math.cpp b/src/framework/stdext/math.cpp index ffc877c2..74bc0a24 100644 --- a/src/framework/stdext/math.cpp +++ b/src/framework/stdext/math.cpp @@ -66,4 +66,4 @@ double round(double r) return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5); } -} \ No newline at end of file +} diff --git a/src/framework/stdext/packed_storage.h b/src/framework/stdext/packed_storage.h index 38b26d27..45fc0791 100644 --- a/src/framework/stdext/packed_storage.h +++ b/src/framework/stdext/packed_storage.h @@ -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 void set(Key id, const T& value) { diff --git a/src/framework/stdext/packed_vector.h b/src/framework/stdext/packed_vector.h index 5b945bb7..3bb812cc 100644 --- a/src/framework/stdext/packed_vector.h +++ b/src/framework/stdext/packed_vector.h @@ -46,7 +46,7 @@ public: template 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& 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& operator=(packed_vector other) { other.swap(*this); return *this; } diff --git a/src/framework/stdext/stdext.h b/src/framework/stdext/stdext.h index 39d66931..6abe259c 100644 --- a/src/framework/stdext/stdext.h +++ b/src/framework/stdext/stdext.h @@ -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 diff --git a/src/framework/stdext/string.cpp b/src/framework/stdext/string.cpp index 8ba6f1c6..ff610959 100644 --- a/src/framework/stdext/string.cpp +++ b/src/framework/stdext/string.cpp @@ -23,7 +23,7 @@ #include "string.h" #include "format.h" #include -#include +#include #include #ifdef _MSC_VER diff --git a/src/framework/stdext/time.cpp b/src/framework/stdext/time.cpp index f6e96aaf..0f37637e 100644 --- a/src/framework/stdext/time.cpp +++ b/src/framework/stdext/time.cpp @@ -21,6 +21,7 @@ */ #include "time.h" + #include #include #include @@ -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() diff --git a/src/framework/ui/uiparticles.cpp b/src/framework/ui/uiparticles.cpp index 7b9ebaa4..8d5035d0 100644 --- a/src/framework/ui/uiparticles.cpp +++ b/src/framework/ui/uiparticles.cpp @@ -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(); } } diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index 8c0131cc..eb0efc04 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -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; diff --git a/src/framework/ui/uitextedit.h b/src/framework/ui/uitextedit.h index a2a76588..7982a9a7 100644 --- a/src/framework/ui/uitextedit.h +++ b/src/framework/ui/uitextedit.h @@ -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; } diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 15d16ead..efdc627c 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -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); diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 4d1a1348..5e412a1e 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -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); } diff --git a/src/framework/util/databuffer.h b/src/framework/util/databuffer.h index 3da6d11b..907f36f8 100644 --- a/src/framework/util/databuffer.h +++ b/src/framework/util/databuffer.h @@ -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