diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParser.h b/Code/Mantid/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParser.h index 3762859846f6..f915766d42a8 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParser.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParser.h @@ -7,12 +7,13 @@ * subscribe method. */ //#define Parser Parser -#define DECLARE_IMPLICIT_FUNCTION_PARAMETER_PARSER(classname) \ - namespace { \ - Mantid::Kernel::RegistrationHelper register_alg_##classname( \ - ((Mantid::API::ImplicitFunctionParameterParserFactory::Instance().subscribe(#classname)) \ - , 0)); \ - } +#define DECLARE_IMPLICIT_FUNCTION_PARAMETER_PARSER(classname) \ + namespace { \ + Mantid::Kernel::RegistrationHelper register_alg_##classname( \ + ((Mantid::API::ImplicitFunctionParameterParserFactory::Instance() \ + .subscribe(#classname)), \ + 0)); \ + } //---------------------------------------------------------------------- // Includes @@ -20,20 +21,18 @@ #include #ifndef Q_MOC_RUN -# include -# include +#include +#include #endif #include "MantidAPI/DllConfig.h" #include "MantidKernel/ArrayProperty.h" #include "ImplicitFunctionParameter.h" -namespace Poco -{ - namespace DOM - { - class Element; - } +namespace Poco { +namespace DOM { +class Element; +} } /** XML Parser for parameter types for ImplicitFunctions @@ -41,7 +40,8 @@ namespace Poco @author Owen Arnold, Tessella plc @date 01/10/2010 - Copyright © 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source + Copyright © 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source This file is part of Mantid. @@ -62,43 +62,38 @@ namespace Poco Code Documentation is available at: */ -namespace Mantid -{ -namespace API -{ +namespace Mantid { +namespace API { /* * Deletion policy for unique pointers. */ -template -class DLLExport DeleterPolicy -{ +template class DLLExport DeleterPolicy { public: - void operator()(T* pParser) - { - delete pParser; - } + void operator()(T *pParser) { delete pParser; } }; /* - * ImplicitFunctionParameterParser definition. Used to parse implicit function xml. + * ImplicitFunctionParameterParser definition. Used to parse implicit function + * xml. */ -class MANTID_API_DLL ImplicitFunctionParameterParser -{ +class MANTID_API_DLL ImplicitFunctionParameterParser { public: + /// Successor type. Unique shared pointer with stack scoped deletion + /// semantics. + typedef boost::interprocess::unique_ptr< + ImplicitFunctionParameterParser, + DeleterPolicy> SuccessorType; + + virtual ImplicitFunctionParameter * + createParameter(Poco::XML::Element *parameterElement) = 0; + virtual void + setSuccessorParser(ImplicitFunctionParameterParser *paramParser) = 0; + virtual ~ImplicitFunctionParameterParser() {} - /// Successor type. Unique shared pointer with stack scoped deletion semantics. - typedef boost::interprocess::unique_ptr > SuccessorType; - - virtual ImplicitFunctionParameter* createParameter(Poco::XML::Element* parameterElement) = 0; - virtual void setSuccessorParser(ImplicitFunctionParameterParser* paramParser) = 0; - virtual ~ImplicitFunctionParameterParser() - { - } protected: SuccessorType m_successor; }; - } } diff --git a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Vector3DParameterParser.h b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Vector3DParameterParser.h index 4d3d30ad0610..c32434ebdb5e 100644 --- a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Vector3DParameterParser.h +++ b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Vector3DParameterParser.h @@ -10,25 +10,22 @@ #include -namespace Poco -{ - namespace DOM - { - class Element; - } +namespace Poco { +namespace DOM { +class Element; +} } -namespace Mantid -{ -namespace MDAlgorithms -{ +namespace Mantid { +namespace MDAlgorithms { /** XML parser for vector value (3 elements) parameter types. @author Owen Arnold, Tessella plc @date 02/11/2011 - Copyright © 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source + Copyright © 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source This file is part of Mantid. @@ -48,92 +45,87 @@ namespace MDAlgorithms File change history is stored at: Code Documentation is available at: */ -template -class DLLExport Vector3DParameterParser: public Mantid::API::ImplicitFunctionParameterParser -{ +template +class DLLExport Vector3DParameterParser + : public Mantid::API::ImplicitFunctionParameterParser { public: Vector3DParameterParser(); - VectorValueParameterType* parseVectorParameter(std::string value); + VectorValueParameterType *parseVectorParameter(std::string value); - Mantid::API::ImplicitFunctionParameter* createParameter(Poco::XML::Element* parameterElement); + Mantid::API::ImplicitFunctionParameter * + createParameter(Poco::XML::Element *parameterElement); - void setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser* paramParser); + void + setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser *paramParser); ~Vector3DParameterParser(); }; //////////////////////////////////////////////////////////////////// -template -Vector3DParameterParser::Vector3DParameterParser() -{ -} +template +Vector3DParameterParser::Vector3DParameterParser() {} -template -VectorValueParameterType* Vector3DParameterParser::parseVectorParameter( - std::string value) -{ +template +VectorValueParameterType * +Vector3DParameterParser::parseVectorParameter( + std::string value) { std::vector strs; boost::split(strs, value, boost::is_any_of(",")); double nx, ny, nz; - try - { + try { nx = atof(strs.at(0).c_str()); ny = atof(strs.at(1).c_str()); nz = atof(strs.at(2).c_str()); - } catch (std::exception& ex) - { - std::string message = std::string(ex.what()) + " Failed to parse " - + VectorValueParameterType::parameterName() + " value: " + value; + } catch (std::exception &ex) { + std::string message = std::string(ex.what()) + " Failed to parse " + + VectorValueParameterType::parameterName() + + " value: " + value; throw std::invalid_argument(message.c_str()); } return new VectorValueParameterType(nx, ny, nz); } -template -Mantid::API::ImplicitFunctionParameter* Vector3DParameterParser::createParameter( - Poco::XML::Element* parameterElement) -{ +template +Mantid::API::ImplicitFunctionParameter * +Vector3DParameterParser::createParameter( + Poco::XML::Element *parameterElement) { std::string typeName = parameterElement->getChildElement("Type")->innerText(); - if (VectorValueParameterType::parameterName() != typeName) - { + if (VectorValueParameterType::parameterName() != typeName) { return m_successor->createParameter(parameterElement); - } - else - { - std::string sParameterValue = parameterElement->getChildElement("Value")->innerText(); + } else { + std::string sParameterValue = + parameterElement->getChildElement("Value")->innerText(); return parseVectorParameter(sParameterValue); } } -template +template void Vector3DParameterParser::setSuccessorParser( - Mantid::API::ImplicitFunctionParameterParser* paramParser) -{ + Mantid::API::ImplicitFunctionParameterParser *paramParser) { Mantid::API::ImplicitFunctionParameterParser::SuccessorType temp(paramParser); m_successor.swap(temp); } -template -Vector3DParameterParser::~Vector3DParameterParser() -{ -} +template +Vector3DParameterParser::~Vector3DParameterParser() {} -//Declare types based on this template. +// Declare types based on this template. /// Parses Origin Parameters -//typedef Vector3DParameterParser OriginParameterParser; +// typedef Vector3DParameterParser OriginParameterParser; /// Parses Normal Parameters -//typedef Vector3DParameterParser NormalParameterParser; +// typedef Vector3DParameterParser NormalParameterParser; /// Parses Up Parameters -//typedef Vector3DParameterParser UpParameterParser; +// typedef Vector3DParameterParser UpParameterParser; /// Parses Perpendicular Parameters -//typedef Vector3DParameterParser PerpendicularParameterParser; +// typedef Vector3DParameterParser +// PerpendicularParameterParser; } } diff --git a/Code/Mantid/Framework/MDAlgorithms/test/InvalidParameterParserTest.h b/Code/Mantid/Framework/MDAlgorithms/test/InvalidParameterParserTest.h index ca1d3104707d..49dd82d38bf9 100644 --- a/Code/Mantid/Framework/MDAlgorithms/test/InvalidParameterParserTest.h +++ b/Code/Mantid/Framework/MDAlgorithms/test/InvalidParameterParserTest.h @@ -11,28 +11,30 @@ #include #include -class InvalidParameterParserTest : public CxxTest::TestSuite -{ +class InvalidParameterParserTest : public CxxTest::TestSuite { public: - - void testParseInvalidParameterFragment() - { - using namespace Poco::XML; - using namespace Mantid::MDAlgorithms; - - DOMParser pParser; - std::string xmlToParse = "SomeUnknownParameterx"; - Poco::AutoPtr pDoc = pParser.parseString(xmlToParse); - - InvalidParameterParser parser; - Mantid::API::ImplicitFunctionParameter* iparam = parser.createParameter(pDoc->documentElement()); - InvalidParameter* pInvalidParam = dynamic_cast(iparam); - boost::scoped_ptr invalparam(pInvalidParam); - - TSM_ASSERT("The paramter generated should be an InvalidParamter", NULL != pInvalidParam); - TSM_ASSERT_EQUALS("The invalid parameter has not been parsed correctly.", "x", invalparam->getValue()); - } - + void testParseInvalidParameterFragment() { + using namespace Poco::XML; + using namespace Mantid::MDAlgorithms; + + DOMParser pParser; + std::string xmlToParse = "" + "SomeUnknownParameterx"; + Poco::AutoPtr pDoc = pParser.parseString(xmlToParse); + + InvalidParameterParser parser; + Mantid::API::ImplicitFunctionParameter *iparam = + parser.createParameter(pDoc->documentElement()); + InvalidParameter *pInvalidParam = dynamic_cast(iparam); + boost::scoped_ptr invalparam(pInvalidParam); + + TSM_ASSERT("The paramter generated should be an InvalidParamter", + NULL != pInvalidParam); + TSM_ASSERT_EQUALS("The invalid parameter has not been parsed correctly.", + "x", invalparam->getValue()); + } }; #endif diff --git a/Code/Mantid/Framework/MDEvents/src/CoordTransformDistanceParser.cpp b/Code/Mantid/Framework/MDEvents/src/CoordTransformDistanceParser.cpp index 32146549d719..42de3c7b0be4 100644 --- a/Code/Mantid/Framework/MDEvents/src/CoordTransformDistanceParser.cpp +++ b/Code/Mantid/Framework/MDEvents/src/CoordTransformDistanceParser.cpp @@ -3,79 +3,84 @@ #include "MantidAPI/VectorParameterParser.h" #include "MantidAPI/SingleValueParameterParser.h" -namespace Mantid -{ - namespace MDEvents - { - /// Constructor - CoordTransformDistanceParser::CoordTransformDistanceParser() - { - } - - //----------------------------------------------------------------------------------------------- - /* - Create the transform object. - @param coordTransElement : xml coordinate transform element - @return a fully constructed coordinate transform object. - */ - Mantid::API::CoordTransform* CoordTransformDistanceParser::createTransform(Poco::XML::Element* coordTransElement) const - { - //Typdef the parameter parsers required. - typedef Mantid::API::SingleValueParameterParser InDimParameterParser; - typedef Mantid::API::SingleValueParameterParser OutDimParameterParser; - typedef Mantid::API::VectorParameterParser CoordCenterParser; - typedef Mantid::API::VectorParameterParser DimsUsedParser; +namespace Mantid { +namespace MDEvents { +/// Constructor +CoordTransformDistanceParser::CoordTransformDistanceParser() {} - using namespace Poco::XML; - if("CoordTransform" != coordTransElement->localName()) - { - std::string message = "This is not a coordinate transform element: " + coordTransElement->localName(); - throw std::invalid_argument(message); - } - if("CoordTransformDistance" != coordTransElement->getChildElement("Type")->innerText()) - { - //Delegate - if(!m_successor) - { - throw std::runtime_error("CoordTransformDistanceParser has no successor parser."); - } - return m_successor->createTransform(coordTransElement); - } +//----------------------------------------------------------------------------------------------- +/* +Create the transform object. +@param coordTransElement : xml coordinate transform element +@return a fully constructed coordinate transform object. +*/ +Mantid::API::CoordTransform *CoordTransformDistanceParser::createTransform( + Poco::XML::Element *coordTransElement) const { + // Typdef the parameter parsers required. + typedef Mantid::API::SingleValueParameterParser + InDimParameterParser; + typedef Mantid::API::SingleValueParameterParser + OutDimParameterParser; + typedef Mantid::API::VectorParameterParser + CoordCenterParser; + typedef Mantid::API::VectorParameterParser + DimsUsedParser; - Element* paramListElement = coordTransElement->getChildElement("ParameterList"); - Poco::AutoPtr parameters = paramListElement->getElementsByTagName("Parameter"); + using namespace Poco::XML; + if ("CoordTransform" != coordTransElement->localName()) { + std::string message = "This is not a coordinate transform element: " + + coordTransElement->localName(); + throw std::invalid_argument(message); + } + if ("CoordTransformDistance" != + coordTransElement->getChildElement("Type")->innerText()) { + // Delegate + if (!m_successor) { + throw std::runtime_error( + "CoordTransformDistanceParser has no successor parser."); + } + return m_successor->createTransform(coordTransElement); + } - // Parse the in dimension parameter. - InDimParameterParser inDimParamParser; - Poco::XML::Element* parameter = dynamic_cast(parameters->item(0)); - Mantid::API::InDimParameter* inDimParameter = inDimParamParser.createWithoutDelegation(parameter); + Element *paramListElement = + coordTransElement->getChildElement("ParameterList"); + Poco::AutoPtr parameters = + paramListElement->getElementsByTagName("Parameter"); - // Parse the out dimension parameter. - OutDimParameterParser outDimParamParser; - parameter = dynamic_cast(parameters->item(1)); - Mantid::API::OutDimParameter* outDimParameter = outDimParamParser.createWithoutDelegation(parameter); - UNUSED_ARG(outDimParameter); //not actually used as an input. + // Parse the in dimension parameter. + InDimParameterParser inDimParamParser; + Poco::XML::Element *parameter = + dynamic_cast(parameters->item(0)); + Mantid::API::InDimParameter *inDimParameter = + inDimParamParser.createWithoutDelegation(parameter); - // Parse the coordinate centre parameter. - CoordCenterParser coordCenterParser; - parameter = dynamic_cast(parameters->item(2)); - Mantid::MDEvents::CoordCenterVectorParam* coordCenterParam = coordCenterParser.createWithoutDelegation(parameter); + // Parse the out dimension parameter. + OutDimParameterParser outDimParamParser; + parameter = dynamic_cast(parameters->item(1)); + Mantid::API::OutDimParameter *outDimParameter = + outDimParamParser.createWithoutDelegation(parameter); + UNUSED_ARG(outDimParameter); // not actually used as an input. - // Parse the dimensions used parameter. - DimsUsedParser dimsUsedParser; - parameter = dynamic_cast(parameters->item(3)); - Mantid::MDEvents::DimensionsUsedVectorParam* dimsUsedVecParm = dimsUsedParser.createWithoutDelegation(parameter); + // Parse the coordinate centre parameter. + CoordCenterParser coordCenterParser; + parameter = dynamic_cast(parameters->item(2)); + Mantid::MDEvents::CoordCenterVectorParam *coordCenterParam = + coordCenterParser.createWithoutDelegation(parameter); - ////Generate the coordinate transform and return - CoordTransformDistance* transform = new CoordTransformDistance(inDimParameter->getValue(), coordCenterParam->getPointerToStart(), dimsUsedVecParm->getPointerToStart()); - return transform; - } + // Parse the dimensions used parameter. + DimsUsedParser dimsUsedParser; + parameter = dynamic_cast(parameters->item(3)); + Mantid::MDEvents::DimensionsUsedVectorParam *dimsUsedVecParm = + dimsUsedParser.createWithoutDelegation(parameter); + ////Generate the coordinate transform and return + CoordTransformDistance *transform = new CoordTransformDistance( + inDimParameter->getValue(), coordCenterParam->getPointerToStart(), + dimsUsedVecParm->getPointerToStart()); + return transform; +} - /// Destructor - CoordTransformDistanceParser::~CoordTransformDistanceParser() - { - } - - } +/// Destructor +CoordTransformDistanceParser::~CoordTransformDistanceParser() {} +} }