Mantid
Loading...
Searching...
No Matches
PropertyWithValueExporter.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
11
12#ifndef Q_MOC_RUN
13#include <boost/python/bases.hpp>
14#include <boost/python/class.hpp>
15#include <boost/python/return_by_value.hpp>
16#include <boost/python/return_value_policy.hpp>
17#endif
18
19// Call the dtype helper function
20template <typename HeldType> std::string dtype(Mantid::Kernel::PropertyWithValue<HeldType> &self) {
21 // Check for the special case of a string
22 if (std::is_same<HeldType, std::string>::value) {
23 std::stringstream ss;
24 std::string val = self.value();
25 ss << "S" << val.size();
26 std::string ret_val = ss.str();
27 return ret_val;
28 }
29
31}
32
33namespace Mantid {
34namespace PythonInterface {
35
39template <typename HeldType, typename ValueReturnPolicy = boost::python::return_by_value>
41 static void define(const char *pythonClassName) {
42 using namespace boost::python;
43 using namespace Mantid::Kernel;
44
45 class_<PropertyWithValue<HeldType>, bases<Property>, boost::noncopyable>(
46 pythonClassName, init<std::string, HeldType>((arg("self"), arg("name"), arg("value"))))
47 .add_property("value",
48 make_function(&PropertyWithValue<HeldType>::operator(), return_value_policy<ValueReturnPolicy>()))
49 .def("dtype", &dtype<HeldType>, arg("self"));
50 }
51};
52} // namespace PythonInterface
53} // namespace Mantid
std::string dtype(Mantid::Kernel::PropertyWithValue< HeldType > &self)
The concrete, templated class for properties.
std::string value() const override
Returns the value of the property as a string.
std::string dtype(const Container< HeldType > &)
Helper class which provides the Collimation Length for SANS instruments.
A helper struct to export PropertyWithValue<> types to Python.
static void define(const char *pythonClassName)