casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FunctionHolder.h
Go to the documentation of this file.
1 //# FunctionHolder.h: A holder for Functions to enable record conversions
2 //# Copyright (C) 2002,2003,2004
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef SCIMATH_FUNCTIONHOLDER_H
29 #define SCIMATH_FUNCTIONHOLDER_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward Declarations
42 
43 // <summary> A holder for Functions to enable record conversions </summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tFunctionHolder" demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // <li> <linkto class=RecordInterface>RecordInterface</linkto> class
52 // <li> <linkto class=Function>Function</linkto> class
53 // </prerequisite>
54 //
55 // <etymology>
56 // A Holder of general Measures
57 // </etymology>
58 //
59 // <synopsis>
60 // This class can be used to handle heterogeneous collections of Functions,
61 // e.g. as a <src>Vector<FunctionHolder></src>. With the aid of the
62 // toRecord() and fromRecord() functions it can be used
63 // to convert a Function object into or from a record.
64 // A FunctionHolder is created from a Function, or can be empty.
65 //
66 // </synopsis>
67 //
68 // <example>
69 // <srcblock>
70 // TableRecord rec;
71 // MDirection dir(MVDirection(Quantity(12.5, 'deg'), Quantity(-2, 'deg')),
72 // MDirection::J2000);
73 // String error; // error message
74 // if (!FunctionHolder(dir).toRecord(error, rec)) {
75 // cout << error << endl;
76 // }
77 // Record grec; // a Record
78 // if (!FunctionHolder(dir).toRecord(error, grec)) { // make record
79 // cout << error << endl;
80 // }
81 // // Note that for GlishRecords use can be made of the
82 // // GlishRecord::to/fromrecord() methods.
83 // </srcblock>
84 // </example>
85 //
86 // <motivation>
87 // To make general conversions between Functions and records, without knowing
88 // the actual Function being converted.
89 // </motivation>
90 
91 template <class T> class FunctionHolder : public RecordTransformable {
92  public:
93  //# Enumerations
94  // Types of functions
95  enum Types {
111  };
112  //# Structures
113  // Structure to hold functional status
114  struct FuncStat {
115  // Name
117  // type
119  // Order (True if needed)
121  };
122 
123  //# Constructors
124  // Creates an empty holder
125  FunctionHolder();
126  // Create from a Function (copy made)
127  FunctionHolder(const Function<T> &in);
128  // Copy a holder (copy semantics)
129  FunctionHolder(const FunctionHolder<T> &other);
130  //# Destructor
131  ~FunctionHolder();
132 
133  //# Operators
134  // Assignment (copy semantics)
136 
137  //# Member Functions
138  // Check the the FunctionHolder holds the specified type. Return
139  // True if if does and False otherwise.
140  // <group>
141  Bool isEmpty() const;
142  // </group>
143  // Get the known names
144  const Vector<String> &names() const;
145  // Get a specific Function from the holder (with lifetime as long
146  // as holder exists).
147  // <thrown>
148  // <li> AipsError if holder empty
149  // <li> AipsError if holder contains wrong Function
150  // </thrown>
151  // <group>
152  const Function<T> &asFunction() const;
153  // </group>
154  // Add a function
155  Bool addFunction(const Function<T> &fnc);
156  // Get the type of currently filled holder
157  Types type() const;
158  // Create a Function from a record. An error message is generated, and False
159  // returned if an invalid record is given. A valid record will return True.
160  // A valid record contains at least the following fields (any additional fields are
161  // ignored):
162  // <ul>
163  // <li> tp = TpString: type of Function (gaussian1d, etc; case
164  // insensitive) -- OR an enumeration code
165  // <li> order = TpInt: the order needed to create a Function (-1 if not
166  // necessary or default)
167  // <li> ndim, npar, params are optional
168  // <li> nfunc, funcs are required for COMBI or COMPOUND
169  // </ul>
170  // A Function can be created from a string. In that case the string
171  // will only indicate the type of function (like polynomial), and will
172  // create a default polynomial of that given type.
173  // Error messages are postfixed to error.
174  // <group>
175  virtual Bool fromRecord(String &error, const RecordInterface &in);
176  virtual Bool fromString(String &error, const String &in);
177  template <class U>
178  Bool getRecord(String &error, Function<U> *&fn,
179  const RecordInterface &in);
180  // </group>
181  // Create a record from a Function. The return will be False and an error
182  // message generated only if the FunctionHolder does not contain a Function.
183  // Error messages are postfixed to error.
184  virtual Bool toRecord(String &error, RecordInterface &out) const;
185  // Get identification of record
186  virtual const String &ident() const;
187 
188 private:
189  //# Data Members
190  // Pointer to a Function
192  // Aids (only filled after a succesful to/fromRecord
193  // <group>
194  mutable Types nf_p;
195  mutable Int order_p;
196  mutable String text_p;
198  // </group>
199  // List of known names
201  // Filled list?
202  mutable Bool isFilled;
203 
204  //# Member functions
205  // Initialise and check the name list
206  void init() const;
207  // Aid for to/from Record, String
208  // <group>
209  Bool putType(String &error, RecordInterface &out) const;
210  template <class U>
211  Bool getType(String &error, Function<U> *&fn, const RecordInterface &in);
212  template <class U>
213  Bool getType(String &error, Function<U> *&fn);
214  void setParameters(Function<T> *&fn, const Vector<T> &params);
215  void setParameters(Function<AutoDiff<T> > *&fn, const Vector<T> &params);
216  // </group>
217 };
218 
219 
220 } //# NAMESPACE CASACORE - END
221 
222 #ifndef CASACORE_NO_AUTO_TEMPLATES
223 #include <casacore/scimath/Functionals/FunctionHolder.tcc>
224 #endif //# CASACORE_NO_AUTO_TEMPLATES
225 #endif
A 1-D Specialization of the Array class.
int Int
Definition: aipstype.h:50
virtual Bool fromRecord(String &error, const RecordInterface &in)
Create a Function from a record.
const Vector< String > & names() const
Get the known names.
Bool getRecord(String &error, Function< U > *&fn, const RecordInterface &in)
const Function< T > & asFunction() const
Get a specific Function from the holder (with lifetime as long as holder exists). ...
Vector< String > nam_p
List of known names.
Bool isEmpty() const
Check the the FunctionHolder holds the specified type.
Structure to hold functional status.
virtual Bool fromString(String &error, const String &in)
Initialise the class from a String representation.
Types nf_p
Aids (only filled after a succesful to/fromRecord.
Interface class for converting to/from records.
PtrHolder< RecordInterface > mode_p
Bool order
Order (True if needed)
FunctionHolder & operator=(const FunctionHolder< T > &other)
Assignment (copy semantics)
Hold and delete pointers not deleted by object destructors.
A holder for Functions to enable record conversions.
Bool getType(String &error, Function< U > *&fn, const RecordInterface &in)
virtual Bool toRecord(String &error, RecordInterface &out) const
Create a record from a Function.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Class that computes partial derivatives by automatic differentiation.
Definition: AutoDiff.h:257
Bool isFilled
Filled list?
virtual const String & ident() const
Get identification of record.
Bool putType(String &error, RecordInterface &out) const
Aid for to/from Record, String.
FunctionHolder()
Creates an empty holder.
void init() const
Initialise and check the name list.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Abstract base class for Record classes.
Types type() const
Get the type of currently filled holder.
PtrHolder< Function< T > > hold_p
Pointer to a Function.
Bool addFunction(const Function< T > &fnc)
Add a function.
void setParameters(Function< T > *&fn, const Vector< T > &params)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42