casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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: EclecticFunctionFactory.h 20229 2008-01-29 15:19:06Z gervandiepen $
00028 
00029 #ifndef SCIMATH_ECLECTICFUNCTIONFACTORY_H
00030 #define SCIMATH_ECLECTICFUNCTIONFACTORY_H
00031 
00032 #include <scimath/Functionals/Function.h>
00033 #include <casa/Containers/OrderedMap.h>
00034 #include <casa/Containers/OrderedPair.h>
00035 #include <casa/Exceptions/Error.h>
00036 #include <scimath/Functionals/AbstractFunctionFactory.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 
00042 class Record;
00043 
00044 // <summary>
00045 //
00046 //
00047 //
00048 //
00049 //
00050 // </summary>
00051 
00052 // <use visibility=export>
00053 
00054 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 //   <li> FunctionFactory
00059 // </prerequisite>
00060 //
00061 // <etymology>
00062 // This class is based on the Factory pattern, similar to the 
00063 // ApplicationObjectFactory
00064 // </etymology>
00065 //
00066 // <synopsis>
00067 //
00068 //
00069 //
00070 //
00071 // </synopsis>
00072 //
00073 // <example>
00074 //
00075 //
00076 //
00077 // </example>
00078 //
00079 // <motivation>
00080 //
00081 //
00082 //
00083 // </motivation>
00084 //
00085 // <templating arg=T>
00086 //    <li> Function must have a constructor for the form T(const Record&)
00087 // </templating>
00088 //
00089 // <thrown>
00090 //    <li> UnrecognizedFunctionError by create() if the Record field 
00091 //         "functype" does not match a Function added via addFactory()
00092 //    <li> InvalidSerializationError by create() if 
00093 //         <ul>
00094 //            <li> Record does not contain a "functype" field containing
00095 //                 a string
00096 //            <li> the associated specific factory throws an
00097 //                 InvalidSerializationError
00098 //         </ul>
00099 // </thrown>
00100 //
00101 // <todo asof="yyyy/mm/dd">
00102 //   <li> 
00103 //   <li> 
00104 //   <li> 
00105 // </todo>
00106 
00107 template<class T> 
00108 class EclecticFunctionFactory : public FunctionFactory<T>
00109 {
00110 public:
00111 
00112     // create an empty EclecticFunctionFactory
00113     EclecticFunctionFactory();
00114 
00115     // create a shallow copy of another EclecticFunctionFactory
00116     EclecticFunctionFactory(const EclecticFunctionFactory& factory);
00117 
00118     // delete this EclecticFunctionFactory.  Those specific factories added
00119     // via addFactory() with <em>own=True</em> will be deleted.
00120     virtual ~EclecticFunctionFactory();
00121 
00122     // create the Function object described in the given Record.  This
00123     // implementation will use the value of the "functype" field to lookup
00124     // the specific factory to use to create the function.  That is, the 
00125     // the "functype" value will be matched against the type names loaded 
00126     // via addFactory().
00127     virtual Function<T> *create(const Record&) const
00128         throw(FunctionFactoryError);
00129 
00130     // add a factory for creating a specific type of function, associating
00131     // it with a given "functype" name.
00132     void addFactory(const String& type, FunctionFactory<T> *factory,
00133                     Bool own=True);
00134 
00135     // return the number of factories that have been loaded thus far.
00136     Int ndefined() { return lookup.ndefined(); }
00137 
00138     // return True if a factory with a given "functype" name has been 
00139     // loaded.
00140     Bool isDefined(const String& type) { return lookup.isDefined(type); }
00141 
00142     // a shallow assignment operator
00143     EclecticFunctionFactory& operator=(const EclecticFunctionFactory& factory);
00144 
00145 protected:
00146 
00147 private:
00148     OrderedMap<String, OrderedPair<FunctionFactory<T>*, Bool> > lookup;
00149 };
00150 
00151 
00152 } //# NAMESPACE CASA - END
00153 
00154 #ifndef CASACORE_NO_AUTO_TEMPLATES
00155 #include <scimath/Functionals/EclecticFunctionFactory.tcc>
00156 #endif //# CASACORE_NO_AUTO_TEMPLATES
00157 #endif
00158 
00159