Skip to content

Commit

Permalink
clang-format them to fix conflict issues, re #8491
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed Jan 20, 2015
1 parent cea958b commit 2059c3d
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 178 deletions.
Expand Up @@ -7,41 +7,41 @@
* 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>(#classname)) \
, 0)); \
}
#define DECLARE_IMPLICIT_FUNCTION_PARAMETER_PARSER(classname) \
namespace { \
Mantid::Kernel::RegistrationHelper register_alg_##classname( \
((Mantid::API::ImplicitFunctionParameterParserFactory::Instance() \
.subscribe<classname>(#classname)), \
0)); \
}

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include <vector>

#ifndef Q_MOC_RUN
# include <boost/shared_ptr.hpp>
# include <boost/interprocess/smart_ptr/unique_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
#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
@author Owen Arnold, Tessella plc
@date 01/10/2010
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Expand All @@ -62,43 +62,38 @@ namespace Poco
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

namespace Mantid
{
namespace API
{
namespace Mantid {
namespace API {

/*
* Deletion policy for unique pointers.
*/
template<typename T>
class DLLExport DeleterPolicy
{
template <typename T> 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<ImplicitFunctionParameterParser>> 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<ImplicitFunctionParameterParser, DeleterPolicy<ImplicitFunctionParameterParser> > SuccessorType;

virtual ImplicitFunctionParameter* createParameter(Poco::XML::Element* parameterElement) = 0;
virtual void setSuccessorParser(ImplicitFunctionParameterParser* paramParser) = 0;
virtual ~ImplicitFunctionParameterParser()
{
}
protected:
SuccessorType m_successor;
};

}
}

Expand Down
Expand Up @@ -10,25 +10,22 @@

#include <boost/algorithm/string.hpp>

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 &copy; 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Expand All @@ -48,92 +45,87 @@ namespace MDAlgorithms
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
template<class VectorValueParameterType>
class DLLExport Vector3DParameterParser: public Mantid::API::ImplicitFunctionParameterParser
{
template <class VectorValueParameterType>
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<typename VectorValueParameterType>
Vector3DParameterParser<VectorValueParameterType>::Vector3DParameterParser()
{
}
template <typename VectorValueParameterType>
Vector3DParameterParser<VectorValueParameterType>::Vector3DParameterParser() {}

template<typename VectorValueParameterType>
VectorValueParameterType* Vector3DParameterParser<VectorValueParameterType>::parseVectorParameter(
std::string value)
{
template <typename VectorValueParameterType>
VectorValueParameterType *
Vector3DParameterParser<VectorValueParameterType>::parseVectorParameter(
std::string value) {
std::vector<std::string> 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<typename VectorValueParameterType>
Mantid::API::ImplicitFunctionParameter* Vector3DParameterParser<VectorValueParameterType>::createParameter(
Poco::XML::Element* parameterElement)
{
template <typename VectorValueParameterType>
Mantid::API::ImplicitFunctionParameter *
Vector3DParameterParser<VectorValueParameterType>::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<typename VectorValueParameterType>
template <typename VectorValueParameterType>
void Vector3DParameterParser<VectorValueParameterType>::setSuccessorParser(
Mantid::API::ImplicitFunctionParameterParser* paramParser)
{
Mantid::API::ImplicitFunctionParameterParser *paramParser) {
Mantid::API::ImplicitFunctionParameterParser::SuccessorType temp(paramParser);
m_successor.swap(temp);
}

template<typename VectorValueParameterType>
Vector3DParameterParser<VectorValueParameterType>::~Vector3DParameterParser()
{
}
template <typename VectorValueParameterType>
Vector3DParameterParser<VectorValueParameterType>::~Vector3DParameterParser() {}

//Declare types based on this template.
// Declare types based on this template.

/// Parses Origin Parameters
//typedef Vector3DParameterParser<OriginParameter> OriginParameterParser;
// typedef Vector3DParameterParser<OriginParameter> OriginParameterParser;

/// Parses Normal Parameters
//typedef Vector3DParameterParser<NormalParameter> NormalParameterParser;
// typedef Vector3DParameterParser<NormalParameter> NormalParameterParser;

/// Parses Up Parameters
//typedef Vector3DParameterParser<UpParameter> UpParameterParser;
// typedef Vector3DParameterParser<UpParameter> UpParameterParser;

/// Parses Perpendicular Parameters
//typedef Vector3DParameterParser<PerpendicularParameter> PerpendicularParameterParser;
// typedef Vector3DParameterParser<PerpendicularParameter>
// PerpendicularParameterParser;
}
}

Expand Down
Expand Up @@ -11,28 +11,30 @@
#include <Poco/DOM/Document.h>
#include <Poco/DOM/Element.h>

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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Parameter><Type>SomeUnknownParameter</Type><Value>x</Value></Parameter>";
Poco::AutoPtr<Document> pDoc = pParser.parseString(xmlToParse);

InvalidParameterParser parser;
Mantid::API::ImplicitFunctionParameter* iparam = parser.createParameter(pDoc->documentElement());
InvalidParameter* pInvalidParam = dynamic_cast<InvalidParameter*>(iparam);
boost::scoped_ptr<InvalidParameter> 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 = "<?xml version=\"1.0\" "
"encoding=\"utf-8\"?><Parameter><Type>"
"SomeUnknownParameter</Type><Value>x</Value></"
"Parameter>";
Poco::AutoPtr<Document> pDoc = pParser.parseString(xmlToParse);

InvalidParameterParser parser;
Mantid::API::ImplicitFunctionParameter *iparam =
parser.createParameter(pDoc->documentElement());
InvalidParameter *pInvalidParam = dynamic_cast<InvalidParameter *>(iparam);
boost::scoped_ptr<InvalidParameter> 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

0 comments on commit 2059c3d

Please sign in to comment.