]> git.tdb.fi Git - libs/datafile.git/commitdiff
Use default member initializers for constant initial values
authorMikko Rasa <tdb@tdb.fi>
Sun, 31 Oct 2021 19:16:01 +0000 (21:16 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 31 Oct 2021 19:16:01 +0000 (21:16 +0200)
30 files changed:
source/argumentstore.h
source/binaryparser.cpp
source/binaryparser.h
source/binarywriter.cpp
source/binarywriter.h
source/binfloat.h
source/builtinsource.cpp
source/builtinsource.h
source/collection.cpp
source/collection.h
source/dynamicobjectloader.h
source/except.h
source/input.cpp
source/input.h
source/jsonparser.cpp
source/jsonparser.h
source/loader.cpp
source/loader.h
source/objectloader.h
source/output.cpp
source/output.h
source/packsource.cpp
source/packsource.h
source/parser.cpp
source/parser.h
source/statement.cpp
source/statement.h
source/token.h
source/writer.cpp
source/writer.h

index 5f4c9dd066159831bfa60a6a40e6e8d1ded198ae..e7a3c5594e3a60f075d7e12eee85368d70eb802b 100644 (file)
@@ -10,7 +10,7 @@ class ArgumentStore
 {
 private:
        const StatementInfo &info;
-       char *store;
+       char *store = nullptr;
 
 public:
        ArgumentStore(const StatementInfo &);
index fa1cf1daa86cd490f3d3697fbf83f5c8949a1a59..11e0badaaa5c148cd37e53659a8119114fae29d9 100644 (file)
@@ -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");
index dfb0de995c7092dd60c9ebc19d6d636b408de84b..c2f70bd8195f0dabdc23cb61a3ed43dea2113190 100644 (file)
@@ -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<unsigned> sub_remaining;
 
 public:
index 59ceffecf28b89f405af90c4e6ed559ee12f8aba..87111f00d091ecada4056e70f5c5c299190f20bc 100644 (file)
@@ -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;
index b10c5abdce2adc887f0c70bb5080eacc92efc518..4737f62cfe5e226b3d41e62f345f3e6b0de729a4 100644 (file)
@@ -19,10 +19,10 @@ private:
        typedef std::map<std::string, unsigned> 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);
index f6e6d1fb5b493a045022fefc7af2c1ecc2aec335..db3e92431823627249365d83f814b9f991a751c0 100644 (file)
@@ -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<typename T>
        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 &);
 
index 3fbc2698025fd4cc9446bffdca5d0ba82483f424..5d19fbe33f809ad0720bea25cf600df61881591a 100644 (file)
@@ -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)
index ec5396334d65282fb2065a069b72e946a52683c0..761d2dcdc2f0c3b98d3275fa7272a1a4cb73f0ab 100644 (file)
@@ -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);
        };
 
