Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::API::FileProperty Class Reference

A specialized class for dealing with file properties. More...

#include <FileProperty.h>

Inheritance diagram for Mantid::API::FileProperty:
Mantid::Kernel::PropertyWithValue< std::string > Mantid::Kernel::Property

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

FilePropertyclone () const override
 'Virtual copy constructor
 
 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.
 
 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.
 
 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.
 
const std::string & getDefaultExt () const
 Returns the main file extension that's used.
 
bool isDirectoryProperty () const
 Check if this is a directory type property.
 
bool isLoadProperty () const
 Check if this is a load type property.
 
bool isOptional () const
 Check if this property is optional.
 
bool isSaveProperty () const
 Check if this is a save type property.
 
std::string isValid () const override
 Returns an empty string if the property is valid, otherwise contains an error message.
 
FilePropertyoperator= (const FileProperty &)=default
 
std::string setValue (const std::string &propValue) override
 Overridden setValue method.
 
- 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.
 
PropertyWithValue< std::string > * clone () const override
 'Virtual copy constructor'
 
std::string getDefault () const override
 Get the value the property was initialised with -its default value.
 
IValidator_sptr getValidator () const
 Returns the validator as a constant variable so it cannot be changed.
 
bool isDefault () const override
 Indicates if the property's value is the same as it was when it was set N.B.
 
bool isMultipleSelectionAllowed () override
 Returns the set of valid values for this property, if such a set exists.
 
std::string isValid () const override
 Check the value chosen for the property is OK, unless overidden it just calls the validator's isValid() N.B.
 
virtual operator const std::string & () const
 Allows you to get the value of the property simply by typing its name.
 
bool operator!= (const PropertyWithValue< std::string > &rhs) const
 Deep comparison (not equal).
 
virtual const std::string & operator() () const
 Allows you to get the value of the property via an expression like myProperty()
 
PropertyWithValueoperator+= (Property const *right) override
 Add the value of another property.
 
PropertyWithValueoperator= (const PropertyWithValue &right)
 Copy assignment operator assigns only the value and the validator not the name, default (initial) value, etc.
 
virtual PropertyWithValueoperator= (const std::string &value)
 Assignment operator.
 
bool operator== (const PropertyWithValue< std::string > &rhs) const
 Deep comparison.
 
 PropertyWithValue ()=delete
 
 PropertyWithValue (const PropertyWithValue< std::string > &right)
 Copy constructor Note the default value of the copied object is the initial value of original.
 
 PropertyWithValue (const std::string &name, const std::string &defaultValue, const std::string &defaultValueStr, IValidator_sptr validator, const unsigned int direction)
 Constructor.
 
 PropertyWithValue (std::string name, std::string defaultValue, const unsigned int direction)
 Constructor.
 
 PropertyWithValue (std::string name, std::string defaultValue, IValidator_sptr validator=IValidator_sptr(new NullValidator), const unsigned int direction=Direction::Input)
 Constructor.
 
virtual void replaceValidator (IValidator_sptr newValidator)
 Replace the current validator with the given one.
 
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 a property value via a DataItem.
 
std::string setValue (const std::string &value) override
 Set the value of the property from a string representation.
 
std::string setValueFromJson (const Json::Value &value) override
 Set the value of the property from a Json representation.
 
int size () const override
 Get the size of the property.
 
std::string value () const override
 Get the value of the property as a string.
 
Json::Value valueAsJson () const override
 Attempt to construct a Json::Value object from the plain value.
 
std::string valueAsPrettyStr (const size_t maxLength=0, const bool collapseLists=true) const override
 Get the value of the property as a string.
 
- Public Member Functions inherited from Mantid::Kernel::Property
bool autoTrim () const
 Returns if the property is set to automatically trim string unput values of whitespace.
 
void clearSettings ()
 Deletes the PropertySettings object contained.
 
virtual const PropertyHistory createHistory () const
 Create a PropertyHistory object representing the current state of the Property.
 
void createTemporaryValue ()
 Create a temporary value for this property.
 
unsigned int direction () const
 returns the direction of the property
 
bool disableReplaceWSButton () const
 Returns if the property is set to disable the creation of the "Replace Workspace" button.
 
const std::string & documentation () const
 Get the property's documentation string.
 
const std::string & getGroup ()
 
virtual size_t getMemorySize () const
 
IPropertySettingsgetSettings ()
 
const IPropertySettingsgetSettings () const
 
bool hasTemporaryValue () const
 Property is using a temporary value for this property.
 
