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

C++11 cleanup on constructors (#6000)

* C++11 cleanup on constructors dir script
This commit is contained in:
Vincent Glize 2017-06-19 23:54:58 +02:00 committed by Loïc Blot
parent 4a78949083
commit 4a5e8ad343
40 changed files with 117 additions and 180 deletions

View file

@ -58,7 +58,7 @@ const Area *AreaStore::getArea(u32 id) const
{
AreaMap::const_iterator it = areas_map.find(id);
if (it == areas_map.end())
return NULL;
return nullptr;
return &it->second;
}
@ -239,7 +239,7 @@ bool SpatialAreaStore::insertArea(Area *a)
if (!areas_map.insert(std::make_pair(a->id, *a)).second)
// ID is not unique
return false;
m_tree->insertData(0, NULL, get_spatial_region(a->minedge, a->maxedge), a->id);
m_tree->insertData(0, nullptr, get_spatial_region(a->minedge, a->maxedge), a->id);
invalidateCache();
return true;
}

View file

@ -38,14 +38,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct Area {
Area() : id(U32_MAX) {}
Area() {}
Area(const v3s16 &mine, const v3s16 &maxe) :
id(U32_MAX), minedge(mine), maxedge(maxe)
minedge(mine), maxedge(maxe)
{
sortBoxVerticies(minedge, maxedge);
}
u32 id;
u32 id = U32_MAX;
v3s16 minedge, maxedge;
std::string data;
};
@ -54,10 +54,7 @@ struct Area {
class AreaStore {
public:
AreaStore() :
m_cache_enabled(true),
m_cacheblock_radius(64),
m_res_cache(1000, &cacheMiss, this),
m_next_id(0)
m_res_cache(1000, &cacheMiss, this)
{}
virtual ~AreaStore() {}
@ -123,13 +120,13 @@ private:
/// Called by the cache when a value isn't found in the cache.
static void cacheMiss(void *data, const v3s16 &mpos, std::vector<Area *> *dest);
bool m_cache_enabled;
bool m_cache_enabled = true;
/// Range, in nodes, of the getAreasForPos cache.
/// If you modify this, call invalidateCache()
u8 m_cacheblock_radius;
u8 m_cacheblock_radius = 64;
LRUCache<v3s16, std::vector<Area *> > m_res_cache;
u32 m_next_id;
u32 m_next_id = 0;
};
@ -165,8 +162,8 @@ protected:
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos);
private:
SpatialIndex::ISpatialIndex *m_tree;
SpatialIndex::IStorageManager *m_storagemanager;
SpatialIndex::ISpatialIndex *m_tree = nullptr;
SpatialIndex::IStorageManager *m_storagemanager = nullptr;
class VectorResultVisitor : public SpatialIndex::IVisitor {
public:
@ -194,8 +191,8 @@ private:
}
private:
SpatialAreaStore *m_store;
std::vector<Area *> *m_result;
SpatialAreaStore *m_store = nullptr;
std::vector<Area *> *m_result = nullptr;
};
};

View file

