13#include <json/value.h>
37 unsigned int direction)
38 :
BaseClass(
name, defaultValue, direction), m_dataServiceKey(), m_defaultAsStr() {
40 throw std::invalid_argument(
"PropertyManagerProperty() requires a name");
52 return (mgr ? mgr->asString(
true) :
"");
78 auto &globalPropMgrs = PropertyManagerDataService::Instance();
80 (*this) = globalPropMgrs.retrieve(strValue);
87 auto pmValue = (*this)();
89 pmValue = std::make_shared<PropertyManager>();
92 std::string strValueToSet = strValue.empty() ?
"{}" : strValue;
93 std::ostringstream msg;
95 const std::unordered_set<std::string> ignored;
96 bool createMissing{
true};
97 pmValue->resetProperties();
98 pmValue->setProperties(strValueToSet, ignored, createMissing);
100 }
catch (std::invalid_argument &exc) {
101 msg <<
"Error setting value from string.\n"
102 "String is expected to contain either the name of a global "
103 "PropertyManager or a json-formatted object.\n"
106 }
catch (std::exception &exc) {
107 msg <<
"Error setting value from string.\n" << exc.what();
119 if (
value.type() == Json::objectValue) {
123 }
catch (std::exception &exc) {
124 return std::string(
"Attempt to set Json value to property failed: ") + exc.what();
127 return std::string(
"Attempt to set incorrect Json type to "
128 "PropertyManager. Expected objectValue, found " +
142 throw std::runtime_error(std::string(
"Attempt to assign property ") +
name +
143 " to incorrect type. Expected shared_ptr<PropertyManager>.");
149IPropertyManager::getValue<PropertyManager_const_sptr>(
const std::string &
name)
const {
152 return prop->operator()();
154 std::string message =
155 "Attempt to assign property " +
name +
" to incorrect type. Expected const shared_ptr<PropertyManager>.";
156 throw std::runtime_error(message);
double value
The value of the point.
Exception for when an item is not found in a collection.
virtual Property * getPointerToProperty(const std::string &name) const =0
Get a pointer to property by name.
std::string m_dataServiceKey
Json::Value valueAsJson() const override
Create a Json::Value objectValue from the PropertyManager.
std::string m_defaultAsStr
std::string setValueFromJson(const Json::Value &value) override
Sets the value of the property from a Json object.
std::string setValue(const std::string &strValue) override
Overwrite the current value.
PropertyManagerProperty(const std::string &name, unsigned int direction=Direction::Input)
Constructor with a default empty pointer.
std::string getDefault() const override
PropertyManager_sptr ValueType
std::string value() const override
const std::string & name() const
Get the property's name.
std::shared_ptr< const PropertyManager > PropertyManager_const_sptr
shared pointer to Mantid::Kernel::PropertyManager(const version)
MANTID_KERNEL_DLL PropertyManager_sptr createPropertyManager(const Json::Value &keyValues)
Attempt to create a PropertyManager from the Json::Value.
std::shared_ptr< PropertyManager > PropertyManager_sptr
Typedef for a shared pointer to a PropertyManager.
std::string to_string(const wide_integer< Bits, Signed > &n)