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 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...
 
FilePropertyoperator= (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
 
PropertyWithValueoperator+= (Property const *right) override
 Add to this. More...
 
PropertyWithValueoperator= (const PropertyWithValue &right)
 
virtual PropertyWithValueoperator= (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 Propertyclone () 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
 
IPropertySettingsgetSettings ()
 
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 Propertymerge (Property *)
 Just returns the property (*this) unless overridden. More...
 
const std::string & name () const
 Get the property's name. More...
 
virtual Propertyoperator+= (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...
 

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 152 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 167 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 180 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(), Mantid::Kernel::FacilityInfo::extensions(), and Mantid::Kernel::SingletonHolder< T >::Instance().

◆ getDefaultExt()

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 200 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 188 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 206 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 194 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 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().

◆ 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 369 of file FileProperty.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), 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 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().

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: