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