Commit 42129c80 authored by Edward Brown's avatar Edward Brown
Browse files

Re #22048: Applied fixes to Framework/PythonInterface.

parent 1de01980
......@@ -42,7 +42,7 @@ namespace PythonInterface {
*/
template <typename BaseAlgorithm>
class AlgorithmAdapter : public BaseAlgorithm {
typedef BaseAlgorithm SuperClass;
using SuperClass = BaseAlgorithm;
public:
/// A constructor that looks like a Python __init__ method
......
......@@ -37,9 +37,9 @@ namespace PythonInterface {
*/
template <typename WorkspaceType> struct WorkspacePropertyExporter {
/// The export type
typedef Mantid::API::WorkspaceProperty<WorkspaceType> TypedWorkspaceProperty;
using TypedWorkspaceProperty = Mantid::API::WorkspaceProperty<WorkspaceType>;
/// Shared pointer to Worksapce type
typedef boost::shared_ptr<WorkspaceType> WorkspaceType_sptr;
using WorkspaceType_sptr = boost::shared_ptr<WorkspaceType>;
/**
* Factory function to act as a constructor so that the validator can be
......
......@@ -52,7 +52,7 @@ struct DLLExport MatrixToNDArray {
const std::pair<size_t, size_t> matrixDims = cmatrix.size();
Py_intptr_t dims[2] = {static_cast<Py_intptr_t>(matrixDims.first),
static_cast<Py_intptr_t>(matrixDims.second)};
typedef typename ConversionPolicy::template apply<ElementType> policy;
using policy = typename ConversionPolicy::apply<ElementType>;
return policy::createFromArray(&(cmatrix[0][0]), 2, dims);
}
};
......
......@@ -48,7 +48,7 @@ struct VectorToNDArray {
*/
inline PyObject *operator()(const std::vector<ElementType> &cdata) const {
// Hand off the work to the conversion policy
typedef typename ConversionPolicy::template apply<ElementType> policy;
using policy = typename ConversionPolicy::apply<ElementType>;
return policy::create1D(cdata);
}
};
......
......@@ -43,8 +43,8 @@ namespace PythonInterface {
*/
template <typename SvcType, typename SvcPtrType> struct DataServiceExporter {
// typedef the type created by boost.python
typedef boost::python::class_<SvcType, boost::noncopyable> PythonType;
typedef boost::weak_ptr<typename SvcPtrType::element_type> WeakPtr;
using PythonType = boost::python::class_<SvcType, boost::noncopyable>;
using WeakPtr = boost::weak_ptr<typename SvcPtrType::element_type>;
/**
* Define the necessary boost.python framework to expor the templated
......
......@@ -73,11 +73,7 @@ template <class ReturnType> struct AsType {
template <class InputType> struct apply {
// Deduce if type is correct for policy, needs to be convertible to
// ReturnType
typedef typename boost::mpl::if_c<
std::is_convertible<InputType, ReturnType>::value,
AsTypeImpl<ReturnType, InputType>,
AsType_Requires_New_Type_Automatically_Convertible_To_Original<
InputType>>::type type;
using type = typename boost::mpl::if_c<std::is_convertible<InputType, ReturnType>::value, AsTypeImpl<ReturnType, InputType>, AsType_Requires_New_Type_Automatically_Convertible_To_Original<InputType> >::type;
};
};
......
......@@ -88,15 +88,9 @@ template <typename ConversionPolicy> struct MatrixRefToNumpy {
template <class T> struct apply {
// Typedef that removes and const or reference qualifiers from the return
// type
typedef typename std::remove_const<
typename std::remove_reference<T>::type>::type non_const_type;
using non_const_type = typename std::remove_const<typename std::remove_reference<T>::type>::type;
// MPL compile-time check that T is a reference to a Kernel::Matrix
typedef typename boost::mpl::if_c<
boost::mpl::and_<std::is_reference<T>,
is_matrix<non_const_type>>::value,
MatrixRefToNumpyImpl<non_const_type, ConversionPolicy>,
MatrixRefToNumpy_Requires_Reference_To_Matrix_Return_Type<T>>::type
type;
using type = typename boost::mpl::if_c<boost::mpl::and_<std::is_reference<T>, is_matrix<non_const_type> >::value, MatrixRefToNumpyImpl<non_const_type, ConversionPolicy>, MatrixRefToNumpy_Requires_Reference_To_Matrix_Return_Type<T> >::type;
};
};
......@@ -132,12 +126,9 @@ struct MatrixToNumpy {
// The boost::python framework calls return_value_policy::apply<T>::type
template <class T> struct apply {
// Typedef that removes any const from the type
typedef typename std::remove_const<T>::type non_const_type;
using non_const_type = typename std::remove_const<T>::type;
// MPL compile-time check that T is a std::vector
typedef typename boost::mpl::if_c<
is_matrix<non_const_type>::value,
MatrixRefToNumpyImpl<non_const_type, Converters::Clone>,
MatrixToNumpy_Requires_Matrix_Return_By_Value<T>>::type type;
using type = typename boost::mpl::if_c<is_matrix<non_const_type>::value, MatrixRefToNumpyImpl<non_const_type, Converters::Clone>, MatrixToNumpy_Requires_Matrix_Return_By_Value<T> >::type;
};
};
}
......
......@@ -72,9 +72,9 @@ struct IsConstSharedPtr<boost::shared_ptr<const T>> : std::true_type {};
// call to this struct
template <typename ConstPtrType> struct RemoveConstImpl {
// Remove the pointer type to leave value type
typedef typename std::remove_pointer<ConstPtrType>::type ValueType;
using ValueType = typename std::remove_pointer<ConstPtrType>::type;
// Remove constness
typedef typename std::remove_const<ValueType>::type NonConstValueType;
using NonConstValueType = typename std::remove_const<ValueType>::type;
inline PyObject *operator()(const ConstPtrType &p) const {
using namespace boost::python;
......@@ -99,10 +99,9 @@ template <typename T> struct RemoveConst_Requires_Pointer_Return_Value {};
// a check as to whether the return type is valid, if so it forwards the
// call to this struct
template <typename ConstSharedPtr> struct RemoveConstSharedPtrImpl {
typedef typename ConstSharedPtr::element_type ConstElementType;
typedef
typename std::remove_const<ConstElementType>::type NonConstElementType;
typedef typename boost::shared_ptr<NonConstElementType> NonConstSharedPtr;
using ConstElementType = typename ConstSharedPtr::element_type;
using NonConstElementType = typename std::remove_const<ConstElementType>::type;
using NonConstSharedPtr = typename boost::shared_ptr<NonConstElementType>;
inline PyObject *operator()(const ConstSharedPtr &p) const {
using namespace boost::python;
......@@ -130,9 +129,7 @@ struct RemoveConstSharedPtr_Requires_SharedPtr_Const_T_Pointer_Return_Value {};
struct RemoveConst {
template <class T> struct apply {
// Deduce if type is correct for policy, needs to be a "T*"
typedef typename boost::mpl::if_c<
std::is_pointer<T>::value, RemoveConstImpl<T>,
RemoveConst_Requires_Pointer_Return_Value<T>>::type type;
using type = typename boost::mpl::if_c<std::is_pointer<T>::value, RemoveConstImpl<T>, RemoveConst_Requires_Pointer_Return_Value<T> >::type;
};
};
......@@ -143,10 +140,7 @@ struct RemoveConstSharedPtr {
template <class T> struct apply {
// Deduce if type is correct for policy, needs to be a
// "boost::shared_ptr<T>"
typedef typename boost::mpl::if_c<
IsConstSharedPtr<T>::value, RemoveConstSharedPtrImpl<T>,
RemoveConstSharedPtr_Requires_SharedPtr_Const_T_Pointer_Return_Value<
T>>::type type;
using type = typename boost::mpl::if_c<IsConstSharedPtr<T>::value, RemoveConstSharedPtrImpl<T>, RemoveConstSharedPtr_Requires_SharedPtr_Const_T_Pointer_Return_Value<T> >::type;
};
};
......
......@@ -53,8 +53,8 @@ struct IsSharedPtr<boost::shared_ptr<T>> : boost::true_type {};
*/
template <typename ArgType> struct ToWeakPtrImpl {
// Useful types
typedef typename ArgType::element_type PointeeType;
typedef boost::weak_ptr<PointeeType> WeakPtr;
using PointeeType = typename ArgType::element_type;
using WeakPtr = boost::weak_ptr<PointeeType>;
inline PyObject *operator()(const ArgType &p) const {
if (!p)
......@@ -80,9 +80,7 @@ template <typename T> struct ToWeakPtr_Requires_Shared_Ptr_Return_Value {};
struct ToWeakPtr {
template <class T> struct apply {
// Deduce if type is correct for policy
typedef typename boost::mpl::if_c<
IsSharedPtr<T>::value, ToWeakPtrImpl<T>,
ToWeakPtr_Requires_Shared_Ptr_Return_Value<T>>::type type;
using type = typename boost::mpl::if_c<IsSharedPtr<T>::value, ToWeakPtrImpl<T>, ToWeakPtr_Requires_Shared_Ptr_Return_Value<T> >::type;
};
};
......
......@@ -85,15 +85,9 @@ template <typename ConversionPolicy> struct VectorRefToNumpy {
// The boost::python framework calls return_value_policy::apply<T>::type
template <class T> struct apply {
// Typedef that removes and const or reference qualifiers from the type
typedef typename std::remove_const<
typename std::remove_reference<T>::type>::type non_const_type;
using non_const_type = typename std::remove_const<typename std::remove_reference<T>::type>::type;
// MPL compile-time check that T is a reference to a std::vector
typedef typename boost::mpl::if_c<
boost::mpl::and_<std::is_reference<T>,
is_std_vector<non_const_type>>::value,
VectorRefToNumpyImpl<non_const_type, ConversionPolicy>,
VectorRefToNumpy_Requires_Reference_To_StdVector_Return_Type<T>>::type
type;
using type = typename boost::mpl::if_c<boost::mpl::and_<std::is_reference<T>, is_std_vector<non_const_type> >::value, VectorRefToNumpyImpl<non_const_type, ConversionPolicy>, VectorRefToNumpy_Requires_Reference_To_StdVector_Return_Type<T> >::type;
};
};
......@@ -130,12 +124,9 @@ struct VectorToNumpy {
// The boost::python framework calls return_value_policy::apply<T>::type
template <class T> struct apply {
// Typedef that removes any const from the type
typedef typename std::remove_const<T>::type non_const_type;
using non_const_type = typename std::remove_const<T>::type;
// MPL compile-time check that T is a std::vector
typedef typename boost::mpl::if_c<
is_std_vector<non_const_type>::value,
VectorRefToNumpyImpl<non_const_type, Converters::Clone>,
VectorToNumpy_Requires_StdVector_Return_By_Value<T>>::type type;
using type = typename boost::mpl::if_c<is_std_vector<non_const_type>::value, VectorRefToNumpyImpl<non_const_type, Converters::Clone>, VectorToNumpy_Requires_StdVector_Return_By_Value<T> >::type;
};
};
}
......
......@@ -40,8 +40,8 @@ namespace Registry {
* - Registers a new PropertyValueHandler for a boost::shared_ptr<T>
*/
template <typename IType> struct DLLExport RegisterWorkspacePtrToPython {
typedef boost::shared_ptr<IType> IType_sptr;
typedef boost::weak_ptr<IType> IType_wptr;
using IType_sptr = boost::shared_ptr<IType>;
using IType_wptr = boost::weak_ptr<IType>;
/// Constructor
RegisterWorkspacePtrToPython() {
using namespace boost::python;
......
......@@ -47,7 +47,7 @@ namespace Registry {
template <typename ValueType, typename Enable = void>
struct DLLExport TypedPropertyValueHandler : public PropertyValueHandler {
/// Type required by TypeRegistry framework
typedef ValueType HeldType;
using HeldType = ValueType;
/**
* Set function to handle Python -> C++ calls and get the correct type
......@@ -101,12 +101,12 @@ struct DLLExport TypedPropertyValueHandler<
typename std::enable_if<std::is_base_of<API::Workspace, T>::value>::type>
: public PropertyValueHandler {
/// Type required by TypeRegistry framework
typedef boost::shared_ptr<T> HeldType;
using HeldType = boost::shared_ptr<T>;
/// Convenience typedef
typedef T PointeeType;
using PointeeType = T;
/// Convenience typedef
typedef boost::shared_ptr<T> PropertyValueType;
using PropertyValueType = boost::shared_ptr<T>;
/**
* Set function to handle Python -> C++ calls and get the correct type
......
......@@ -83,7 +83,7 @@ std::string toString(const SequenceType &values) {
*/
template <typename ElementType> struct std_vector_exporter {
/// A typedef of a vector of template ElementTypes
typedef std::vector<ElementType> w_t;
using w_t = std::vector<ElementType>;
static std::string to_string(const w_t &values) {
if (values.empty())
......@@ -111,8 +111,8 @@ template <typename ElementType> struct std_vector_exporter {
// Found this at
// http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/scitbx/stl/set_wrapper.h?view=log
template <typename ElementType> struct std_set_exporter {
typedef std::set<ElementType> w_t;
typedef ElementType e_t;
using w_t = std::set<ElementType>;
using e_t = ElementType;
static void insert_element(w_t &self, e_t const &x) { self.insert(x); }
......
......@@ -38,8 +38,7 @@ PyArrayObject *cloneArray(MatrixWorkspace &workspace, DataField field,
npy_intp stride(0);
// Find out which function we need to call to access the data
typedef const MantidVec &(MatrixWorkspace::*ArrayAccessFn)(const size_t)
const;
using ArrayAccessFn = const MantidVec &(MatrixWorkspace::*)(const size_t) const;
ArrayAccessFn dataAccesor;
/**
* Can do better than this with a templated object that knows how to access
......
......@@ -34,30 +34,19 @@ GET_POINTER_SPECIALIZATION(ParallelAlgorithm)
GET_POINTER_SPECIALIZATION(DistributedAlgorithm)
namespace {
typedef AlgorithmAdapter<Algorithm> PythonAlgorithm;
typedef AlgorithmAdapter<SerialAlgorithm> PythonSerialAlgorithm;
typedef AlgorithmAdapter<ParallelAlgorithm> PythonParallelAlgorithm;
typedef AlgorithmAdapter<DistributedAlgorithm> PythonDistributedAlgorithm;
using PythonAlgorithm = AlgorithmAdapter<Algorithm>;
using PythonSerialAlgorithm = AlgorithmAdapter<SerialAlgorithm>;
using PythonParallelAlgorithm = AlgorithmAdapter<ParallelAlgorithm>;
using PythonDistributedAlgorithm = AlgorithmAdapter<DistributedAlgorithm>;
// declarePyAlgProperty(property*,doc)
typedef void (*declarePropertyType1)(boost::python::object &self,
Mantid::Kernel::Property *,
const std::string &);
using declarePropertyType1 = void (*)(boost::python::object &, Mantid::Kernel::Property *, const std::string &);
// declarePyAlgProperty(name, defaultValue, validator, doc, direction)
typedef void (*declarePropertyType2)(boost::python::object &self,
const std::string &,
const boost::python::object &,
const boost::python::object &,
const std::string &, const int);
using declarePropertyType2 = void (*)(boost::python::object &, const std::string &, const boost::python::object &, const boost::python::object &, const std::string &, const int);
// declarePyAlgProperty(name, defaultValue, doc, direction)
typedef void (*declarePropertyType3)(boost::python::object &self,
const std::string &,
const boost::python::object &,
const std::string &, const int);
using declarePropertyType3 = void (*)(boost::python::object &, const std::string &, const boost::python::object &, const std::string &, const int);
// declarePyAlgProperty(name, defaultValue, direction)
typedef void (*declarePropertyType4)(boost::python::object &self,
const std::string &,
const boost::python::object &, const int);
using declarePropertyType4 = void (*)(boost::python::object &, const std::string &, const boost::python::object &, const int);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
......
......@@ -43,7 +43,7 @@ AlgorithmProperty *createPropertyWithValidator(const std::string &name,
void export_AlgorithmProperty() {
// AlgorithmProperty has base PropertyWithValue<boost::shared_ptr<IAlgorithm>>
// which must be exported
typedef boost::shared_ptr<IAlgorithm> HeldType;
using HeldType = boost::shared_ptr<IAlgorithm>;
PropertyWithValueExporter<HeldType>::define("AlgorithmPropertyWithValue");
class_<AlgorithmProperty, bases<PropertyWithValue<HeldType>>,
......
......@@ -11,8 +11,7 @@ using namespace boost::python;
GET_POINTER_SPECIALIZATION(AnalysisDataServiceImpl)
void export_AnalysisDataService() {
typedef DataServiceExporter<AnalysisDataServiceImpl, Workspace_sptr>
ADSExporter;
using ADSExporter = DataServiceExporter<AnalysisDataServiceImpl, Workspace_sptr>;
auto pythonClass = ADSExporter::define("AnalysisDataServiceImpl");
pythonClass.def("Instance", &AnalysisDataService::Instance,
return_value_policy<reference_existing_object>(),
......
......@@ -18,35 +18,19 @@ void export_BinaryOperations() {
using namespace boost::python;
// Typedefs the various function types
typedef IMDWorkspace_sptr (*binary_fn_md_md)(
const IMDWorkspace_sptr, const IMDWorkspace_sptr, const std::string &,
const std::string &, bool, bool);
typedef WorkspaceGroup_sptr (*binary_fn_md_gp)(
const IMDWorkspace_sptr, const WorkspaceGroup_sptr, const std::string &,
const std::string &, bool, bool);
typedef WorkspaceGroup_sptr (*binary_fn_gp_md)(
const WorkspaceGroup_sptr, const IMDWorkspace_sptr, const std::string &,
const std::string &, bool, bool);
typedef WorkspaceGroup_sptr (*binary_fn_gp_gp)(
const WorkspaceGroup_sptr, const WorkspaceGroup_sptr, const std::string &,
const std::string &, bool, bool);
typedef IMDHistoWorkspace_sptr (*binary_fn_mh_mh)(
const IMDHistoWorkspace_sptr, const IMDHistoWorkspace_sptr,
const std::string &, const std::string &, bool, bool);
typedef IMDWorkspace_sptr (*binary_fn_md_db)(const IMDWorkspace_sptr, double,
const std::string &,
const std::string &, bool, bool);
typedef IMDHistoWorkspace_sptr (*binary_fn_mh_db)(
const IMDHistoWorkspace_sptr, double, const std::string &,
const std::string &, bool, bool);
typedef WorkspaceGroup_sptr (*binary_fn_gp_db)(
const WorkspaceGroup_sptr, double, const std::string &,
const std::string &, bool, bool);
using binary_fn_md_md = IMDWorkspace_sptr (*)(const IMDWorkspace_sptr, const IMDWorkspace_sptr, const std::string &, const std::string &, bool, bool);
using binary_fn_md_gp = WorkspaceGroup_sptr (*)(const IMDWorkspace_sptr, const WorkspaceGroup_sptr, const std::string &, const std::string &, bool, bool);
using binary_fn_gp_md = WorkspaceGroup_sptr (*)(const WorkspaceGroup_sptr, const IMDWorkspace_sptr, const std::string &, const std::string &, bool, bool);
using binary_fn_gp_gp = WorkspaceGroup_sptr (*)(const WorkspaceGroup_sptr, const WorkspaceGroup_sptr, const std::string &, const std::string &, bool, bool);
using binary_fn_mh_mh = IMDHistoWorkspace_sptr (*)(const IMDHistoWorkspace_sptr, const IMDHistoWorkspace_sptr, const std::string &, const std::string &, bool, bool);
using binary_fn_md_db = IMDWorkspace_sptr (*)(const IMDWorkspace_sptr, double, const std::string &, const std::string &, bool, bool);
using binary_fn_mh_db = IMDHistoWorkspace_sptr (*)(const IMDHistoWorkspace_sptr, double, const std::string &, const std::string &, bool, bool);
using binary_fn_gp_db = WorkspaceGroup_sptr (*)(const WorkspaceGroup_sptr, double, const std::string &, const std::string &, bool, bool);
// Always a return a Workspace_sptr
typedef return_value_policy<AsType<Workspace_sptr>> ReturnWorkspaceSptr;
using ReturnWorkspaceSptr = return_value_policy<AsType<Workspace_sptr> >;
// Binary operations that return a workspace
using boost::python::def;
......
......@@ -12,12 +12,10 @@ GET_POINTER_SPECIALIZATION(CompositeFunction)
namespace {
typedef double (CompositeFunction::*getParameterType1)(size_t) const;
typedef double (CompositeFunction::*getParameterType2)(
const std::string &) const;
using getParameterType1 = double (CompositeFunction::*)(size_t) const;
using getParameterType2 = double (CompositeFunction::*)(const std::string &) const;
typedef void (CompositeFunction::*setParameterType2)(const std::string &,
const double &, bool);
using setParameterType2 = void (CompositeFunction::*)(const std::string &, const double &, bool);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
......
......@@ -11,7 +11,7 @@ using namespace boost::python;
void export_FunctionProperty() {
// FuncitonProperty has base PropertyWithValue<boost::shared_ptr<IFunction>>
// which must be exported
typedef boost::shared_ptr<IFunction> HeldType;
using HeldType = boost::shared_ptr<IFunction>;
PropertyWithValueExporter<HeldType>::define("FunctionPropertyWithValue");
class_<FunctionProperty, bases<PropertyWithValue<HeldType>>,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment