Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Arroyo::fits_factory< abstract_product > Class Template Reference

#include <fits_factory.h>

List of all members.

Static Public Member Functions

bool Register (const fits_keyval_set &fkvs, abstract_product *(*creator)(const iofits &))
abstract_product * create (const iofits &iof)


Detailed Description

template<class abstract_product>
class Arroyo::fits_factory< abstract_product >

A template factory class used for loading classes from a fits file. This factory is a singleton. You instantiate it for the particular type of base class that you want to return from this factory. You then register your derived classes using the register function, by supplying a map from a fits_keyval_header_map to a function pointer. The fits_keyval_header_map is itself a map between pairs of strings and integers. The pairs of strings are interpreted as fits keyval pairs, and the int is interpreted as an HDU offset in the fits file where the keyval pair is found. This function must take as its argument an iofits reference. This factory then runs through its registry searching the fits file for each set of keyval pairs. If it finds a match, it calls the function supplied to the registry.

The fits_keyval_header_map between pairs of strings and integers is intended to facilitate polymorphic reading and writing of aggregate and multiply inherited objects. The idea is that for one of these compound objects, the first fits header would hold information necessary to identify the compound object, and subsequent fits HDU's would hold the atomic objects. Thus the factory must know which keyval pairs to look for in each header, and the int contains this information. Since every compound object may itself become incorporated into a larger object through inheritance or aggregation, we interpret the integer identifying the fits HDU as a relative offset from the current HDU. In order for this scheme to work, the fits_keyval_header_map must be sorted from smallest header offset (zero offset) to largest header offset. The Register function ensures that this is the case by sorting the vector of fits

The first entry in the pair of strings must match the fits header key exactly. The second entry in the map must either match the fits header value exactly, or must be empty. If the second entry in the map is empty then this class will consider the entry a match if the first entry matches the fits header key.

This class was modelled after the Object Factory class described by Alexandrescu in "Modern C++ design". While this class could almost have been generated from an instantiation of the more general class he proposed, this instantiation would have relied on his functor, typelist, and singleton classes. Since no version of his library is available as yet, I wrote this simpler version.


Member Function Documentation

template<class abstract_product>
abstract_product* Arroyo::fits_factory< abstract_product >::create const iofits iof  )  [inline, static]
 

template<class abstract_product>
bool Arroyo::fits_factory< abstract_product >::Register const fits_keyval_set fkvs,
abstract_product *(*)(const iofits &)  creator
[inline, static]
 


The documentation for this class was generated from the following file:
Generated on Thu Nov 29 17:16:34 2007 for arroyo by  doxygen 1.3.9.1