index 8e9543a0d1feef9717184c2a06d10c5e64f6f489..e1c25ddc914e6afd0f2be1b8e4ef198846c5c209 100644 (file)
@@ -7,10 +7,6 @@ using namespace std;
 namespace Msp {
 namespace DataFile {
 
-Collection::Collection():
-       fallback(nullptr)
-{ }
-
 Collection::~Collection()
 {
        for(CollectionItemTypeBase *t: types)
index db4e50a0c44211e58ff238af429102faf5185376..98a08b6757a2c3eeed121c4c262e79248d57af02 100644 (file)
@@ -89,10 +89,9 @@ private:
        std::vector<CollectionItemTypeBase *> types;
        ItemMap items;
        std::vector<const CollectionSource *> sources;
-       Collection *fallback;
+       Collection *fallback = nullptr;
 
 public:
-       Collection();
        virtual ~Collection();
 
        /** Adds an object into the collection.  The name must not pre-exist.  The
index 9706c957e7403eba40960e016d79dec1171fb8ac..be4bf8af79a93b75b95df4ec8d928cf5fa410b03 100644 (file)
@@ -30,11 +30,11 @@ protected:
 
        typedef Msp::TypeRegistry<CreateObject, DynamicObjectLoader &> 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<T, C>::shared_actions;
 
 template<typename T, typename C>
 DynamicObjectLoader<T, C>::DynamicObjectLoader(Collection *c):
-       coll(c),
-       object(nullptr),
-       obj_loader(nullptr),
-       store_func(nullptr)
+       coll(c)
 {
        set_actions(shared_actions);
 }
index 7107fe1625a856551812faa2381b597970ec511f..ceb95e30f13a6ebeaf83950f5a2fc711054699a9 100644 (file)
@@ -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 &);
index 86623ea36dd6063d94f037428f5c026b47fcf528..8aec39e4aa82ef6ad47506f84c4dbdf91eafd18a 100644 (file)
@@ -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()
index 61633458f53af02e411294822cc1d60dc2dd9d9c..6cc53e7af3674ee31fbd18bbff24e3d699830294 100644 (file)
@@ -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 &); 
index e26ce5fa2ee6116fbc5cb26d68daf865fa253e85..dcb1cf6a911343d3915598856f4e77e1747738e7 100644 (file)
@@ -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()
index 611eea0070586884750887fb809289c3e50edd98..3fda68fa92b0fb7d9e21c1083c0949654b409115 100644 (file)
@@ -18,7 +18,7 @@ private:
                STATE_END
        };
 
-       State toplevel_state;
+       State toplevel_state = STATE_INIT;
 
 public:
        JsonParser(Input &, const std::string &);
index 1ee6df3057ae9e7bad8e31cc0fb36ada2265ba0e..7e910b8a73c5d79adc63b161a2e01248edf50211 100644 (file)
@@ -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)
index 24cd7df1a503badc3b09ead5d36438e8307598d2..648c414cd2158b7d83983988f8027525b53940e6 100644 (file)
@@ -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<Loader *> aux_loaders;
 protected:
-       bool check_sub_loads;
+       bool check_sub_loads = false;
 
-       Loader();
+       Loader() = default;
 public:
        virtual ~Loader() = default;
 
index e383109f791937739c7e80e5e3d10486bc1641ff..4c5dd020b722943fdd78fdcca067a67a565f12f5 100644 (file)
@@ -63,7 +63,7 @@ public:
        typedef C Collection;
 
 protected:
-       C *coll;
+       C *coll = nullptr;
 
        CollectionObjectLoader(O &o, C *c): ObjectLoader<O>(o), coll(c) { }
 
index 5ee19115a5b0eedad79ee18ccbdcb9b9adb7b254..f4673378b69e95a7ff55baabf001606e3726a3dc 100644 (file)
@@ -7,8 +7,7 @@ namespace Msp {
 namespace DataFile {
 
 Output::Output(IO::Base &o):
-       out(&o),
-       compressed(nullptr)
+       out(&o)
 { }
 
 Output::~Output()
index bd75651d1ebaef4f0ba3108918126b1d76bda144..931c01fba091e8f36ac74d8385ee595c1b9aed29 100644 (file)
@@ -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 &);
index 4a0bb15e1a34554be1ef6668537081da716c589c..0fb64843b305edd8839a4e93bf1bb04c9c3f33de 100644 (file)
@@ -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):
index 67c14f5c15539a3d7457401625aeb9967776c80d..946e86eaa459f5dd6329cb851460e1bfad4c4aad 100644 (file)
@@ -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<File> 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<Object> objects;
 
        public:
index 7d0bb3b465d7d2f1a8c36db3826aa60bdcdc90f8..e0ad8547e84e93124e2704e851ccaceaf8615af2 100644 (file)
@@ -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=='[')
index c15fee8eb6ade6445d2f485ae5b86fe7a23f199d..ed7a037cdb12a7eeb1d49f2526a4925800921012 100644 (file)
@@ -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);
index e6b31a72b1096e71d71adf7ea24fc7db290f5cb6..57364bbd4d1563e7c0f1f5753216d1cd7e1cacf5 100644 (file)
@@ -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)
index cd1797c4551d7c702347f91ba6631da8d06c2c7a..f20bf119d0fa07e1886e88e7e1b45b6b3841ac85 100644 (file)
@@ -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<Statement> 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<unsigned> arg_offsets;
 
-       StatementInfo();
+       StatementInfo() = default;
        StatementInfo(const std::string &, const std::string &);
 };
 
index b0d2655f5af5ffbb8f82f3e95e9994b390c47c25..cbf5882f605fd17b3c88913402c683b7c3e504ae 100644 (file)
@@ -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) { }
 };
 
index ff4f2248bee7e7d3035c3a4174e44a52251d2450..bb3ff5e9a413cae4eeff64748d0257aacc357b29 100644 (file)
@@ -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()
index 241ea9a9d460a598c46a5a5a7e32b3329b8a060c..5f32786f443b443f15c33d996ed070d10fb0461d 100644 (file)
@@ -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);