00001 #ifndef COMPOSITESPIKINGNEURON_H_ 00002 #define COMPOSITESPIKINGNEURON_H_ 00003 00004 #include "PCSIMException.h" 00005 #include "SingleThreadSimEngine.h" 00006 #include "SimNetwork.h" 00007 #include "LifNeuron.h" 00008 #include "aEIFNeuron.h" 00009 00010 template<typename BaseNeuron> 00011 class CompositeNeuron : public BaseNeuron 00012 { 00013 00014 public: 00015 CompositeNeuron(const SimObjectFactory &response) 00016 { 00017 syn_responses.push_back(response.create()); 00018 } 00019 00020 CompositeNeuron(const SimObjectFactory &response, 00021 const SimObjectFactory &response2) { 00022 syn_responses.push_back(response.create()); 00023 syn_responses.push_back(response2.create()); 00024 } 00025 00026 00027 virtual void deepCopy(const SimObject *obj) { 00028 const CompositeNeuron<BaseNeuron> * comp_nrn = 00029 dynamic_cast<const CompositeNeuron<BaseNeuron> *>(obj); 00030 syn_responses.clear(); 00031 if (comp_nrn) { 00032 for (unsigned i = 0; i < (unsigned)comp_nrn->getNumberOfSynapses(); ++i) { 00033 syn_responses.push_back(comp_nrn->getInnerSynapse(i)->create()); 00034 } 00035 } 00036 else { 00037 throw( PCSIM::Exception( "CompositeNeuron<BaseNeuron>::deepCopy", "Trying to deepCopy a CompositeNeuron<BaseNeuron> SimObject from a SimObject of another type" ) ); 00038 } 00039 } 00040 00041 virtual ~CompositeNeuron() { 00042 for (unsigned i = 0; i != (unsigned)syn_responses.size(); ++i) { 00043 delete syn_responses[i]; 00044 } 00045 00046 } 00047 00048 virtual int init(InitializeInfo *ii) { 00049 for (unsigned i = 0; i < (unsigned)syn_responses.size(); ++i) { 00050 syn_responses[i]->outgoing(this); 00051 this->incoming(syn_responses[i]); 00052 } 00053 return 0; 00054 } 00055 00056 virtual int reset(double dt) 00057 { 00058 for (unsigned i = 0; i < (unsigned)syn_responses.size(); ++i) { 00059 syn_responses[i]->reset(dt); 00060 } 00061 return BaseNeuron::reset(dt); 00062 } 00063 00064 virtual int advance(AdvanceInfo const &ai) { 00065 for (unsigned i = 0 ; i < (unsigned)syn_responses.size(); ++i) { 00066 syn_responses[i]->advance(ai); 00067 } 00068 return BaseNeuron::advance(ai); 00069 } 00070 00071 SimObject *getInnerSynapse(unsigned i) const 00072 { 00073 return syn_responses[i]; 00074 } 00075 00076 unsigned getNumberOfSynapses() const 00077 { 00078 return syn_responses.size(); 00079 } 00080 00081 virtual void insert(const SimObjectFactory & model) { 00082 syn_responses.push_back(model.create()); 00083 }; 00084 00085 virtual void insert(const SimObjectFactory & model, int n) { 00086 for (int i = 0; i < n; ++i) 00087 syn_responses.push_back(model.create()); 00088 }; 00089 00090 virtual SimObject * getInputTarget(int target_id = 0) 00091 { 00092 if (target_id == 0) 00093 return this; 00094 else if (target_id <= (int)syn_responses.size()) 00095 return syn_responses[target_id - 1]; 00096 else 00097 return syn_responses[0]; 00098 } 00099 00100 virtual int nSpikeInputPorts() const {return 0;} 00101 00102 virtual int nSpikeOutputPorts() const {return 1;} 00103 00104 virtual int nAnalogInputPorts() const {return 0;} 00105 00106 virtual int nAnalogOutputPorts() const {return 0;} 00107 00108 virtual SimObject::PortType outputPortType(port_t p) const { 00109 if (p == 0) 00110 return SimObject::spiking; 00111 return SimObject::undefined; 00112 } 00113 00114 protected: 00115 vector<SimObject *> syn_responses; 00116 }; 00117 00118 #endif /*COMPOSITENEURON_H_*/