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 : public FilterHandle, public CustomOptionType<Filter<ReadAcc, WriteAcc>>
32  {
33  public:
34  /// \name construction
35  /// Constructs a new filter based on \p text.
36  /** If \p text is empty or "pass", results in an empty base handle.*/
37  ///@{
38  Filter(const String& text = String());
39  Filter(const char *text);
40  Filter(const Filter&);
41  ///@}
42 
43  Filter& operator= (const Filter&);
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 FilterWithPlaceHolders
55 
56  \tparam ReadAcc read access
57  \tparam WriteAcc write access
58 
59  \brief A Filter with additional support for place holders. See \ref ref_filter
60 
61  Place holders are words surrounded by curly braces in \p text, to be replaced before evaluation.
62 
63  See \ref ref_filter
64 
65  \author wk
66  \date 27.07.2020
67 
68  */
69  template<DM::IFilter::ReadAccess ReadAcc, DM::IFilter::WriteAccess WriteAcc>
70  class OPALS_API FilterWithPlaceHolders : public Filter<ReadAcc, WriteAcc>, public CustomOptionType<FilterWithPlaceHolders<ReadAcc, WriteAcc>>
71  {
72  String text_;
73  public:
74  /// \name construction
75  /// Constructs a new filter based on \p text.
76  /** If \p text is empty or "pass", results in an empty base handle.
77  If \p placeHolders, constructs DM::FilterHandle with all place holders in \p text replaced with "pass".
78  Otherwise, this throws if \p text contains place holders. */
79  ///@{
80  FilterWithPlaceHolders(const String& text = String(), bool placeHolders = true);
81  FilterWithPlaceHolders(const char *text, bool placeHolders = true);
82  ///@}
83 
84  /// The text that was passed to the constructor (with unchanged place holders).
85  String text() const;
86 
87  /// Returns a new filter with \p placeHolder replaced by a filter node that is equivalent to \p trafo.
88  /** If this is empty, returns a filter that consists of this node only.
89  Throws if this is non-empty and \p text contains no such place holder.
90  Constructs the filter to be returned with \p placeHolders = furtherPlaceHolders */
91  FilterWithPlaceHolders replaced(const opals::TrafPars3dAffine &trafo, const String& placeHolder = String(), bool furtherPlaceHolders = false) const;
92  };
93 
94 }
95 
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:70
A dynamic character string whose interface conforms to STL's std::string.
Definition: String.hpp:35