diff options
author | Vincent Glize <vincentglize@hotmail.fr> | 2017-06-19 23:54:58 +0200 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-06-19 23:54:58 +0200 |
commit | 4a5e8ad343079f6552fab639770e5771ed7c4e7a (patch) | |
tree | eeab3adec1fc3e7a3b06d9f53b92ab99a5e0d290 /src/util | |
parent | 4a789490834157baa8788a2f36c95b86c1e4440e (diff) | |
download | minetest-4a5e8ad343079f6552fab639770e5771ed7c4e7a.tar.gz minetest-4a5e8ad343079f6552fab639770e5771ed7c4e7a.tar.bz2 minetest-4a5e8ad343079f6552fab639770e5771ed7c4e7a.zip |
C++11 cleanup on constructors (#6000)
* C++11 cleanup on constructors dir script
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/areastore.cpp | 4 | ||||
-rw-r--r-- | src/util/areastore.h | 25 | ||||
-rw-r--r-- | src/util/auth.cpp | 6 | ||||
-rw-r--r-- | src/util/enriched_string.cpp | 3 | ||||
-rw-r--r-- | src/util/enriched_string.h | 2 | ||||
-rw-r--r-- | src/util/numeric.h | 4 | ||||
-rw-r--r-- | src/util/pointedthing.cpp | 10 | ||||
-rw-r--r-- | src/util/pointedthing.h | 6 | ||||
-rw-r--r-- | src/util/serialize.cpp | 6 | ||||
-rw-r--r-- | src/util/serialize.h | 5 | ||||
-rw-r--r-- | src/util/sha1.cpp | 9 | ||||
-rw-r--r-- | src/util/sha1.h | 10 | ||||
-rw-r--r-- | src/util/timetaker.cpp | 3 | ||||
-rw-r--r-- | src/util/timetaker.h | 6 |
14 files changed, 39 insertions, 60 deletions
diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp index cef67da2c..c660502f6 100644 --- a/src/util/areastore.cpp +++ b/src/util/areastore.cpp @@ -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; } diff --git a/src/util/areastore.h b/src/util/areastore.h index bebecfd78..8c22c3ad7 100644 --- a/src/util/areastore.h +++ b/src/util/areastore.h @@ -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; }; }; diff --git a/src/util/auth.cpp b/src/util/auth.cpp index 912987259..c329e36e6 100644 --- a/src/util/auth.cpp +++ b/src/util/auth.cpp @@ -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); diff --git a/src/util/enriched_string.cpp b/src/util/enriched_string.cpp index a7fc3a828..05d7b8c25 100644 --- a/src/util/enriched_string.cpp +++ b/src/util/enriched_string.cpp @@ -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) diff --git a/src/util/enriched_string.h b/src/util/enriched_string.h index 1aca8948a..a3b8feb2a 100644 --- a/src/util/enriched_string.h +++ b/src/util/enriched_string.h @@ -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; }; diff --git a/src/util/numeric.h b/src/util/numeric.h index 3b1b85f64..5143c92e6 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -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; }; diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index ed3d4bb67..f1f1d3f20 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -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); diff --git a/src/util/pointedthing.h b/src/util/pointedthing.h index f695a4ebd..92c33968f 100644 --- a/src/util/pointedthing.h +++ b/src/util/pointedthing.h @@ -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); diff --git a/src/util/serialize.cpp b/src/util/serialize.cpp index 61d369bc4..75843cb1b 100644 --- a/src/util/serialize.cpp +++ b/src/util/serialize.cpp @@ -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; diff --git a/src/util/serialize.h b/src/util/serialize.h index e22434191..f43480557 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -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 diff --git a/src/util/sha1.cpp b/src/util/sha1.cpp index 6ed7385d5..c04b6c0c0 100644 --- a/src/util/sha1.cpp +++ b/src/util/sha1.cpp @@ -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 ******************************************************** diff --git a/src/util/sha1.h b/src/util/sha1.h index 0ac08c67b..a55f94f44 100644 --- a/src/util/sha1.h +++ b/src/util/sha1.h @@ -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: diff --git a/src/util/timetaker.cpp b/src/util/timetaker.cpp index ac686c3a3..6079e5cca 100644 --- a/src/util/timetaker.cpp +++ b/src/util/timetaker.cpp @@ -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) { diff --git a/src/util/timetaker.h b/src/util/timetaker.h index c10f4f535..34564ee4b 100644 --- a/src/util/timetaker.h +++ b/src/util/timetaker.h @@ -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 |