diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-04-15 22:27:01 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-04-16 22:19:05 +0200 |
| commit | f85c63c42fda45293d6c75e8cbf018bbc0e15f58 (patch) | |
| tree | 7f39d3ec9e32f8946583b3870766577d89e471b2 /src | |
| parent | b0520d7a1bffaff1ca7161f5b7672f06b13808a1 (diff) | |
Use a map and boost::any to make it a little neater to add more metadata to VerificationNote.
Diffstat (limited to 'src')
| -rw-r--r-- | src/verify.h | 58 |
1 files changed, 38 insertions, 20 deletions
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 <boost/any.hpp> #include <boost/filesystem.hpp> #include <boost/function.hpp> #include <boost/optional.hpp> @@ -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 <class T> + boost::optional<T> data(Data key) const + { + auto iter = _data.find(key); + if (iter == _data.end()) { + return {}; + } + return boost::any_cast<T>(iter->second); + } + +public: boost::optional<std::string> note () const { - return _note; + return data<std::string>(Data::NOTE); } boost::optional<boost::filesystem::path> file () const { - return _file; + return data<boost::filesystem::path>(Data::FILE); } boost::optional<uint64_t> line () const { - return _line; + return data<uint64_t>(Data::LINE); } private: Type _type; Code _code; - /** Further information about the error, if applicable */ - boost::optional<std::string> _note; - /** Path of file containing the error, if applicable */ - boost::optional<boost::filesystem::path> _file; - /** Error line number within _file, if applicable */ - boost::optional<uint64_t> _line; + std::map<Data, boost::any> _data; }; |
