Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

netloader.h

00001 /***************************************************************************
00002                           netloader.h  -  description
00003                              -------------------
00004     begin                : Mon Apr 29 2002
00005     copyright            : (C) 2002 by Rüdiger Koch
00006     email                : rkoch@rkoch.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef NETLOADER_H
00019 #define NETLOADER_H
00020 
00021 using namespace std;
00022 #include <amygdala/types.h>
00023 #if GCC_VERSION >= 30000
00024     #include <ext/hash_map>
00025 #else
00026     #include <hash_map>
00027 #endif
00028 #include <string>
00029 #include <strings.h>
00030 #include <stdio.h>
00031 
00032 
00033 #include <amygdala/neuron.h>
00034 
00035 class Layer;
00036 
00037 class NeuronFactoryBase {
00038 public:
00039     NeuronFactoryBase() {}
00040     virtual Neuron * NewNeuron(AmIdInt id) = 0;
00041     virtual string GetType() = 0;
00042 };
00043 
00051 template<class neuron>
00052 class NeuronFactory : public NeuronFactoryBase {
00053 public:
00054     NeuronFactory(){
00055     }
00056     virtual ~NeuronFactory(){}
00057 
00058     virtual Neuron * NewNeuron(AmIdInt id){
00059         neuron *n = new neuron(id);
00060         return n;
00061     }
00063     virtual string GetType() {
00064         // We instantiate a dummy neuron here so we can call the virtual
00065         // function.
00066         neuron n(0);
00067         return n.ClassId();
00068     }
00069 };
00070 
00071 
00082 class NetLoader {
00083 public:
00084     NetLoader(Network *_net);
00085     ~NetLoader();
00087     void RegisterNeuronClass(NeuronFactoryBase *factory);
00090     void LoadXML(const char *filename);
00093     void SaveXML(string filename);
00095     Layer* BuildLayer(int size, int startNrnId, LayerConstants layerConst, string neuronType);
00096 
00098     void SAXStartElement1(const char *name, const char **attrs);
00100     void SAXEndElement1(const char *name);
00101 
00103     void SAXStartElement2(const char *name, const char **attrs);
00105     void SAXEndElement2(const char *name);
00107     void SAXError();
00108 
00109 protected: // Protected attributes
00110     struct eqstr {
00111         bool operator()(const char* s1, const char* s2) const {
00112             return strcmp(s1, s2) == 0;
00113         }
00114     };
00117     hash_map <const char*, NeuronFactoryBase*, hash<const char*>, eqstr > registry;
00118 
00120     Network* net;
00121     Layer *currLayer;
00122     AmIdInt currNeuron;
00123     unsigned int saxErrors;
00124 
00125 private: // Private methods
00127     NetLoader();
00128 
00129 
00130 protected: // Protected methods
00132     void WriteSynapses(FILE *netFile, Neuron* preNrn);
00134     void SaveLayers(FILE *netFile);
00136     string LayerTypeStr(LayerType lType);
00139     void SAXPass(const char* filename, int pass);
00140 
00141 
00142     void ParseLayerConstants(LayerConstants *layerConst, char **name, const char **attrs);
00143 };
00144 
00145 #endif

Generated on Wed Sep 4 02:30:35 2002 for Amygdala by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002