10#include "MantidKernel/DllConfig.h"
23#include <unordered_set>
39class IPropertySettings;
43class SplittingInterval;
45template <
typename T>
class TimeSeriesProperty;
46template <
typename T>
class Matrix;
64 virtual void declareProperty(std::unique_ptr<Property> p,
const std::string &doc =
"") = 0;
82 const std::string &doc =
"",
const unsigned int direction = Direction::Input) {
83 std::unique_ptr<PropertyWithValue<T>> p = std::make_unique<PropertyWithValue<T>>(
name,
value, validator, direction);
84 declareProperty(std::move(p), doc);
99 const unsigned int direction = Direction::Input) {
100 std::unique_ptr<PropertyWithValue<T>> p =
101 std::make_unique<PropertyWithValue<T>>(
name,
value, std::make_shared<NullValidator>(), direction);
102 declareProperty(std::move(p), doc);
114 std::unique_ptr<PropertyWithValue<T>> p =
115 std::make_unique<PropertyWithValue<T>>(
name,
value, std::make_shared<NullValidator>(), direction);
116 declareProperty(std::move(p));
139 const std::string &doc = std::string(),
const unsigned int direction = Direction::Input) {
140 if (
value ==
nullptr)
141 throw std::invalid_argument(
"Attempted to set " +
name +
" to nullptr");
143 declareProperty(
name, std::string(
value), std::move(validator), doc, direction);
168 const unsigned int direction = Direction::Input) {
169 if (
value ==
nullptr)
170 throw std::invalid_argument(
"Attempted to set " +
name +
" to nullptr");
172 declareProperty(
name, std::string(
value), std::move(validator), doc, direction);
184 if (
value ==
nullptr)
185 throw std::invalid_argument(
"Attempted to set " +
name +
" to nullptr");
187 declareProperty(
name, std::string(
value), std::make_shared<NullValidator>(),
"", direction);
205 const std::string &propertiesString,
206 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>()) = 0;
217 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
218 bool createMissing =
false) = 0;
228 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
229 bool createMissing =
false) = 0;
283 setTypedProperty(
name, std::move(
value), std::is_convertible<std::unique_ptr<T>, std::shared_ptr<DataItem>>());
284 this->afterPropertySet(
name);
297 if (
value ==
nullptr)
298 throw std::invalid_argument(
"Attempted to set " +
name +
" to nullptr");
299 return setProperty(
name, std::string(
value));
318 virtual std::string
asString(
bool withDefaultValues =
false)
const = 0;
321 virtual ::Json::Value
asJson(
bool withDefaultValues =
false)
const = 0;
346 throw std::logic_error(
"Not implemented yet.");
401 operator unsigned long();
408 operator std::string();
413 template <
typename T>
operator std::vector<T>() {
return pm.
getValue<std::vector<T>>(prop); }
415 template <
typename T>
operator std::vector<std::vector<T>>() {
416 return pm.
getValue<std::vector<std::vector<T>>>(prop);
419 template <
typename T>
operator std::shared_ptr<T>() {
return pm.
getValue<std::shared_ptr<T>>(prop); }
421 template <
typename T>
operator std::shared_ptr<const T>() {
return pm.
getValue<std::shared_ptr<T>>(prop); }
441 setTypedProperty(
name,
value, std::is_convertible<T, std::shared_ptr<DataItem>>());
442 this->afterPropertySet(
name);
462 static_cast<void>(
sizeof(T));
463 setTypedProperty(
name,
value, std::is_convertible<T *, DataItem *>());
464 this->afterPropertySet(
name);
476 template <
typename T>
482 throw std::invalid_argument(
"Attempt to assign to property (" +
name +
") of incorrect type");
494 template <
typename T>
497 std::shared_ptr<DataItem> data = std::static_pointer_cast<DataItem>(
value);
498 std::string
error = getPointerToProperty(
name)->setDataItem(data);
499 if (!
error.empty()) {
500 throw std::invalid_argument(
error);
514 template <
typename T>
517 std::shared_ptr<DataItem> data(std::move(
value));
518 std::string
error = getPointerToProperty(
name)->setDataItem(data);
519 if (!
error.empty()) {
520 throw std::invalid_argument(
error);
532#define DEFINE_IPROPERTYMANAGER_GETVALUE(type) \
535 template <> DLLExport type IPropertyManager::getValue<type>(const std::string &name) const { \
536 PropertyWithValue<type> *prop = dynamic_cast<PropertyWithValue<type> *>(getPointerToProperty(name)); \
540 std::string message = "Attempt to assign property " + name + " to incorrect type. Expected type " #type; \
541 throw std::runtime_error(message); \
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
Interface to PropertyManager.
void declareProperty(const std::string &name, const char *value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc=std::string(), const unsigned int direction=Direction::Input)
Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue...
virtual void clear()=0
Clears all properties under management.
virtual void resetProperties()=0
virtual Property * getPointerToPropertyOrdinal(const int &index) const =0
Get a property by an index.
IPropertyManager * doSetProperty(const std::string &name, const T &value)
Helper method to set the value of a PropertyWithValue.
IPropertyManager * setProperty(const std::string &name, const char *value)
Specialised version of setProperty template method to handle const char *.
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
virtual bool validateProperties() const =0
Validates all the properties in the collection.
bool isPropertyVisible(const std::string &name) const
Test if a given property should be visible.
void declareProperty(const std::string &name, T value, const unsigned int direction)
Add a property of the template type to the list of managed properties.
IPropertyManager * setProperty(const std::string &name, const std::string &value)
Specialised version of setProperty template method to handle std::string.
virtual ::Json::Value asJson(bool withDefaultValues=false) const =0
Return the property manager serialized as a json object.
virtual void setProperties(const ::Json::Value &jsonValue, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false)=0
Sets all the properties from a json object.
std::vector< Property * > getPropertiesInGroup(const std::string &group) const
Get the list of managed properties in a given group.
IPropertyManager * setTypedProperty(const std::string &name, std::unique_ptr< T > value, const std::true_type &)
Set a property value from std::unique_ptr that is convertible to a DataItem_sptr.
virtual bool existsProperty(const std::string &name) const =0
Checks whether the named property is already in the list of managed property.
virtual void setPropertyOrdinal(const int &index, const std::string &value)=0
Set the value of a property by an index.
virtual void setPropertiesWithString(const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >())=0
Sets all the declared properties from a string.
void declareProperty(const std::string &name, T value, const std::string &doc, const unsigned int direction=Direction::Input)
Add a property to the list of managed properties with no validator.
virtual void removeProperty(const std::string &name, const bool delproperty=true)=0
Removes the property from management.
virtual ~IPropertyManager()=default
IPropertyManager * doSetProperty(const std::string &name, const std::shared_ptr< T > &value)
Helper method to set the value of a PropertyWithValue, variant for shared_ptr types.
virtual std::string asString(bool withDefaultValues=false) const =0
Return the property manager serialized as a string.
void declareProperty(const std::string &name, const char *value, const unsigned int direction)
Add a property of string type to the list of managed properties.
virtual void declareProperty(std::unique_ptr< Property > p, const std::string &doc="")=0
Function to declare properties (i.e. store them)
IPropertyManager * setTypedProperty(const std::string &name, const T &value, const std::false_type &)
Set a property value that is not convertible to a DataItem_sptr.
virtual void declareOrReplaceProperty(std::unique_ptr< Property > p, const std::string &doc="")=0
Function to declare properties (i.e. store them)
virtual Property * getPointerToProperty(const std::string &name) const =0
Get a pointer to property by name.
virtual std::vector< std::string > getDeclaredPropertyNames() const noexcept=0
Get the list of managed property names.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
virtual void setProperties(const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false)=0
Sets all properties from a string.
virtual std::string getPropertyValue(const std::string &name) const =0
Get the value of a property as a string.
void declareProperty(const std::string &name, const char *value, const std::string &doc, IValidator_sptr validator=std::make_shared< NullValidator >(), const unsigned int direction=Direction::Input)
Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue...
virtual size_t propertyCount() const =0
Returns the number of properties under management.
virtual std::unique_ptr< Property > takeProperty(const size_t index)=0
Removes the property from management and returns a pointer to it.
virtual void afterPropertySet(const std::string &)
Override this method to perform a custom action right after a property was set.
void declareProperty(const std::string &name, T value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc="", const unsigned int direction=Direction::Input)
Add a property of the template type to the list of managed properties.
void updatePropertyValues(const IPropertyManager &other)
Update values of the existing properties.
virtual void filterByProperty(Mantid::Kernel::LogFilter *, const std::vector< std::string > &)
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings const > settings)
Add a PropertySettings instance to the chain of settings for a given property.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
virtual const std::vector< Property * > & getProperties() const =0
Get the list of managed properties.
IPropertyManager * setProperty(const std::string &name, std::unique_ptr< T > value)
Templated method to set the value of a PropertyWithValue from a std::unique_ptr.
IPropertyManager * setTypedProperty(const std::string &name, const T &value, const std::true_type &)
Set a property value that is convertible to a DataItem_sptr.
bool isPropertyEnabled(const std::string &name) const
Test if a given property should be enabled.
T getValue(const std::string &name) const
Templated method to get the value of a property.
virtual void setPropertyValueFromJson(const std::string &name, const Json::Value &value)=0
Sets property value from a Json::Value.
This class is for filtering TimeSeriesProperty data.
OptionalBool : Tri-state bool.
The concrete, templated class for properties.
Base class for properties.
void setGroup(const std::string &group)
Set the group this property belongs to.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Helper class which provides the Collimation Length for SANS instruments.
Utility class that enables the getProperty() method to effectively be templated on the return type.
const IPropertyManager & pm
Reference to the containing PropertyManager.
TypedValue(const IPropertyManager &p, const std::string &name)
Constructor.
const std::string prop
The name of the property desired.