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

A property to allow a user to specify multiple files to load. More...

#include <MultipleFileProperty.h>

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

Public Member Functions

MultipleFilePropertyclone () const override
 'Virtual copy constructor'
 
std::string getDefault () const override
 Get the value the property was initialised with -its default value.
 
const std::string & getDefaultExt () const
 Returns the main file extension that's used.
 
const std::vector< std::string > & getExts () const
 
bool isOptional () const
 Check if this property is optional.
 
 MultipleFileProperty (const MultipleFileProperty &)=default
 
 MultipleFileProperty (const std::string &name, const std::vector< std::string > &exts=std::vector< std::string >())
 Default constructor with default action.
 
 MultipleFileProperty (const std::string &name, unsigned int action, const std::vector< std::string > &exts=std::vector< std::string >(), bool allowEmptyTokens=false)
 Alternative constructor with action.
 
MultipleFilePropertyoperator= (const MultipleFileProperty &)=default
 
std::string setValue (const std::string &propValue) override
 Convert the given propValue into a comma and plus separated list of full filenames, and pass to the parent's setValue method to store as a vector of vector of strings.
 
std::string value () const override
 Returns the value of the property as a string.
 
- Public Member Functions inherited from Mantid::Kernel::PropertyWithValue< std::vector< std::vector< 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::vector< std::vector< 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::vector< std::vector< std::string > > & () const
 Allows you to get the value of the property simply by typing its name.
 
bool operator!= (const PropertyWithValue< std::vector< std::vector< std::string > > > &rhs) const
 Deep comparison (not equal).
 
virtual const std::vector< std::vector< 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::vector< std::vector< std::string > > &value)
 Assignment operator.
 
