mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
mx::fits::fitsHeader< verboseT > Class Template Reference

template<class verboseT = verbose::d>
class mx::fits::fitsHeader< verboseT >

Class to manage a FITS file metadata header and provide fast access to the cards by keyword.

Manages tasks such as insertion (avoiding duplicates), and keyword lookup.

The cards are stored in a std::list to preserve order, but a std::unordered_multimap is used to provide fast keyword lookup into the list.

Template Parameters
verboseTsets the error reporting verbosity

Definition at line 53 of file fitsHeader.hpp.

#include <ioutils/fits/fitsHeader.hpp>

Public Types

typedef std::list< fitsHeaderCard< verboseT > > cardListT
 The list type.
 
typedef cardListT::iterator headerIteratorT
 The iterator type for the cards list.
 
typedef std::unordered_multimap< std::string, headerIteratorTcardMapT
 The map type.
 
typedef cardMapT::value_type cardMapValueT
 The value type for the card map.
 
typedef cardMapT::iterator mapIteratorT
 The iterator type for the card map.
 

Public Member Functions

 fitsHeader ()
 Default c'tor.
 
 fitsHeader (const fitsHeader &head)
 Copy constructor.
 
 ~fitsHeader ()
 Destructor.
 
fitsHeaderoperator= (const fitsHeader &head)
 Assignment operator.
 
headerIteratorT begin ()
 Get iterator to the beginning of the cards list.
 
headerIteratorT end ()
 Get iterator to the end of the cards list.
 
headerIteratorT iterator (const std::string &keyword)
 Get iterator pointing to a specific element.
 
bool empty ()
 Test whether the header is empty.
 
size_t size ()
 Get number of cards currently stored in the header.
 
error_t clear ()
 Clear all cards from the header.
 
size_t count (const std::string &keyword)
 Get number of cards with a given keyword.
 
error_t erase (const std::string &keyword)
 Erase card by keyword.
 
error_t erase (headerIteratorT it)
 Erase card by iterator.
 
error_t eraseStandardTop ()
 Erase the standard entries at the top of the header.
 
error_t append (const fitsHeaderCard< verboseT > &card)
 Append a fitsHeaderCard to the end of the header.
 
error_t append (const std::string &k, const char *v, const std::string &c)
 Append a string card to the end of the header, from the three components of a card.
 
template<typename typeT >
error_t append (const std::string &k, const typeT &v, const std::string &c)
 Append a card to the end of the header, from the three components of a card.
 
template<typename typeT >
error_t append (const std::string &k, const typeT &v)
 Append a card to the end of the header, from the components of a card with no comment.
 
error_t append (const std::string &k)
 Append a card to the end of the header, with just a keyword.
 
error_t append (fitsHeader &head)
 Append a fitsHeader to the end of the header.
 
error_t insert_before (headerIteratorT it, fitsHeaderCard< verboseT > card)
 Insert a card before another card.
 
template<typename typeT >
error_t insert_before (headerIteratorT it, const std::string &k, typeT v, const std::string &c)
 Insert a card before another card, specifying the card by its components.
 
template<typename typeT >
error_t insert_before (headerIteratorT it, const std::string &k, typeT v)
 Insert a card before another card, specifying the card by its components.
 
error_t insert_after (headerIteratorT it, fitsHeaderCard< verboseT > card)
 Insert a card after another card.
 
template<typename typeT >
error_t insert_after (headerIteratorT it, const std::string &k, typeT v, const std::string &c)
 Insert a card after another card, specifying the card by its components.
 
template<typename typeT >
error_t insert_after (headerIteratorT it, const std::string &k, typeT v)
 Insert a card after another card, specifying the card by its components.
 
fitsHeaderCard< verboseT > & operator[] (const std::string &keyword)
 Card access by keyword operator.
 
const fitsHeaderCard< verboseT > & operator[] (const std::string &keyword) const
 Card access by keyword operator (const version)
 

Protected Attributes

cardListT m_cardList
 The storage for the FITS header cards.
 
cardMapT m_cardMap
 This multimap allows for fast lookup by keyword.
 
fitsHeaderCard< verboseT > m_emptyCard
 Card with empty keyword used as an error sentinel.
 

Member Typedef Documentation

◆ cardListT

template<class verboseT = verbose::d>
typedef std::list<fitsHeaderCard<verboseT> > mx::fits::fitsHeader< verboseT >::cardListT

