SpikeStream Library  0.2
Connection.cpp
Go to the documentation of this file.
00001 #include "Connection.h"
00002 #include "Util.h"
00003 using namespace spikestream;
00004 
00005 //Other includes
00006 #include <iostream>
00007 using namespace std;
00008 
00009 //Outputs memory information
00010 //#define MEMORY_DEBUG
00011 
00012 
00014 Connection::Connection(){
00015         this->id = 0;
00016         this->fromNeuronID = 0;
00017         this->toNeuronID = 0;
00018         this->delay = 0;
00019         this->weight = 0;
00020         this->tempWeight = this->weight;
00021 
00022         #ifdef MEMORY_DEBUG
00023                 cout<<"New connection (empty constructor). Size of connection: "<<sizeof(*this)<<endl;
00024         #endif//MEMORY_DEBUG
00025 }
00026 
00027 
00029 Connection::Connection (unsigned int fromNeuronID, unsigned int toNeuronID, float delay, float weight){
00030         if(delay > DELAY_MAX)
00031                 throw SpikeStreamException("Delay out of range: " + QString::number(delay) + "; maximum possible delay value: " + QString::number(DELAY_MAX));
00032         if(weight > WEIGHT_MAX)
00033                 throw SpikeStreamException("Weight out of range: " + QString::number(weight) + "; maximum possible weight value: " + QString::number(WEIGHT_MAX));
00034         if(weight < WEIGHT_MIN)
00035                 throw SpikeStreamException("Weight out of range: " + QString::number(weight) + "; minimum possible weight value: " + QString::number(WEIGHT_MIN));
00036 
00037         this->id = 0;
00038         this->fromNeuronID = fromNeuronID;
00039         this->toNeuronID = toNeuronID;
00040         this->delay = (unsigned short) rint(delay* DELAY_FACTOR);
00041         this->weight = (short) rint(weight * WEIGHT_FACTOR);
00042         this->tempWeight = this->weight;
00043 
00044         #ifdef MEMORY_DEBUG
00045                 cout<<"New connection (standard constructor no ID). Size of connection: "<<sizeof(*this)<<endl;
00046         #endif//MEMORY_DEBUG
00047 }
00048 
00049 
00051 Connection::Connection (unsigned id, unsigned fromNeuronID, unsigned toNeuronID, float delay, float weight){
00052         if(delay > DELAY_MAX)
00053                 throw SpikeStreamException("Delay out of range: " + QString::number(delay) + "; maximum possible delay value: " + QString::number(DELAY_MAX));
00054         if(weight > WEIGHT_MAX)
00055                 throw SpikeStreamException("Weight out of range: " + QString::number(weight) + "; maximum possible weight value: " + QString::number(WEIGHT_MAX));
00056         if(weight < WEIGHT_MIN)
00057                 throw SpikeStreamException("Weight out of range: " + QString::number(weight) + "; minimum possible weight value: " + QString::number(WEIGHT_MIN));
00058 
00059         this->id = id;
00060         this->fromNeuronID = fromNeuronID;
00061         this->toNeuronID = toNeuronID;
00062         this->delay = (unsigned short) rint(delay* DELAY_FACTOR);
00063         this->weight = (short) rint(weight * WEIGHT_FACTOR);
00064         this->tempWeight = this->weight;
00065 
00066 #ifdef MEMORY_DEBUG
00067         cout<<"New connection (standard constructor with ID). Size of connection: "<<sizeof(*this)<<endl;
00068 #endif//MEMORY_DEBUG
00069 }
00070 
00071 
00073 Connection::Connection(const Connection& conn){
00074         this->id = conn.id;
00075     this->fromNeuronID = conn.fromNeuronID;
00076     this->toNeuronID = conn.toNeuronID;
00077     this->delay = conn.delay;
00078     this->weight = conn.weight;
00079     this->tempWeight = conn.tempWeight;
00080 
00081         #ifdef MEMORY_DEBUG
00082                 cout<<"New connection (copy constructor). Size of connection: "<<sizeof(*this)<<endl;
00083         #endif//MEMORY_DEBUG
00084 }
00085 
00086 
00087 /*--------------------------------------------------------*/
00088 /*-------             PUBLIC METHODS               -------*/
00089 /*--------------------------------------------------------*/
00090 
00092 Connection& Connection::operator=(const Connection& rhs){
00093     //Check for self assignment
00094     if(this == &rhs)
00095         return *this;
00096 
00097         this->id = rhs.id;
00098     this->fromNeuronID = rhs.fromNeuronID;
00099     this->toNeuronID = rhs.toNeuronID;
00100     this->delay = rhs.delay;
00101     this->weight = rhs.weight;
00102     this->tempWeight = rhs.tempWeight;
00103 
00104     return *this;
00105 }
00106 
00107 
00109 void Connection::print(){
00110    cout<<"Connection: ID="<<id<<"; fromNeuronID="<<fromNeuronID;
00111    cout<<" toNeuronID="<<toNeuronID<<"; delay="<<delay<<"; weight="<<weight<<"; tempWeight="<<tempWeight<<endl;
00112 }
00113 
 All Classes Files Functions Variables Typedefs Defines