#include <Header.h>
Reader-writer for the header unit.
This class provides services to read and write records in the header units. Several groups of methods are available:
read
-prefixed methods read the raw ASCII characters from the header unit as std::string
s;parse
-prefixed methods parse the values of the records;write
-prefixed methods write provided values following a strategy defined as a RecordMode
enumerator.When reading or writing several records, it is recommended to use the Seq
-suffixed methods (e.g. one call to write_n()
instead of several calls to write()
), which are optimized.
To write sequences of records, the following types are accepted, as well as their constant and reference counterparts:
std::vector<Record<T>>
(where T
can be VariantValue
),RecordVec<T>
(where T
can be VariantValue
),std::array<Record<T>>
(where T
can be VariantValue
);Record<Ts>...
,std::tuple<Record<Ts>...>
.For reading, the following return types are available:
std::vector<Record<T>>
(where T
can be VariantValue
),RecordVec<T>
(where T
can be VariantValue
);std::tuple<Record<Ts>...>
,{ Record<Ts>... }
or { Ts... }
. More details and examples are provided in the methods documentation.Relying on VariantValue
is the way to go when types are not all known at compile time, and can be the most comfortable option in many other cases. Indeed, working with a tuple might become a nightmare with many values, where std::vector<VariantValue>
and RecordVec<VariantValue>
(aka RecordSeq
) can provide valuable help by reducing the boilerplate. The impact on runtime is negligible.
Public Member Functions | |
Read the records of given categories | |
std::vector< std::string > | read_all_keywords (KeywordCategory categories=KeywordCategory::All) const |
List keywords. More... | |
std::map< std::string, std::string > | read_all_keywords_values (KeywordCategory categories=KeywordCategory::All) const |
List keywords and their values. More... | |
std::string | read_all (KeywordCategory categories=KeywordCategory::All) const |
Read the whole header as a single string. More... | |
RecordSeq | parse_all (KeywordCategory categories=KeywordCategory::All) const |
Parse records of given categories. More... | |
Read a single record | |
bool | has (const std::string &keyword) const |
Check whether the HDU contains a given keyword. | |
template<typename T > | |
Record< T > | parse (const std::string &keyword) const |
Parse a record. More... | |
template<typename T > | |
Record< T > | parse_or (const Record< T > &fallback) const |
Parse a record if it exists, return a fallback record otherwise. More... | |
template<typename T > | |
Record< T > | parse_or (const std::string &keyword, T fallback_value, const std::string &fallback_unit="", const std::string &fallback_comment="") const |
Parse a record if it exists, return a fallback record otherwise. More... | |
Read a sequence of records as a vector or a tuple | |
template<typename T = VariantValue> | |
RecordVec< T > | parse_n (const std::vector< std::string > &keywords) const |
Parse a sequence of homogeneous records. More... | |
template<typename... Ts> | |
std::tuple< Record< Ts >... > | parse_n (const TypedKey< Ts, std::string > &... keywords) const |
Parse a sequence of heterogeneous records. More... | |
template<typename TSeq > | |
TSeq | parse_n_or (TSeq &&fallbacks) const |
Parse a sequence of records if they exist, return fallbacks for those which don't. More... | |
template<typename... Ts> | |
std::tuple< Record< Ts >... > | parse_n_or (const Record< Ts > &... fallbacks) const |
Parse a heterogeneous sequence of records if they exist, return fallbacks for those which don't. More... | |
Read a sequence of records as a user-defined structure | |
template<typename TOut , typename... Ts> | |
TOut | parse_struct (const TypedKey< Ts, std::string > &... keywords) const |
Parse a sequence of records. More... | |
template<typename TOut , typename... Ts> | |
TOut | parse_struct_or (const Record< Ts > &... fallbacks) const |
Parse a sequence of records if they exist, return fallbacks for those which don't. More... | |
template<typename TOut , typename TSeq > | |
TOut | parse_struct_or (TSeq &&fallbacks) const |
Parse a sequence of records if they exist, return fallbacks for those which don't. More... | |
Write a single record | |
template<RecordMode Mode = RecordMode::CreateOrUpdate, typename T > | |
void | write (const Record< T > &record) const |
Write a record. More... | |
template<RecordMode Mode = RecordMode::CreateOrUpdate, typename T > | |
void | write (const std::string &k, T v, const std::string &u="", const std::string &c="") const |
Write a record. More... | |
void | remove (const std::string &keyword) const |
Delete a record. More... | |
Write a sequence of records | |
template<RecordMode Mode = RecordMode::CreateOrUpdate, typename... Ts> | |
void | write_n (const Record< Ts > &... records) const |
Write a homogeneous sequence of records. More... | |
template<RecordMode Mode = RecordMode::CreateOrUpdate, typename TSeq > | |
void | write_n (TSeq &&records) const |
Write a homogeneous or heterogeneous sequence of records. More... | |
template<RecordMode Mode = RecordMode::CreateOrUpdate, typename... Ts> | |
void | write_n_in (const std::vector< std::string > &keywords, const Record< Ts > &... records) const |
Write a subset of a heterogeneous sequence of records. More... | |
template<RecordMode Mode = RecordMode::CreateOrUpdate, typename TSeq > | |
void | write_n_in (const std::vector< std::string > &keywords, TSeq &&records) const |
Write a subset of a homogeneous or heterogeneous sequence of records. More... | |
Write comment records | |
void | write_comment (const std::string &comment) const |
Write a COMMENT record. | |
void | write_history (const std::string &history) const |
Write a HISTORY record. | |
Deprecated | |
std::vector< std::string > | readKeywords (KeywordCategory categories=KeywordCategory::All) const |
std::map< std::string, std::string > | readKeywordsValues (KeywordCategory categories=KeywordCategory::All) const |
std::string | readAll (KeywordCategory categories=KeywordCategory::All) const |
RecordSeq | parseAll (KeywordCategory categories=KeywordCategory::All) const |
template<typename... TArgs> | |
auto | parseOr (TArgs &&... args) const |
template<typename... TArgs> | |
auto | parseSeq (TArgs &&... args) const |
template<typename... TArgs> | |
auto | parseSeqOr (TArgs &&... args) const |
template<typename TOut , typename... Ts> | |
TOut | parseStruct (const TypedKey< Ts, std::string > &... keywords) const |
template<typename TOut , typename... TArgs> | |
TOut | parseStructOr (TArgs &&... args) const |
template<RecordMode Mode = RecordMode::CreateOrUpdate, typename... TArgs> | |
void | writeSeq (TArgs &&... args) const |
template<RecordMode Mode = RecordMode::CreateOrUpdate, typename... TArgs> | |
void | writeSeqIn (const std::vector< std::string > &keywords, TArgs &&... args) const |
void | writeComment (const std::string &comment) const |
void | writeHistory (const std::string &history) const |