The list type.

We use a list, rather than forward_list, so that append (insert at end) is constant time.

Definition at line 60 of file fitsHeader.hpp.

◆ cardMapT

template<class verboseT = verbose::d>
typedef std::unordered_multimap<std::string, headerIteratorT> mx::fits::fitsHeader< verboseT >::cardMapT

The map type.

Use unordered_multimap to allow multiple HISTORY and COMMENT properly, but be as efficient as possible.

Definition at line 68 of file fitsHeader.hpp.

◆ cardMapValueT

template<class verboseT = verbose::d>
typedef cardMapT::value_type mx::fits::fitsHeader< verboseT >::cardMapValueT

The value type for the card map.

Definition at line 71 of file fitsHeader.hpp.

◆ headerIteratorT

template<class verboseT = verbose::d>
typedef cardListT::iterator mx::fits::fitsHeader< verboseT >::headerIteratorT

The iterator type for the cards list.

Definition at line 63 of file fitsHeader.hpp.

◆ mapIteratorT

template<class verboseT = verbose::d>
typedef cardMapT::iterator mx::fits::fitsHeader< verboseT >::mapIteratorT

The iterator type for the card map.

Definition at line 74 of file fitsHeader.hpp.

Constructor & Destructor Documentation

◆ fitsHeader() [1/2]

template<class verboseT >
mx::fits::fitsHeader< verboseT >::fitsHeader ( )

Default c'tor.

Definition at line 270 of file fitsHeader.hpp.

◆ fitsHeader() [2/2]

template<class verboseT >
mx::fits::fitsHeader< verboseT >::fitsHeader ( const fitsHeader< verboseT > &  head)

Copy constructor.

Parameters
headThe fitsHeader to copy

Definition at line 275 of file fitsHeader.hpp.

◆ ~fitsHeader()

template<class verboseT >
mx::fits::fitsHeader< verboseT >::~fitsHeader ( )

Destructor.

Definition at line 281 of file fitsHeader.hpp.

Member Function Documentation

◆ append() [1/6]

◆ append() [2/6]

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::append ( const std::string &  k)

Append a card to the end of the header, with just a keyword.

Appends a headerCard with unknownType

Parameters
[in]kthe keyword of the new card

Definition at line 620 of file fitsHeader.hpp.

References mxlib_error_return.

◆ append() [3/6]

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::append ( const std::string &  k,
const char *  v,
const std::string &  c 
)

Append a string card to the end of the header, from the three components of a card.

Parameters
[in]kthe keyword of the new card
[in]vthe value of the new card
[in]cthe comment of the new card

Definition at line 626 of file fitsHeader.hpp.

References mxlib_error_return.

◆ append() [4/6]

template<class verboseT >
template<typename typeT >
error_t mx::fits::fitsHeader< verboseT >::append ( const std::string &  k,
const typeT &  v 
)

Append a card to the end of the header, from the components of a card with no comment.

Template Parameters
typeTis the data type of the value
Parameters
[in]kthe keyword of the new card
[in]vthe value of the new card

Definition at line 640 of file fitsHeader.hpp.

References mxlib_error_return.

◆ append() [5/6]

template<class verboseT >
template<typename typeT >
error_t mx::fits::fitsHeader< verboseT >::append ( const std::string &  k,
const typeT &  v,
const std::string &  c 
)

Append a card to the end of the header, from the three components of a card.

Template Parameters
typeTis the data type of the value
Parameters
[in]kthe keyword of the new card
[in]vthe value of the new card
[in]cthe comment of the new card

Definition at line 633 of file fitsHeader.hpp.

References mxlib_error_return.

◆ append() [6/6]

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::append ( fitsHeader< verboseT > &  head)

Append a fitsHeader to the end of the header.

Parameters
[in]headthe fitsHeader to append

Definition at line 607 of file fitsHeader.hpp.

References mx::fits::fitsHeader< verboseT >::begin(), mx::fits::fitsHeader< verboseT >::end(), mxlib_error_check, and mx::noerror.

◆ begin()

template<class verboseT >
fitsHeader< verboseT >::headerIteratorT mx::fits::fitsHeader< verboseT >::begin ( )

Get iterator to the beginning of the cards list.

Definition at line 304 of file fitsHeader.hpp.

