diff --git a/Framework/API/src/Algorithm.cpp b/Framework/API/src/Algorithm.cpp index 0e4c36bb38e985db7b7bace28b978784ea5bcd1f..cc743f92b8d0bb845cd645796a0d3903761d92d5 100644 --- a/Framework/API/src/Algorithm.cpp +++ b/Framework/API/src/Algorithm.cpp @@ -1624,9 +1624,8 @@ void Algorithm::setLoggingOffset(const int value) { if (m_communicator->rank() == 0) g_log.setLevelOffset(value); else { - int offset{1}; - ConfigService::Instance().getValue("mpi.loggingOffset", offset); - g_log.setLevelOffset(value + offset); + auto offset = ConfigService::Instance().getValue<int>("mpi.loggingOffset"); + g_log.setLevelOffset(value + offset.get_value_or(1)); } } diff --git a/Framework/API/src/AlgorithmManager.cpp b/Framework/API/src/AlgorithmManager.cpp index 608ba36df4c9f42866d028cde9047944efe6eb00..ed3d7cdc62d58df635325e284e0f07a5bb371af3 100644 --- a/Framework/API/src/AlgorithmManager.cpp +++ b/Framework/API/src/AlgorithmManager.cpp @@ -16,9 +16,9 @@ Kernel::Logger g_log("AlgorithmManager"); /// Private Constructor for singleton class AlgorithmManagerImpl::AlgorithmManagerImpl() : m_managed_algs() { - if (!Kernel::ConfigService::Instance().getValue("algorithms.retained", - m_max_no_algs) || - m_max_no_algs < 1) { + auto max_no_algs = Kernel::ConfigService::Instance().getValue<int>("algorithms.retained"); + + if (max_no_algs.get_value_or(0) < 1) { m_max_no_algs = 100; // Default to keeping 100 algorithms if not specified } diff --git a/Framework/API/src/FrameworkManager.cpp b/Framework/API/src/FrameworkManager.cpp index 7ac8daf23a62d3ff1622c58170daa3099b29dfa8..e1e32f7b1b6ad2a1721f14a4c5e49916c2fe8e91 100644 --- a/Framework/API/src/FrameworkManager.cpp +++ b/Framework/API/src/FrameworkManager.cpp @@ -161,11 +161,9 @@ void FrameworkManagerImpl::loadPlugins() { */ void FrameworkManagerImpl::setNumOMPThreadsToConfigValue() { // Set the number of threads to use for this process - int maxCores(0); - int retVal = Kernel::ConfigService::Instance().getValue( - "MultiThreaded.MaxCores", maxCores); - if (retVal > 0 && maxCores > 0) { - setNumOMPThreads(maxCores); + auto maxCores = Kernel::ConfigService::Instance().getValue<int>("MultiThreaded.MaxCores"); + if (maxCores.get_value_or(0) > 0) { + setNumOMPThreads(maxCores.get()); } } @@ -438,20 +436,18 @@ void FrameworkManagerImpl::disableNexusOutput() { /// Starts asynchronous tasks that are done as part of Start-up. void FrameworkManagerImpl::asynchronousStartupTasks() { - int instrumentUpdates(0); - int retVal = Kernel::ConfigService::Instance().getValue( - "UpdateInstrumentDefinitions.OnStartup", instrumentUpdates); - if ((retVal == 1) && (instrumentUpdates == 1)) { + auto instrumentUpdates = Kernel::ConfigService::Instance().getValue<bool>( + "UpdateInstrumentDefinitions.OnStartup"); + + if (instrumentUpdates.get_value_or(false)) { updateInstrumentDefinitions(); } else { g_log.information() << "Instrument updates disabled - cannot update " "instrument definitions.\n"; } - int newVersionCheck(0); - int retValVersionCheck = Kernel::ConfigService::Instance().getValue( - "CheckMantidVersion.OnStartup", newVersionCheck); - if ((retValVersionCheck == 1) && (newVersionCheck == 1)) { + auto newVersionCheck = Kernel::ConfigService::Instance().getValue<bool>("CheckMantidVersion.OnStartup"); + if (newVersionCheck.get_value_or(false)) { checkIfNewerVersionIsAvailable(); } else { g_log.information() << "Version check disabled.\n"; @@ -461,16 +457,14 @@ void FrameworkManagerImpl::asynchronousStartupTasks() { } void FrameworkManagerImpl::setupUsageReporting() { - int enabled = 0; - int interval = 0; auto &configSvc = ConfigService::Instance(); - int retVal = configSvc.getValue("Usage.BufferCheckInterval", interval); + auto interval = configSvc.getValue<int>("Usage.BufferCheckInterval"); auto &usageSvc = UsageService::Instance(); - if ((retVal == 1) && (interval > 0)) { - usageSvc.setInterval(interval); + if (interval.get_value_or(0) > 0) { + usageSvc.setInterval(interval.get()); } - retVal = configSvc.getValue("usagereports.enabled", enabled); - usageSvc.setEnabled((retVal == 1) && (enabled > 0)); + auto enabled = configSvc.getValue<bool>("usagereports.enabled"); + usageSvc.setEnabled(enabled.get_value_or(false)); usageSvc.registerStartup(); } diff --git a/Framework/API/src/IPowderDiffPeakFunction.cpp b/Framework/API/src/IPowderDiffPeakFunction.cpp index d3c92d2b86f8e4508eb1a1b56f2263c7d754c326..118cdb74fcd478429f91f382b9db3ad0025ca0f8 100644 --- a/Framework/API/src/IPowderDiffPeakFunction.cpp +++ b/Framework/API/src/IPowderDiffPeakFunction.cpp @@ -26,13 +26,10 @@ IPowderDiffPeakFunction::IPowderDiffPeakFunction() m_unitCell(), m_unitCellSize(0.), m_parameterValid(false), mH(0), mK(0), mL(0), mHKLSet(false), LATTICEINDEX(9999), HEIGHTINDEX(9999) { // Set peak's radius from configuration - int peakRadius; - if (Kernel::ConfigService::Instance().getValue("curvefitting.peakRadius", - peakRadius)) { - if (peakRadius != s_peakRadius) { - setPeakRadius(peakRadius); + auto peakRadius = Kernel::ConfigService::Instance().getValue<int>("curvefitting.peakRadius"); + if (peakRadius.is_initialized() && peakRadius.get() != s_peakRadius) { + setPeakRadius(peakRadius.get()); } - } } //---------------------------------------------------------------------------------------------- diff --git a/Framework/CurveFitting/src/Functions/PawleyFunction.cpp b/Framework/CurveFitting/src/Functions/PawleyFunction.cpp index 24ff27897047b4fe79acbdd3d4e7370e7bb87c6b..3a8c237d386be0ee7c006941cacb1d3d1de7a955 100644 --- a/Framework/CurveFitting/src/Functions/PawleyFunction.cpp +++ b/Framework/CurveFitting/src/Functions/PawleyFunction.cpp @@ -317,11 +317,8 @@ PawleyFunction::PawleyFunction() : IPawleyFunction(), m_compositeFunction(), m_pawleyParameterFunction(), m_peakProfileComposite(), m_hkls(), m_dUnit(), m_wsUnit(), m_peakRadius(5) { - int peakRadius; - if (Kernel::ConfigService::Instance().getValue("curvefitting.peakRadius", - peakRadius)) { - m_peakRadius = peakRadius; - } + auto peakRadius = Kernel::ConfigService::Instance().getValue<int>("curvefitting.peakRadius"); + m_peakRadius = peakRadius.get_value_or(5); } void PawleyFunction::setMatrixWorkspace( diff --git a/Framework/DataHandling/src/LoadInstrumentFromNexus.cpp b/Framework/DataHandling/src/LoadInstrumentFromNexus.cpp index dfd8ad904034414108098a8b1efa56f2b0880975..6ca86886b4eb2bce5fef42781d16991f66d9706a 100644 --- a/Framework/DataHandling/src/LoadInstrumentFromNexus.cpp +++ b/Framework/DataHandling/src/LoadInstrumentFromNexus.cpp @@ -74,15 +74,13 @@ void LoadInstrumentFromNexus::exec() { new Geometry::ObjComponent("Unknown", instrument.get()); instrument->add(source); instrument->markAsSource(source); - double l1 = 0.0; // If user has provided an L1, use that - if (!Kernel::ConfigService::Instance().getValue("instrument.L1", l1)) { - // Otherwise try and get it from the nexus file - but not there at present! - // l1 = nxload.ivpb.i_l1; - // Default to 10 if the file doesn't have it set - if (l1 == 0) - l1 = 10.0; - } + auto l1ConfigVal = Kernel::ConfigService::Instance().getValue<double>("instrument.L1"); + // Otherwise try and get it from the nexus file - but not there at present! + // l1 = nxload.ivpb.i_l1; + // Default to 10 if the file doesn't have it set + double l1 = l1ConfigVal.get_value_or(10.0); + source->setPos(0.0, -1.0 * l1, 0.0); localWorkspace->setInstrument(instrument); progress(1.0); diff --git a/Framework/DataHandling/src/LoadInstrumentFromRaw.cpp b/Framework/DataHandling/src/LoadInstrumentFromRaw.cpp index 6d75d43314794c25d770365b1fb30c1398f5077e..694e5ee14afcde0ee619f7ef3c3c0fe5f593b570 100644 --- a/Framework/DataHandling/src/LoadInstrumentFromRaw.cpp +++ b/Framework/DataHandling/src/LoadInstrumentFromRaw.cpp @@ -84,15 +84,14 @@ void LoadInstrumentFromRaw::exec() { instrument->markAsSource(source); progress(0.5); - double l1; - // If user has provided an L1, use that - if (!Kernel::ConfigService::Instance().getValue("instrument.L1", l1)) { + // If user has provided an L1, use that + auto l1ConfigValue = Kernel::ConfigService::Instance().getValue<double>("instrument.L1"); // Otherwise try and get it from the raw file - l1 = iraw.ivpb.i_l1; + double l1 = l1ConfigValue.get_value_or(iraw.ivpb.i_l1); // Default to 10 if the raw file doesn't have it set if (l1 == 0) l1 = 10.0; - } + source->setPos(0.0, 0.0, -1.0 * l1); // add detectors diff --git a/Framework/DataHandling/src/LoadRaw/isisraw2.cpp b/Framework/DataHandling/src/LoadRaw/isisraw2.cpp index 3f484643f769f512b8924968e40d2acd0ecc770f..2acf22f1b5ef9c444bafaed791e28df0407d59f1 100644 --- a/Framework/DataHandling/src/LoadRaw/isisraw2.cpp +++ b/Framework/DataHandling/src/LoadRaw/isisraw2.cpp @@ -18,12 +18,14 @@ ISISRAW2::ISISRAW2() : ISISRAW(nullptr, false), ndes(0), outbuff(nullptr), m_bufferSize(0) { // Determine the size of the output buffer to create from the config service. g_log.debug("Determining ioRaw buffer size\n"); - if (Mantid::Kernel::ConfigService::Instance().getValue( - "loadraw.readbuffer.size", m_bufferSize) == 0) { + auto bufferSizeConfigVal = Mantid::Kernel::ConfigService::Instance().getValue<int>("loadraw.readbuffer.size"); + +if (!bufferSizeConfigVal.is_initialized()){ m_bufferSize = 200000; g_log.debug() << "loadraw.readbuffer.size not found, setting to " << m_bufferSize << "\n"; } else { + m_bufferSize = bufferSizeConfigVal.get(); g_log.debug() << "loadraw.readbuffer.size set to " << m_bufferSize << "\n"; } } diff --git a/Framework/DataObjects/src/PeakColumn.cpp b/Framework/DataObjects/src/PeakColumn.cpp index 7210b7f4ad28afde4946869b96b118f83f393bb7..9d686036ddedfcee4a4cf059ee67718a6a68736a 100644 --- a/Framework/DataObjects/src/PeakColumn.cpp +++ b/Framework/DataObjects/src/PeakColumn.cpp @@ -80,14 +80,15 @@ PeakColumn::PeakColumn(std::vector<Peak> &peaks, const std::string &name) : m_peaks(peaks), m_oldRows() { this->m_name = name; this->m_type = typeFromName(name); // Throws if the name is unknown - this->m_hklPrec = 2; const std::string key = "PeakColumn.hklPrec"; - int gotit = ConfigService::Instance().getValue(key, this->m_hklPrec); - if (!gotit) - g_log.information() - << "In PeakColumn constructor, did not find any value for '" << key - << "' from the Config Service. Using default: " << this->m_hklPrec - << "\n"; + auto hklPrec = ConfigService::Instance().getValue<int>(key); + this->m_hklPrec = hklPrec.get_value_or(2); + if (!hklPrec.is_initialized()) { + g_log.information() + << "In PeakColumn constructor, did not find any value for '" << key + << "' from the Config Service. Using default: " << this->m_hklPrec + << "\n"; + } } /// Returns typeid for the data in the column diff --git a/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Framework/Kernel/inc/MantidKernel/ConfigService.h index 1da60b745ee0b73714a2a5b8933d7f58bca17ded..12f0279fd24e6b9885f5216bf082493e8be5b44a 100644 --- a/Framework/Kernel/inc/MantidKernel/ConfigService.h +++ b/Framework/Kernel/inc/MantidKernel/ConfigService.h @@ -7,14 +7,17 @@ #include "MantidKernel/DllConfig.h" #include "MantidKernel/SingletonHolder.h" #include "MantidKernel/ProxyInfo.h" + +#include <Poco/Notification.h> +#include <Poco/NotificationCenter.h> + +#include <boost/optional/optional.hpp> + #include <map> #include <set> #include <string> #include <vector> -#include <Poco/Notification.h> -#include <Poco/NotificationCenter.h> - //---------------------------------------------------------------------- // Forward declarations //---------------------------------------------------------------------- @@ -150,7 +153,7 @@ public: /// Sets a configuration property void setString(const std::string &key, const std::string &value); // Searches for a configuration property and returns its value - template <typename T> int getValue(const std::string &keyName, T &out); + template <typename T> boost::optional<T> getValue(const std::string &keyName); /// Return the local properties filename. std::string getLocalFilename() const; /// Return the user properties filename diff --git a/Framework/Kernel/inc/MantidKernel/DataService.h b/Framework/Kernel/inc/MantidKernel/DataService.h index 3d6de5faf49853b46c7b000922b295f1dc3808d4..7049aa61cd91597a2772645bf558c99c384567e5 100644 --- a/Framework/Kernel/inc/MantidKernel/DataService.h +++ b/Framework/Kernel/inc/MantidKernel/DataService.h @@ -503,14 +503,8 @@ public: } static bool showingHiddenObjects() { - int showingHiddenFlag; - const int success = ConfigService::Instance().getValue( - "MantidOptions.InvisibleWorkspaces", showingHiddenFlag); - if (success == 1 && showingHiddenFlag == 1) { - return true; - } else { - return false; - } + auto showingHiddenFlag = ConfigService::Instance().getValue<bool>("MantidOptions.InvisibleWorkspaces"); + return showingHiddenFlag.get_value_or(false); } /// Sends notifications to observers. Observers can subscribe to diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp index 16a6189f4383f869766cb4a85af77f4091e5493f..d61d6b0200913deaa325f87afcdea1a4dcdc6d45 100644 --- a/Framework/Kernel/src/ConfigService.cpp +++ b/Framework/Kernel/src/ConfigService.cpp @@ -44,6 +44,7 @@ #include <boost/algorithm/string/join.hpp> #include <boost/regex.hpp> +#include <boost/optional/optional.hpp> #include <algorithm> #include <cctype> @@ -1104,19 +1105,45 @@ void ConfigServiceImpl::setString(const std::string &key, m_changed_keys.insert(key); } -/** Searches for a string within the currently loaded configuaration values and +/** Searches for a string within the currently loaded configuration values and * attempts to convert the values to the template type supplied. * * @param keyName :: The case sensitive name of the property that you need the *value of. - * @param out :: The value if found - * @returns A success flag - 0 on failure, 1 on success + * @returns An optional container with the value if found */ template <typename T> -int ConfigServiceImpl::getValue(const std::string &keyName, T &out) { +boost::optional<T> ConfigServiceImpl::getValue(const std::string &keyName) { std::string strValue = getString(keyName); - int result = Mantid::Kernel::Strings::convert(strValue, out); - return result; + T output; + int result = Mantid::Kernel::Strings::convert(strValue, output); + + if (result != 1) { + return boost::none; + } + + return boost::optional<T>(output); +} + +/** Searches for a string within the currently loaded configuration values and +* attempts to convert the values to a boolean value +* +* @param keyName :: The case sensitive name of the property that you need the +*value of. +* @returns An optional container with the value if found +*/ +template <> +boost::optional<bool> ConfigServiceImpl::getValue(const std::string &keyName) { + auto returnedValue = getValue<std::string>(keyName); + if (!returnedValue.is_initialized()) { + return boost::none; + } + + bool trueString = returnedValue->find("true") != std::string::npos; + bool valueOne = returnedValue->find("1") != std::string::npos; + + // A string of 1 or true both count + return trueString || valueOne; } /** @@ -1990,12 +2017,14 @@ Kernel::ProxyInfo &ConfigServiceImpl::getProxy(const std::string &url) { if (!m_isProxySet) { // set the proxy // first check if the proxy is defined in the properties file - std::string proxyHost; - int proxyPort; - if ((getValue("proxy.host", proxyHost) == 1) && - (getValue("proxy.port", proxyPort) == 1)) { + auto proxyHost = getValue<std::string>("proxy.host"); + auto proxyPort = getValue<int>("proxy.port"); + + + + if ( proxyHost.is_initialized() && proxyPort.is_initialized()) { // set it from the config values - m_proxyInfo = ProxyInfo(proxyHost, proxyPort, true); + m_proxyInfo = ProxyInfo(proxyHost.get(), proxyPort.get(), true); } else { // get the system proxy Poco::URI uri(url); @@ -2084,13 +2113,11 @@ int ConfigServiceImpl::FindLowestFilterLevel() const { } /// \cond TEMPLATE -template DLLExport int ConfigServiceImpl::getValue(const std::string &, - double &); -template DLLExport int ConfigServiceImpl::getValue(const std::string &, - std::string &); -template DLLExport int ConfigServiceImpl::getValue(const std::string &, int &); -template DLLExport int ConfigServiceImpl::getValue(const std::string &, - std::size_t &); +template DLLExport boost::optional<double> ConfigServiceImpl::getValue(const std::string &); +template DLLExport boost::optional<std::string> ConfigServiceImpl::getValue(const std::string &); +template DLLExport boost::optional<int> ConfigServiceImpl::getValue(const std::string &); +template DLLExport boost::optional<size_t> ConfigServiceImpl::getValue(const std::string &); +template DLLExport boost::optional<bool> ConfigServiceImpl::getValue(const std::string &); /// \endcond TEMPLATE } // namespace Kernel diff --git a/Framework/Kernel/src/ErrorReporter.cpp b/Framework/Kernel/src/ErrorReporter.cpp index 1735acc0473e1b9a418fd9efd10ee42511296687..7ed8a3bf22135de0d89310a2e1d6e6c8962332d0 100644 --- a/Framework/Kernel/src/ErrorReporter.cpp +++ b/Framework/Kernel/src/ErrorReporter.cpp @@ -38,11 +38,13 @@ ErrorReporter::ErrorReporter(std::string application, std::string email) : m_application(application), m_exitCode(exitCode), m_upTime(upTime), m_share(share), m_name(name), m_email(email) { - int retval = Mantid::Kernel::ConfigService::Instance().getValue( - "errorreports.rooturl", m_url); - if (retval == 0) { + auto url = Mantid::Kernel::ConfigService::Instance().getValue<std::string>("errorreports.rooturl"); + if (!url.is_initialized()) { g_log.debug() << "Failed to load error report url\n"; } + else { + m_url = url.get(); + } } /** Generates an error message and then calls an internet helper to send it diff --git a/Framework/Kernel/src/InternetHelper.cpp b/Framework/Kernel/src/InternetHelper.cpp index a0f907826417babc6e63e92f558692af311e680f..73736c74664e7f9986486e5eb8856dea77ea1c88 100644 --- a/Framework/Kernel/src/InternetHelper.cpp +++ b/Framework/Kernel/src/InternetHelper.cpp @@ -477,8 +477,8 @@ void InternetHelper::throwNotConnected(const std::string &url, **/ int InternetHelper::getTimeout() { if (!m_isTimeoutSet) { - if (!ConfigService::Instance().getValue("network.default.timeout", - m_timeout)) { + auto m_timeout = ConfigService::Instance().getValue<int>("network.default.timeout"); + if (!m_timeout.is_initialized()) { m_timeout = 30; // the default value if the key is not found } } diff --git a/Framework/Kernel/src/MultiFileNameParser.cpp b/Framework/Kernel/src/MultiFileNameParser.cpp index 8232a6c211859830ee802ecf7b0d1a54109f5467..39206e379fc0b18fe3b2e0213cbf7cccb4758c3b 100644 --- a/Framework/Kernel/src/MultiFileNameParser.cpp +++ b/Framework/Kernel/src/MultiFileNameParser.cpp @@ -549,9 +549,8 @@ generateRange(unsigned int const from, unsigned int const to, "Unable to generate a range with a step size of zero."); size_t limit; - std::string limitStr; - ConfigService::Instance().getValue("loading.multifilelimit", limitStr); - if (!Strings::convert(limitStr, limit)) { + auto limitStr = ConfigService::Instance().getValue<std::string>("loading.multifilelimit"); + if (!limitStr.is_initialized() || !Strings::convert(limitStr.get(), limit)) { limit = ConfigService::Instance().getFacility().multiFileLimit(); } diff --git a/Framework/Kernel/src/ThreadPool.cpp b/Framework/Kernel/src/ThreadPool.cpp index d38c15b11ad06b0f64d464c83367811b829ba221..25b74b63af826236d5cedd69d39d081bbeb8b588 100644 --- a/Framework/Kernel/src/ThreadPool.cpp +++ b/Framework/Kernel/src/ThreadPool.cpp @@ -73,11 +73,10 @@ size_t ThreadPool::getNumPhysicalCores() { int physicalCores = PARALLEL_GET_MAX_THREADS; #endif - int maxCores(0); - int retVal = Kernel::ConfigService::Instance().getValue( - "MultiThreaded.MaxCores", maxCores); - if (retVal > 0 && maxCores > 0) - return std::min(maxCores, physicalCores); + auto maxCores = Kernel::ConfigService::Instance().getValue<int>("MultiThreaded.MaxCores"); + + if (!maxCores.is_initialized()) + return std::min(maxCores.get_value_or(0), physicalCores); else return physicalCores; } diff --git a/Framework/Kernel/src/UsageService.cpp b/Framework/Kernel/src/UsageService.cpp index 647854aecbb05c8359926b2fb9ab406394488d35..9365b9ae0296babe1323cbcf7137b3b83e1c846a 100644 --- a/Framework/Kernel/src/UsageService.cpp +++ b/Framework/Kernel/src/UsageService.cpp @@ -65,11 +65,11 @@ UsageServiceImpl::UsageServiceImpl() m_startupActiveMethod(this, &UsageServiceImpl::sendStartupAsyncImpl), m_featureActiveMethod(this, &UsageServiceImpl::sendFeatureAsyncImpl) { setInterval(60); - int retval = Mantid::Kernel::ConfigService::Instance().getValue( - "usagereports.rooturl", m_url); - if (retval == 0) { + auto url = Mantid::Kernel::ConfigService::Instance().getValue<std::string>("usagereports.rooturl"); + if (!url.is_initialized()) { g_log.debug() << "Failed to load usage report url\n"; } else { + m_url = url.get(); g_log.debug() << "Root usage reporting url is " << m_url << "\n"; } m_startTime = Types::Core::DateAndTime::getCurrentTime(); diff --git a/Framework/Kernel/test/ConfigServiceTest.h b/Framework/Kernel/test/ConfigServiceTest.h index 0485fd2b6c03ec15a2bdd0398d9e853e626002aa..816d466d05b417d585a9998e6213820fe55318cb 100644 --- a/Framework/Kernel/test/ConfigServiceTest.h +++ b/Framework/Kernel/test/ConfigServiceTest.h @@ -386,10 +386,8 @@ public: void TestCustomPropertyAsValue() { // Mantid.legs is defined in the properties script as 6 - int value = 0; - ConfigService::Instance().getValue("algorithms.retained", value); - double dblValue = 0; - ConfigService::Instance().getValue("algorithms.retained", dblValue); + int value = ConfigService::Instance().getValue<int>("algorithms.retained").get_value_or(0); + double dblValue = ConfigService::Instance().getValue<double>("algorithms.retained").get_value_or(0); TS_ASSERT_EQUALS(value, 50); TS_ASSERT_EQUALS(dblValue, 50.0); diff --git a/Framework/LiveData/src/FakeEventDataListener.cpp b/Framework/LiveData/src/FakeEventDataListener.cpp index 60d5d09b9be5e34aed7178a1ebdaa440be894a93..fd455cfe7898ffec2dccd1603871e1acf224bc13 100644 --- a/Framework/LiveData/src/FakeEventDataListener.cpp +++ b/Framework/LiveData/src/FakeEventDataListener.cpp @@ -20,17 +20,16 @@ DECLARE_LISTENER(FakeEventDataListener) FakeEventDataListener::FakeEventDataListener() : LiveListener(), m_buffer(), m_rand(new Kernel::MersenneTwister(5489)), m_timer(), m_callbackloop(1), m_numExtractDataCalls(0), m_runNumber(1) { - if (!ConfigService::Instance().getValue("fakeeventdatalistener.datarate", - m_datarate)) - m_datarate = 200; // Default data rate. Low so that our lowest-powered + + auto datarateConfigVal = ConfigService::Instance().getValue<int>("fakeeventdatalistener.datarate"); + m_datarate = datarateConfigVal.get_value_or(200); // Default data rate. Low so that our lowest-powered // buildserver can cope. // For auto-ending and restarting runs - if (!ConfigService::Instance().getValue("fakeeventdatalistener.endrunevery", - m_endRunEvery)) - m_endRunEvery = 0; - if (!ConfigService::Instance().getValue("fakeeventdatalistener.notyettimes", - m_notyettimes)) - m_notyettimes = 0; + auto endRunEveryConfigVal = ConfigService::Instance().getValue<int>("fakeeventdatalistener.endrunevery"); + m_endRunEvery = endRunEveryConfigVal.get_value_or(0); + + auto notyettimesConfigVal = ConfigService::Instance().getValue<int>("fakeeventdatalistener.notyettimes"); + m_notyettimes = notyettimesConfigVal.get_value_or(0); } /// Destructor diff --git a/Framework/LiveData/src/FileEventDataListener.cpp b/Framework/LiveData/src/FileEventDataListener.cpp index 72a0c2e60cb160d087808aeb82e7383df647036e..0e52c923f6fcbc9a6e4346296b521778e43a18a3 100644 --- a/Framework/LiveData/src/FileEventDataListener.cpp +++ b/Framework/LiveData/src/FileEventDataListener.cpp @@ -53,11 +53,11 @@ FileEventDataListener::FileEventDataListener() } } - if (!ConfigService::Instance().getValue("fileeventdatalistener.chunks", - m_numChunks)) { + auto numChunks = ConfigService::Instance().getValue<int>("fileeventdatalistener.chunks"); + m_numChunks = numChunks.get_value_or(0); + if (!numChunks.is_initialized()) { g_log.error("Configuration property fileeventdatalistener.chunks not " "found. The algorithm will fail!"); - m_numChunks = 0; // Set it to 0 so the algorithm just fails } // Add an integer, incremented for each listener instance, to the temporary diff --git a/Framework/LiveData/src/ISIS/DAE/isisds_command.cpp b/Framework/LiveData/src/ISIS/DAE/isisds_command.cpp index 142166d3c0950f202de4716020a315b92fcf2f4d..04a518575f3c9b31a39b2b4c0661483169a6329f 100644 --- a/Framework/LiveData/src/ISIS/DAE/isisds_command.cpp +++ b/Framework/LiveData/src/ISIS/DAE/isisds_command.cpp @@ -161,12 +161,9 @@ SOCKET isisds_send_open(const char *host, ISISDSAccessMode access_type, return INVALID_SOCKET; } - int timeoutinSec = 120; - if (!Mantid::Kernel::ConfigService::Instance().getValue("ISISDAE.Timeout", - timeoutinSec) || - timeoutinSec < 1) { - timeoutinSec = 120; // Default to 120 seconds if not specified - } + auto timeoutInSecConfigVal = Mantid::Kernel::ConfigService::Instance().getValue<int>("ISISDAE.Timeout"); + int timeoutinSec = timeoutInSecConfigVal.get_value_or(120); // Default to 120 seconds if not specified + #ifdef WIN32 // WINDOWS DWORD timeout = timeoutinSec * 1000; diff --git a/Framework/LiveData/src/SNSLiveEventDataListener.cpp b/Framework/LiveData/src/SNSLiveEventDataListener.cpp index 6053943d2a1c83a258b435ae49bdb3e3b9862fb1..795f21be390a4ec222d3a94f2ed2b9da0695c666 100644 --- a/Framework/LiveData/src/SNSLiveEventDataListener.cpp +++ b/Framework/LiveData/src/SNSLiveEventDataListener.cpp @@ -90,14 +90,10 @@ SNSLiveEventDataListener::SNSLiveEventDataListener() // Initialize m_keepPausedEvents from the config file. // NOTE: To the best of my knowledge, the existence of this property is not // documented anywhere and this lack of documentation is deliberate. - int keepPausedEvents; - if (ConfigService::Instance().getValue("livelistener.keeppausedevents", - keepPausedEvents)) { - m_keepPausedEvents = (keepPausedEvents != 0); - } else { - // If the property hasn't been set, assume false - m_keepPausedEvents = false; - } + auto keepPausedEvents = ConfigService::Instance().getValue<bool>("livelistener.keeppausedevents"); + + // If the property hasn't been set, assume false + m_keepPausedEvents = keepPausedEvents.get_value_or(false); } /// Destructor diff --git a/Framework/LiveData/test/TestDataListener.cpp b/Framework/LiveData/test/TestDataListener.cpp index c958a5ec23975838434355eee41c8f018848b0e3..8aa2ae1a3ea6138edfaf1846814790597bfe4604 100644 --- a/Framework/LiveData/test/TestDataListener.cpp +++ b/Framework/LiveData/test/TestDataListener.cpp @@ -30,23 +30,23 @@ TestDataListener::TestDataListener() m_dataReset = false; m_timesCalled = 0; - if (!ConfigService::Instance().getValue("testdatalistener.reset_after", - m_resetAfter)) - m_resetAfter = 0; - if (!ConfigService::Instance().getValue( - "testdatalistener.m_changeStatusAfter", m_changeStatusAfter)) - m_changeStatusAfter = 0; - int temp = 0; - if (!ConfigService::Instance().getValue("testdatalistener.m_newStatus", - temp)) { - if (temp == 0) - m_newStatus = ILiveListener::NoRun; - if (temp == 1) - m_newStatus = ILiveListener::BeginRun; - if (temp == 2) - m_newStatus = ILiveListener::Running; - if (temp == 4) - m_newStatus = ILiveListener::EndRun; + m_resetAfter = ConfigService::Instance().getValue<int>("testdatalistener.reset_after").get_value_or(0); + m_changeStatusAfter = ConfigService::Instance().getValue<int>("testdatalistener.m_changeStatusAfter").get_value_or(0); + int temp = ConfigService::Instance().getValue<int>("testdatalistener.m_newStatus").get_value_or(0); + + switch (temp) { + case 0: + m_newStatus = ILiveListener::NoRun; + break; + case 1: + m_newStatus = ILiveListener::BeginRun; + break; + case 2: + m_newStatus = ILiveListener::Running; + break; + case 4: + m_newStatus = ILiveListener::EndRun; + break; } } diff --git a/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp b/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp index 498c164d284a9223e8f8308b88b6b38786966abe..2ae538308066401e2f186f1c43ed873e848c8a76 100644 --- a/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp +++ b/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp @@ -1384,11 +1384,8 @@ void ScriptRepositoryImpl::doDownloadFile(const std::string &url_file, // Configure Poco HTTP Client Session try { Kernel::InternetHelper inetHelper; - int timeout; - if (!ConfigService::Instance().getValue("network.scriptrepo.timeout", - timeout)) { - timeout = DEFAULT_TIMEOUT_SEC; - } + auto timeoutConfigVal = ConfigService::Instance().getValue<int>("network.scriptrepo.timeout"); + int timeout = timeoutConfigVal.get_value_or(DEFAULT_TIMEOUT_SEC); inetHelper.setTimeout(timeout); // std::stringstream ss; diff --git a/MantidPlot/src/ProjectRecovery.cpp b/MantidPlot/src/ProjectRecovery.cpp index 98c664ea88e61abbaae8c4a03034c9f22a10d25c..4b5c208cc3498fd7cf06201bc466f8ee6013215e 100644 --- a/MantidPlot/src/ProjectRecovery.cpp +++ b/MantidPlot/src/ProjectRecovery.cpp @@ -39,25 +39,11 @@ Mantid::Kernel::Logger g_log("ProjectRecovery"); // Config helper methods template <typename T> boost::optional<T> getConfigValue(const std::string &key) { - T returnedValue; - - int valueIsGood = - Mantid::Kernel::ConfigService::Instance().getValue<T>(key, returnedValue); - - if (valueIsGood != 1) { - return boost::optional<T>{}; - } - - return boost::optional<T>{returnedValue}; + return Mantid::Kernel::ConfigService::Instance().getValue<T>(key); } boost::optional<bool> getConfigBool(const std::string &key) { - auto returnedValue = getConfigValue<std::string>(key); - if (!returnedValue.is_initialized()) { - return boost::optional<bool>{}; - } - - return returnedValue->find("true") != std::string::npos; + return Mantid::Kernel::ConfigService::Instance().getValue<bool>(key); } /// Returns a string to the current top level recovery folder diff --git a/qt/widgets/sliceviewer/src/QPeaksTableModel.cpp b/qt/widgets/sliceviewer/src/QPeaksTableModel.cpp index 9ca18beb52fdf6d2e45c14837a24e52828974145..676c47f219a039ad6a4290931fd2e33bbb291f2a 100644 --- a/qt/widgets/sliceviewer/src/QPeaksTableModel.cpp +++ b/qt/widgets/sliceviewer/src/QPeaksTableModel.cpp @@ -35,10 +35,8 @@ static QString v3dAsString(const Mantid::Kernel::V3D &v3d) { * @returns :: number of decimals to round displayed HKL values to. */ static int getHKLPrecision() { - int hklPrec = 0; - if (!Mantid::Kernel::ConfigService::Instance().getValue("PeakColumn.hklPrec", - hklPrec)) - hklPrec = 2; + auto hklPrecConfigVal = Mantid::Kernel::ConfigService::Instance().getValue<int>("PeakColumn.hklPrec"); + int hklPrec = hklPrecConfigVal.get_value_or(2); return hklPrec; } diff --git a/qt/widgets/sliceviewer/src/SliceViewer.cpp b/qt/widgets/sliceviewer/src/SliceViewer.cpp index 24fe16c32dbb784b53ab07e83b901bf63f4b2f77..fe48ae135be5687c2c6c064c26ddb63262885886 100644 --- a/qt/widgets/sliceviewer/src/SliceViewer.cpp +++ b/qt/widgets/sliceviewer/src/SliceViewer.cpp @@ -101,11 +101,8 @@ SliceViewer::SliceViewer(QWidget *parent) ui.setupUi(this); std::string enableNonOrthogonal; - Kernel::ConfigService::Instance().getValue("sliceviewer.nonorthogonal", - enableNonOrthogonal); - if (enableNonOrthogonal == "true") { - m_nonOrthogonalDefault = true; - } + auto nonOrthogonalDefaultValue = Kernel::ConfigService::Instance().getValue<bool>("sliceviewer.nonorthogonal"); + m_nonOrthogonalDefault = nonOrthogonalDefaultValue.get_value_or(false); m_inf = std::numeric_limits<double>::infinity();