ifw-daq
2.1.0-pre1
IFW Data Acquisition modules
|
Go to the documentation of this file.
8 #include <fmt/format.h>
9 #include <fmt/ostream.h>
18 auto it = std::begin(ex);
19 auto end = std::end(ex);
22 throw std::invalid_argument(
"empty expression is invalid");
29 op = Operator::Include;
35 throw std::invalid_argument(
36 fmt::format(
"invalid operator '{}', must be one of '+' or '-': '{}'", *it, ex));
41 throw std::invalid_argument(
42 fmt::format(
"unexpected end of expression, expected ' ' or scope: '{}'", ex));
61 throw std::invalid_argument(
62 fmt::format(
"invalid scope '{}', must be one of 'v' (value), 'e' (ESO hierarchical) or "
63 "'c' (commentary): '{}'",
69 if (scope != Scope::Any) {
73 throw std::invalid_argument(
74 fmt::format(
"unexpected end of expression, expected pattern: '{}'", ex));
79 throw std::invalid_argument(
80 fmt::format(
"whitespace ' ' expected after scope, got '{}': ", *it, ex));
86 throw std::invalid_argument(
87 fmt::format(
"unexpected end of expression, expected pattern: '{}'", ex));
91 std::string pattern(it, end);
92 return {op, scope, pattern};
125 auto name = std::string(kw.
name);
126 auto match = fnmatch(rule.
pattern.c_str(), name.c_str(), 0);
130 }
else if (match == FNM_NOMATCH) {
134 throw std::invalid_argument(fmt::format(
"invalid fnmatch pattern '{}'", rule.
pattern));
139 std::string
RegexReplace(std::string_view str, std::regex
const& re,
char const* fmt) {
141 std::regex_replace(std::back_inserter(result), std::begin(str), std::end(str), re, fmt);
153 for (
auto const& rule : ex.
GetRules()) {
157 match = (*opt_match) == detail::Operator::Include;
176 std::throw_with_nested(std::runtime_error(fmt::format(
177 "Keyword transform failed for keyword `{}` with transform format `{}`", keyword, fmt)));
187 std::throw_with_nested(std::runtime_error(fmt::format(
188 "Keyword transform failed for keyword `{}` with transform format `{}`", keyword, fmt)));
197 components.
name = new_name;
198 auto new_kw =
Format(components);
199 if (new_kw.GetType() != keyword.
GetType()) {
200 throw std::runtime_error(
201 fmt::format(
"Keyword transform mutated keyword into a different type. Before: {}, "
202 "after: {}. Before transformation: `{}`, after: `{}`",
206 new_kw.GetRecord()));
208 if (new_kw.GetComponents().value != components.value) {
209 throw std::runtime_error(fmt::format(
210 "Keyword transform mutated keyword such that the value field was affected "
211 " Before transformation: `{}`, after: `{}`",
213 new_kw.GetRecord()));
217 std::throw_with_nested(std::runtime_error(
218 fmt::format(
"Keyword transform failed for keyword `{}` with transform format `{}`",
std::string_view GetRecord() const &noexcept
constexpr std::vector< detail::Rule > const & GetRules() const noexcept
std::variant< ValueKeyword, EsoKeyword, LiteralKeyword > KeywordVariant
The different variants of keywords that are supported.
constexpr Components GetComponents() const &noexcept
Get components of the keyword in its literal form with insignifant whitespaces removed.
KeywordType
Type of FITS keyword.
Contains data structure for FITS keywords.
fits::KeywordVariant KeywordTransform(fits::KeywordVariant const &keyword, std::regex const &re, char const *fmt)
Transforms keyword name using regex.
@ Eso
An ESO hiearchical keyword.
bool KeywordScopeMatch(fits::KeywordType kwtype, Scope scope)
BasicKeyword< EsoKeywordTraits > EsoKeyword
ESO hiearchical keyword.
LiteralKeyword Format(KeywordVariant const &keyword)
A type safe version of LiteralKeyword that consist of the three basic components of a FITS keyword ke...
constexpr KeywordNameView GetName() const &noexcept
Query logical keyword name.
std::optional< std::string > comment
Trimmed keyword comment.
Create keyword expression that memoize the provided string pattern.
@ Commentary
A commentary keyword, which are keywords that do not fall into the previous categories.
std::optional< Operator > KeywordMatch(fits::KeywordNameView kw, Rule const &rule)
Determines if keyword match rule and if yes, whether it matches;.
constexpr KeywordType GetType() const noexcept
BasicKeyword< ValueKeywordTraits > ValueKeyword
Standard FITS value keyword.
constexpr KeywordNameView GetKeywordName(EsoKeyword const &keyword) noexcept
Get keyword name from keyword.
Rule ParseEx(std::string_view ex)
Parse expression of the form documented in KeywordEx.
bool KeywordMatch(fits::KeywordVariant const &keyword, KeywordEx const &ex)
Represents a keyword rule expression.
Represents the literal 80-character FITS keyword record.
std::string RegexReplace(std::string_view str, std::regex const &re, char const *fmt)
std::string name
Trimmed keyword name.