?? netloader.cpp
字號:
/*************************************************************************** netloader.cpp - description ------------------- begin : Mon Apr 29 2002 copyright : (C) 2002 by Rudiger Koch email : rkoch@amygdala.org ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include "amygdala/netloader.h"#include "amygdala/synapse.h"#include "amygdala/synapseproperties.h"#include "amygdala/neuron.h"#include "amygdala/inputneuron.h"#include "amygdala/basicneuron.h"#include "amygdala/utilities.h"#include "amygdala/axon.h"#include "amygdala/axonnode.h"#include "amygdala/physicalproperties.h"#include "amygdala/spikeinput.h"#include "amygdala/spikeoutput.h"#include "amygdala/outputmanager.h"#include "amygdala/nconnector.h"#include <stdexcept>#include <iostream>#include <libxml/parser.h>#include <libxml/parserInternals.h>using namespace std;using namespace Amygdala;extern "C" { void __SAXStartElement1(NetLoader *netLoader, const char *name, const char **attrs){ netLoader->SAXStartElement1(name, attrs); } void __SAXEndElement1(NetLoader *netLoader, const char *name){ netLoader->SAXEndElement1(name); } void __SAXStartElement2(NetLoader *netLoader, const char *name, const char **attrs){ netLoader->SAXStartElement2(name, attrs); } void __SAXEndElement2(NetLoader *netLoader, const char *name){ netLoader->SAXEndElement2(name); } void __SAXError(NetLoader *netLoader, const char *msg, ...){ cerr << msg << endl; netLoader->SAXError(); }} // extern "C"NetLoader::NetLoader(){}NetLoader::~NetLoader(){}void NetLoader::SAXError(){ saxErrors++;}void NetLoader::SAXStartElement1(string name, const char **attrs){ if(name == "synapse"){ return; } else if(name == "property"){ if(attrs == NULL) return; ParseProperties(attrs); return; } else if(name == "neuron"){ if(attrs == NULL) return; ParseNeuron(attrs); return; } else if(name == "topology"){ if(attrs == NULL) return; ParseTopology(attrs); return; } else if(name == "network"){ return; }}void NetLoader::SAXEndElement1(string name){ if(name == "synapse"){ sProps = NULL; } else if(name == "neuron"){ NFactory * nf = dynamic_cast<NFactory*> (FactoryBase::GetRegistry().GetFactory(currNType)); if (nf == NULL) throw runtime_error("No neuron type " + currNType + " registered!"); nf->MakeNeuron(currNId, nProps, currTop); currNId = 0; nProps = NULL; } else if(name == "topology"){ currTop = NULL; }}void NetLoader::SAXEndElement2(string name){ if(name == "neuron") { currNId = 0; currNType.clear(); nProps = NULL; }else if(name == "synapse"){ SpikingNeuron * post = dynamic_cast <SpikingNeuron * > (Network::GetNetworkRef()->GetNeuron(postNId)); connector->Connect(currNeuron, post, *sProps); sProps = NULL; } else if(name == "outputgroup"){ outputGroup = 0; } else if(name == "spikeinput"){ spikeInput = NULL; } else if(name == "spikeoutput"){ spikeOutput = NULL; }}void NetLoader::SAXStartElement2(string name, const char **attrs){ if(name == "synapse"){ if(attrs == NULL) return; ParseSynapse(attrs); return; } else if(name == "property"){ if(attrs == NULL) return; ParseProperties(attrs); return; } else if(name == "neuron"){ if(attrs == NULL) return; ParseNeuron(attrs); return; } else if(name == "topology"){ if(attrs == NULL) return; ParseTopology(attrs); return; } else if(name == "outputgroup"){ if(attrs == NULL) return; ParseOutputGroup(attrs); return; } else if(name == "spikeoutput"){ if(attrs == NULL) return; ParseSpikeOutput(attrs); return; } else if(name == "spikeinput"){ if(attrs == NULL) return; ParseSpikeInput(attrs); return; }}void NetLoader::ParseSpikeInput(const char **attrs){ string siName; string siType; for (unsigned int i = 0; attrs[i] != NULL; i++) { string name(attrs[i]); string value(attrs[++i]); if ( name == "type" ) { siType = value; } else if ( name == "name" ) { siName = value; } } SIFactory * sif = dynamic_cast<SIFactory*> (FactoryBase::GetRegistry().GetFactory(siType)); if (sif == NULL) throw runtime_error("No SpikeInput type " + siType + " registered!"); spikeInput = sif->MakeSpikeInput(siName);}void NetLoader::ParseSpikeOutput(const char **attrs){ string soName; string soType; for (unsigned int i = 0; attrs[i] != NULL; i++) { string name(attrs[i]); string value(attrs[++i]); if ( name == "type" ) { soType = value; } else if ( name == "name" ) { soName = value; } } SOFactory * sof = dynamic_cast<SOFactory*> (FactoryBase::GetRegistry().GetFactory(soType)); if (sof == NULL) throw runtime_error("No SpikeOutput type " + soType + " registered!"); spikeOutput = sof->MakeSpikeOutput(soName);}void NetLoader::ParseOutputGroup(const char **attrs){ unsigned int enabled=0; for (unsigned int i = 0; attrs[i] != NULL; i++) { string name(attrs[i]); string value(attrs[++i]); if ( name == "id" ) { outputGroup = atoi(value.c_str()); } else if ( name == "enabled" ) { enabled = atoi(value.c_str()); } } OutputManager::EnableOutput(enabled, outputGroup);}void NetLoader::ParseSynapse(const char **attrs){ string sType; AmTimeInt delay=0; for (unsigned int i = 0; attrs[i] != NULL; i++) { string name(attrs[i]); string value(attrs[++i]); if ( name == "postneuron" ){ postNId = atoi(value.c_str()); } else if ( name == "type" ) { sType = value; } else if ( name == "delay" ) { delay = atoi(value.c_str()); } } ConnectorRegistry & cr = ConnectorRegistry::GetRegistry(); connector = cr.GetConnector(sType); sProps = connector->GetDefaultProperties(); sProps->SetDelay(delay);}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -