AlgorithmProperty.h 2.99 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2011 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8

9
#include "MantidAPI/DllConfig.h"
10
#include "MantidKernel/NullValidator.h"
LamarMoore's avatar
LamarMoore committed
11
#include "MantidKernel/PropertyWithValue.h"
12

13
14
15
16
17
18
namespace Mantid {
namespace API {
//-------------------------------------------------------------------------
// Forward declarations
//-------------------------------------------------------------------------
class IAlgorithm;
19

20
#ifdef _WIN32
21
#pragma warning(push)
22
23
// Disable 'multiple assignment operators specified' warning for this class
//  - it's not an accident that we have more than one
24
#pragma warning(disable : 4522)
25
26
#endif

27
28
29
30
31
32
33
34
35
/**
Define an algorithm property that can be used to supply an algorithm object
to a subsequent algorithm. It is a specialized version of PropertyWithValue
where the type a pointer to an object implementing the
API::IAlgorithm interface.

@author Martyn Gigg, Tessella Plc
@date 24/03/2011
*/
36
class MANTID_API_DLL AlgorithmProperty
37
38
39
    : public Kernel::PropertyWithValue<boost::shared_ptr<IAlgorithm>> {
public:
  /// Typedef the held type
40
  using HeldType = boost::shared_ptr<IAlgorithm>;
41
42
43
44
45
46

  /// Constructor
  AlgorithmProperty(const std::string &propName,
                    Kernel::IValidator_sptr validator =
                        Kernel::IValidator_sptr(new Kernel::NullValidator),
                    unsigned int direction = Kernel::Direction::Input);
47
48
  // Unhide base class member that would be hidden by implicitly declared
  // assignment operator
49
  using Kernel::PropertyWithValue<HeldType>::operator=;
50

51
  /// 'Virtual copy constructor'
52
  inline AlgorithmProperty *clone() const override {
53
54
55
56
    return new AlgorithmProperty(*this);
  }

  /// Add the value of another property. Doesn't make sense here.
57
  AlgorithmProperty &operator+=(Kernel::Property const *) override {
58
59
60
61
62
    throw Kernel::Exception::NotImplementedError(
        "+= operator is not implemented for AlgorithmProperty.");
    return *this;
  }
  /// Return the algorithm as string
63
  std::string value() const override;
64
65
  /// Create a Json::Value from the algorithm value
  Json::Value valueAsJson() const override;
66
  /// Get the default
67
  std::string getDefault() const override;
68
  /// Sets the value of the algorithm from a string representation
69
  std::string setValue(const std::string &value) override;
70
71
  /// Sets the value of the algorithm from a Json representation
  std::string setValueFromJson(const Json::Value &value) override;
72
73

private:
74
  std::string setBaseValue(const HeldType &algm);
75

76
77
  // Cached string as value() can be called frequently
  std::string m_algmStr;
78
};
79
80

#ifdef _WIN32
81
82
#pragma warning(                                                               \
    pop) // Re-enable the warning about multiple assignment operators
83
84
#endif

85
} // namespace API
86
} // namespace Mantid