Iterate over HDUs with selected categories and/or states.
An iterator class and begin/end functions are defined to enable looping over all the HDUs of a MefFile. Usage is straightforward:
HDUs can be selected using one of two dedicated classes: HduCategory or HduFilter.
An HduCategory object positions flags like: Primary or extension HDU, image or binary table HDU... HDU categories can be composed with binary operators &
(and), |
(or) and ~
(not). For example, to get the list of image extensions with integer values:
An HduFilter is a list of acceptable HDU categories and unacceptable HDU categories. They are buit with operators +
(accept) and -
(reject). For example, to accept the Primary HDU and all the real-valued image HDUs, excluding the HDUs which were just created:
It is possible to check if an HDU is of given category or matches a given filter with method Hdu::matches
, as follows:
Similarly to the range loop presented at the beginning of this page, it is possible to loop over a subset of HDUs. This is done by creating the adequate iterator using method MefFile::filter()
:
The template parameter specifies the class to be returned: Hdu, ImageHdu, or BintableHdu. It is used to constrain the given filter: for ImageHdu (resp. BintableHdu), HduCategory::Image (resp. HduCategory::Bintable) is added to the filter. Therefore, f.filter<ImageHdu>()
is strictly equivalent to f.filter<ImageHdu>(HduCategory::Image)
, and the above example can be rewritten more straightforwardly:
Classes | |
class | HduCategory |
An HDU categorization for filtering and iteration. More... | |
class | HduFilter |
HDU filter built from HDU categories. More... | |
class | HduIterator< THdu > |
Iterator for MefFile's HDUs. More... | |
struct | HduSelector< THdu > |
Helper class to provide filtered iterators. More... | |
class | KeywordCategory |
Keyword categories and related tools. More... | |
Properties | |
virtual HduCategory | category () const |
Read the category of the HDU. More... | |
bool | matches (HduFilter filter) const |
Check whether the HDU matches a given filter. More... | |
Element access | |
template<typename T = Hdu> | |
HduSelector< T > | filter (const HduFilter &categories=HduCategory::Any) |
Get an iterable object which represents a filtered set of HDUs. More... | |