Minor changes here and there.
[aesalon.git] / src / config / Vault.cpp
blobc77bedff8bb4eb92fe911889546f706124292425
1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/config/Vault.cpp
8 */
10 #include "config/Vault.h"
12 namespace Config {
14 Vault::Vault() {
18 void Vault::clear(const std::string &key) {
19 m_dataMap.erase(key);
22 void Vault::set(const std::string &key, const std::string &value) {
23 m_dataMap.insert(DataMap::value_type(key, value));
26 std::string Vault::get(const std::string &key) {
27 DataMap::iterator i = m_dataMap.find(key);
28 if(i != m_dataMap.end()) return i->second;
29 return "";
32 void Vault::get(const std::string &key, std::vector<std::string> &values) {
33 for(DataMap::iterator i = m_dataMap.begin(); i != m_dataMap.end(); ++i) {
34 if(i->first == key) values.push_back(i->second);
38 void Vault::match(const std::string &pattern, std::vector<KeyPair> &values) {
39 for(DataMap::iterator i = m_dataMap.begin(); i != m_dataMap.end(); ++i) {
40 if(matches(i->first, pattern)) values.push_back(*i);
44 bool Vault::matches(const std::string &string, const std::string &pattern) {
45 if(string == pattern) return true;
46 else if(pattern == "*") return true;
48 std::string::size_type starPos = pattern.find('*');
50 if(starPos == std::string::npos) return false;
51 if(string.substr(0, starPos) == pattern.substr(0, starPos)) return true;
53 return false;
56 } // namespace Config