From 74feef4718770d20273aa97f9176484149f178ae Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 12 Dec 2018 11:25:33 +0100 Subject: Improve config error handling --- src/CudaDartMaskAlgorithm.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/CudaDartMaskAlgorithm.cpp') diff --git a/src/CudaDartMaskAlgorithm.cpp b/src/CudaDartMaskAlgorithm.cpp index 3c5519c..bd9f59f 100644 --- a/src/CudaDartMaskAlgorithm.cpp +++ b/src/CudaDartMaskAlgorithm.cpp @@ -66,14 +66,14 @@ bool CCudaDartMaskAlgorithm::initialize(const Config& _cfg) // reconstruction data XMLNode node = _cfg.self.getSingleNode("SegmentationDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No SegmentationDataId tag specified."); - int id = node.getContentInt(); + int id = StringUtil::stringToInt(node.getContent(), -1); m_pSegmentation = dynamic_cast(CData2DManager::getSingleton().get(id)); CC.markNodeParsed("SegmentationDataId"); // reconstruction data node = _cfg.self.getSingleNode("MaskDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No MaskDataId tag specified."); - id = node.getContentInt(); + id = StringUtil::stringToInt(node.getContent(), -1); m_pMask = dynamic_cast(CData2DManager::getSingleton().get(id)); CC.markNodeParsed("MaskDataId"); @@ -84,16 +84,28 @@ bool CCudaDartMaskAlgorithm::initialize(const Config& _cfg) if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); - // Option: Connectivity - m_iConn = (unsigned int)_cfg.self.getOptionNumerical("Connectivity", 8); + // Option: Connectivity + try { + m_iConn = _cfg.self.getOptionInt("Connectivity", 8); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "CudaDartMask", "Connectivity must be an integer."); + } CC.markOptionParsed("Connectivity"); // Option: Threshold - m_iThreshold = (unsigned int)_cfg.self.getOptionNumerical("Threshold", 1); + try { + m_iThreshold = _cfg.self.getOptionInt("Threshold", 1); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "CudaDartMask", "Threshold must be an integer."); + } CC.markOptionParsed("Threshold"); // Option: Radius - m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1); + try { + m_iRadius = _cfg.self.getOptionInt("Radius", 1); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "CudaDartMask", "Radius must be an integer."); + } CC.markOptionParsed("Radius"); _check(); -- cgit v1.2.3