8#ifndef DAQ_OCM_DAQ_FITS_KEYWORD_HPP_
9#define DAQ_OCM_DAQ_FITS_KEYWORD_HPP_
20#include <cfitsio/fitsio.h>
25class KeywordFormatter;
31static constexpr std::size_t RECORD_LENGTH = 80u;
35static constexpr std::size_t KEYWORD_NAME_LENGTH = 8u;
39static constexpr std::string_view ESO_HIERARCH_PREFIX =
"HIERARCH ESO ";
43static constexpr std::size_t ESO_HIERARCH_MAX_NAME_LENGTH =
44 RECORD_LENGTH - ESO_HIERARCH_PREFIX.size() - 2u;
48static constexpr std::size_t ESO_HIERARCH_NAME_VALUE_PACKED_LIMIT = ESO_HIERARCH_MAX_NAME_LENGTH;
53static constexpr std::string_view VALUE_INDICATOR =
"= ";
57static constexpr std::string_view BLANK_CHARS = std::string_view(
" \0", 2);
102 HduId = TYP_HDUID_KEY,
155 explicit
LiteralKeyword(std::array<
char, constants::RECORD_LENGTH> record);
175 return m_components.
type;
191 return {m_components.
name, m_components.
type};
200 std::string_view
GetRecord() const& noexcept;
201 constexpr std::string_view
GetRecord() && noexcept = delete;
211 std::array<char, constants::RECORD_LENGTH> m_record;
213 Components m_components;
252 using ValueType = std::variant<std::string, std::int64_t, std::uint64_t, double, bool>;
274template <
class Trait>
280 char const* string_value,
281 std::optional<std::
string>
comment = std::nullopt);
284 std::optional<std::
string>
comment = std::nullopt);
398template <
class Trait>
401template <
class Trait>
437 return keyword.GetName();
441 return keyword.GetName();
449 return std::visit([&](
auto const& kw) {
return kw.GetName(); }, keyword);
514 KeywordVector::iterator position,
515 KeywordVector::const_iterator from_first,
516 KeywordVector::const_iterator from_last);
545 UnknownKeyword(std::string_view kw, std::vector<std::string>
const& dictionaries);
625void StandardSort(std::vector<LiteralKeyword>& keywords);
Indicates keyword is invalid for some reason.
Represents the literal 80-character FITS keyword record.
std::string_view comment
Comment may be empty.
constexpr Components GetComponents() const &noexcept
Get components of the keyword in its literal form with insignifant whitespaces removed.
constexpr KeywordType GetType() const noexcept
std::string_view GetRecord() const &noexcept
KeywordNameView GetName() &&noexcept=delete
constexpr KeywordNameView GetName() const &noexcept
Query logical keyword name.
LiteralKeyword() noexcept
Initializes an empty record (filled with ' ' characters)
Decomposed components a literal keyword.
Indicates keyword is unknown and cannot be formatted.
void StandardSort(std::vector< LiteralKeyword > &keywords)
Sorts keywords according to ESO DICD standards.
constexpr KeywordNameView GetKeywordName(EsoKeyword const &keyword) noexcept
Get keyword name from keyword.
void InsertKeywords(KeywordVector &keywords, KeywordVector::iterator position, KeywordVector::const_iterator from_first, KeywordVector::const_iterator from_last)
Insert keywords.
KeywordType
Type of FITS keyword.
@ Eso
An ESO hiearchical keyword.
@ Commentary
A commentary keyword, which are keywords that do not fall into the previous categories.
bool NameEquals(KeywordVariant const &lhs, KeywordVariant const &rhs) noexcept
Compare logical keyword names of keyword of the same type.
bool operator==(KeywordNameView lhs, KeywordNameView rhs) noexcept
LiteralKeyword Format(KeywordVariant const &keyword)
bool operator<(LiteralKeyword const &, LiteralKeyword const &) noexcept
Sort by logical keyword name (not DICD sort)
std::variant< ValueKeyword, EsoKeyword > TypedKeywordVariant
Subset of value-typed keywords.
KeywordClass GetKeywordClass(std::string_view name)
Get keyword class.
auto FormatFitsValue(KeywordNameView name, BasicKeywordBase::ValueType const &value) -> std::string
Format keyword value using built-in rules such that it can be used as a component when formatting a c...
auto UntypedFormat(KeywordNameView name, std::string_view value, std::string_view comment) -> LiteralKeyword
Untyped formatting where value already has been formatted correctly.
KeywordClass
Fits keyword type.
std::vector< KeywordVariant > KeywordVector
Vector of keywords.
bool operator!=(KeywordNameView lhs, KeywordNameView rhs) noexcept
std::variant< ValueKeyword, EsoKeyword, LiteralKeyword > KeywordVariant
The different variants of keywords that are supported.
void UpdateKeywords(KeywordVector &to, KeywordVector const &from, ConflictPolicy policy=ConflictPolicy::Replace)
Updates to with keywords from from.
std::ostream & operator<<(std::ostream &os, HduType hdu_type)
Format HduType hdu_type to os.
@ Replace
Replace keyword that conflicts.
@ Skip
Skip keyword that conflicts.
Non template base class that is purely used to avoid type-deduction issues of ValueType.
std::variant< std::string, std::int64_t, std::uint64_t, double, bool > ValueType
A type safe version of LiteralKeyword that consist of the three basic components of a FITS keyword ke...
bool operator==(BasicKeyword const &rhs) const noexcept
Compares all members for equality.
bool operator!=(BasicKeyword const &rhs) const noexcept
Compares all members for inequality.
BasicKeyword(BasicKeyword const &)=default
bool operator<(BasicKeyword const &rhs) const noexcept
Uses name property as the sorting index.
KeywordNameView GetName() &&=delete
BasicKeyword(BasicKeyword &&) noexcept=default
std::string name
Trimmed keyword name.
std::optional< std::string > comment
Trimmed keyword comment.
constexpr KeywordNameView GetName() const &noexcept
Query logical keyword name.
static constexpr KeywordType GetKeywordType() noexcept
static constexpr KeywordType GetKeywordType() noexcept
bool operator()(LiteralKeyword const &, LiteralKeyword const &) noexcept