Referenced by mx::fits::fitsHeader< verboseT >::append(), mx::fits::fitsFile< dataT, verboseT >::readHeader(), and mx::fits::fitsFile< dataT, verboseT >::write().

◆ clear()

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::clear ( )

Clear all cards from the header.

Definition at line 334 of file fitsHeader.hpp.

References mx::noerror.

◆ count()

template<class verboseT >
size_t mx::fits::fitsHeader< verboseT >::count ( const std::string &  keyword)

Get number of cards with a given keyword.

Returns the result of the count() method of the header map.

Return values
thenumber of cards with keyword.
Parameters
[in]keywordthe keyword to look up

Definition at line 343 of file fitsHeader.hpp.

◆ empty()

template<class verboseT >
bool mx::fits::fitsHeader< verboseT >::empty ( )

Test whether the header is empty.

Definition at line 322 of file fitsHeader.hpp.

◆ end()

template<class verboseT >
fitsHeader< verboseT >::headerIteratorT mx::fits::fitsHeader< verboseT >::end ( )

◆ erase() [1/2]

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::erase ( const std::string &  keyword)

Erase card by keyword.

This can not be used to erase COMMENT or HISTORY cards.

Parameters
[in]keywordthe keyword of the card to delete

Definition at line 349 of file fitsHeader.hpp.

References mx::invalidarg, mx::noerror, mx::notfound, and mx::std_exception.

Referenced by mx::fits::fitsFile< dataT, verboseT >::readHeader().

◆ erase() [2/2]

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::erase ( headerIteratorT  it)

Erase card by iterator.

This handles COMMENT and HISTORY cards, deleting only the one pointed to by it using all the contents of the card (not just the keyword)

Parameters
[in]ititerator pointing to the card to delete.

Definition at line 419 of file fitsHeader.hpp.

References mx::invalidarg, mx::noerror, mx::notfound, and mx::std_exception.

◆ eraseStandardTop()

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::eraseStandardTop ( )

Erase the standard entries at the top of the header.

Erases each entry down to BSCALE. This is useful for appending a header from a previous image to a newly created file. Also erases boilerplate comments, such as for long string.

Definition at line 473 of file fitsHeader.hpp.

References mxlib_error_check, and mx::noerror.

◆ insert_after() [1/3]

template<class verboseT >
template<typename typeT >
error_t mx::fits::fitsHeader< verboseT >::insert_after ( headerIteratorT  it,
const std::string &  k,
typeT  v 
)

Insert a card after another card, specifying the card by its components.

Template Parameters
typeTis the type of the value, which is converted to string for insertion
Parameters
[in]itinterator pointing to the element after which to insert
[in]kthe keyword of the new card
[in]vthe value of the new card

Definition at line 824 of file fitsHeader.hpp.

References mxlib_error_return.

◆ insert_after() [2/3]

template<class verboseT >
template<typename typeT >
error_t mx::fits::fitsHeader< verboseT >::insert_after ( headerIteratorT  it,
const std::string &  k,
typeT  v,
const std::string &  c 
)

Insert a card after another card, specifying the card by its components.

Template Parameters
typeTis the type of the value, which is converted to string for insertion
Parameters
[in]ititerator pointing to the element after which to insert
[in]kthe keyword of the new card
[in]vthe value of the new card
[in]cthe comment of the new card

Definition at line 739 of file fitsHeader.hpp.

References mxlib_error_return.

◆ insert_after() [3/3]

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::insert_after ( headerIteratorT  it,
fitsHeaderCard< verboseT >  card 
)

Insert a card after another card.

Parameters
[in]ititerator pointing to the element after which to insert
[in]cardthe card to insert

Definition at line 745 of file fitsHeader.hpp.

References mx::invalidarg, mx::fits::fitsHeaderCard< verboseT >::keyword(), mx::noerror, mx::std_bad_alloc, mx::std_exception, and mx::fits::fitsHeaderCard< verboseT >::type().

◆ insert_before() [1/3]

template<class verboseT >
template<typename typeT >
error_t mx::fits::fitsHeader< verboseT >::insert_before ( headerIteratorT  it,
const std::string &  k,
typeT  v 
)

Insert a card before another card, specifying the card by its components.

Template Parameters
typeTis the type of the value, which is converted to string for insertion
Parameters
[in]ititerator pointing to the element before which to insert
[in]kthe keyword of the new card
[in]vthe value of the new card

