diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-15 17:03:54 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-15 17:03:54 +0100 |
commit | 6bd77fce8400ecf531a4f7ff56431010b6bbb6f1 (patch) | |
tree | 2b428a23bddbd87c08ee47351bc31768f54b63fe /libnitrokey/misc.h | |
parent | 8d67c0f80aab724d67a1b6efb8af16aa71631a84 (diff) | |
parent | e853275784e48823be0f39f0855efbe85c0f905c (diff) | |
download | libnitrokey-6bd77fce8400ecf531a4f7ff56431010b6bbb6f1.tar.gz libnitrokey-6bd77fce8400ecf531a4f7ff56431010b6bbb6f1.tar.bz2 |
Merge branch 'contributions'
Multiple PR's merged and tested as a whole
Platform:
Pro v0.7
Storage v0.53
Fedora 29
Run Python tests
Diffstat (limited to 'libnitrokey/misc.h')
-rw-r--r-- | libnitrokey/misc.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libnitrokey/misc.h b/libnitrokey/misc.h index 88254dd..d10c8df 100644 --- a/libnitrokey/misc.h +++ b/libnitrokey/misc.h @@ -29,12 +29,37 @@ #include "log.h" #include "LibraryException.h" #include <sstream> +#include <stdexcept> #include <iomanip> namespace nitrokey { namespace misc { +/** + * Simple replacement for std::optional (C++17). + */ +template<typename T> +class Option { +public: + Option() : m_hasValue(false), m_value() {} + Option(T value) : m_hasValue(true), m_value(value) {} + + bool has_value() const { + return m_hasValue; + } + T value() const { + if (!m_hasValue) { + throw std::logic_error("Called Option::value without value"); + } + return m_value; + } + +private: + bool m_hasValue; + T m_value; +}; + template<typename T> std::string toHex(T value){ using namespace std; |