casacore
Loading...
Searching...
No Matches
EclecticFunctionFactory.h
Go to the documentation of this file.
1//# EclecticFunctionFactory.cc: a class for creating various Function objects from Records
2//# Copyright (C) 2002
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: casa-feedback@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#ifndef SCIMATH_ECLECTICFUNCTIONFACTORY_H
27#define SCIMATH_ECLECTICFUNCTIONFACTORY_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/scimath/Functionals/Function.h>
31#include <casacore/casa/Containers/OrderedMap.h>
32#include <casacore/casa/Containers/OrderedPair.h>
33#include <casacore/casa/Exceptions/Error.h>
34#include <casacore/scimath/Functionals/AbstractFunctionFactory.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39
40class Record;
41
42// <summary>
43//
44//
45//
46//
47//
48// </summary>
49
50// <use visibility=export>
51
52// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
53// </reviewed>
54
55// <prerequisite>
56// <li> FunctionFactory
57// </prerequisite>
58//
59// <etymology>
60// This class is based on the Factory pattern, similar to the
61// ApplicationObjectFactory
62// </etymology>
63//
64// <synopsis>
65//
66//
67//
68//
69// </synopsis>
70//
71// <example>
72//
73//
74//
75// </example>
76//
77// <motivation>
78//
79//
80//
81// </motivation>
82//
83// <templating arg=T>
84// <li> Function must have a constructor for the form T(const Record&)
85// </templating>
86//
87// <thrown>
88// <li> UnrecognizedFunctionError by create() if the Record field
89// "functype" does not match a Function added via addFactory()
90// <li> InvalidSerializationError by create() if
91// <ul>
92// <li> Record does not contain a "functype" field containing
93// a string
94// <li> the associated specific factory throws an
95// InvalidSerializationError
96// </ul>
97// </thrown>
98//
99// <todo asof="yyyy/mm/dd">
100// <li>
101// <li>
102// <li>
103// </todo>
104
105template<class T>
107{
108public:
109
110 // create an empty EclecticFunctionFactory
112
113 // create a shallow copy of another EclecticFunctionFactory
115
116 // delete this EclecticFunctionFactory. Those specific factories added
117 // via addFactory() with <em>own=True</em> will be deleted.
119
120 // create the Function object described in the given Record. This
121 // implementation will use the value of the "functype" field to lookup
122 // the specific factory to use to create the function. That is, the
123 // the "functype" value will be matched against the type names loaded
124 // via addFactory().
125 virtual Function<T> *create(const Record&) const
127
128 // add a factory for creating a specific type of function, associating
129 // it with a given "functype" name.
130 void addFactory(const String& type, FunctionFactory<T> *factory,
131 Bool own=True);
132
133 // return the number of factories that have been loaded thus far.
134 Int ndefined() { return lookup.ndefined(); }
135
136 // return True if a factory with a given "functype" name has been
137 // loaded.
138 Bool isDefined(const String& type) { return lookup.isDefined(type); }
139
140 // a shallow assignment operator
142
143protected:
144
145private:
146 OrderedMap<String, OrderedPair<FunctionFactory<T>*, Bool> > lookup;
147};
148
149
150} //# NAMESPACE CASACORE - END
151
152#ifndef CASACORE_NO_AUTO_TEMPLATES
153#include <casacore/scimath/Functionals/EclecticFunctionFactory.tcc>
154#endif //# CASACORE_NO_AUTO_TEMPLATES
155#endif
156
157
virtual Function< T > * create(const Record &) const
create the Function object described in the given Record.
Int ndefined()
return the number of factories that have been loaded thus far.
EclecticFunctionFactory & operator=(const EclecticFunctionFactory &factory)
a shallow assignment operator
OrderedMap< String, OrderedPair< FunctionFactory< T > *, Bool > > lookup
EclecticFunctionFactory(const EclecticFunctionFactory &factory)
create a shallow copy of another EclecticFunctionFactory
void addFactory(const String &type, FunctionFactory< T > *factory, Bool own=True)
add a factory for creating a specific type of function, associating it with a given "functype" name.
Bool isDefined(const String &type)
return True if a factory with a given "functype" name has been loaded.
virtual ~EclecticFunctionFactory()
delete this EclecticFunctionFactory.
EclecticFunctionFactory()
create an empty EclecticFunctionFactory
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41