From f85c63c42fda45293d6c75e8cbf018bbc0e15f58 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 15 Apr 2023 22:27:01 +0200 Subject: Use a map and boost::any to make it a little neater to add more metadata to VerificationNote. --- src/verify.h | 58 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/verify.h b/src/verify.h index ed5cac4c..8eec9749 100644 --- a/src/verify.h +++ b/src/verify.h @@ -41,6 +41,7 @@ #define LIBDCP_VERIFY_H +#include #include #include #include @@ -446,29 +447,33 @@ public: VerificationNote (Type type, Code code, std::string note) : _type (type) , _code (code) - , _note (note) - {} + { + _data[Data::NOTE] = note; + } VerificationNote (Type type, Code code, boost::filesystem::path file) : _type (type) , _code (code) - , _file (file) - {} + { + _data[Data::FILE] = file; + } VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file) : _type (type) , _code (code) - , _note (note) - , _file (file) - {} + { + _data[Data::NOTE] = note; + _data[Data::FILE] = file; + } VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file, uint64_t line) : _type (type) , _code (code) - , _note (note) - , _file (file) - , _line (line) - {} + { + _data[Data::NOTE] = note; + _data[Data::FILE] = file; + _data[Data::LINE] = line; + } Type type () const { return _type; @@ -478,27 +483,40 @@ public: return _code; } +private: + enum class Data { + NOTE, ///< further information about the error + FILE, ///< path of file containing the error + LINE ///< error line number within the FILE + }; + + template + boost::optional data(Data key) const + { + auto iter = _data.find(key); + if (iter == _data.end()) { + return {}; + } + return boost::any_cast(iter->second); + } + +public: boost::optional note () const { - return _note; + return data(Data::NOTE); } boost::optional file () const { - return _file; + return data(Data::FILE); } boost::optional line () const { - return _line; + return data(Data::LINE); } private: Type _type; Code _code; - /** Further information about the error, if applicable */ - boost::optional _note; - /** Path of file containing the error, if applicable */ - boost::optional _file; - /** Error line number within _file, if applicable */ - boost::optional _line; + std::map _data; }; -- cgit v1.2.3