From: Mikko Rasa Date: Sun, 31 Oct 2021 22:50:40 +0000 (+0200) Subject: Use the override specifier to mark overridden virtual functions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d8bda96a0aac09774bb1e2a8b57ac2e48a93b3c1;p=libs%2Fdatafile.git Use the override specifier to mark overridden virtual functions --- diff --git a/source/binaryparser.h b/source/binaryparser.h index c2f70bd..f6226a1 100644 --- a/source/binaryparser.h +++ b/source/binaryparser.h @@ -26,11 +26,11 @@ private: public: BinaryParser(Input &i, const std::string &s); - virtual Statement parse(); - virtual void process_control_statement(const Statement &); + Statement parse() override; + void process_control_statement(const Statement &) override; - virtual const StatementKey *peek(unsigned); - virtual bool parse_and_load(unsigned, Loader &, const LoaderAction &); + const StatementKey *peek(unsigned) override; + bool parse_and_load(unsigned, Loader &, const LoaderAction &) override; private: IntType::Store parse_int(); diff --git a/source/binarywriter.h b/source/binarywriter.h index 4737f62..dafc7eb 100644 --- a/source/binarywriter.h +++ b/source/binarywriter.h @@ -27,8 +27,8 @@ private: public: BinaryWriter(Output &o); - virtual void set_float_precision(unsigned); - virtual void write(const Statement &st); + void set_float_precision(unsigned) override; + void write(const Statement &st) override; private: void write_(const Statement &st); void collect_keywords(const Statement &st); diff --git a/source/builtinsource.h b/source/builtinsource.h index 761d2dc..8278508 100644 --- a/source/builtinsource.h +++ b/source/builtinsource.h @@ -24,10 +24,10 @@ public: void add_object(const std::string &, const char *, unsigned); void add_object(const std::string &, const char *); - virtual bool is_loadable(const CollectionItemTypeBase &, const std::string &) const; - virtual NameList get_names(const CollectionItemTypeBase &) const; - virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const; - virtual IO::Seekable *open(const std::string &) const; + bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override; + NameList get_names(const CollectionItemTypeBase &) const override; + void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override; + IO::Seekable *open(const std::string &) const override; }; } // namespace DataFile diff --git a/source/collection.h b/source/collection.h index 98a08b6..c8470dd 100644 --- a/source/collection.h +++ b/source/collection.h @@ -396,7 +396,7 @@ private: template struct Extractor: CollectionItemTypeBase::Extractor { - virtual B &extract(const Variant &var) const + B &extract(const Variant &var) const override { return *var.value >(); } }; @@ -451,19 +451,19 @@ public: return *this; } - virtual bool is_same_type(const CollectionItemTypeBase &other) const + bool is_same_type(const CollectionItemTypeBase &other) const override { return dynamic_cast *>(&other); } - virtual bool check_item_type(const Variant &var) const + bool check_item_type(const Variant &var) const override { return var.check_type >(); } - virtual void add_to_loader(Collection::Loader &) const + void add_to_loader(Collection::Loader &) const override { } - virtual bool can_create() const + bool can_create() const override { return static_cast(create_func); } - virtual void create_item(Collection &coll, const std::string &name) const + void create_item(Collection &coll, const std::string &name) const override { if(!create_func) throw std::runtime_error("no creator"); @@ -472,12 +472,12 @@ public: coll.add(name, obj); } - virtual void load_item(Collection &, Parser &, const std::string &) const + void load_item(Collection &, Parser &, const std::string &) const override { throw std::runtime_error("this type cannot be loaded"); } - virtual void notify_item(const std::string &name, const Variant &var) const + void notify_item(const std::string &name, const Variant &var) const override { RefPtr obj = var.value >(); for(const auto &n: notify_funcs) @@ -490,10 +490,10 @@ template class LoadableCollectionItemType: public CollectionItemType { public: - virtual void add_to_loader(Collection::Loader &loader) const + void add_to_loader(Collection::Loader &loader) const override { loader.add(this->kwd, &Collection::Loader::item); } - virtual void load_item(Collection &coll, Parser &parser, const std::string &name) const + void load_item(Collection &coll, Parser &parser, const std::string &name) const override { RefPtr obj = new T; Collection::ItemLoader ldr(*obj, coll); diff --git a/source/directorysource.h b/source/directorysource.h index 660d4e8..6549065 100644 --- a/source/directorysource.h +++ b/source/directorysource.h @@ -20,10 +20,10 @@ private: public: void add_directory(const FS::Path &, bool = true); - virtual bool is_loadable(const CollectionItemTypeBase &, const std::string &) const; - virtual NameList get_names(const CollectionItemTypeBase &) const; - virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const; - virtual IO::Seekable *open(const std::string &) const; + bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override; + NameList get_names(const CollectionItemTypeBase &) const override; + void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override; + IO::Seekable *open(const std::string &) const override; bool lookup_file(const std::string &, FS::Path &) const; }; diff --git a/source/dynamicobjectloader.h b/source/dynamicobjectloader.h index be4bf8a..687daca 100644 --- a/source/dynamicobjectloader.h +++ b/source/dynamicobjectloader.h @@ -44,7 +44,7 @@ public: ~DynamicObjectLoader() { delete object; delete obj_loader; } private: - virtual void init_actions(); + void init_actions() override; public: T *get_object() { T *o = object; object = 0; return o; } diff --git a/source/except.h b/source/except.h index ceb95e3..8357c7e 100644 --- a/source/except.h +++ b/source/except.h @@ -18,7 +18,7 @@ public: data_error(const std::string &, unsigned, const std::string &); data_error(const std::string &, unsigned, const std::exception &); data_error(const std::string &, unsigned, const data_error &); - virtual ~data_error() throw() = default; + ~data_error() throw() override = default; const std::string &get_source() const { return source; } unsigned get_line() const { return line; } @@ -32,7 +32,7 @@ class parse_error: public std::runtime_error { public: parse_error(const std::string &); - virtual ~parse_error() throw() = default; + ~parse_error() throw() override = default; }; @@ -40,7 +40,7 @@ class syntax_error: public std::runtime_error { public: syntax_error(const std::string &t); - virtual ~syntax_error() throw() = default; + ~syntax_error() throw() override = default; }; @@ -48,7 +48,7 @@ class bad_definition: public std::runtime_error { public: bad_definition(const std::string &w); - virtual ~bad_definition() throw() = default; + ~bad_definition() throw() override = default; }; @@ -56,7 +56,7 @@ class nesting_error: public std::logic_error { public: nesting_error(const std::string &); - virtual ~nesting_error() throw() = default; + ~nesting_error() throw() override = default; }; @@ -64,7 +64,7 @@ class unknown_keyword: public std::runtime_error { public: unknown_keyword(const std::string &); - virtual ~unknown_keyword() throw() = default; + ~unknown_keyword() throw() override = default; }; @@ -72,7 +72,7 @@ class invalid_signature: public std::runtime_error { public: invalid_signature(const std::string &, const std::string &); - virtual ~invalid_signature() throw() = default; + ~invalid_signature() throw() override = default; }; diff --git a/source/jsonparser.h b/source/jsonparser.h index 3fda68f..0a3890b 100644 --- a/source/jsonparser.h +++ b/source/jsonparser.h @@ -23,7 +23,7 @@ private: public: JsonParser(Input &, const std::string &); - virtual Statement parse(); + Statement parse() override; private: Statement parse_statement(const Token *, State, const std::string &); Token parse_token(); diff --git a/source/loaderaction.h b/source/loaderaction.h index 2329842..9e08dac 100644 --- a/source/loaderaction.h +++ b/source/loaderaction.h @@ -51,17 +51,17 @@ private: public: LoaderFunc0(FuncType f): func(f) { } - virtual void execute(Loader &l, const Statement &) const + void execute(Loader &l, const Statement &) const override { (dynamic_cast(l).*func)(); }; - virtual void execute(Loader &l, const ArgumentStore &) const + void execute(Loader &l, const ArgumentStore &) const override { (dynamic_cast(l).*func)(); }; - virtual std::string get_signature() const + std::string get_signature() const override { return std::string(); } }; @@ -80,17 +80,17 @@ private: public: LoaderFunc1(FuncType f): func(f) { } - virtual void execute(Loader &l, const Statement &st) const + void execute(Loader &l, const Statement &st) const override { (dynamic_cast(l).*func)(st.args[0].get()); } - virtual void execute(Loader &l, const ArgumentStore &as) const + void execute(Loader &l, const ArgumentStore &as) const override { (dynamic_cast(l).*func)(as.get(0)); } - virtual std::string get_signature() const + std::string get_signature() const override { return std::string(1, TypeInfo::signature); } }; @@ -109,7 +109,7 @@ private: public: LoaderFunc1(FuncType f): func(f) { } - virtual void execute(Loader &l, const Statement &st) const + void execute(Loader &l, const Statement &st) const override { std::vector values; values.reserve(st.args.size()); @@ -118,7 +118,7 @@ public: (dynamic_cast(l).*func)(values); } - virtual void execute(Loader &l, const ArgumentStore &as) const + void execute(Loader &l, const ArgumentStore &as) const override { std::vector values; unsigned n_args = as.get_info().key.signature.size(); @@ -128,7 +128,7 @@ public: (dynamic_cast(l).*func)(values); } - virtual std::string get_signature() const + std::string get_signature() const override { std::string result; result += TypeInfo::signature; @@ -152,17 +152,17 @@ private: public: LoaderFunc1(FuncType f): func(f) { } - virtual void execute(Loader &l, const Statement &st) const + void execute(Loader &l, const Statement &st) const override { (dynamic_cast(l).*func)(st); } - virtual void execute(Loader &, const ArgumentStore &) const + void execute(Loader &, const ArgumentStore &) const override { throw std::logic_error("incompatible format"); } - virtual std::string get_signature() const + std::string get_signature() const override { return "*"; } }; @@ -214,17 +214,17 @@ protected: public: LoaderFuncN(FuncType f): func(f) { } - virtual void execute(Loader &l, const Statement &st) const + void execute(Loader &l, const Statement &st) const override { Apply<0, Args...>::apply(dynamic_cast(l), func, st); } - virtual void execute(Loader &l, const ArgumentStore &as) const + void execute(Loader &l, const ArgumentStore &as) const override { Apply<0, Args...>::apply(dynamic_cast(l), func, as); } - virtual std::string get_signature() const + std::string get_signature() const override { return create_signature(); } }; @@ -243,17 +243,17 @@ public: LoaderFuncNBound1(FuncType f, const B0 &b0): func(f), bound0(b0) { } LoaderFuncNBound1(FuncType f, B0 &&b0): func(f), bound0(std::move(b0)) { } - virtual void execute(Loader &l, const Statement &st) const + void execute(Loader &l, const Statement &st) const override { Apply<0, Args...>::apply(dynamic_cast(l), func, st, bound0); } - virtual void execute(Loader &l, const ArgumentStore &as) const + void execute(Loader &l, const ArgumentStore &as) const override { Apply<0, Args...>::apply(dynamic_cast(l), func, as, bound0); } - virtual std::string get_signature() const + std::string get_signature() const override { return create_signature(); } }; @@ -269,17 +269,17 @@ private: public: LoadValue1(Pointer0Type p0): ptr0(p0) { } - virtual void execute(Loader &l, const Statement &st) const + void execute(Loader &l, const Statement &st) const override { dynamic_cast(l).get_object().*ptr0 = st.args[0].get(); } - virtual void execute(Loader &l, const ArgumentStore &as) const + void execute(Loader &l, const ArgumentStore &as) const override { dynamic_cast(l).get_object().*ptr0 = as.get(0); } - virtual std::string get_signature() const + std::string get_signature() const override { return std::string(1, TypeInfo::signature); } }; @@ -295,19 +295,19 @@ private: public: LoadValue1(Pointer0Type p0): ptr0(p0) { } - virtual void execute(Loader &l, const Statement &st) const + void execute(Loader &l, const Statement &st) const override { typename L::Loader &ldr = dynamic_cast(l); ldr.get_object().*ptr0 = &ldr.get_collection().template get(st.args[0].get()); } - virtual void execute(Loader &l, const ArgumentStore &as) const + void execute(Loader &l, const ArgumentStore &as) const override { typename L::Loader &ldr = dynamic_cast(l); ldr.get_object().*ptr0 = &ldr.get_collection().template get(as.get(0)); } - virtual std::string get_signature() const + std::string get_signature() const override { return std::string(1, TypeInfo::signature); } }; @@ -325,19 +325,19 @@ private: public: LoadValue2(Pointer0Type p0, Pointer1Type p1): ptr0(p0), ptr1(p1) { } - virtual void execute(Loader &l, const Statement &st) const + void execute(Loader &l, const Statement &st) const override { dynamic_cast(l).get_object().*ptr0 = st.args[0].get(); dynamic_cast(l).get_object().*ptr1 = st.args[1].get(); } - virtual void execute(Loader &l, const ArgumentStore &as) const + void execute(Loader &l, const ArgumentStore &as) const override { dynamic_cast(l).get_object().*ptr0 = as.get(0); dynamic_cast(l).get_object().*ptr1 = as.get(1); } - virtual std::string get_signature() const + std::string get_signature() const override { std::string result; result += TypeInfo::signature; diff --git a/source/packsource.h b/source/packsource.h index 946e86e..d2194e0 100644 --- a/source/packsource.h +++ b/source/packsource.h @@ -73,7 +73,7 @@ private: public: Loader(File &); private: - virtual void finish(); + void finish() override; void object(const std::string &, const std::string &); }; @@ -150,10 +150,10 @@ public: /// Returns information about the files in the pack. std::list list_files() const; - virtual bool is_loadable(const CollectionItemTypeBase &, const std::string &) const; - virtual NameList get_names(const CollectionItemTypeBase &) const; - virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const; - virtual IO::Seekable *open(const std::string &) const; + bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override; + NameList get_names(const CollectionItemTypeBase &) const override; + void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override; + IO::Seekable *open(const std::string &) const override; }; } // namespace DataFile diff --git a/source/textparser.h b/source/textparser.h index 1eec9c6..33ec17d 100644 --- a/source/textparser.h +++ b/source/textparser.h @@ -13,7 +13,7 @@ class TextParser: public ParserMode public: TextParser(Input &, const std::string &); - virtual Statement parse(); + Statement parse() override; protected: Statement parse_statement(const Token *); Token parse_token(); diff --git a/source/textwriter.h b/source/textwriter.h index 74a6767..641fc2e 100644 --- a/source/textwriter.h +++ b/source/textwriter.h @@ -15,8 +15,8 @@ private: public: TextWriter(Output &o); - virtual void set_float_precision(unsigned); - virtual void write(const Statement &st); + void set_float_precision(unsigned) override; + void write(const Statement &st) override; private: void write_(const Statement &st, unsigned); };