Skip to content

Commit

Permalink
Better ahndling of vectors
Browse files Browse the repository at this point in the history
Refs #9067
  • Loading branch information
DanNixon authored and quantumsteve committed Apr 16, 2015
1 parent b5ff8c3 commit ebd24b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h
Expand Up @@ -132,8 +132,6 @@ 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 under a given root key
std::vector<std::string> getKeysRecursive(const std::string &root = "") const;
/// Returns a list of all full keys in the config
std::vector<std::string> keys() const;
/// Removes the value from a selected keyName
Expand Down Expand Up @@ -287,6 +285,9 @@ class MANTID_KERNEL_DLL ConfigServiceImpl {
/// if valid
bool addDirectoryifExists(const std::string &directoryName,
std::vector<std::string> &directoryList);
/// Returns a list of all keys under a given root key
void getKeysRecursive(const std::string &root,
std::vector<std::string> &allKeys) const;

// Forward declaration of inner class
template <class T> class WrappedObject;
Expand Down
23 changes: 9 additions & 14 deletions Code/Mantid/Framework/Kernel/src/ConfigService.cpp
Expand Up @@ -1003,10 +1003,13 @@ ConfigServiceImpl::getKeys(const std::string &keyName) const {
*
* @return Vector containing all config options
*/
std::vector<std::string> ConfigServiceImpl::getKeysRecursive(const std::string &root) const {
std::vector<std::string> allKeys;
void ConfigServiceImpl::getKeysRecursive(const std::string &root,
std::vector<std::string> &allKeys) const {
std::vector<std::string> rootKeys = getKeys(root);

if(rootKeys.size() == 0)
allKeys.push_back(root);

for (auto rkIt = rootKeys.begin(); rkIt != rootKeys.end(); ++rkIt) {
std::string searchString;
if (root.empty()) {
Expand All @@ -1015,18 +1018,8 @@ std::vector<std::string> ConfigServiceImpl::getKeysRecursive(const std::string &
searchString = root + "." + *rkIt;
}

std::vector<std::string> subKeys = getKeysRecursive(searchString);

if (subKeys.size() == 0) {
allKeys.push_back(*rkIt);
} else {
for (auto skIt = subKeys.begin(); skIt != subKeys.end(); ++skIt) {
allKeys.push_back(*rkIt + "." + *skIt);
}
}
getKeysRecursive(searchString, allKeys);
}

return allKeys;
}

/**
Expand All @@ -1038,7 +1031,9 @@ std::vector<std::string> ConfigServiceImpl::getKeysRecursive(const std::string &
* @return Vector containing all config options
*/
std::vector<std::string> ConfigServiceImpl::keys() const {
return getKeysRecursive();
std::vector<std::string> allKeys;
getKeysRecursive("", allKeys);
return allKeys;
}

/** Removes a key from the memory stored properties file and inserts the key
Expand Down

0 comments on commit ebd24b9

Please sign in to comment.