From e14c01b5775dd2e324b16ff49498db9b9113c523 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 31 Oct 2021 21:16:01 +0200 Subject: [PATCH] Use default member initializers for constant initial values --- source/argumentstore.h | 2 +- source/binaryparser.cpp | 4 +--- source/binaryparser.h | 4 ++-- source/binarywriter.cpp | 5 +---- source/binarywriter.h | 6 +++--- source/binfloat.h | 12 ++++++------ source/builtinsource.cpp | 5 ----- source/builtinsource.h | 6 +++--- source/collection.cpp | 4 ---- source/collection.h | 3 +-- source/dynamicobjectloader.h | 13 +++++-------- source/except.h | 2 +- source/input.cpp | 5 +---- source/input.h | 8 ++++---- source/jsonparser.cpp | 3 +-- source/jsonparser.h | 2 +- source/loader.cpp | 7 ------- source/loader.h | 16 ++++++++-------- source/objectloader.h | 2 +- source/output.cpp | 3 +-- source/output.h | 4 ++-- source/packsource.cpp | 8 ++------ source/packsource.h | 12 ++++++------ source/parser.cpp | 3 +-- source/parser.h | 4 ++-- source/statement.cpp | 13 +------------ source/statement.h | 12 ++++++------ source/token.h | 4 ++-- source/writer.cpp | 3 +-- source/writer.h | 4 ++-- 30 files changed, 66 insertions(+), 113 deletions(-) diff --git a/source/argumentstore.h b/source/argumentstore.h index 5f4c9dd..e7a3c55 100644 --- a/source/argumentstore.h +++ b/source/argumentstore.h @@ -10,7 +10,7 @@ class ArgumentStore { private: const StatementInfo &info; - char *store; + char *store = nullptr; public: ArgumentStore(const StatementInfo &); diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index fa1cf1d..11e0bad 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -14,9 +14,7 @@ namespace Msp { namespace DataFile { BinaryParser::BinaryParser(Input &i, const string &s): - ParserMode(i, s), - float_precision(32), - cur_info(nullptr) + ParserMode(i, s) { dict[-1] = StatementInfo("__kwd", "iss"); dict[-2] = StatementInfo("__str", "is"); diff --git a/source/binaryparser.h b/source/binaryparser.h index dfb0de9..c2f70bd 100644 --- a/source/binaryparser.h +++ b/source/binaryparser.h @@ -19,8 +19,8 @@ private: Dictionary dict; StringMap strings; - unsigned float_precision; - StatementInfo *cur_info; + unsigned float_precision = 32; + StatementInfo *cur_info = nullptr; std::vector sub_remaining; public: diff --git a/source/binarywriter.cpp b/source/binarywriter.cpp index 59ceffe..87111f0 100644 --- a/source/binarywriter.cpp +++ b/source/binarywriter.cpp @@ -11,10 +11,7 @@ namespace Msp { namespace DataFile { BinaryWriter::BinaryWriter(Output &o): - WriterMode(o), - next_kwd_id(1), - next_str_id(1), - float_precision(32) + WriterMode(o) { dict[StatementKey("__kwd", "iss")] = -1; dict[StatementKey("__str", "is")] = -2; diff --git a/source/binarywriter.h b/source/binarywriter.h index b10c5ab..4737f62 100644 --- a/source/binarywriter.h +++ b/source/binarywriter.h @@ -19,10 +19,10 @@ private: typedef std::map StringMap; Dictionary dict; - unsigned next_kwd_id; + unsigned next_kwd_id = 1; StringMap strings; - unsigned next_str_id; - unsigned float_precision; + unsigned next_str_id = 1; + unsigned float_precision = 32; public: BinaryWriter(Output &o); diff --git a/source/binfloat.h b/source/binfloat.h index f6e6d1f..db3e924 100644 --- a/source/binfloat.h +++ b/source/binfloat.h @@ -20,8 +20,8 @@ struct BinFloat { struct Bits { - unsigned exponent; - unsigned mantissa; + unsigned exponent = 8; + unsigned mantissa = 23; Bits(unsigned); }; @@ -29,10 +29,10 @@ struct BinFloat template struct MatchingInt; - bool sign; - bool infinity; - int exponent; - std::uint64_t mantissa; + bool sign = false; + bool infinity = false; + int exponent = 0; + std::uint64_t mantissa = 0; static BinFloat explode(std::uint64_t, const Bits &); diff --git a/source/builtinsource.cpp b/source/builtinsource.cpp index 3fbc269..5d19fbe 100644 --- a/source/builtinsource.cpp +++ b/source/builtinsource.cpp @@ -53,11 +53,6 @@ IO::Seekable *BuiltinSource::open(const string &name) const } -BuiltinSource::Object::Object(): - data(nullptr), - size(0) -{ } - BuiltinSource::Object::Object(const char *d, unsigned s): data(d), size(s) diff --git a/source/builtinsource.h b/source/builtinsource.h index ec53963..761d2dc 100644 --- a/source/builtinsource.h +++ b/source/builtinsource.h @@ -11,10 +11,10 @@ class BuiltinSource: public CollectionSource private: struct Object { - const char *data; - unsigned size; + const char *data = nullptr; + unsigned size = 0; - Object(); + Object() = default; Object(const char *, unsigned); }; diff --git a/source/collection.cpp b/source/collection.cpp index 8e9543a..e1c25dd 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -7,10 +7,6 @@ using namespace std; namespace Msp { namespace DataFile { -Collection::Collection(): - fallback(nullptr) -{ } - Collection::~Collection() { for(CollectionItemTypeBase *t: types) diff --git a/source/collection.h b/source/collection.h index db4e50a..98a08b6 100644 --- a/source/collection.h +++ b/source/collection.h @@ -89,10 +89,9 @@ private: std::vector types; ItemMap items; std::vector sources; - Collection *fallback; + Collection *fallback = nullptr; public: - Collection(); virtual ~Collection(); /** Adds an object into the collection. The name must not pre-exist. The diff --git a/source/dynamicobjectloader.h b/source/dynamicobjectloader.h index 9706c95..be4bf8a 100644 --- a/source/dynamicobjectloader.h +++ b/source/dynamicobjectloader.h @@ -30,11 +30,11 @@ protected: typedef Msp::TypeRegistry TypeRegistry; - Collection *coll; - T *object; + Collection *coll = nullptr; + T *object = nullptr; private: - Loader *obj_loader; - void (*store_func)(Collection &, const std::string &, T *); + Loader *obj_loader = nullptr; + void (*store_func)(Collection &, const std::string &, T *) = nullptr; static ActionMap shared_actions; @@ -70,10 +70,7 @@ Loader::ActionMap DynamicObjectLoader::shared_actions; template DynamicObjectLoader::DynamicObjectLoader(Collection *c): - coll(c), - object(nullptr), - obj_loader(nullptr), - store_func(nullptr) + coll(c) { set_actions(shared_actions); } diff --git a/source/except.h b/source/except.h index 7107fe1..ceb95e3 100644 --- a/source/except.h +++ b/source/except.h @@ -12,7 +12,7 @@ class data_error: public std::runtime_error { private: std::string source; - unsigned line; + unsigned line = 0; public: data_error(const std::string &, unsigned, const std::string &); diff --git a/source/input.cpp b/source/input.cpp index 86623ea..8aec39e 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -5,10 +5,7 @@ namespace Msp { namespace DataFile { Input::Input(IO::Base &i): - in(&i), - compressed(nullptr), - line(1), - next(-1) + in(&i) { } Input::~Input() diff --git a/source/input.h b/source/input.h index 6163345..6cc53e7 100644 --- a/source/input.h +++ b/source/input.h @@ -10,10 +10,10 @@ namespace DataFile { class Input: private NonCopyable { private: - IO::Base *in; - IO::Base *compressed; - unsigned line; - int next; + IO::Base *in = nullptr; + IO::Base *compressed = nullptr; + unsigned line = 1; + int next = -1; public: Input(IO::Base &); diff --git a/source/jsonparser.cpp b/source/jsonparser.cpp index e26ce5f..dcb1cf6 100644 --- a/source/jsonparser.cpp +++ b/source/jsonparser.cpp @@ -9,8 +9,7 @@ namespace Msp { namespace DataFile { JsonParser::JsonParser(Input &i, const string &s): - ParserMode(i, s), - toplevel_state(STATE_INIT) + ParserMode(i, s) { } Statement JsonParser::parse() diff --git a/source/jsonparser.h b/source/jsonparser.h index 611eea0..3fda68f 100644 --- a/source/jsonparser.h +++ b/source/jsonparser.h @@ -18,7 +18,7 @@ private: STATE_END }; - State toplevel_state; + State toplevel_state = STATE_INIT; public: JsonParser(Input &, const std::string &); diff --git a/source/loader.cpp b/source/loader.cpp index 1ee6df3..7e910b8 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -47,13 +47,6 @@ int signature_match(const string &st_sig, const string &act_sig) namespace Msp { namespace DataFile { -Loader::Loader(): - actions(nullptr), - cur_st(nullptr), - direct(false), - check_sub_loads(false) -{ } - void Loader::load(Parser &p) { if(!actions) diff --git a/source/loader.h b/source/loader.h index 24cd7df..648c414 100644 --- a/source/loader.h +++ b/source/loader.h @@ -45,17 +45,17 @@ protected: private: ActionMap local_actions; - ActionMap *actions; - Parser *cur_parser; - unsigned cur_level; - const Statement *cur_st; - bool sub_loaded; - bool direct; + ActionMap *actions = nullptr; + Parser *cur_parser = nullptr; + unsigned cur_level = 0; + const Statement *cur_st = nullptr; + bool sub_loaded = false; + bool direct = false; std::vector aux_loaders; protected: - bool check_sub_loads; + bool check_sub_loads = false; - Loader(); + Loader() = default; public: virtual ~Loader() = default; diff --git a/source/objectloader.h b/source/objectloader.h index e383109..4c5dd02 100644 --- a/source/objectloader.h +++ b/source/objectloader.h @@ -63,7 +63,7 @@ public: typedef C Collection; protected: - C *coll; + C *coll = nullptr; CollectionObjectLoader(O &o, C *c): ObjectLoader(o), coll(c) { } diff --git a/source/output.cpp b/source/output.cpp index 5ee1911..f467337 100644 --- a/source/output.cpp +++ b/source/output.cpp @@ -7,8 +7,7 @@ namespace Msp { namespace DataFile { Output::Output(IO::Base &o): - out(&o), - compressed(nullptr) + out(&o) { } Output::~Output() diff --git a/source/output.h b/source/output.h index bd75651..931c01f 100644 --- a/source/output.h +++ b/source/output.h @@ -10,8 +10,8 @@ namespace DataFile { class Output: private NonCopyable { private: - IO::Base *out; - IO::Base *compressed; + IO::Base *out = nullptr; + IO::Base *compressed = nullptr; public: Output(IO::Base &); diff --git a/source/packsource.cpp b/source/packsource.cpp index 4a0bb15..0fb6484 100644 --- a/source/packsource.cpp +++ b/source/packsource.cpp @@ -161,8 +161,7 @@ IO::Seekable *PackSource::open(const string &fn) const PackSource::Pack::Pack(IO::Seekable *i, const string &fn): filename(fn), - io(i), - base_offset(0) + io(i) { } PackSource::Pack::Pack(const Pack &other): @@ -203,10 +202,7 @@ void PackSource::Pack::translate_files(FileMap &fm, const Pack &source) const PackSource::File::File(const Pack &p, const string &fn): pack(p), - filename(fn), - offset(0), - length(0), - collection(false) + filename(fn) { } PackSource::File::File(const File &other, const Pack &p): diff --git a/source/packsource.h b/source/packsource.h index 67c14f5..946e86e 100644 --- a/source/packsource.h +++ b/source/packsource.h @@ -26,7 +26,7 @@ public: struct FileInfo { std::string name; - IO::SeekOffset size; + IO::SeekOffset size = 0; }; private: @@ -49,8 +49,8 @@ private: private: std::string filename; - IO::Seekable *io; - IO::SeekOffset base_offset; + IO::Seekable *io = nullptr; + IO::SeekOffset base_offset = 0; std::list files; public: @@ -80,9 +80,9 @@ private: private: const Pack &pack; std::string filename; - IO::SeekOffset offset; - IO::SeekOffset length; - bool collection; + IO::SeekOffset offset = 0; + IO::SeekOffset length = 0; + bool collection = false; std::list objects; public: diff --git a/source/parser.cpp b/source/parser.cpp index 7d0bb3b..e0ad854 100644 --- a/source/parser.cpp +++ b/source/parser.cpp @@ -14,8 +14,7 @@ namespace DataFile { Parser::Parser(IO::Base &i, const string &s): in(i), main_src(s), - src(s), - good(true) + src(s) { char c = in.peek(); if(c=='{' || c=='[') diff --git a/source/parser.h b/source/parser.h index c15fee8..ed7a037 100644 --- a/source/parser.h +++ b/source/parser.h @@ -25,8 +25,8 @@ private: Input in; std::string main_src; std::string src; - bool good; - ParserMode *mode; + bool good = true; + ParserMode *mode = nullptr; public: Parser(IO::Base &i, const std::string &s); diff --git a/source/statement.cpp b/source/statement.cpp index e6b31a7..57364bb 100644 --- a/source/statement.cpp +++ b/source/statement.cpp @@ -8,17 +8,10 @@ using namespace std; namespace Msp { namespace DataFile { -Statement::Statement(): - valid(false), - control(false), - line(0) -{ } - Statement::Statement(const string &kw): keyword(kw), valid(true), - control(!kw.compare(0, 2, "__")), - line(0) + control(!kw.compare(0, 2, "__")) { } string Statement::get_location() const @@ -59,10 +52,6 @@ Statement &Statement::append_from_token(const Token &token) } -StatementInfo::StatementInfo(): - args_size(0) -{ } - StatementInfo::StatementInfo(const string &k, const string &s): key(k, s), args_size(0) diff --git a/source/statement.h b/source/statement.h index cd1797c..f20bf11 100644 --- a/source/statement.h +++ b/source/statement.h @@ -15,13 +15,13 @@ struct Statement std::string keyword; Arguments args; - bool valid; - bool control; + bool valid = false; + bool control = false; std::string source; - unsigned line; + unsigned line = 0; std::list sub; - Statement(); + Statement() = default; Statement(const std::string &); std::string get_location() const; std::string get_signature() const; @@ -55,10 +55,10 @@ struct StatementKey struct StatementInfo { StatementKey key; - unsigned args_size; + unsigned args_size = 0; std::vector arg_offsets; - StatementInfo(); + StatementInfo() = default; StatementInfo(const std::string &, const std::string &); }; diff --git a/source/token.h b/source/token.h index b0d2655..cbf5882 100644 --- a/source/token.h +++ b/source/token.h @@ -17,10 +17,10 @@ struct Token SPECIAL }; - Type type; + Type type = SPECIAL; std::string str; - Token(): type(SPECIAL) { } + Token() = default; Token(Type t, const std::string &s): type(t), str(s) { } }; diff --git a/source/writer.cpp b/source/writer.cpp index ff4f224..bb3ff5e 100644 --- a/source/writer.cpp +++ b/source/writer.cpp @@ -11,8 +11,7 @@ namespace DataFile { Writer::Writer(IO::Base &o): out(o), - mode(new TextWriter(out)), - binary(false) + mode(new TextWriter(out)) { } Writer::~Writer() diff --git a/source/writer.h b/source/writer.h index 241ea9a..5f32786 100644 --- a/source/writer.h +++ b/source/writer.h @@ -19,8 +19,8 @@ class Writer: private NonCopyable { private: Output out; - WriterMode *mode; - bool binary; + WriterMode *mode = nullptr; + bool binary = false; public: Writer(IO::Base &o); -- 2.43.0