bool isDynamicDefault () const
 Returns a flag indicating that the property's value has been set programmatically, for example, if the property has a default value which depends on the value of an upstream property.
 
virtual bool isValueSerializable () const
 Whether the string returned by value() can be used for serialization.
 
virtual Propertymerge (Property *)
 Just returns the property (*this) unless overridden.
 
const std::string & name () const
 Get the property's name.
 
bool remember () const
 Whether to save input values.
 
void setAutoTrim (const bool &setting)
 Sets if the property is set to automatically trim string unput values of whitespace.
 
void setDisableReplaceWSButton (const bool &disable)
 Sets the property to disable the creation of the "Replace Workspace" button.
 
void setDocumentation (const std::string &documentation)
 Sets the user level description of the property.
 
void setGroup (const std::string &group)
 Set the group this property belongs to.
 
void setIsDynamicDefault (const bool &flag)
 Set or clear the flag indicating whether or not the property's value has been set programmatically.
 
void setName (const std::string &name)
 Set the property's name.
 
void setRemember (bool)
 Set wheter to remeber this property input.
 
void setSettings (std::unique_ptr< IPropertySettings > settings)
 Set the PropertySettings object.
 
virtual void setUnits (const std::string &unit)
 Sets the units of the property, as a string.
 
const std::string type () const
 Returns the type of the property as a string.
 
const std::type_info * type_info () const
 Get the property type_info.
 
virtual const std::string & units () const
 Returns the units of the property, if any, as a string.
 
virtual ~Property ()
 Virtual destructor.
 

Private Member Functions

bool extsMatchRunFiles ()
 Do the allowed values match the facility preference extensions for run files.
 
std::string isEmptyValueValid () const
 Returns a string depending on whether an empty value is valid.
 
std::string setLoadProperty (const std::string &propValue)
 Handles the filename if this is a save property.
 
std::string setSaveProperty (const std::string &propValue)
 Handles the filename if this is a save property.
 

Private Attributes

unsigned int m_action
 The action type of this property, i.e. load/save.
 
std::string m_defaultExt
 The default file extension associated with the type of file this property will handle.
 
std::string m_oldLoadFoundFile
 Last value of foundFile used in FileProperty::setLoadProperty.
 
std::string m_oldLoadPropValue
 Last value of propValue used in FileProperty::setLoadProperty.
 
bool m_runFileProp
 Is this property for run files?
 

Additional Inherited Members

- Protected Member Functions inherited from Mantid::Kernel::Property
 Property (const Property &right)
 Copy constructor.
 
 Property (std::string name, const std::type_info &type, const unsigned int &direction=Direction::Input)
 Constructor.
 
- Protected Attributes inherited from Mantid::Kernel::PropertyWithValue< std::string >
std::string m_initialValue
 the property's default value which is also its initial value
 
std::string m_value
 The value of the property.
 
- Protected Attributes inherited from Mantid::Kernel::Property
std::string m_name
 The name of the property.
 

Detailed Description

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.

Member Enumeration Documentation

◆ FileAction

An enumeration for load/save types.

This is passed on to the FileValidator as a constructor parameter.

Enumerator
Save 

to specify a file to write to, the file may or may not exist

OptionalSave 

to specify a file to write to but an empty string is

Load 

allowed here which will be passed to the algorithm

to specify a file to open for reading, the file must exist

OptionalLoad 

to specify a file to read but the file doesn't have to exist

Directory 

to specify a directory that must exist

OptionalDirectory 

to specify a directory that does not have to exist

Definition at line 46 of file FileProperty.h.

Constructor & Destructor Documentation

◆ FileProperty() [1/4]

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.

Parameters
nameThe name of the property
defaultValueA default value for the property
actionInndicate whether this should be a load/save property
extsThe allowed extensions. The front entry in the vector will be the default extension
directionAn optional direction (default=Input)

Definition at line 153 of file FileProperty.cpp.

◆ FileProperty() [2/4]

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.

Parameters
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 168 of file FileProperty.cpp.

◆ FileProperty() [3/4]

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.

Parameters
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 181 of file FileProperty.cpp.

◆ FileProperty() [4/4]

Mantid::API::FileProperty::FileProperty ( const FileProperty )
default

Member Function Documentation

◆ clone()

FileProperty * Mantid::API::FileProperty::clone ( ) const
inlineoverridevirtual

'Virtual copy constructor

Implements Mantid::Kernel::Property.

Definition at line 73 of file FileProperty.h.

◆ extsMatchRunFiles()