@ -71,7 +71,7 @@ std::string generate_srp_verifier(const std::string &name,
// get modified if &salt_ptr isn't NULL.
char *salt_ptr = (char *)salt.c_str();
char *bytes_v = NULL;
char *bytes_v = nullptr;
size_t verifier_len = 0;
gen_srp_v(name, password, &salt_ptr, &salt_len, &bytes_v, &verifier_len);
std::string verifier = std::string(bytes_v, verifier_len);
@ -84,9 +84,9 @@ void generate_srp_verifier_and_salt(const std::string &name,
const std::string &password, std::string *verifier,
std::string *salt)
{
char *bytes_v = NULL;
char *bytes_v = nullptr;
size_t verifier_len;
char *salt_ptr = NULL;
char *salt_ptr = nullptr;
size_t salt_len;
gen_srp_v(name, password, &salt_ptr, &salt_len, &bytes_v, &verifier_len);
*verifier = std::string(bytes_v, verifier_len);

View file

@ -30,8 +30,7 @@ EnrichedString::EnrichedString()
EnrichedString::EnrichedString(const std::wstring &string,
const std::vector<SColor> &colors):
m_string(string),
m_colors(colors),
m_has_background(false)
m_colors(colors)
{}
EnrichedString::EnrichedString(const std::wstring &s, const SColor &color)

View file

@ -84,7 +84,7 @@ public:
private:
std::wstring m_string;
std::vector<irr::video::SColor> m_colors;
bool m_has_background;
bool m_has_background = false;
irr::video::SColor m_background;
};

View file

@ -282,7 +282,7 @@ inline aabb3f getNodeBox(v3s16 p, float d)
class IntervalLimiter
{
public:
IntervalLimiter() : m_accumulator(0) {}
IntervalLimiter() {}
/*
dtime: time from last call to this method
wanted_interval: interval wanted
@ -300,7 +300,7 @@ public:
}
private:
float m_accumulator;
float m_accumulator = 0.0f;
};

View file

@ -23,16 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "../exceptions.h"
#include <sstream>
PointedThing::PointedThing():
type(POINTEDTHING_NOTHING),
node_undersurface(0,0,0),
node_abovesurface(0,0,0),
node_real_undersurface(0,0,0),
intersection_point(0,0,0),
intersection_normal(0,0,0),
object_id(-1)
{}
std::string PointedThing::dump() const
{
std::ostringstream os(std::ios::binary);

View file

@ -36,7 +36,7 @@ enum PointedThingType
struct PointedThing
{
//! The type of the pointed object.
PointedThingType type;
PointedThingType type = POINTEDTHING_NOTHING;
/*!
* Only valid if type is POINTEDTHING_NODE.
* The coordinates of the node which owns the
@ -74,9 +74,9 @@ struct PointedThing
* Only valid if type is POINTEDTHING_OBJECT.
* The ID of the object the ray hit.
*/
s16 object_id;
s16 object_id = -1;
PointedThing();
PointedThing() {};
std::string dump() const;
void serialize(std::ostream &os) const;
void deSerialize(std::istream &is);

View file

@ -422,7 +422,7 @@ bool deSerializeStringToStruct(std::string valstr,
char *fmtpos, *fmt = &format[0];
while ((f = strtok_r(fmt, ",", &fmtpos)) && s) {
fmt = NULL;
fmt = nullptr;
bool is_unsigned = false;
int width = 0;
@ -510,7 +510,7 @@ bool deSerializeStringToStruct(std::string valstr,
bufpos += sizeof(std::string *);
strs_alloced.push_back(str);
s = *snext ? snext + 1 : NULL;
s = *snext ? snext + 1 : nullptr;
break;
case 'v':
while (*s == ' ' || *s == '\t')
@ -582,7 +582,7 @@ bool serializeStructToString(std::string *out,
char *bufpos = (char *) value;
char *fmtpos, *fmt = &format[0];
while ((f = strtok_r(fmt, ",", &fmtpos))) {
fmt = NULL;
fmt = nullptr;
bool is_unsigned = false;
int width = 0;
char valtype = *f;

View file

@ -454,8 +454,7 @@ class BufReader {
public:
BufReader(const u8 *data_, size_t size_) :
data(data_),
size(size_),
pos(0)
size(size_)
{
}
@ -515,7 +514,7 @@ public:
const u8 *data;
size_t size;
size_t pos;
size_t pos = 0;
};
#undef MAKE_BUFREADER_GET_FXN

View file

@ -66,15 +66,6 @@ SHA1::SHA1()
{
// make sure that the data type is the right size
assert( sizeof( Uint32 ) * 5 == 20 );
// initialize
H0 = 0x67452301;
H1 = 0xefcdab89;
H2 = 0x98badcfe;
H3 = 0x10325476;
H4 = 0xc3d2e1f0;
unprocessedBytes = 0;
size = 0;
}
// Destructor ********************************************************

View file

@ -31,10 +31,14 @@ class SHA1
{
private:
// fields
Uint32 H0, H1, H2, H3, H4;
Uint32 H0 = 0x67452301;
Uint32 H1 = 0xefcdab89;
Uint32 H2 = 0x98badcfe;
Uint32 H3 = 0x10325476;
Uint32 H4 = 0xc3d2e1f0;
unsigned char bytes[64];
int unprocessedBytes;
Uint32 size;
int unprocessedBytes = 0;
Uint32 size = 0;
void process();
public:

View file

@ -27,7 +27,6 @@ TimeTaker::TimeTaker(const std::string &name, u64 *result, TimePrecision prec)
{
m_name = name;
m_result = result;
m_running = true;
m_precision = prec;
m_time1 = porting::getTime(prec);
}
@ -36,7 +35,7 @@ u64 TimeTaker::stop(bool quiet)
{
if (m_running) {
u64 dtime = porting::getTime(m_precision) - m_time1;
if (m_result != NULL) {
if (m_result != nullptr) {
(*m_result) += dtime;
} else {
if (!quiet) {

View file

@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class TimeTaker
{
public:
TimeTaker(const std::string &name, u64 *result=NULL,
TimeTaker(const std::string &name, u64 *result=nullptr,
TimePrecision prec=PRECISION_MILLI);
~TimeTaker()
@ -45,9 +45,9 @@ public:
private:
std::string m_name;
u64 m_time1;
bool m_running;
bool m_running = true;
TimePrecision m_precision;
u64 *m_result;
u64 *m_result = nullptr;
};
#endif