EclecticFunctionFactory.h

Go to the documentation of this file.
00001 //# EclecticFunctionFactory.cc: a class for creating various Function objects from Records
00002 //# Copyright (C) 2002
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id$
00028 
00029 #ifndef SCIMATH_ECLECTICFUNCTIONFACTORY_H
00030 #define SCIMATH_ECLECTICFUNCTIONFACTORY_H
00031 
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/scimath/Functionals/Function.h>
00034 #include <casacore/casa/Containers/OrderedMap.h>
00035 #include <casacore/casa/Containers/OrderedPair.h>
00036 #include <casacore/casa/Exceptions/Error.h>
00037 #include <casacore/scimath/Functionals/AbstractFunctionFactory.h>
00038 
00039 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00040 
00041 //# Forward Declarations
00042 
00043 class Record;
00044 
00045 // <summary>
00046 //
00047 //
00048 //
00049 //
00050 //
00051 // </summary>
00052 
00053 // <use visibility=export>
00054 
00055 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00056 // </reviewed>
00057 
00058 // <prerequisite>
00059 //   <li> FunctionFactory
00060 // </prerequisite>
00061 //
00062 // <etymology>
00063 // This class is based on the Factory pattern, similar to the 
00064 // ApplicationObjectFactory
00065 // </etymology>
00066 //
00067 // <synopsis>
00068 //
00069 //
00070 //
00071 //
00072 // </synopsis>
00073 //
00074 // <example>
00075 //
00076 //
00077 //
00078 // </example>
00079 //
00080 // <motivation>
00081 //
00082 //
00083 //
00084 // </motivation>
00085 //
00086 // <templating arg=T>
00087 //    <li> Function must have a constructor for the form T(const Record&)
00088 // </templating>
00089 //
00090 // <thrown>
00091 //    <li> UnrecognizedFunctionError by create() if the Record field 
00092 //         "functype" does not match a Function added via addFactory()
00093 //    <li> InvalidSerializationError by create() if 
00094 //         <ul>
00095 //            <li> Record does not contain a "functype" field containing
00096 //                 a string
00097 //            <li> the associated specific factory throws an
00098 //                 InvalidSerializationError
00099 //         </ul>
00100 // </thrown>
00101 //
00102 // <todo asof="yyyy/mm/dd">
00103 //   <li> 
00104 //   <li> 
00105 //   <li> 
00106 // </todo>
00107 
00108 template<class T> 
00109 class EclecticFunctionFactory : public FunctionFactory<T>
00110 {
00111 public:
00112 
00113     // create an empty EclecticFunctionFactory
00114     EclecticFunctionFactory();
00115 
00116     // create a shallow copy of another EclecticFunctionFactory
00117     EclecticFunctionFactory(const EclecticFunctionFactory& factory);
00118 
00119     // delete this EclecticFunctionFactory.  Those specific factories added
00120     // via addFactory() with <em>own=True</em> will be deleted.
00121     virtual ~EclecticFunctionFactory();
00122 
00123     // create the Function object described in the given Record.  This
00124     // implementation will use the value of the "functype" field to lookup
00125     // the specific factory to use to create the function.  That is, the 
00126     // the "functype" value will be matched against the type names loaded 
00127     // via addFactory().
00128     virtual Function<T> *create(const Record&) const
00129         throw(FunctionFactoryError);
00130 
00131     // add a factory for creating a specific type of function, associating
00132     // it with a given "functype" name.
00133     void addFactory(const String& type, FunctionFactory<T> *factory,
00134                     Bool own=True);
00135 
00136     // return the number of factories that have been loaded thus far.
00137     Int ndefined() { return lookup.ndefined(); }
00138 
00139     // return True if a factory with a given "functype" name has been 
00140     // loaded.
00141     Bool isDefined(const String& type) { return lookup.isDefined(type); }
00142 
00143     // a shallow assignment operator
00144     EclecticFunctionFactory& operator=(const EclecticFunctionFactory& factory);
00145 
00146 protected:
00147 
00148 private:
00149     OrderedMap<String, OrderedPair<FunctionFactory<T>*, Bool> > lookup;
00150 };
00151 
00152 
00153 } //# NAMESPACE CASACORE - END
00154 
00155 #ifndef CASACORE_NO_AUTO_TEMPLATES
00156 #include <casacore/scimath/Functionals/EclecticFunctionFactory.tcc>
00157 #endif //# CASACORE_NO_AUTO_TEMPLATES
00158 #endif
00159 
00160 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1