include/nnfwfactory.h

Go to the documentation of this file.
00001 /********************************************************************************
00002  *  Neural Network Framework.                                                   *
00003  *  Copyright (C) 2005-2008 Gianluca Massera <emmegian@yahoo.it>                     *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef NNFWFACTORY_H
00021 #define NNFWFACTORY_H
00022 
00023 #include "types.h"
00024 #include "propertized.h"
00025 #include "clonable.h"
00026 #include <map>
00027 #include <string>
00028 
00037 namespace nnfw {
00038 
00041 class NNFW_API AbstractCreator : public Clonable {
00042 public:
00045 
00048     virtual Propertized* create( PropertySettings& param ) const = 0;
00049 
00052     virtual AbstractCreator* clone() const = 0;
00054 };
00055 
00058 template<class T>
00059 class NNFW_TEMPLATE Creator : public AbstractCreator {
00062 
00065     virtual Propertized* create( PropertySettings& param ) const {
00066         return ( new T(param) );
00067     };
00068 
00071     virtual Creator* clone() const {
00072         return new Creator();
00073     };
00075 };
00076 
00079 class NNFW_API AbstractModifier : public Clonable {
00080 public:
00083 
00085     virtual void setUpdatable( Updatable* tolearn ) {
00086         learnable = tolearn;
00087     };
00088 
00090     virtual void rule( Real r, const RealVec& x, const RealVec& y ) const = 0;
00091 
00093     virtual AbstractModifier* clone() const = 0;
00095 protected:
00096     // --- learnable object
00097     Updatable* learnable;
00098 };
00099 
00109 class NNFW_API Factory {
00110 public:
00113 
00116     static Cluster* createCluster( const char* type, PropertySettings& param );
00117 
00120     static Linker* createLinker( const char* type, PropertySettings& param );
00121 
00124     static OutputFunction* createOutputFunction( const char* type, PropertySettings& param );
00125 
00128     static Propertized* createPropertized( const char* type, PropertySettings& param );
00129 
00134     static bool registerCluster( const AbstractCreator& c, const char* type );
00135 
00140     static bool registerLinker( const AbstractCreator& c, const char* type );
00141 
00146     static bool registerOutputFunction( const AbstractCreator& c, const char* type );
00147 
00155     static bool registerPropertized( const AbstractCreator& c, const char* type );
00156 
00158     static AbstractModifier* createModifierFor( Updatable* objectToLearn );
00159 
00161     static bool registerModifier( const AbstractModifier& m, const char* type );
00162 
00164 
00165 private:
00168     Factory() {
00169         // You can't instantiate this class
00170     };
00171 
00173     static void initFactory();
00174 
00176     static bool isInit;
00177 
00179     static std::map<std::string, AbstractCreator*> clustertypes;
00181     static std::map<std::string, AbstractCreator*> linkertypes;
00183     static std::map<std::string, AbstractCreator*> outfuntypes;
00185     static std::map<std::string, AbstractCreator*> proptypes;
00186 
00188     static std::map<std::string, AbstractModifier*> modtypes;
00189 };
00190 
00191 }
00192 
00193 #endif
BerliOS Developer Logo Valid XHTML 1.0 Transitional Valid CSS!