00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
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