10#include <boost/python/class.hpp>
11#include <boost/python/enum.hpp>
12#include <boost/python/register_ptr_to_python.hpp>
13#include <boost/python/tuple.hpp>
26const std::string deprecatedName(
const Unit &self) {
27 PyErr_Warn(PyExc_DeprecationWarning,
"'name' is deprecated, use 'caption' instead.");
35const std::string deprecatedLabel(
const Unit &self) {
36 PyErr_Warn(PyExc_DeprecationWarning,
"'unit.label()' is deprecated, use 'str(unit.symbol())' instead.");
40template <
class T> tuple quickConversionWrapper(
const Unit &self,
const T &destUnitName) {
41 double wavelengthFactor = 0;
42 double wavelengthPower = 0;
43 bool converted = self.
quickConversion(destUnitName, wavelengthFactor, wavelengthPower);
45 throw std::runtime_error(
"Quick conversion is not possible from unit:" + std::string(self.
unitID()) +
46 " to the desired unit.");
48 return boost::python::make_tuple<double>(wavelengthFactor, wavelengthPower);
54 register_ptr_to_python<std::shared_ptr<Unit>>();
56 enum_<Mantid::Kernel::UnitParams>(
"UnitParams")
65 class_<Unit, boost::noncopyable>(
"Unit", no_init)
66 .def(
"name", &deprecatedName, arg(
"self"),
"Return the full name of the unit (deprecated, use caption)")
67 .def(
"caption", &
Unit::caption, arg(
"self"),
"Return the full name of the unit")
68 .def(
"label", &deprecatedLabel, arg(
"self"),
69 "Returns a plain-text label to be used "
70 "as the symbol for the unit (deprecated, "
73 "Returns a UnitLabel object that holds "
74 "information on the symbol to use for unit")
76 "Returns the string ID of the unit. This may/may not match "
78 .def(
"quickConversion", &quickConversionWrapper<Unit>, (arg(
"self"), arg(
"destUnitName")),
79 "Check whether the unit can be converted to another via a "
81 .def(
"quickConversion", &quickConversionWrapper<std::string>, (arg(
"self"), arg(
"destination")),
82 "Check whether the unit can be converted to another via a "
#define GET_POINTER_SPECIALIZATION(TYPE)
const AsciiString & ascii() const
Return an ascii label for unit.
The base units (abstract) class.
virtual const UnitLabel label() const =0
A label for the unit to be printed on axes,.
virtual const std::string caption() const =0
The full name of the unit.
virtual const std::string unitID() const =0
The name of the unit.
bool quickConversion(const Unit &destination, double &factor, double &power) const
Is conversion by constant multiplication possible?
std::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.