diff options
Diffstat (limited to 'src/utils/datastor')
-rw-r--r-- | src/utils/datastor/datastor.cpp | 16 | ||||
-rw-r--r-- | src/utils/datastor/datastor.h | 5 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp index d32c4787e..7563e9309 100644 --- a/src/utils/datastor/datastor.cpp +++ b/src/utils/datastor/datastor.cpp @@ -64,13 +64,27 @@ std::string Data_Store::get1(const std::string& key) const std::vector<std::string> vals = get(key); if(vals.empty()) - throw Invalid_State("Data_Store::get1: Not values for " + key); + throw Invalid_State("Data_Store::get1: No values set for " + key); if(vals.size() > 1) throw Invalid_State("Data_Store::get1: More than one value for " + key); return vals[0]; } +std::string Data_Store::get1(const std::string& key, + const std::string& default_value) const + { + std::vector<std::string> vals = get(key); + + if(vals.size() > 1) + throw Invalid_State("Data_Store::get1: More than one value for " + key); + + if(vals.empty()) + return default_value; + + return vals[0]; + } + /* * Get a single std::vector atom */ diff --git a/src/utils/datastor/datastor.h b/src/utils/datastor/datastor.h index b471f85e1..1c0504fc9 100644 --- a/src/utils/datastor/datastor.h +++ b/src/utils/datastor/datastor.h @@ -33,7 +33,10 @@ class BOTAN_DLL Data_Store std::vector<std::string> get(const std::string&) const; - std::string get1(const std::string&) const; + std::string get1(const std::string& key) const; + + std::string get1(const std::string& key, + const std::string& default_value) const; std::vector<byte> get1_memvec(const std::string&) const; u32bit get1_u32bit(const std::string&, u32bit = 0) const; |