Skip to content

Commit

Permalink
Add ConfigService.keys() function
Browse files Browse the repository at this point in the history
Refs #9067
  • Loading branch information
DanNixon committed Apr 15, 2015
1 parent c96aaa6 commit 93d8524
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h
Expand Up @@ -132,6 +132,8 @@ class MANTID_KERNEL_DLL ConfigServiceImpl {
bool use_cache = true) const;
/// Searches for a key in the configuration property
std::vector<std::string> getKeys(const std::string &keyName) const;
/// Returns a list of all keys in the configuration property
std::vector<std::string> keys() const;
/// Removes the value from a selected keyName
void remove(const std::string &rootName) const;
/// Checks to see whether a key has a value assigned to it
Expand Down
22 changes: 22 additions & 0 deletions Code/Mantid/Framework/Kernel/src/ConfigService.cpp
Expand Up @@ -1000,6 +1000,28 @@ ConfigServiceImpl::getKeys(const std::string &keyName) const {
return keyVector;
}

/**
* Gets a list of all config options as property.key.
*
* @return Vector containing all config options
*/
std::vector<std::string> ConfigServiceImpl::keys() const {
std::vector<std::string> rootKeys;
m_pConf->keys(rootKeys);

std::vector<std::string> allKeys;
for(auto rkIt = rootKeys.begin(); rkIt != rootKeys.end(); ++rkIt) {
std::vector<std::string> subKeys;
m_pConf->keys(*rkIt, subKeys);

for(auto skIt = subKeys.begin(); skIt != subKeys.end(); ++skIt) {
allKeys.push_back(*riIt + "." + *skIt);
}
}

return allKeys;
}

/** Removes a key from the memory stored properties file and inserts the key
*into the
* changed key list so that when the program calls saveConfig the properties
Expand Down
Expand Up @@ -98,6 +98,8 @@ void export_ConfigService()

.def("saveConfig", &ConfigServiceImpl::saveConfig, "Saves the keys that have changed from their default to the given filename")

.def("keys", &ConfigServiceImpl::keys)

// Treat this as a dictionary
.def("__getitem__", &getStringUsingCache)
.def("__setitem__", &ConfigServiceImpl::setString)
Expand Down

0 comments on commit 93d8524

Please sign in to comment.