PropagatedSpikeBuffer.h

Go to the documentation of this file.
00001 #ifndef PROPAGATEDSPIKEBUFFER_H_
00002 #define PROPAGATEDSPIKEBUFFER_H_
00003 
00004 #include "globaldefinitions.h"
00005 #include "SimParameter.h"
00006 
00007 #include <iostream>
00008 using std::cout;
00009 using std::endl;
00010 
00011 #include <list>
00012 using std::list;
00013 
00014 #include <vector>
00015 using std::vector;
00016 
00017 #include <assert.h>
00018 
00020 class PropagatedSpikeBuffer
00021 {
00022 
00023 public:
00024 
00026 
00032     PropagatedSpikeBuffer(int minDelay,
00033                           int maxDelay,
00034                           int chunkSize = PROPAGATED_SPIKE_BUFFER_CHUNK_SIZE );
00035 
00037     virtual ~PropagatedSpikeBuffer();
00038 
00040 
00044     void scheduleSpikeTargetGroup(spikegroupid_t stg, delaystep_t delay, float offsetFraction );
00045 
00047     struct StgNode
00048     {
00049         spikegroupid_t stg;
00050         float offsetFraction;
00051         StgNode *next;
00052     };
00053 
00055     class const_iterator
00056     {
00057     public:
00058         const_iterator(): node(NULL) {};
00059         const_iterator(StgNode *n): node(n) {};
00060 
00061         StgNode* operator->() { return node; }
00062         spikegroupid_t operator*() { return node->stg; }
00063 
00064         bool operator==(const const_iterator& other) { return ( this->node == other.node ); }
00065 
00066         bool operator!=(const const_iterator& other) { return ( this->node != other.node ); }
00067 
00068         inline const_iterator& operator++() { node = node->next; return *this; }
00069 
00070     private:
00071         StgNode *node;
00072     };
00073 
00075 
00078     const_iterator beginSpikeTargetGroups(int stepOffset = 0)
00079     {
00080 #ifdef DEBUG
00081         // this assertion fails if stepOffset < -length()
00082         if (const_iterator( ringBufferFront[ (currIdx + stepOffset + length() ) % length()  ] ) != NULL)
00083             //        cout << "in beginSTG currT=" << currT << " stepOffset=" << stepOffset << endl;
00084             assert( (currIdx + stepOffset + length() ) % length() >= 0 );
00085 #endif
00086         return const_iterator( ringBufferFront[ (currIdx + stepOffset + length() ) % length()  ] );
00087     };
00088 
00090     const_iterator endSpikeTargetGroups(int stepOffset = 0)
00091     {
00092         return const_iterator(NULL);
00093     };
00094 
00096     void nextTimeStep();
00097 
00099 
00102     void reset(int minDelay, int maxDelay);
00103 
00105     inline size_t length() { return ringBufferFront.size(); };
00106 
00107     // PropagatedSpikeBuffer & operator=(const PropagatedSpikeBuffer &src);
00108 
00109 private :
00110 
00112     void init(size_t maxDelaySteps);
00113 
00115     StgNode *getFreeNode(void);
00116 
00118     int currIdx ;
00119 
00121     vector< StgNode* > ringBufferFront;
00122 
00124     vector< StgNode* > ringBufferBack;
00125 
00127     vector< StgNode* > chunkBuffer;
00128 
00130     StgNode *currentFreeChunk;
00131 
00133     int  nextFreeSrgNodeIdx;
00134 
00136     size_t nextFreeChunkIdx;
00137 
00139     StgNode* recycledNodes;
00140 
00142     int chunkSize;
00143 
00144     int currT;
00145 
00146     double fillitup[32];
00147 };
00148 
00149 #endif /*PROPAGATEDSPIKEBUFFER_H_*/

Generated on Wed Jul 9 16:34:38 2008 for PCSIM by  doxygen 1.5.5