1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Modernize source code: last part (#6285)

* Modernize source code: last par

* Use empty when needed
* Use emplace_back instead of push_back when needed
* For range-based loops
* Initializers fixes
* constructors, destructors default
* c++ C stl includes
This commit is contained in:
Loïc Blot 2017-08-20 13:30:50 +02:00 committed by GitHub
parent 50669cd282
commit 1c1c97cbd1
72 changed files with 446 additions and 584 deletions

View file

@ -68,9 +68,8 @@ void AreaStore::serialize(std::ostream &os) const
// TODO: Compression?
writeU16(os, areas_map.size());
for (AreaMap::const_iterator it = areas_map.begin();
it != areas_map.end(); ++it) {
const Area &a = it->second;
for (const auto &it : areas_map) {
const Area &a = it.second;
writeV3S16(os, a.minedge);
writeV3S16(os, a.maxedge);
writeU16(os, a.data.size());
@ -193,10 +192,9 @@ bool VectorAreaStore::removeArea(u32 id)
void VectorAreaStore::getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos)
{
for (size_t i = 0; i < m_areas.size(); ++i) {
Area *b = m_areas[i];
if (AST_CONTAINS_PT(b, pos)) {
result->push_back(b);
for (Area *area : m_areas) {
if (AST_CONTAINS_PT(area, pos)) {
result->push_back(area);
}
}
}
@ -204,11 +202,10 @@ void VectorAreaStore::getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos)
void VectorAreaStore::getAreasInArea(std::vector<Area *> *result,
v3s16 minedge, v3s16 maxedge, bool accept_overlap)
{
for (size_t i = 0; i < m_areas.size(); ++i) {
Area *b = m_areas[i];
if (accept_overlap ? AST_AREAS_OVERLAP(minedge, maxedge, b) :
AST_CONTAINS_AREA(minedge, maxedge, b)) {
result->push_back(b);
for (Area *area : m_areas) {
if (accept_overlap ? AST_AREAS_OVERLAP(minedge, maxedge, area) :
AST_CONTAINS_AREA(minedge, maxedge, area)) {
result->push_back(area);
}
}
}

View file

@ -37,7 +37,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct Area {
Area() {}
Area() = default;
Area(const v3s16 &mine, const v3s16 &maxe) :
minedge(mine), maxedge(maxe)
{
@ -56,7 +57,7 @@ public:
m_res_cache(1000, &cacheMiss, this)
{}
virtual ~AreaStore() {}
virtual ~AreaStore() = default;
static AreaStore *getOptimalImplementation();

View file

@ -97,7 +97,6 @@ void EnrichedString::addAtEnd(const std::wstring &s, const SColor &initial_color
parseColorString(wide_to_utf8(parts[1]), m_background, true);
m_has_background = true;
}
continue;
}
}
@ -111,7 +110,7 @@ void EnrichedString::addCharNoColor(wchar_t c)
{
m_string += c;
if (m_colors.empty()) {
m_colors.push_back(SColor(255, 255, 255, 255));
m_colors.emplace_back(255, 255, 255, 255);
} else {
m_colors.push_back(m_colors[m_colors.size() - 1]);
}
@ -138,15 +137,16 @@ EnrichedString EnrichedString::substr(size_t pos, size_t len) const
}
if (len == std::string::npos || pos + len > m_string.length()) {
return EnrichedString(
m_string.substr(pos, std::string::npos),
std::vector<SColor>(m_colors.begin() + pos, m_colors.end())
);
} else {
return EnrichedString(
m_string.substr(pos, len),
std::vector<SColor>(m_colors.begin() + pos, m_colors.begin() + pos + len)
);
m_string.substr(pos, std::string::npos),
std::vector<SColor>(m_colors.begin() + pos, m_colors.end())
);
}
return EnrichedString(
m_string.substr(pos, len),
std::vector<SColor>(m_colors.begin() + pos, m_colors.begin() + pos + len)
);
}
const wchar_t *EnrichedString::c_str() const

View file

@ -281,7 +281,8 @@ inline aabb3f getNodeBox(v3s16 p, float d)
class IntervalLimiter
{
public:
IntervalLimiter() {}
IntervalLimiter() = default;
/*
dtime: time from last call to this method
wanted_interval: interval wanted

View file

@ -697,7 +697,7 @@ struct SRPVerifier *srp_verifier_new(SRP_HashAlgorithm alg,
goto cleanup_and_exit;
}
memcpy((char *)ver->username, username, ulen);
memcpy(ver->username, username, ulen);
ver->authenticated = 0;

View file

@ -167,7 +167,7 @@ std::string wide_to_utf8(const std::wstring &input)
wchar_t *utf8_to_wide_c(const char *str)
{
std::wstring ret = utf8_to_wide(std::string(str)).c_str();
std::wstring ret = utf8_to_wide(std::string(str));
size_t len = ret.length();
wchar_t *ret_c = new wchar_t[len + 1];
memset(ret_c, 0, (len + 1) * sizeof(wchar_t));
@ -308,8 +308,8 @@ std::string wide_to_narrow(const std::wstring &wcs)
size_t len = wcstombs(*mbs, wcs.c_str(), mbl);
if (len == (size_t)(-1))
return "Character conversion failed!";
else
mbs[len] = 0;
mbs[len] = 0;
return *mbs;
}
@ -321,8 +321,7 @@ std::string urlencode(const std::string &str)
// followed by two hex digits. See RFC 3986, section 2.3.
static const char url_hex_chars[] = "0123456789ABCDEF";
std::ostringstream oss(std::ios::binary);
for (u32 i = 0; i < str.size(); i++) {
unsigned char c = str[i];
for (unsigned char c : str) {
if (isalnum(c) || c == '-' || c == '.' || c == '_' || c == '~') {
oss << c;
} else {

View file

@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "irrlichttypes_bloated.h"
#include <stdlib.h>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
@ -231,12 +231,12 @@ inline std::vector<std::basic_string<T> > str_split(
*/
inline std::string lowercase(const std::string &str)
{
std::string s2 = "";
std::string s2;
s2.reserve(str.size());
for (size_t i = 0; i < str.size(); i++)
s2 += tolower(str[i]);
for (char i : str)
s2 += tolower(i);
return s2;
}
@ -607,8 +607,8 @@ std::vector<std::basic_string<T> > split(const std::basic_string<T> &s, T delim)
*/
inline bool is_number(const std::string &to_check)
{
for (size_t i = 0; i < to_check.size(); i++)
if (!std::isdigit(to_check[i]))
for (char i : to_check)
if (!std::isdigit(i))
return false;
return !to_check.empty();