Filter.hpp
1 #pragma once
2 
3 #include <DM/IFilter.hpp>
4 #include <opals/String.hpp>
5 #include <opals/CustomOptionType.hpp>
6 
7 namespace opals {
8 
10 
11  /**
12  \class Filter
13 
14  \tparam ReadAcc read access
15  \tparam WriteAcc write access
16 
17  \brief A typed version of DM::IFilter. See \ref ref_filter
18 
19  Derives from a handle for simplicity, but every object holds its own clone.
20 
21  See \ref ref_filter
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::IFilter::ReadAccess ReadAcc, DM::IFilter::WriteAccess WriteAcc>
31  class OPALS_API Filter :
32  public FilterHandle,
33  public CustomOptionType<Filter<ReadAcc, WriteAcc>>
34  {
35  public:
36  /// \name construction
37  /// Constructs a new filter based on \p text.
38  /** If \p text is empty or "pass", results in an empty base handle.*/
39  ///@{
40  Filter(const String& text = String());
41  Filter(const char *text);
42  Filter(const Filter&);
43  ///@}
44 
45  Filter& operator= (const Filter&);
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 FilterWithPlaceHolders
57 
58  \tparam ReadAcc read access
59  \tparam WriteAcc write access
60 
61  \brief A Filter with additional support for place holders. See \ref ref_filter
62 
63  Place holders are words surrounded by curly braces in \p text, to be replaced before evaluation.
64 
65  See \ref ref_filter
66 
67  \author wk
68  \date 27.07.2020
69 
70  */
71  template<DM::IFilter::ReadAccess ReadAcc, DM::IFilter::WriteAccess WriteAcc>
72  class OPALS_API FilterWithPlaceHolders :
73  public Filter<ReadAcc, WriteAcc>,
74  public CustomOptionType<FilterWithPlaceHolders<ReadAcc, WriteAcc>>
75  {
76  String text_;
77  public:
78  /// \name construction
79  /// Constructs a new filter based on \p text.
80  /** If \p text is empty or "pass", results in an empty base handle.
81  If \p placeHolders, constructs DM::FilterHandle with all place holders in \p text replaced with "pass".
82  Otherwise, this throws if \p text contains place holders. */
83  ///@{
84  FilterWithPlaceHolders(const String& text = String(), bool placeHolders = true);
85  FilterWithPlaceHolders(const char *text, bool placeHolders = true);
86  ///@}
87 
88  /// The text that was passed to the constructor (with unchanged place holders).
89  String text() const;
90 
91  /// Returns a new filter with \p placeHolder replaced by a filter node that is equivalent to \p trafo.
92  /** If this is empty, returns a filter that consists of this node only.
93  Throws if this is non-empty and \p text contains no such place holder.
94  Constructs the filter to be returned with \p placeHolders = furtherPlaceHolders */
95  FilterWithPlaceHolders replaced(const opals::TrafPars3dAffine &trafo, const String& placeHolder = String(), bool furtherPlaceHolders = false) const;
96  };
97 
98 }
99 
Base class for all custom parameter types.
Definition: CustomOptionType.hpp:39
Definition: TrafPars3dAffine.hpp:55
Definition: Filter.hpp:9
Contains the public interface of OPALS.
Definition: AbsValueOrQuantile.hpp:8
A typed version of DM::IFilter. See Filters.
Definition: Filter.hpp:31
A Filter with additional support for place holders. See Filters.
Definition: Filter.hpp:72
A dynamic character string whose interface conforms to STL's std::string.
Definition: String.hpp:35