projects
/
libdcp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b0520d7
)
Use a map and boost::any to make it a little neater to add more metadata to Verificat...
author
Carl Hetherington
<cth@carlh.net>
Sat, 15 Apr 2023 20:27:01 +0000
(22:27 +0200)
committer
Carl Hetherington
<cth@carlh.net>
Sun, 16 Apr 2023 20:19:05 +0000
(22:19 +0200)
src/verify.h
patch
|
blob
|
history
diff --git
a/src/verify.h
b/src/verify.h
index ed5cac4c05ec8ef89d8b5c339051935dfbef439c..8eec9749c44c3a121bea8ea10fc12ea12f9f0c23 100644
(file)
--- a/
src/verify.h
+++ b/
src/verify.h
@@
-41,6
+41,7
@@
#define LIBDCP_VERIFY_H
#define LIBDCP_VERIFY_H
+#include <boost/any.hpp>
#include <boost/filesystem.hpp>
#include <boost/function.hpp>
#include <boost/optional.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)
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)
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)
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)
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;
Type type () const {
return _type;
@@
-478,27
+483,40
@@
public:
return _code;
}
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 {
boost::optional<std::string> note () const {
- return
_note
;
+ return
data<std::string>(Data::NOTE)
;
}
boost::optional<boost::filesystem::path> file () const {
}
boost::optional<boost::filesystem::path> file () const {
- return
_file
;
+ return
data<boost::filesystem::path>(Data::FILE)
;
}
boost::optional<uint64_t> line () const {
}
boost::optional<uint64_t> line () const {
- return
_line
;
+ return
data<uint64_t>(Data::LINE)
;
}
private:
Type _type;
Code _code;
}
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;
};
};