Calculator.hpp
1 #pragma once
2 
3 #include <DM/ICalculator.hpp>
4 #include <opals/String.hpp>
5 #include <opals/CustomOptionType.hpp>
6 
7 namespace opals {
8 
10 
11  /**
12  \class Calculator
13 
14  \tparam ReadAcc read access
15  \tparam WriteAcc write access
16 
17  \brief A typed version of DM::ICalculator. See \ref ref_calculator
18 
19  Derives from a handle for simplicity, but every object holds its own clone.
20 
21  See \ref ref_calculator
22 
23  \internal
24  Behaves like an object and not like a handle, because this should be usable as element type of containers (with independent elements).
25 
26  \author wk
27  \date 27.07.2020
28 
29  */
30  template<DM::ICalculator::ReadAccess ReadAcc, DM::ICalculator::WriteAccess WriteAcc>
31  class OPALS_API Calculator : public CalculatorHandle, public CustomOptionType<Calculator<ReadAcc, WriteAcc>>
32  {
33  public:
34  /// \name construction
35  /// Constructs a new calculator based on \p text.
36  /** If \p text is empty or "pass", results in an empty base handle.*/
37  ///@{
38  Calculator(const String& text = String());
39  Calculator(const char *text);
40  Calculator(const Calculator&);
41  ///@}
42 
43  Calculator& operator= (const Calculator&);
44 
45  /// The text that was passed to the constructor.
46  String text() const;
47 
48  static const char* help(bool);
49  static const char* syntax();
50  static bool exportsPythonType();
51  };
52 
53  /**
54  \class CalculatorWithPythonSupport
55 
56  \tparam ReadAcc read access
57  \tparam WriteAcc write access
58 
59  \brief A Calculator that alternatively supports Python formulas. See \ref ref_calculator
60 
61  Prefix \p text with pythonPrefix() to indicate usage of Python syntax.
62 
63  See \ref ref_calculator
64 
65  \author wk
66  \date 27.07.2020
67 
68  */
69  template<DM::ICalculator::ReadAccess ReadAcc, DM::ICalculator::WriteAccess WriteAcc>
70  class OPALS_API CalculatorWithPythonSupport : public Calculator<ReadAcc, WriteAcc>, public CustomOptionType<CalculatorWithPythonSupport<ReadAcc, WriteAcc>>
71  {
72  String text_;
73  public:
74  /// \name construction
75  /// Constructs a new calculator based on \p text.
76  ///@{
77  CalculatorWithPythonSupport(const String& text = String());
78  CalculatorWithPythonSupport(const char *text);
79  ///@}
80 
81  /// The text that was passed to the constructor.
82  String text() const;
83 
84  /// Returns true if \p text starts with "python:"
85  bool isPythonFormula() const;
86  /// \p text without the prefix indicating Python syntax.
87  String pyText() const;
88 
89  static const char* help(bool);
90  };
91 
92 }
93 
A Calculator that alternatively supports Python formulas. See Calculator.
Definition: Calculator.hpp:70
Base class for all custom parameter types.
Definition: CustomOptionType.hpp:39
Definition: Calculator.hpp:9
A typed version of DM::ICalculator. See Calculator.
Definition: Calculator.hpp:31
Contains the public interface of OPALS.
Definition: AbsValueOrQuantile.hpp:8
A dynamic character string whose interface conforms to STL's std::string.
Definition: String.hpp:35