FunctionHolder.h

Classes

FunctionHolder -- A holder for Functions to enable record conversions (full description)

template <class T> class FunctionHolder : public RecordTransformable

Types

enum Types

GAUSSIAN1D
GAUSSIAN2D
GAUSSIAN3D
GAUSSIANND
HYPERPLANE
POLYNOMIAL
EVENPOLYNOMIAL
ODDPOLYNOMIAL
SINUSOID1D
CHEBYSHEV
BUTTERWORTH
COMBINE
COMPOUND
COMPILED
N_Types

Interface

Public Members
FunctionHolder()
FunctionHolder(const Function<T> &in)
FunctionHolder(const FunctionHolder<T> &other)
~FunctionHolder()
FunctionHolder &operator=(const FunctionHolder<T> &other)
Bool isEmpty() const
const Vector<String> &names() const
const Function<T> &asFunction() const
Bool addFunction(const Function<T> &fnc)
FunctionHolder<T>::Types type() const
virtual Bool fromRecord(String &error, const RecordInterface &in)
virtual Bool fromString(String &error, const String &in)
template <class U> Bool getRecord(U &error, String<U> *&fn, const RecordInterface &in)
virtual Bool toRecord(String &error, RecordInterface &out) const
virtual const String &ident() const
Private Members
void init() const
Bool putType(String &error, RecordInterface &out) const
template <class U> Bool getType(U &error, String<U> *&fn, const RecordInterface &in)
template <class U> Bool getType(U &error, String<U> *&fn)
void FunctionHolder<T>::setParameters(Function<T> *&fn, const Function<T> &params)
void FunctionHolder<T>::setParameters(Function<Function<T> > *&fn, const AutoDiff<T> &params)

Description

Review Status

Date Reviewed:
yyyy/mm/dd
Programs:
Tests:

Prerequisite

Etymology

A Holder of general Measures

Synopsis

This class can be used to handle heterogeneous collections of Functions, e.g. as a Vector<FunctionHolder>. With the aid of the toRecord() and fromRecord() functions it can be used to convert a Function object into or from a record. A FunctionHolder is created from a Function, or can be empty.

Example

	TableRecord rec;
	MDirection dir(MVDirection(Quantity(12.5, 'deg'), Quantity(-2, 'deg')),
		       MDirection::J2000);
	String error;		// error message
	if (!FunctionHolder(dir).toRecord(error, rec)) {
		cout << error << endl;
	};
	Record grec;		// a Record
	if (!FunctionHolder(dir).toRecord(error, grec)) {  // make record
		cout << error << endl;
	};
 // Note that for GlishRecords use can be made of the
 // GlishRecord::to/fromrecord() methods.

Motivation

To make general conversions between Functions and records, without knowing the actual Function being converted.

Member Description

enum Types

Types of functions

FunctionHolder()

Creates an empty holder

FunctionHolder(const Function<T> &in)

Create from a Function (copy made)

FunctionHolder(const FunctionHolder<T> &other)

Copy a holder (copy semantics)

~FunctionHolder()

FunctionHolder &operator=(const FunctionHolder<T> &other)

Assignment (copy semantics)

Bool isEmpty() const

Check the the FunctionHolder holds the specified type. Return True if if does and False otherwise.

const Vector<String> &names() const

Get the known names

const Function<T> &asFunction() const

Get a specific Function from the holder (with lifetime as long as holder exists).

Thrown Exceptions

Bool addFunction(const Function<T> &fnc)

Add a function

FunctionHolder<T>::Types type() const

Get the type of currently filled holder

virtual Bool fromRecord(String &error, const RecordInterface &in)
virtual Bool fromString(String &error, const String &in)
template <class U> Bool getRecord(U &error, String<U> *&fn, const RecordInterface &in)

Create a Function from a record. An error message is generated, and False returned if an invalid record is given. A valid record will return True. A valid record contains at least the following fields (any additional fields are ignored): A Function can be created from a string. In that case the string will only indicate the type of function (like polynomial), and will create a default polynomial of that given type. Error messages are postfixed to error.

virtual Bool toRecord(String &error, RecordInterface &out) const

Create a record from a Function. The return will be False and an error message generated only if the FunctionHolder does not contain a Function. Error messages are postfixed to error.

virtual const String &ident() const

Get identification of record

void init() const

Initialise and check the name list

Bool putType(String &error, RecordInterface &out) const
template <class U> Bool getType(U &error, String<U> *&fn, const RecordInterface &in)
template <class U> Bool getType(U &error, String<U> *&fn)
void FunctionHolder<T>::setParameters(Function<T> *&fn, const Function<T> &params)
void FunctionHolder<T>::setParameters(Function<Function<T> > *&fn, const AutoDiff<T> &params)

Aid for to/from Record, String