8 #ifndef DAQ_OCM_DAQ_FITS_KEYWORD_HPP_
9 #define DAQ_OCM_DAQ_FITS_KEYWORD_HPP_
21 #include <cfitsio/fitsio.h>
31 static constexpr
size_t RECORD_LENGTH = 80u;
35 static constexpr
size_t KEYWORD_NAME_LENGTH = 8u;
39 static constexpr std::string_view ESO_HIERARCH_PREFIX =
"HIERARCH ESO ";
44 static constexpr
size_t ESO_HIERARCH_MAX_NAME_LENGTH =
45 RECORD_LENGTH - ESO_HIERARCH_PREFIX.size() - 4u;
49 static constexpr std::string_view VALUE_INDICATOR =
"= ";
53 static constexpr std::string_view BLANK_CHARS = std::string_view(
" \0", 2);
98 HduId = TYP_HDUID_KEY,
112 bool operator==(KeywordNameView lhs, KeywordNameView rhs) noexcept;
118 bool operator!=(KeywordNameView lhs, KeywordNameView rhs) noexcept;
151 explicit
LiteralKeyword(std::array<
char, constants::RECORD_LENGTH> record);
171 return m_components.
type;
187 return {m_components.
name, m_components.
type};
196 std::string_view
GetRecord() const& noexcept;
197 constexpr std::string_view
GetRecord() && noexcept = delete;
207 std::array<char, constants::RECORD_LENGTH> m_record;
209 Components m_components;
218 bool operator<(LiteralKeyword
const&, LiteralKeyword
const&) noexcept;
226 bool operator==(LiteralKeyword
const& lhs, LiteralKeyword
const& rhs) noexcept;
234 bool operator!=(LiteralKeyword
const&, LiteralKeyword
const&) noexcept;
236 std::ostream&
operator<<(std::ostream& os, LiteralKeyword
const& kw);
243 using ValueType = std::variant<std::string, int64_t, uint64_t, double, bool>;
265 template <
class Trait>
271 char const* string_value,
272 std::optional<std::
string>
comment = std::nullopt);
275 std::optional<std::
string>
comment = std::nullopt);
389 template <
class Trait>
392 template <
class Trait>
428 return keyword.GetName();
432 return keyword.GetName();
440 return std::visit([&](
auto const& kw) {
return kw.GetName(); }, keyword);
505 KeywordVector::iterator position,
506 KeywordVector::const_iterator from_first,
507 KeywordVector::const_iterator from_last);
520 LiteralKeyword
Format(LiteralKeyword::Components
const& keyword);
554 void StandardSort(std::vector<LiteralKeyword>& keywords);
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.
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.
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.
BasicKeyword< ValueKeywordTraits > ValueKeyword
Standard FITS value keyword.
@ Replace
Replace keyword that conflicts.
@ Skip
Skip keyword that conflicts.
std::ostream & operator<<(std::ostream &os, LiteralKeyword const &kw)
BasicKeyword< EsoKeywordTraits > EsoKeyword
ESO hiearchical keyword.
Non template base class that is purely used to avoid type-deduction issues of ValueType.
std::variant< std::string, int64_t, 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