Definition at line 732 of file fitsHeader.hpp.

References mxlib_error_return.

◆ insert_before() [2/3]

template<class verboseT >
template<typename typeT >
error_t mx::fits::fitsHeader< verboseT >::insert_before ( headerIteratorT  it,
const std::string &  k,
typeT  v,
const std::string &  c 
)

Insert a card before another card, specifying the card by its components.

Template Parameters
typeTis the type of the value, which is converted to string for insertion
Parameters
[in]ititerator pointing to the element before which to insert
[in]kthe keyword of the new card
[in]vthe value of the new card
[in]cthe comment of the new card

Definition at line 725 of file fitsHeader.hpp.

References mxlib_error_return.

◆ insert_before() [3/3]

template<class verboseT >
error_t mx::fits::fitsHeader< verboseT >::insert_before ( headerIteratorT  it,
fitsHeaderCard< verboseT >  card 
)

Insert a card before another card.

Parameters
[in]ititerator pointing to the element before which to insert
[in]cardthe card to insert

Definition at line 646 of file fitsHeader.hpp.

References mx::invalidarg, mx::fits::fitsHeaderCard< verboseT >::keyword(), mx::noerror, mx::std_bad_alloc, mx::std_exception, and mx::fits::fitsHeaderCard< verboseT >::type().

◆ iterator()

template<class verboseT >
fitsHeader< verboseT >::headerIteratorT mx::fits::fitsHeader< verboseT >::iterator ( const std::string &  keyword)

Get iterator pointing to a specific element.

Parameters
keywordThe keyword to look up

Definition at line 316 of file fitsHeader.hpp.

◆ operator=()

template<class verboseT >
fitsHeader< verboseT > & mx::fits::fitsHeader< verboseT >::operator= ( const fitsHeader< verboseT > &  head)

Assignment operator.

Parameters
headThe fitsHeader to copy

Definition at line 287 of file fitsHeader.hpp.

References mx::fits::fitsHeader< verboseT >::m_cardList.

◆ operator[]() [1/2]

template<class verboseT >
fitsHeaderCard< verboseT > & mx::fits::fitsHeader< verboseT >::operator[] ( const std::string &  keyword)

Card access by keyword operator.

Looks up the card by its keyword, and returns a reference to it.

Returns
on success: fitsHeaderCard& reference to the fitsHeaderCard
on error: a fitsHeaderCard& to a card with an empty keyword
Parameters
[in]keywordthe header keyword to look up

Definition at line 830 of file fitsHeader.hpp.

References mx::noerror, and mx::notfound.

◆ operator[]() [2/2]

template<class verboseT >
const fitsHeaderCard< verboseT > & mx::fits::fitsHeader< verboseT >::operator[] ( const std::string &  keyword) const

Card access by keyword operator (const version)

Looks up the card by its keyword, and returns a reference to it.

Returns
on success: fitsHeaderCard& reference to the fitsHeaderCard
on error: a fitsHeaderCard& to a card with an empty keyword
Parameters
[in]keywordthe header keyword to look up

Definition at line 862 of file fitsHeader.hpp.

References mx::notfound.

◆ size()

template<class verboseT >
size_t mx::fits::fitsHeader< verboseT >::size ( )

Get number of cards currently stored in the header.

Definition at line 328 of file fitsHeader.hpp.

Referenced by mx::fits::fitsFile< dataT, verboseT >::readHeader().

Member Data Documentation

◆ m_cardList

template<class verboseT = verbose::d>
cardListT mx::fits::fitsHeader< verboseT >::m_cardList
protected

The storage for the FITS header cards.

Definition at line 78 of file fitsHeader.hpp.

Referenced by mx::fits::fitsHeader< verboseT >::operator=().

◆ m_cardMap

template<class verboseT = verbose::d>
cardMapT mx::fits::fitsHeader< verboseT >::m_cardMap
protected

This multimap allows for fast lookup by keyword.

Definition at line 81 of file fitsHeader.hpp.

◆ m_emptyCard

template<class verboseT = verbose::d>
fitsHeaderCard<verboseT> mx::fits::fitsHeader< verboseT >::m_emptyCard
mutableprotected

Card with empty keyword used as an error sentinel.

Definition at line 84 of file fitsHeader.hpp.


The documentation for this class was generated from the following file: