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  using DM::FilterHandle::FilterHandle;
12  };
13 
14  /**
15  \class Filter
16 
17  \tparam ReadAcc read access
18  \tparam WriteAcc write access
19 
20  \brief A typed version of DM::IFilter. See \ref ref_filter
21 
22  Derives from a handle for simplicity, but every object holds its own clone.
23 
24  See \ref ref_filter
25 
26  \internal
27  Behaves like an object and not like a handle, because this should be usable as element type of containers (with independent elements).
28 
29  \author wk
30  \date 27.07.2020
31 
32  */
33  template<DM::IFilter::ReadAccess ReadAcc, DM::IFilter::WriteAccess WriteAcc>
34  class OPALS_API Filter :
35  public FilterHandle,
36  public CustomOptionType<Filter<ReadAcc, WriteAcc>>
37  {
38  public:
39  /// \name construction
40  /// Constructs a new filter based on \p text.
41  /** If \p text is empty or "pass", results in an empty base handle.*/
42  ///@{
43  Filter(const String& text = String());
44  Filter(const char *text);
45  Filter(const Filter&);
46  ///@}
47 
48  Filter& operator=(const Filter&);
49 
50  /// The text that was passed to the constructor.
51  String text() const;
52 
53  static const char* help(bool);
54  static const char* syntax();
55  static bool exportsPythonType();
56  };
57 
58  /**
59  \class FilterWithPlaceHolders
60 
61  \tparam ReadAcc read access
62  \tparam WriteAcc write access
63 
64  \brief A Filter with additional support for place holders. See \ref ref_filter
65 
66  Place holders are words surrounded by curly braces in \p text, to be replaced before evaluation.
67 
68  See \ref ref_filter
69 
70  \author wk
71  \date 27.07.2020
72 
73  */
74  template<DM::IFilter::ReadAccess ReadAcc, DM::IFilter::WriteAccess WriteAcc>
75  class OPALS_API FilterWithPlaceHolders :
76  public Filter<ReadAcc, WriteAcc>,
77  public CustomOptionType<FilterWithPlaceHolders<ReadAcc, WriteAcc>>
78  {
79  String text_;
80  public:
81  /// \name construction
82  /// Constructs a new filter based on \p text.
83  /** If \p text is empty or "pass", results in an empty base handle.
84  If \p placeHolders, constructs DM::FilterHandle with all place holders in \p text replaced with "pass".
85  Otherwise, this throws if \p text contains place holders. */
86  ///@{
87  FilterWithPlaceHolders(const String& text = String(), bool placeHolders = true);
88  FilterWithPlaceHolders(const char *text, bool placeHolders = true);
89  ///@}
90 
91  /// The text that was passed to the constructor (with unchanged place holders).
92  String text() const;
93 
94  /// Returns a new filter with \p placeHolder replaced by a filter node that is equivalent to \p trafo.
95  /** If this is empty, returns a filter that consists of this node only.
96  Throws if this is non-empty and \p text contains no such place holder.
97  Constructs the filter to be returned with \p placeHolders = furtherPlaceHolders */
98  FilterWithPlaceHolders replaced(const opals::TrafPars3dAffine &trafo, const String& placeHolder = String(), bool furtherPlaceHolders = false) const;
99  };
100 
101 }
102 
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:34
A Filter with additional support for place holders. See Filters.
Definition: Filter.hpp:75
A dynamic character string whose interface conforms to STL's std::string.
Definition: String.hpp:35