Skip to content

Commit

Permalink
Shorter name for python converters. Refs #4399
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Apr 15, 2012
1 parent 7e55a90 commit d62796c
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/PythonInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ add_subdirectory ( mantid )
set ( TEST_FILES
test/cpp/PropertyWithValueFactoryTest.h
test/cpp/PythonObjectInstantiatorTest.h
test/cpp/PySequenceToVectorConverterTest.h
test/cpp/PySequenceToVectorTest.h
)

if ( CXXTEST_FOUND )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ namespace Mantid
* type is defined by the template type
*/
template <typename DestElementType>
struct DLLExport NDArrayToVectorConverter
struct DLLExport NDArrayToVector
{
/// Constructor
NDArrayToVectorConverter(const boost::python::object & value);
NDArrayToVector(const boost::python::object & value);
/// Do the conversion
const std::vector<DestElementType> operator()();
private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ namespace Mantid
* type is defined by the template type
*/
template <typename DestElementType>
struct DLLExport PySequenceToVectorConverter
struct DLLExport PySequenceToVector
{
PySequenceToVectorConverter(const boost::python::object & value)
PySequenceToVector(const boost::python::object & value)
: m_obj(value.ptr())
{
check(value);
Expand Down Expand Up @@ -108,7 +108,7 @@ namespace Mantid
{
if( !PySequence_Check(obj.ptr()) )
{
throw std::invalid_argument(std::string("PySequenceToVectorConverter expects Python sequence type, found ")
throw std::invalid_argument(std::string("PySequenceToVector expects Python sequence type, found ")
+ obj.ptr()->ob_type->tp_name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

using Mantid::API::FileProperty;
using Mantid::Kernel::PropertyWithValue;
using Mantid::PythonInterface::Converters::PySequenceToVectorConverter;
using Mantid::PythonInterface::Converters::PySequenceToVector;
namespace bpl = boost::python;

void export_ActionEnum()
Expand Down Expand Up @@ -54,7 +54,7 @@ namespace
}
else
{
extsAsVector = PySequenceToVectorConverter<std::string>(extensions)();
extsAsVector = PySequenceToVector<std::string>(extensions)();
}
}
return new FileProperty(name, defaultValue, action, extsAsVector, direction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ namespace Mantid
namespace Converters
{
//-------------------------------------------------------------------------
// NDArrayToVectorConverter definitions
// NDArrayToVector definitions
//-------------------------------------------------------------------------

/**
* Constructor
* @param value :: A boost python object wrapping a numpy.ndarray
*/
template<typename DestElementType>
NDArrayToVectorConverter<DestElementType>::
NDArrayToVectorConverter(const boost::python::object & value)
NDArrayToVector<DestElementType>::
NDArrayToVector(const boost::python::object & value)
: m_arr(value)
{
typeCheck();
Expand All @@ -126,7 +126,7 @@ namespace Mantid
*/
template<typename DestElementType>
const std::vector<DestElementType>
NDArrayToVectorConverter<DestElementType>::operator()()
NDArrayToVector<DestElementType>::operator()()
{
npy_intp length = PyArray_SIZE(m_arr.ptr()); // Returns the total number of elements in the array
std::vector<DestElementType> cvector(length);
Expand All @@ -145,7 +145,7 @@ namespace Mantid
*/
template<typename DestElementType>
void
NDArrayToVectorConverter<DestElementType>::typeCheck()
NDArrayToVector<DestElementType>::typeCheck()
{
if( !PyArray_Check(m_arr.ptr()) )
{
Expand All @@ -160,7 +160,7 @@ namespace Mantid
// Explicit instantiations
//------------------------------------------------------------------------
#define INSTANTIATE(ElementType)\
template DLLExport struct NDArrayToVectorConverter<ElementType>;
template DLLExport struct NDArrayToVector<ElementType>;

INSTANTIATE(int);
INSTANTIATE(long);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace
createArrayPropertyFromList(const std::string &name, const boost::python::list & values,
IValidator_sptr validator, const unsigned int direction)
{
return new ArrayProperty<T>(name, Converters::PySequenceToVectorConverter<T>(values)(), validator, direction);
return new ArrayProperty<T>(name, Converters::PySequenceToVector<T>(values)(), validator, direction);
}

/**
Expand All @@ -83,7 +83,7 @@ namespace
createArrayPropertyFromNDArray(const std::string &name, const boost::python::numeric::array & values,
IValidator_sptr validator, const unsigned int direction)
{
return new ArrayProperty<T>(name, Converters::NDArrayToVectorConverter<T>(values)(), validator, direction);
return new ArrayProperty<T>(name, Converters::NDArrayToVector<T>(values)(), validator, direction);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace
void setDataSearchDirs(ConfigServiceImpl &self, const boost::python::list & paths)
{
using namespace Mantid::PythonInterface;
self.setDataSearchDirs(Converters::PySequenceToVectorConverter<std::string>(paths)());
self.setDataSearchDirs(Converters::PySequenceToVector<std::string>(paths)());
}

/// Overload generator for getInstrument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ namespace Mantid
// numpy arrays requires special handling to extract their types. Hand-off to a more appropriate handler
if( PyArray_Check(value.ptr()) )
{
alg->setProperty(name, Converters::NDArrayToVectorConverter<DestElementType>(value)());
alg->setProperty(name, Converters::NDArrayToVector<DestElementType>(value)());
}
else if( PySequence_Check(value.ptr()) )
{
alg->setProperty(name, Converters::PySequenceToVectorConverter<DestElementType>(value)());
alg->setProperty(name, Converters::PySequenceToVector<DestElementType>(value)());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

using namespace Mantid::PythonInterface::Converters;

class PySequenceToVectorConverterTest : public CxxTest::TestSuite
class PySequenceToVectorTest : public CxxTest::TestSuite
{
private:
typedef PySequenceToVectorConverter<double> PySequenceToVectorDouble;
typedef PySequenceToVector<double> PySequenceToVectorDouble;
public:

void test_construction_succeeds_with_a_valid_sequence_type()
Expand Down Expand Up @@ -47,7 +47,7 @@ class PySequenceToVectorConverterTest : public CxxTest::TestSuite
{
// Double->int is not generally safe so should not be allowed
boost::python::list testlist = createHomogeneousPythonList();
typedef PySequenceToVectorConverter<int> PySequenceToVectorInt;
typedef PySequenceToVector<int> PySequenceToVectorInt;
std::vector<int> cvector;
TS_ASSERT_THROWS(cvector = PySequenceToVectorInt(testlist)(), boost::python::error_already_set);
}
Expand Down

0 comments on commit d62796c

Please sign in to comment.