Mantid
|
A specialized class for dealing with file properties. More...
#include <FileProperty.h>
Public Types | |
enum | FileAction { Save = 0 , OptionalSave = 1 , Load = 2 , OptionalLoad = 3 , Directory = 4 , OptionalDirectory = 5 } |
An enumeration for load/save types. More... | |
Public Member Functions | |
FileProperty * | clone () const override |
'Virtual copy constructor More... | |
FileProperty (const FileProperty &)=default | |
FileProperty (const std::string &name, const std::string &default_value, unsigned int action, const std::string &ext, unsigned int direction=Kernel::Direction::Input) | |
Constructor taking a single extension as a string. More... | |
FileProperty (const std::string &name, const std::string &default_value, unsigned int action, std::initializer_list< std::string > exts, unsigned int direction=Kernel::Direction::Input) | |
Constructor taking a list of extensions as an initializer_list. More... | |
FileProperty (const std::string &name, const std::string &defaultValue, unsigned int action, const std::vector< std::string > &exts=std::vector< std::string >(), unsigned int direction=Kernel::Direction::Input) | |
Constructor taking a list of extensions as a vector. More... | |
std::string | getDefaultExt () const |
Returns the main file extension that's used. More... | |
bool | isDirectoryProperty () const |
Check if this is a directory type property. More... | |
bool | isLoadProperty () const |
Check if this is a load type property. More... | |
bool | isOptional () const |
Check if this property is optional. More... | |
bool | isSaveProperty () const |
Check if this is a save type property. More... | |
std::string | isValid () const override |
Returns an empty string if the property is valid, otherwise contains an error message. More... | |
FileProperty & | operator= (const FileProperty &)=default |
std::string | setValue (const std::string &propValue) override |
Overridden setValue method. More... | |
Public Member Functions inherited from Mantid::Kernel::PropertyWithValue< std::string > | |
std::vector< std::string > | allowedValues () const override |
Returns the set of valid values for this property, if such a set exists. More... | |
PropertyWithValue< std::string > * | clone () const override |
'Virtual copy constructor' More... | |
std::string | getDefault () const override |
Get the default value for the property which is the value the property was initialised with. More... | |
IValidator_sptr | getValidator () const |
bool | isDefault () const override |
Overriden function that returns if property has the same value that it was initialised with, if applicable. More... | |
bool | isMultipleSelectionAllowed () override |
Is Multiple Selection Allowed. More... | |
std::string | isValid () const override |
Overridden function that checks whether the property, if not overriden returns "". More... | |
virtual | operator const std::string & () const |
bool | operator!= (const PropertyWithValue< std::string > &rhs) const |
virtual const std::string & | operator() () const |
PropertyWithValue & | operator+= (Property const *right) override |
Add to this. More... | |
PropertyWithValue & | operator= (const PropertyWithValue &right) |
virtual PropertyWithValue & | operator= (const std::string &value) |
bool | operator== (const PropertyWithValue< std::string > &rhs) const |
PropertyWithValue (const PropertyWithValue< std::string > &right) | |
PropertyWithValue (const std::string &name, std::string defaultValue, const std::string &defaultValueStr, IValidator_sptr validator, const unsigned int direction) | |
PropertyWithValue (std::string name, std::string defaultValue, const unsigned int direction) | |
PropertyWithValue (std::string name, std::string defaultValue, IValidator_sptr validator=IValidator_sptr(new NullValidator), const unsigned int direction=Direction::Input) | |
virtual void | replaceValidator (IValidator_sptr newValidator) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
MANTID_KERNEL_DLL void | saveProperty (::NeXus::File *file) |
void | saveProperty (::NeXus::File *file) override |
std::string | setDataItem (const std::shared_ptr< DataItem > &data) override |
Set the value of the property via a DataItem pointer. More... | |
std::string | setValue (const std::string &value) override |
Set the value of the property via a string. More... | |
std::string | setValueFromJson (const Json::Value &value) override |
Set the value of the property via a Json object. More... | |
int | size () const override |
Return the size of this property. More... | |
std::string | value () const override |
Returns the value of the property as a string. More... | |
Json::Value | valueAsJson () const override |
Returns the value of the property as a Json::Value. More... | |
std::string | valueAsPrettyStr (const size_t maxLength=0, const bool collapseLists=true) const override |
Returns the value of the property as a pretty printed string. More... | |
Public Member Functions inherited from Mantid::Kernel::Property | |
virtual std::vector< std::string > | allowedValues () const |
Returns the set of valid values for this property, if such a set exists. More... | |
bool | autoTrim () const |
Returns if the property is set to automatically trim string unput values of whitespace. More... | |
void | clearSettings () |
Deletes the PropertySettings object contained. More... | |
virtual Property * | clone () const =0 |
'Virtual copy constructor' More... | |
virtual const PropertyHistory | createHistory () const |
Create a PropertyHistory object representing the current state of the Property. More... | |
void | createTemporaryValue () |
Create a temporary value for this property. More... | |
unsigned int | direction () const |
returns the direction of the property More... | |
const std::string & | documentation () const |
Get the property's documentation string. More... | |
virtual void | filterByTime (const Types::Core::DateAndTime &start, const Types::Core::DateAndTime &stop) |
Filter out a property by time. More... | |
virtual std::string | getDefault () const =0 |
Get the default value for the property which is the value the property was initialised with. More... | |
const std::string & | getGroup () |
virtual size_t | getMemorySize () const |
IPropertySettings * | getSettings () |
bool | hasTemporaryValue () const |
Property is using a temporary value for this property. More... | |
virtual bool | isDefault () const =0 |
Overriden function that returns if property has the same value that it was initialised with, if applicable. More... | |
virtual bool | isMultipleSelectionAllowed () |
Is Multiple Selection Allowed. More... | |
virtual std::string | isValid () const |
Overridden function that checks whether the property, if not overriden returns "". More... | |
virtual bool | isValueSerializable () const |
Whether the string returned by value() can be used for serialization. More... | |
virtual Property & | merge (Property *) |
Just returns the property (*this) unless overridden. More... | |
const std::string & | name () const |
Get the property's name. More... | |
virtual Property & | operator+= (Property const *rhs)=0 |
Add to this. More... | |
bool | remember () const |
Whether to save input values. More... | |
virtual void | saveProperty (::NeXus::File *) |
void | setAutoTrim (const bool &setting) |
Sets if the property is set to automatically trim string unput values of whitespace. More... | |
virtual std::string | setDataItem (const std::shared_ptr< DataItem > &)=0 |
Set the value of the property via a DataItem pointer. More... | |
void | setDocumentation (const std::string &documentation) |
Sets the user level description of the property. More... | |
void | setGroup (const std::string &group) |
Set the group this property belongs to. More... | |
void | setRemember (bool) |
Set wheter to remeber this property input. More... | |
void | setSettings (std::unique_ptr< IPropertySettings > settings) |
Set the PropertySettings object. More... | |
virtual void | setUnits (const std::string &unit) |
Sets the units of the property, as a string. More... | |
virtual std::string | setValue (const std::string &)=0 |
Set the value of the property via a string. More... | |
virtual std::string | setValueFromJson (const Json::Value &)=0 |
Set the value of the property via a Json object. More... | |
virtual std::string | setValueFromProperty (const Property &right)=0 |
Set the value of the property via a reference to another property. More... | |
virtual int | size () const |
Return the size of this property. More... | |
virtual void | splitByTime (std::vector< SplittingInterval > &splitter, std::vector< Property * > outputs, bool isProtonCharge=true) const |
Split a property by time. More... | |
const std::string | type () const |
Returns the type of the property as a string. More... | |
const std::type_info * | type_info () const |
Get the property type_info. More... | |
virtual const std::string & | units () const |
Returns the units of the property, if any, as a string. More... | |
virtual std::string | value () const =0 |
Returns the value of the property as a string. More... | |
virtual Json::Value | valueAsJson () const =0 |
Returns the value of the property as a Json::Value. More... | |
virtual std::string | valueAsPrettyStr (const size_t maxLength=0, const bool collapseLists=true) const |
Returns the value of the property as a pretty printed string. More... | |
virtual | ~Property () |
Virtual destructor. More... | |
Private Member Functions | |
bool | extsMatchRunFiles () |
Do the allowed values match the facility preference extensions for run files. More... | |
std::string | isEmptyValueValid () const |
Returns a string depending on whether an empty value is valid. More... | |
std::string | setLoadProperty (const std::string &propValue) |
Handles the filename if this is a save property. More... | |
std::string | setSaveProperty (const std::string &propValue) |
Handles the filename if this is a save property. More... | |
Private Attributes | |
unsigned int | m_action |
The action type of this property, i.e. load/save. More... | |
std::string | m_defaultExt |
The default file extension associated with the type of file this property will handle. More... | |
std::string | m_oldLoadFoundFile |
Last value of foundFile used in FileProperty::setLoadProperty. More... | |
std::string | m_oldLoadPropValue |
Last value of propValue used in FileProperty::setLoadProperty. More... | |
bool | m_runFileProp |
Is this property for run files? More... | |
Additional Inherited Members | |
Protected Member Functions inherited from Mantid::Kernel::Property | |
Property (const Property &right) | |
Copy constructor. More... | |
Property (std::string name, const std::type_info &type, const unsigned int &direction=Direction::Input) | |
Constructor. More... | |
Protected Attributes inherited from Mantid::Kernel::PropertyWithValue< std::string > | |
std::string | m_initialValue |
the property's default value which is also its initial value More... | |
std::string | m_value |
The value of the property. More... | |
Protected Attributes inherited from Mantid::Kernel::Property | |
std::string | m_name |
The name of the property. More... | |
A specialized class for dealing with file properties.
Mantid allows multiple search paths to be defined so that each of these is used when attempting to load a file with a relative path.
When attempting to load a file this class handles searching the specified paths and, if found, the value()
method returns the full path to the file. For saving, Mantid's default save directory is used when a relative path is encountered.
This class can also be used to browse for a Directory, by specify the appropriate FileAction type parameter in the constructor.
Definition at line 42 of file FileProperty.h.
An enumeration for load/save types.
This is passed on to the FileValidator as a constructor parameter.
Definition at line 46 of file FileProperty.h.
Mantid::API::FileProperty::FileProperty | ( | const std::string & | name, |
const std::string & | defaultValue, | ||
unsigned int | action, | ||
const std::vector< std::string > & | exts = std::vector<std::string>() , |
||
unsigned int | direction = Kernel::Direction::Input |
||
) |
Constructor taking a list of extensions as a vector.
Constructor.
name | The name of the property |
defaultValue | A default value for the property |
action | Inndicate whether this should be a load/save property |
exts | The allowed extensions. The front entry in the vector will be the default extension |
direction | An optional direction (default=Input) |
Definition at line 152 of file FileProperty.cpp.
Mantid::API::FileProperty::FileProperty | ( | const std::string & | name, |
const std::string & | default_value, | ||
unsigned int | action, | ||
const std::string & | ext, | ||
unsigned int | direction = Kernel::Direction::Input |
||
) |
Constructor taking a single extension as a string.
Constructor.
name | :: The name of the property |
default_value | :: A default value for the property |
ext | :: The allowed extension |
action | :: An enum indicating whether this should be a load/save property |
direction | :: An optional direction (default=Input) |
Definition at line 167 of file FileProperty.cpp.
Mantid::API::FileProperty::FileProperty | ( | const std::string & | name, |
const std::string & | default_value, | ||
unsigned int | action, | ||
std::initializer_list< std::string > | exts, | ||
unsigned int | direction = Kernel::Direction::Input |
||
) |
Constructor taking a list of extensions as an initializer_list.
Constructor.
name | :: The name of the property |
default_value | :: A default value for the property |
exts | :: The braced-list of allowed extensions |
action | :: An enum indicating whether this should be a load/save property |
direction | :: An optional direction (default=Input) |
Definition at line 180 of file FileProperty.cpp.
|
default |
|
inlineoverridevirtual |
'Virtual copy constructor
Implements Mantid::Kernel::Property.
Definition at line 73 of file FileProperty.h.
|
private |
Do the allowed values match the facility preference extensions for run files.
Definition at line 286 of file FileProperty.cpp.
References Mantid::Kernel::PropertyWithValue< std::string >::allowedValues(), Mantid::Kernel::FacilityInfo::extensions(), and Mantid::Kernel::SingletonHolder< T >::Instance().
|
inline |
Returns the main file extension that's used.
Definition at line 90 of file FileProperty.h.
Referenced by MantidQt::API::FileFinderWidget::getFileExtensionsFromAlgorithm(), MantidQt::MantidWidgets::SaveWorkspaces::getSaveAlgExt(), and MantidQt::MantidWidgets::WorkspaceTreeWidget::saveToProgram().
bool Mantid::API::FileProperty::isDirectoryProperty | ( | ) | const |
Check if this is a directory type property.
Check if this is a directory selection property.
Definition at line 200 of file FileProperty.cpp.
References Directory, m_action, and OptionalDirectory.
|
private |
Returns a string depending on whether an empty value is valid.
Definition at line 272 of file FileProperty.cpp.
References isOptional().
Referenced by isValid(), and setValue().
bool Mantid::API::FileProperty::isLoadProperty | ( | ) | const |
Check if this is a load type property.
Check if this is a load property.
Definition at line 188 of file FileProperty.cpp.
References m_action, and OptionalLoad.
Referenced by setValue().
bool Mantid::API::FileProperty::isOptional | ( | ) | const |
Check if this property is optional.
Definition at line 206 of file FileProperty.cpp.
References m_action, OptionalDirectory, OptionalLoad, and OptionalSave.
Referenced by isEmptyValueValid().
bool Mantid::API::FileProperty::isSaveProperty | ( | ) | const |
Check if this is a save type property.
Check if this is a Save property.
Definition at line 194 of file FileProperty.cpp.
References m_action, OptionalSave, and Save.
Referenced by setValue().
|
overridevirtual |
Returns an empty string if the property is valid, otherwise contains an error message.
Checks whether the current value is considered valid.
Use the validator unless the value is an empty string. In this case it is only valid if the property is not optional
Reimplemented from Mantid::Kernel::Property.
Definition at line 260 of file FileProperty.cpp.
References isEmptyValueValid(), Mantid::Kernel::PropertyWithValue< TYPE >::isValid(), and Mantid::Kernel::PropertyWithValue< std::string >::value().
|
default |
|
private |
Handles the filename if this is a save property.
Handles the filename if this is a load property.
propValue | :: The filename to treat as a filepath to be loaded |
Definition at line 313 of file FileProperty.cpp.
References Mantid::Kernel::PropertyWithValue< std::string >::allowedValues(), Mantid::Kernel::SingletonHolder< T >::Instance(), lower, m_defaultExt, m_oldLoadFoundFile, m_oldLoadPropValue, m_runFileProp, Mantid::Kernel::PropertyWithValue< TYPE >::setValue(), Mantid::Kernel::Strings::toLower(), Mantid::Kernel::Strings::toUpper(), and upper.
Referenced by setValue().
|
private |
Handles the filename if this is a save property.
propValue | :: The filename to treat as a filepath to be saved |
Definition at line 369 of file FileProperty.cpp.
References Mantid::Kernel::SingletonHolder< T >::Instance(), m_action, OptionalSave, and Mantid::Kernel::PropertyWithValue< TYPE >::setValue().
Referenced by setValue().
|
overridevirtual |
Overridden setValue method.
Set the value of the property.
propValue | :: The value here is treated as relating to a filename |
Implements Mantid::Kernel::Property.
Definition at line 216 of file FileProperty.cpp.
References error, isEmptyValueValid(), isLoadProperty(), isSaveProperty(), setLoadProperty(), setSaveProperty(), Mantid::Kernel::PropertyWithValue< TYPE >::setValue(), and Mantid::Kernel::Strings::strip().
Referenced by Mantid::API::MultipleFileProperty::setValueAsMultipleFiles(), and Mantid::API::MultipleFileProperty::setValueAsSingleFile().
|
private |
The action type of this property, i.e. load/save.
Definition at line 106 of file FileProperty.h.
Referenced by isDirectoryProperty(), isLoadProperty(), isOptional(), isSaveProperty(), and setSaveProperty().
|
private |
The default file extension associated with the type of file this property will handle.
Definition at line 109 of file FileProperty.h.
Referenced by setLoadProperty().
|
private |
Last value of foundFile used in FileProperty::setLoadProperty.
Definition at line 115 of file FileProperty.h.
Referenced by setLoadProperty().
|
private |
Last value of propValue used in FileProperty::setLoadProperty.
Definition at line 113 of file FileProperty.h.
Referenced by setLoadProperty().
|
private |
Is this property for run files?
Definition at line 111 of file FileProperty.h.
Referenced by setLoadProperty().