bool operator== (const PropertyWithValue< std::vector< std::vector< std::string > > > &rhs) const
 Deep comparison.
 
 PropertyWithValue ()=delete
 
 PropertyWithValue (const PropertyWithValue< std::vector< std::vector< 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::vector< std::vector< std::string > > &defaultValue, const std::string &defaultValueStr, IValidator_sptr validator, const unsigned int direction)
 Constructor.
 
 PropertyWithValue (std::string name, std::vector< std::vector< std::string > > defaultValue, const unsigned int direction)
 Constructor.
 
 PropertyWithValue (std::string name, std::vector< std::vector< 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

std::string isEmptyValueValid () const
 Returns a string depending on whether an empty value is valid.
 
std::string setValueAsMultipleFiles (const std::string &propValue)
 Called by setValue in the case where multiple file loading is enabled.
 
std::string setValueAsSingleFile (const std::string &propValue)
 Called by setValue in the case where a user has disabled multiple file loading.
 

Private Attributes

unsigned int m_action {2}
 The action type of this property Load (dafault) or OptionalLoad are supported.
 
bool m_allowEmptyTokens {false}
 Whether to allow for empty tokens.
 
std::string m_defaultExt
 The default file extension associated with the type of file this property will handle.
 
std::vector< std::string > m_exts
 Suggested extensions.
 
bool m_multiFileLoadingEnabled
 Whether or not the user has turned on multifile loading.
 
std::vector< std::vector< std::string > > m_oldFoundValue
 Last value of the found files used in MultipleFileProperty::setValueAsMultipleFiles and MultipleFileProperty::setValueAsSingleFile.
 
std::string m_oldPropValue
 Last value of propValue used in MultipleFileProperty::setValueAsMultipleFiles and MultipleFileProperty::setValueAsSingleFile.
 
Kernel::MultiFileNameParsing::Parser m_parser
 Parser used to parse multi-file strings.
 

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::vector< std::vector< std::string > > >
std::vector< std::vector< std::string > > m_initialValue
 the property's default value which is also its initial value
 
std::vector< std::vector< 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 property to allow a user to specify multiple files to load.

The current functionality is such that there are two basic forms of syntax. For the puposes of documentation we'll call these the "Long Form" and "Short Form".


[A] Short Form

These strings are of the format "[dir][inst][under][runs][ext]" where:

[dir]   (Optional) = The OS-specific file directory, e.g. "c:/data/"
[inst]  (Optional) = The instrument name, e.g. "IRS" or "PG3".
[under] (Optional) = Some instrument filenames require an underscore.
[runs]  (Required) = The run numbers, e.g. "0102, 0110-0115, 0120,

0130:0140:2" [ext] (Optional) = The file extension, e.g. ".raw" For optional values, defaults or user settings are used where necessary. For [runs], users specify lists and ranges of runs using comma, plus, minus and colon. Some examples: @iverbatim - "TSC0001,0002" = Runs 1 and 2 of the TOSCA instrument are to be loaded. - "0003+0004" = Runs 3 and 4 of the default instrument are to be loaded and added together. - "0005:0009.raw" = The raw files containing runs 5 to 9 of the default instrument are to be loaded. - "c:/data/0010-0014" = The files in "c:/data/" containing runs 10 to 14 of the default instrument are to be loaded and added together. - "IRS0020:0028:2.nxs" = The nexus files containing runs 20, 22, 24, 26 and 28 for IRIS are to be loaded. - "INST_0030-0038:3" = Runs 30, 33, and 36 of INST are to be loaded and added together. @endiverbatim <hr> [B] Long Form @iverbatim These strings are of the format "[[short_form][operator]]...[short_form]" where: [short_form] = [dir][inst][under][runs][ext], which is the "Short Form" outlined above. [operator] = Either a comma or a plus. Some examples: - "TSC0001,TSC0002+0003" = Runs 1, 2 and 3 of the TOSCA instrument should be loaded, but 2 and 3 are added together. - "TSC0005+TSC0006,TSC0007.raw" = Runs 5 and 6 as well as the raw file containing run 7 of the TOSCA instrument should be loaded, but 5 and 6 are added together. @endiverbatim <hr> NOTES: [1] Presently, we disallow more complex algebra such as "TSC0005,0006+TSC0007". In such a case it is ambiguous whether or not the user wishes to just add run 7 to 6, or add run 7 to both 5 and 6. [2] The "Short Form" is parsed by the Kernel::MultiFileNameParsing::Parser class, whereas this class is responsible for splitting up the Long Form. [3] The functionality of this class is such that all strings are stored only after being converted to the Long Form, and all filenames are fully resolved. For example "0005,0006+0007" is stored as "[dir][inst][under]0005[ext],[dir][inst][under]0006[ext]+[dir][inst][under]0007[ext]". [4] The default functionality of this Property can be changed to emulate a simple FileProperty - to do this, the user must change the properties file. Disabling multi file loading in this way will allow users to use "," and "+" in their filenames, and in this case we use the dummy "" delimiters to call toValue and toString.


The value returned by getProperty is of type std::vector<std::vector<std::string>>. While the property itself does expand ranges, the value needs some intepretation by the client code. Specifically, values inside the same std::vector<std::string> should be added together, while values between them should be treated separately. In other words, if the value was [[a1,a2], [b1,b2]]. The results should be two workspaces, a1+a2 and b1+b2.


Definition at line 103 of file MultipleFileProperty.h.

Constructor & Destructor Documentation

◆ MultipleFileProperty() [1/3]

Mantid::API::MultipleFileProperty::MultipleFileProperty ( const std::string &  name,
unsigned int  action,
const std::vector< std::string > &  exts = std::vector<std::string>(),
bool  allowEmptyTokens = false 
)

Alternative constructor with action.

Parameters
name:: The name of the property
action:: File action
exts:: The allowed/suggested extensions
allowEmptyTokens:: whether to allow empty tokens

raise error for unsupported actions

Definition at line 73 of file MultipleFileProperty.cpp.

References Mantid::API::FileProperty::Load, m_action, m_exts, m_multiFileLoadingEnabled, and Mantid::API::FileProperty::OptionalLoad.

◆ MultipleFileProperty() [2/3]

Mantid::API::MultipleFileProperty::MultipleFileProperty ( const std::string &  name,
const std::vector< std::string > &  exts = std::vector<std::string>() 
)

Default constructor with default action.

Parameters
name:: The name of the property
exts:: The allowed/suggested extensions

Definition at line 96 of file MultipleFileProperty.cpp.

◆ MultipleFileProperty() [3/3]

Mantid::API::MultipleFileProperty::MultipleFileProperty ( const MultipleFileProperty )
default

Member Function Documentation

◆ clone()

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

'Virtual copy constructor'

Implements Mantid::Kernel::Property.

Definition at line 114 of file MultipleFileProperty.h.

◆ getDefault()

std::string Mantid::API::MultipleFileProperty::getDefault ( ) const
overridevirtual

Get the value the property was initialised with -its default value.

Returns
The default value

Implements Mantid::Kernel::Property.

Definition at line 174 of file MultipleFileProperty.cpp.

References Mantid::Kernel::PropertyWithValue< std::vector< std::vector< std::string > > >::m_initialValue, m_multiFileLoadingEnabled, and Mantid::Kernel::toString().

◆ getDefaultExt()

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

Returns the main file extension that's used.

Definition at line 125 of file MultipleFileProperty.h.

◆ getExts()

const std::vector< std::string > & Mantid::API::MultipleFileProperty::getExts ( ) const
inline
Returns
the vector of suggested extensions. For use in GUIs showing files.

Definition at line 122 of file MultipleFileProperty.h.

◆ isEmptyValueValid()

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

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

Returns
Empty string if empty value is valid, error message otherwise

Definition at line 108 of file MultipleFileProperty.cpp.

References isOptional(), and SUCCESS.

◆ isOptional()

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

Check if this property is optional.

Returns
True if the property is optinal, false otherwise

Definition at line 103 of file MultipleFileProperty.cpp.

References m_action, and Mantid::API::FileProperty::OptionalLoad.

Referenced by isEmptyValueValid(), and setValue().

◆ operator=()

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

◆ setValue()

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

Convert the given propValue into a comma and plus separated list of full filenames, and pass to the parent's setValue method to store as a vector of vector of strings.

READ HEADER FILE DOCUMENTATION FOR A MORE DETAILED OVERVIEW.

Parameters
propValue:: A string of the allowed format, indicating the user's choice of files.
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 128 of file MultipleFileProperty.cpp.

References Mantid::Kernel::Logger::debug(), error, Mantid::API::g_log, isOptional(), m_multiFileLoadingEnabled, setValueAsMultipleFiles(), setValueAsSingleFile(), and SUCCESS.

◆ setValueAsMultipleFiles()

std::string Mantid::API::MultipleFileProperty::setValueAsMultipleFiles ( const std::string &  propValue)
private

Called by setValue in the case where multiple file loading is enabled.

NOTE: If multifile loading is enabled, then users make the concession that they cannot use "," or "+" in directory names; they are used as operators only.

Parameters
propValue:: A string of the allowed format, indicating the user's choice of files.
Returns
A string indicating the outcome of the attempt to set the property. An empty string indicates success.

Definition at line 234 of file MultipleFileProperty.cpp.

References Mantid::Kernel::Property::autoTrim(), error, Mantid::Kernel::Logger::error(), Mantid::Kernel::MultiFileNameParsing::Parser::fileNames(), Mantid::Kernel::VectorHelper::flattenVector(), Mantid::API::g_log, Mantid::Kernel::Direction::Input, Mantid::API::FileProperty::Load, m_allowEmptyTokens, m_exts, m_oldFoundValue, m_oldPropValue, m_parser, Mantid::Kernel::MultiFileNameParsing::Parser::parse(), Mantid::Kernel::MultiFileNameParsing::Parser::setTrimWhiteSpaces(), Mantid::API::FileProperty::setValue(), and SUCCESS.

Referenced by setValue().

◆ setValueAsSingleFile()

std::string Mantid::API::MultipleFileProperty::setValueAsSingleFile ( const std::string &  propValue)
private

Called by setValue in the case where a user has disabled multiple file loading.

Parameters
propValue:: A string of the allowed format, indicating the user's choice of files.
Returns
A string indicating the outcome of the attempt to set the property. An empty string indicates success.

Definition at line 190 of file MultipleFileProperty.cpp.

References Mantid::Kernel::Logger::debug(), error, Mantid::API::g_log, Mantid::Kernel::Direction::Input, Mantid::API::FileProperty::Load, m_exts, m_oldFoundValue, m_oldPropValue, Mantid::Kernel::Property::name(), Mantid::API::FileProperty::setValue(), SUCCESS, and Mantid::Kernel::toValue().

Referenced by setValue().

◆ value()

std::string Mantid::API::MultipleFileProperty::value ( ) const
overridevirtual

Member Data Documentation

◆ m_action

unsigned int Mantid::API::MultipleFileProperty::m_action {2}
private

The action type of this property Load (dafault) or OptionalLoad are supported.

Definition at line 147 of file MultipleFileProperty.h.

Referenced by isOptional(), and MultipleFileProperty().

◆ m_allowEmptyTokens

bool Mantid::API::MultipleFileProperty::m_allowEmptyTokens {false}
private

Whether to allow for empty tokens.

Definition at line 157 of file MultipleFileProperty.h.

Referenced by setValueAsMultipleFiles().

◆ m_defaultExt

std::string Mantid::API::MultipleFileProperty::m_defaultExt
private

The default file extension associated with the type of file this property will handle.

Definition at line 144 of file MultipleFileProperty.h.

◆ m_exts

std::vector<std::string> Mantid::API::MultipleFileProperty::m_exts
private

Suggested extensions.

Definition at line 139 of file MultipleFileProperty.h.

Referenced by MultipleFileProperty(), setValueAsMultipleFiles(), and setValueAsSingleFile().

◆ m_multiFileLoadingEnabled

bool Mantid::API::MultipleFileProperty::m_multiFileLoadingEnabled
private

Whether or not the user has turned on multifile loading.

Definition at line 136 of file MultipleFileProperty.h.

Referenced by getDefault(), MultipleFileProperty(), setValue(), and value().

◆ m_oldFoundValue

std::vector<std::vector<std::string> > Mantid::API::MultipleFileProperty::m_oldFoundValue
private

◆ m_oldPropValue

std::string Mantid::API::MultipleFileProperty::m_oldPropValue
private

◆ m_parser

Kernel::MultiFileNameParsing::Parser Mantid::API::MultipleFileProperty::m_parser
private

Parser used to parse multi-file strings.

Definition at line 141 of file MultipleFileProperty.h.

Referenced by setValueAsMultipleFiles().


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