ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
keywordRule.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_dpm_libmerge
4  * @copyright ESO - European Southern Observatory
5  */
6 #ifndef DAQ_DPM_KEYWORD_RULE_HPP
7 #define DAQ_DPM_KEYWORD_RULE_HPP
8 #include <vector>
9 
10 #include <daq/dpm/keywordEx.hpp>
11 #include <daq/fits/keyword.hpp>
12 
13 namespace daq::dpm {
14 
15 /**
16  * Interface for keyword rule processors
17  */
19 public:
20  enum class DefaultRule {
21  /**
22  * Default rule is to keep all keywords (useful for in-place merge)
23  */
24  All,
25  /**
26  * Default is to keep only user-keywords.
27  */
28  User
29  };
30  virtual fits::KeywordVector
31  Process(fits::KeywordVector const&, DefaultRule default_rule) const = 0;
32  virtual ~KeywordRuleProcessor() noexcept = default;
33 };
34 
36 public:
37  using Rule = std::function<fits::KeywordVector(fits::KeywordVector const&)>;
38 
40  virtual fits::KeywordVector
41  Process(fits::KeywordVector const& keywords, DefaultRule default_rule) const override;
42 
43  void AddRule(Rule rule) {
44  m_rules.emplace_back(std::move(rule));
45  }
46 
47 private:
48  std::vector<Rule> m_rules;
49 };
50 
51 template <class InputIt, class OutputIt>
52 constexpr OutputIt
53 Filter(InputIt first, InputIt last, OutputIt d_first, KeywordEx const& filter_ex) {
54  return std::copy_if(
55  first, last, d_first, [&filter_ex](auto const kw) { return KeywordMatch(kw, filter_ex); });
56 }
57 
58 template <class InputIt, class OutputIt>
59 OutputIt Transform(InputIt first,
60  InputIt last,
61  OutputIt d_first,
62  KeywordEx const& filter_ex,
63  std::regex const& regex,
64  char const* fmt) {
65  while (first != last) {
66  if (KeywordMatch(*first, filter_ex)) {
67  *d_first++ = KeywordTransform(*first, regex, fmt);
68  } else {
69  *d_first++ = *first;
70  }
71  ++first;
72  }
73  return d_first;
74 }
75 
76 } // namespace daq::dpm
77 #endif // #ifndef DAQ_DPM_KEYWORD_RULE_HPP
keywordEx.hpp
daq::dpm::StandardKeywordRuleProcessor
Definition: keywordRule.hpp:35
daq::dpm::KeywordRuleProcessor::~KeywordRuleProcessor
virtual ~KeywordRuleProcessor() noexcept=default
daq::dpm::KeywordRuleProcessor::DefaultRule
DefaultRule
Definition: keywordRule.hpp:20
daq::dpm::KeywordRuleProcessor::Process
virtual fits::KeywordVector Process(fits::KeywordVector const &, DefaultRule default_rule) const =0
keyword.hpp
Contains data structure for FITS keywords.
daq::dpm::StandardKeywordRuleProcessor::Rule
std::function< fits::KeywordVector(fits::KeywordVector const &)> Rule
Definition: keywordRule.hpp:37
daq::dpm::KeywordTransform
fits::KeywordVariant KeywordTransform(fits::KeywordVariant const &keyword, std::regex const &re, char const *fmt)
Transforms keyword name using regex.
Definition: keywordEx.cpp:164
daq::dpm::KeywordRuleProcessor::DefaultRule::User
@ User
Default is to keep only user-keywords.
daq::dpm::StandardKeywordRuleProcessor::AddRule
void AddRule(Rule rule)
Definition: keywordRule.hpp:43
daq::dpm::KeywordEx
Create keyword expression that memoize the provided string pattern.
Definition: keywordEx.hpp:59
daq::dpm::Filter
constexpr OutputIt Filter(InputIt first, InputIt last, OutputIt d_first, KeywordEx const &filter_ex)
Definition: keywordRule.hpp:53
daq::dpm
Definition: testDpSpec.cpp:16
daq::dpm::StandardKeywordRuleProcessor::StandardKeywordRuleProcessor
StandardKeywordRuleProcessor()=default
daq::dpm::KeywordRuleProcessor::DefaultRule::All
@ All
Default rule is to keep all keywords (useful for in-place merge)
daq::fits::KeywordVector
std::vector< KeywordVariant > KeywordVector
Vector of keywords.
Definition: keyword.hpp:414
daq::dpm::Transform
OutputIt Transform(InputIt first, InputIt last, OutputIt d_first, KeywordEx const &filter_ex, std::regex const &regex, char const *fmt)
Definition: keywordRule.hpp:59
daq::dpm::KeywordMatch
bool KeywordMatch(fits::KeywordVariant const &keyword, KeywordEx const &ex)
Definition: keywordEx.cpp:150
daq::dpm::KeywordRuleProcessor
Interface for keyword rule processors.
Definition: keywordRule.hpp:18