Mantid
Loading...
Searching...
No Matches
FileProperty.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//-----------------------------------------------------------------
10// Includes
11//-----------------------------------------------------------------
12#include "MantidAPI/DllConfig.h"
14
15namespace Mantid {
16namespace API {
17
18#ifdef _WIN32
19#pragma warning(push)
20// Disable 'multiple assignment operators specified' warning for this class
21// - it's not an accident that we have more than one
22#pragma warning(disable : 4522)
23#endif
24
42class MANTID_API_DLL FileProperty : public Kernel::PropertyWithValue<std::string> {
43public:
47 // Note that the order here ensures that the correct boolean gets passed to
48 // the FileValidator.
49 Save = 0,
50 OptionalSave = 1,
52 Load = 2,
53 OptionalLoad = 3,
54 Directory = 4,
55 OptionalDirectory = 5
56 };
57
59 FileProperty(const std::string &name, const std::string &defaultValue, unsigned int action,
60 const std::vector<std::string> &exts = std::vector<std::string>(),
61 unsigned int direction = Kernel::Direction::Input);
63 FileProperty(const std::string &name, const std::string &default_value, unsigned int action, const std::string &ext,
64 unsigned int direction = Kernel::Direction::Input);
66 FileProperty(const std::string &name, const std::string &default_value, unsigned int action,
67 std::initializer_list<std::string> exts, unsigned int direction = Kernel::Direction::Input);
68
69 FileProperty(const FileProperty &) = default;
70 FileProperty &operator=(const FileProperty &) = default;
71
73 FileProperty *clone() const override { return new FileProperty(*this); }
74
76 bool isLoadProperty() const;
78 bool isSaveProperty() const;
80 bool isDirectoryProperty() const;
82 bool isOptional() const;
84 std::string setValue(const std::string &propValue) override;
87 std::string isValid() const override;
88
90 std::string getDefaultExt() const { return m_defaultExt; }
91
92 // Unhide the PropertyWithValue assignment operator
93 using Kernel::PropertyWithValue<std::string>::operator=;
94
95private:
97 std::string isEmptyValueValid() const;
100 bool extsMatchRunFiles();
102 std::string setLoadProperty(const std::string &propValue);
104 std::string setSaveProperty(const std::string &propValue);
106 unsigned int m_action;
109 std::string m_defaultExt;
116};
117
118#ifdef _WIN32
119#pragma warning(pop) // Re-enable the warning about multiple assignment operators
120#endif
121} // namespace API
122} // namespace Mantid
A specialized class for dealing with file properties.
Definition: FileProperty.h:42
unsigned int m_action
The action type of this property, i.e. load/save.
Definition: FileProperty.h:106
FileProperty(const FileProperty &)=default
FileProperty & operator=(const FileProperty &)=default
std::string m_oldLoadPropValue
Last value of propValue used in FileProperty::setLoadProperty.
Definition: FileProperty.h:113
bool m_runFileProp
Is this property for run files?
Definition: FileProperty.h:111
std::string m_oldLoadFoundFile
Last value of foundFile used in FileProperty::setLoadProperty.
Definition: FileProperty.h:115
std::string getDefaultExt() const
Returns the main file extension that's used.
Definition: FileProperty.h:90
FileProperty * clone() const override
'Virtual copy constructor
Definition: FileProperty.h:73
std::string m_defaultExt
The default file extension associated with the type of file this property will handle.
Definition: FileProperty.h:109
FileAction
An enumeration for load/save types.
Definition: FileProperty.h:46
Loads a workspace from a data file.
Definition: Load.h:23
The concrete, templated class for properties.
Helper class which provides the Collimation Length for SANS instruments.