AnimatLab  2
Test
PropagatedSpikeBuffer.h
1 #ifndef PROPAGATEDSPIKEBUFFER_H_
2 #define PROPAGATEDSPIKEBUFFER_H_
3 
5 // IMPORTED FROM PCSIM SOURCE CODE http://www.lsm.tugraz.at/pcsim/
7 
8 //#include "globaldefinitions.h"
9 //#include "SimParameter.h"
10 
11 #include <iostream>
12 using std::cout;
13 using std::endl;
14 
15 #include <list>
16 using std::list;
17 
18 #include <vector>
19 using std::vector;
20 
21 #include <assert.h>
22 
23 typedef int spikegroupid_t ;
24 
26 typedef unsigned short int delay_t;
27 
29 typedef unsigned short int delaystep_t;
30 
32 #define PROPAGATED_SPIKE_BUFFER_CHUNK_SIZE 1024
33 
36 {
37 
38 public:
39 
41 
47  PropagatedSpikeBuffer(int minDelay,
48  int maxDelay,
49  int chunkSize = PROPAGATED_SPIKE_BUFFER_CHUNK_SIZE );
50 
52  virtual ~PropagatedSpikeBuffer();
53 
55 
59  void scheduleSpikeTargetGroup(spikegroupid_t stg, delaystep_t delay);
60 
62  struct StgNode
63  {
64  spikegroupid_t stg;
65  delaystep_t delay;
66  StgNode *next;
67  };
68 
71  {
72  public:
73  const_iterator(): node(NULL) {};
74  const_iterator(StgNode *n): node(n) {};
75 
76  StgNode* operator->() { return node; }
77  spikegroupid_t operator*() { return node->stg; }
78 
79  bool operator==(const const_iterator& other) { return ( this->node == other.node ); }
80 
81  bool operator!=(const const_iterator& other) { return ( this->node != other.node ); }
82 
83  inline const_iterator& operator++() { node = node->next; return *this; }
84 
85  private:
86  StgNode *node;
87  };
88 
90 
94  {
95 #ifdef DEBUG
96  // this assertion fails if stepOffset < -length()
97  if (const_iterator( ringBufferFront[ (currIdx + stepOffset + length() ) % length() ] ) != NULL)
98  // cout << "in beginSTG currT=" << currT << " stepOffset=" << stepOffset << endl;
99  assert( (currIdx + stepOffset + length() ) % length() >= 0 );
100 #endif
101  return const_iterator( ringBufferFront[ (currIdx + stepOffset + length() ) % length() ] );
102  };
103 
106  {
107  return const_iterator(NULL);
108  };
109 
111  void nextTimeStep();
112 
114 
117  void reset(int minDelay, int maxDelay);
118 
120  inline size_t length() { return ringBufferFront.size(); };
121 
122  // PropagatedSpikeBuffer & operator=(const PropagatedSpikeBuffer &src);
123 
124 private :
125 
127  void init(size_t maxDelaySteps);
128 
130  StgNode *getFreeNode(void);
131 
133  int currIdx ;
134 
136  vector< StgNode* > ringBufferFront;
137 
139  vector< StgNode* > ringBufferBack;
140 
142  vector< StgNode* > chunkBuffer;
143 
145  StgNode *currentFreeChunk;
146 
148  int nextFreeSrgNodeIdx;
149 
151  size_t nextFreeChunkIdx;
152 
154  StgNode* recycledNodes;
155 
157  int chunkSize;
158 
159  int currT;
160 
161  double fillitup[32];
162 };
163 
164 #endif /*PROPAGATEDSPIKEBUFFER_H_*/
void nextTimeStep()
Must be called to tell the buffer that it should move on to the next time step.
void reset(int minDelay, int maxDelay)
Must be called at the begin (reset) of a simulation.
Schedule/Store spikes to be delivered at a later point in the simulation.
Iterator to loop over the scheduled spikes at a certain delay.
Structure which stores the index of the spike target group and a pointer to the next element in vario...
const_iterator beginSpikeTargetGroups(int stepOffset=0)
Returns an iterator to loop over all scheduled spike target groups.
void scheduleSpikeTargetGroup(spikegroupid_t stg, delaystep_t delay)
Schedule a group of spike targets to get a spike at time t + delay.
const_iterator endSpikeTargetGroups()
End iterator corresponding to beginSynapseGroups.
PropagatedSpikeBuffer(int minDelay, int maxDelay, int chunkSize=PROPAGATED_SPIKE_BUFFER_CHUNK_SIZE)
New spike buffer.
size_t length()
Return the actual length of the buffer.
virtual ~PropagatedSpikeBuffer()
Destructor: Deletes all scheduled spikes.