00001
00027 #ifndef __dlogger_h
00028 #define __dlogger_h
00029
00030 #include "dneuron.h"
00031 #include <mak/infinity.h>
00032
00033 namespace punnets_common {
00034
00037
00051 class tlogger : public taction
00052 {
00053 mutable tqueue que;
00054 ntime_t step, from, until, delaymin, delaymax;
00055 public:
00058 enum logoption
00059 {
00060 shownone = 0,
00061 showthr = 1,
00062 showext = 2,
00063 showpart = 4
00064 };
00065 private:
00067 struct neuentry
00068 {
00069 ntime_t delay;
00070 real lastthr;
00071 tneuron_base *neuron;
00072 logoption logopt;
00073 real offset;
00074
00075 neuentry(tneuron_base *in, ntime_t idelay, bool ishowthr, bool ishowext=true, real ioffset=0.0) :
00076 delay(idelay), lastthr(1), neuron(in), logopt((logoption)((ishowthr ? showthr : 0) | (ishowext ? showext : 0))), offset(ioffset) { }
00077 neuentry(tneuron_base *in, ntime_t idelay, logoption ilogopt = showthr, real ioffset=0.0) :
00078 delay(idelay), lastthr(1), neuron(in), logopt(ilogopt), offset(ioffset) { }
00079 };
00080
00081 std::vector< neuentry > neus;
00082 std::vector< std::pair<tsynapse_base *, ntime_t> > syns;
00083 std::ostream &out;
00084
00085 public:
00087 tlogger(std::ostream &iout, ntime_t istep, ntime_t ifrom = 0, ntime_t iuntil = mak::Infinity) : step(istep), from(ifrom), until(iuntil), delaymin(0.0), delaymax(0.0), out(iout) { }
00088 virtual ~tlogger() { }
00089
00090 virtual const char *getClassName() const { return "tlogger"; }
00091 virtual tqueue *queue() const { return &que; }
00092
00094 void add(tneuron_base &p, ntime_t delay, bool ishowthr, bool ishowext=false, real offset = 0.0)
00095 { neus.push_back(neuentry(&p, delay, ishowthr, ishowext, offset)); if( delay < delaymin ) delaymin = delay; if( delay > delaymax ) delaymax = delay; }
00097 void add(tneuron_base &p, ntime_t delay = 0.0, logoption logopt = showthr, real offset = 0.0)
00098 { neus.push_back(neuentry(&p, delay, logopt, offset)); if( delay < delaymin ) delaymin = delay; if( delay > delaymax ) delaymax = delay; }
00100 void add(tsynapse_base &p, ntime_t delay = 0.0) { syns.push_back(std::make_pair(&p, delay)); if( delay < delaymin ) delaymin = delay; if( delay > delaymax ) delaymax = delay; }
00101
00103 virtual void activate(tscheduler &scheduler, ntime_t current_time);
00104
00106 void schedule(tscheduler &scheduler) {
00107 scheduler.scheduleEvent( from + delaymin, *this );
00108 }
00109
00112 void gnuplot_def(std::ostream &os, std::string file);
00113 };
00114
00116
00117 }
00118
00119 #endif