bool Mantid::API::FileProperty::extsMatchRunFiles ( )
private

Do the allowed values match the facility preference extensions for run files.

Returns
True if the extensions match those in the facility's preference list for run file extensions, false otherwise

Definition at line 286 of file FileProperty.cpp.

References Mantid::Kernel::PropertyWithValue< std::string >::allowedValues(), and Mantid::Kernel::FacilityInfo::extensions().

◆ getDefaultExt()

const std::string & Mantid::API::FileProperty::getDefaultExt ( ) const
inline

◆ isDirectoryProperty()

bool Mantid::API::FileProperty::isDirectoryProperty ( ) const

Check if this is a directory type property.

Check if this is a directory selection property.

Returns
True if the property is a Directory property

Definition at line 201 of file FileProperty.cpp.

References Directory, m_action, and OptionalDirectory.

◆ isEmptyValueValid()

std::string Mantid::API::FileProperty::isEmptyValueValid ( ) const
private

Returns a string depending on whether an empty value is valid.

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().

◆ isLoadProperty()

bool Mantid::API::FileProperty::isLoadProperty ( ) const

Check if this is a load type property.

Check if this is a load property.

Returns
True if the property is a Load property and false otherwise

Definition at line 189 of file FileProperty.cpp.

References m_action, and OptionalLoad.

Referenced by setValue().

◆ isOptional()

bool Mantid::API::FileProperty::isOptional ( ) const

Check if this property is optional.

Returns
True if the property is optinal, false otherwise

Definition at line 207 of file FileProperty.cpp.

References m_action, OptionalDirectory, OptionalLoad, and OptionalSave.

Referenced by isEmptyValueValid().

◆ isSaveProperty()

bool Mantid::API::FileProperty::isSaveProperty ( ) const

Check if this is a save type property.

Check if this is a Save property.

Returns
True if the property is a Save property and false otherwise

Definition at line 195 of file FileProperty.cpp.

References m_action, OptionalSave, and Save.

Referenced by setValue().

◆ isValid()

std::string Mantid::API::FileProperty::isValid ( ) const
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

Returns
an empty string if the property is valid, otherwise contains an error message

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().

◆ operator=()

FileProperty & Mantid::API::FileProperty::operator= ( const FileProperty )
default

◆ setLoadProperty()

std::string Mantid::API::FileProperty::setLoadProperty ( const std::string &  propValue)
private

Handles the filename if this is a save property.

Handles the filename if this is a load property.

Parameters
propValue:: The filename to treat as a filepath to be loaded
Returns
A string contain the result of the operation, empty if successful.

Definition at line 308 of file FileProperty.cpp.

References Mantid::Kernel::PropertyWithValue< std::string >::allowedValues(), 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().

◆ setSaveProperty()

std::string Mantid::API::FileProperty::setSaveProperty ( const std::string &  propValue)
private

Handles the filename if this is a save property.

Parameters
propValue:: The filename to treat as a filepath to be saved
Returns
A string contain the result of the operation, empty if successful.

Definition at line 364 of file FileProperty.cpp.

References m_action, OptionalSave, and Mantid::Kernel::PropertyWithValue< TYPE >::setValue().

Referenced by setValue().

◆ setValue()

std::string Mantid::API::FileProperty::setValue ( const std::string &  propValue)
overridevirtual

Overridden setValue method.

Set the value of the property.

Parameters
propValue:: The value here is treated as relating to a filename
Returns
A string indicating the outcome of the attempt to set the property. An empty string indicates success.

Implements Mantid::Kernel::Property.

Definition at line 217 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().

Member Data Documentation

◆ m_action

unsigned int Mantid::API::FileProperty::m_action
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().

◆ m_defaultExt

std::string Mantid::API::FileProperty::m_defaultExt
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().

◆ m_oldLoadFoundFile

std::string Mantid::API::FileProperty::m_oldLoadFoundFile
private

Last value of foundFile used in FileProperty::setLoadProperty.

Definition at line 115 of file FileProperty.h.

Referenced by setLoadProperty().

◆ m_oldLoadPropValue

std::string Mantid::API::FileProperty::m_oldLoadPropValue
private

Last value of propValue used in FileProperty::setLoadProperty.

Definition at line 113 of file FileProperty.h.

Referenced by setLoadProperty().

◆ m_runFileProp

bool Mantid::API::FileProperty::m_runFileProp
private

Is this property for run files?

Definition at line 111 of file FileProperty.h.

Referenced by setLoadProperty().


The documentation for this class was generated from the following files: