Mantid
Loading...
Searching...
No Matches
AlgorithmProperty.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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//-----------------------------------------------------------------------------
8// Includes
9//-----------------------------------------------------------------------------
11#include "MantidAPI/Algorithm.h"
13
14#include <json/value.h>
15
16#include <memory>
17#include <utility>
18
19namespace Mantid::API {
20
21//-----------------------------------------------------------------------------
22// Public member functions
23//-----------------------------------------------------------------------------
24
33 unsigned int direction)
34 : Kernel::PropertyWithValue<HeldType>(propName, HeldType(), std::move(validator), direction), m_algmStr() {}
35
40std::string AlgorithmProperty::value() const { return m_algmStr; }
41
45Json::Value AlgorithmProperty::valueAsJson() const { return (*this)()->toJson(); }
46
51std::string AlgorithmProperty::getDefault() const { return ""; }
52
60std::string AlgorithmProperty::setValue(const std::string &value) {
61 try {
63 } catch (std::exception &exc) {
64 return exc.what();
65 }
66}
67
74std::string AlgorithmProperty::setValueFromJson(const Json::Value &value) {
75 try {
77 } catch (std::exception &exc) {
78 return exc.what();
79 }
80}
81
89 std::string message;
90 try {
92 } catch (std::exception &e) {
93 message = e.what();
94 }
95
96 if (message.empty()) {
97 m_algmStr = algm->toString();
98 return isValid();
99 } else
100 return message;
101}
102
103} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
std::shared_ptr< IAlgorithm > HeldType
Typedef the held type.
std::string setValue(const std::string &value) override
Sets the value of the algorithm from a string representation.
AlgorithmProperty(const std::string &propName, Kernel::IValidator_sptr validator=Kernel::IValidator_sptr(new Kernel::NullValidator), unsigned int direction=Kernel::Direction::Input)
Constructor.
std::string setValueFromJson(const Json::Value &value) override
Sets the value of the algorithm from a Json representation.
std::string setBaseValue(const HeldType &algm)
Set the value from the algorithm pointer.
std::string value() const override
Return the algorithm as string.
std::string getDefault() const override
Get the default.
Json::Value valueAsJson() const override
Create a Json::Value from the algorithm value.
static IAlgorithm_sptr fromString(const std::string &input)
De-serialize an object from a string.
Definition: Algorithm.cpp:967
static IAlgorithm_sptr fromJson(const Json::Value &input)
De-serialize an object from a Json.
Definition: Algorithm.cpp:983
The concrete, templated class for properties.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26
STL namespace.