From ebd24b919475c1ada60636a715c22bfd41f3cac0 Mon Sep 17 00:00:00 2001 From: Dan Nixon <dan@dan-nixon.com> Date: Wed, 15 Apr 2015 13:16:19 +0100 Subject: [PATCH] Better ahndling of vectors Refs #9067 --- .../Kernel/inc/MantidKernel/ConfigService.h | 5 ++-- .../Framework/Kernel/src/ConfigService.cpp | 23 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h index 2502c966c5d..5f218e2a1dc 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h @@ -132,8 +132,6 @@ public: 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 @@ -287,6 +285,9 @@ private: /// 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; diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp index 5ba7a9c5f15..0d1c898db51 100644 --- a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp +++ b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp @@ -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()) { @@ -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; } /** @@ -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 -- GitLab