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 :
32  public CalculatorHandle,
33  public CustomOptionType<Calculator<ReadAcc, WriteAcc>>
34  {
35  public:
36  /// \name construction
37  /// Constructs a new calculator based on \p text.
38  /** If \p text is empty or "pass", results in an empty base handle.*/
39  ///@{
40  Calculator(const String& text = String());
41  Calculator(const char *text);
42  Calculator(const Calculator&);
43  ///@}
44 
45  Calculator& operator= (const Calculator&);
46 
47  /// The text that was passed to the constructor.
48  String text() const;
49 
50  static const char* help(bool);
51  static const char* syntax();
52  static bool exportsPythonType();
53  };
54 
55  /**
56  \class CalculatorWithPythonSupport
57 
58  \tparam ReadAcc read access
59  \tparam WriteAcc write access
60 
61  \brief A Calculator that alternatively supports Python formulas. See \ref ref_calculator
62 
63  Prefix \p text with pythonPrefix() to indicate usage of Python syntax.
64 
65  See \ref ref_calculator
66 
67  \author wk
68  \date 27.07.2020
69 
70  */
71  template<DM::ICalculator::ReadAccess ReadAcc, DM::ICalculator::WriteAccess WriteAcc>
72  class OPALS_API CalculatorWithPythonSupport :
73  public Calculator<ReadAcc, WriteAcc>,
74  public CustomOptionType<CalculatorWithPythonSupport<ReadAcc, WriteAcc>>
75  {
76  String text_;
77  public:
78  /// \name construction
79  /// Constructs a new calculator based on \p text.
80  ///@{
81  CalculatorWithPythonSupport(const String& text = String());
82  CalculatorWithPythonSupport(const char *text);
83  ///@}
84 
85  /// The text that was passed to the constructor.
86  String text() const;
87 
88  /// Returns true if \p text starts with "python:"
89  bool isPythonFormula() const;
90  /// \p text without the prefix indicating Python syntax.
91  String pyText() const;
92 
93  static const char* help(bool);
94  };
95 
96 }
97 
A Calculator that alternatively supports Python formulas. See Calculator.
Definition: Calculator.hpp:72
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
Smart pointer class using reference counting with support for DM objects (see ObjectBase)
Definition: Handle.hpp:75
A dynamic character string whose interface conforms to STL's std::string.
Definition: String.hpp:35