diff options
Diffstat (limited to 'src/utils/datastor')
-rw-r--r-- | src/utils/datastor/datastor.cpp | 41 | ||||
-rw-r--r-- | src/utils/datastor/datastor.h | 17 |
2 files changed, 11 insertions, 47 deletions
diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp index 49e7b2dda..363136c69 100644 --- a/src/utils/datastor/datastor.cpp +++ b/src/utils/datastor/datastor.cpp @@ -14,16 +14,6 @@ namespace Botan { /* -* Default Matcher transform operation (identity) -*/ -std::pair<std::string, std::string> -Data_Store::Matcher::transform(const std::string& key, - const std::string& value) const - { - return std::make_pair(key, value); - } - -/* * Data_Store Equality Comparison */ bool Data_Store::operator==(const Data_Store& other) const @@ -42,26 +32,14 @@ bool Data_Store::has_value(const std::string& key) const /* * Search based on an arbitrary predicate */ -std::multimap<std::string, std::string> -Data_Store::search_with(const Matcher& matcher) const +std::multimap<std::string, std::string> Data_Store::search_for( + std::function<bool (std::string, std::string)> predicate) const { std::multimap<std::string, std::string> out; - std::multimap<std::string, std::string>::const_iterator i = - contents.begin(); - - while(i != contents.end()) - { - if(matcher(i->first, i->second)) - { - std::pair<std::string, std::string> p( - matcher.transform(i->first, i->second)); - - multimap_insert(out, p.first, p.second); - } - - ++i; - } + for(auto i = contents.begin(); i != contents.end(); ++i) + if(predicate(i->first, i->second)) + out.insert(std::make_pair(i->first, i->second)); return out; } @@ -71,12 +49,9 @@ Data_Store::search_with(const Matcher& matcher) const */ std::vector<std::string> Data_Store::get(const std::string& looking_for) const { - typedef std::multimap<std::string, std::string>::const_iterator iter; - - std::pair<iter, iter> range = contents.equal_range(looking_for); - std::vector<std::string> out; - for(iter i = range.first; i != range.second; ++i) + auto range = contents.equal_range(looking_for); + for(auto i = range.first; i != range.second; ++i) out.push_back(i->second); return out; } @@ -144,7 +119,7 @@ void Data_Store::add(const std::string& key, const std::string& val) */ void Data_Store::add(const std::string& key, u32bit val) { - add(key, to_string(val)); + add(key, std::to_string(val)); } /* diff --git a/src/utils/datastor/datastor.h b/src/utils/datastor/datastor.h index 8d41b07a8..26a0d418c 100644 --- a/src/utils/datastor/datastor.h +++ b/src/utils/datastor/datastor.h @@ -9,6 +9,7 @@ #define BOTAN_DATA_STORE_H__ #include <botan/secmem.h> +#include <functional> #include <utility> #include <string> #include <vector> @@ -25,22 +26,10 @@ class BOTAN_DLL Data_Store /** * A search function */ - class BOTAN_DLL Matcher - { - public: - virtual bool operator()(const std::string&, - const std::string&) const = 0; - - virtual std::pair<std::string, std::string> - transform(const std::string&, const std::string&) const; - - virtual ~Matcher() {} - }; - bool operator==(const Data_Store&) const; - std::multimap<std::string, std::string> - search_with(const Matcher&) const; + std::multimap<std::string, std::string> search_for( + std::function<bool (std::string, std::string)> predicate) const; std::vector<std::string> get(const std::string&) const; |