EleFits  4.0.0
A modern C++ API on top of CFitsIO

◆ parseStructOr() [2/2]

template<typename TOut , typename TSeq >
TOut Euclid::Fits::Header::parseStructOr ( TSeq &&  fallbacks) const

Parse a sequence of records if they exist, return fallbacks for those which don't.

Parse a sequence of records.

Template Parameters
TOutThe return type
Ts...The desired record value types (automatically deduced)
TSeqThe record sequence type (automatically deduced)

Several methods are provided to return records or record values as a user-defined structure, instead of a std::vector or std::tuple. These methods differe from parseSeq-prefixed methods in that the returned sequence is interpretted as a user-defined structure, provided that it can be constructed from a brace-enclosed list of Records or from a brace-enclosed list of record values. For example, the return type can be a mere structure like:

struct TOut {
T0 p0;
T1 p1;
T2 p2;
};

or a class with such a constructor:

TOut::TOut(T0 p0, T1 p1, T2 p2)

where T0, T1, T2 are record value types or Records.

The output structure can be used to mimic a named tuple, which is generally more convenient than a std::tuple, because the records or values are accessed as named parameters – e.g. tout.p1 – instead of being accessed by their indices – e.g. std::get<1>(tout).

Example usage:

struct Body {
int age;
float height;
float mass;
float bmi() const { return mass / (height * height); }
};
// Body can be constructed from a brace-enclosed list:
// Body body { name, age, height, mass };
auto body = hdu.parseStruct<Body>(
Named<std::string>("NAME"),
Named<int>("AGE"),
Named<float>("HEIGHT"),
Named<float>("MASS"));
std::cout << "Hello, " << body.name << "!" << std::endl;
std::cout << "Your BMI is: " << body.bmi() << std::endl;
std::string
STL class.
std::cout
Euclid::Cfitsio::FileAccess::name
std::string name(fitsfile *fptr)
Get the file name.
std::endl
T endl(T... args)