NEURON
nrnste.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include <stdio.h>
3 #include <InterViews/resource.h>
4 #include <string.h>
5 #include <nrnoc2iv.h>
6 #include <nrniv_mf.h>
7 #include <classreg.h>
8 #include <objcmd.h>
9 #include <nrnste.h>
10 #include <netcon.h>
11 
12 extern int hoc_return_type_code;
13 
14 static double ste_transition(void* v) {
16  int src = (int)chkarg(1, 0, ste->nstate()-1);
17  int dest = (int)chkarg(2, 0, ste->nstate()-1);
18  double* var1 = hoc_pgetarg(3);
19  double* var2 = hoc_pgetarg(4);
20  HocCommand* hc = NULL;
21  if (ifarg(5)) {
22  Object* obj = NULL;
23  if (hoc_is_str_arg(5)) {
24  char* stmt = NULL;
25  stmt = gargstr(5);
26  if (ifarg(6)) {
27  obj = *hoc_objgetarg(6);
28  }
29  hc = new HocCommand(stmt, obj);
30  }else{
31  obj = *hoc_objgetarg(5);
32  hc = new HocCommand(obj);
33  }
34  }
35  ste->transition(src, dest, var1, var2, hc);
36  return 1.;
37 }
38 
39 static double ste_state(void* v) {
41  hoc_return_type_code = 1; // integer
42  int state = ste->state();
43  if (ifarg(1)) {
44  ste->state((int)chkarg(1, 0, ste->nstate()-1));
45  }
46  return (double)state;
47 }
48 
49 static Member_func members[] = {
50  "transition", ste_transition,
51  "state", ste_state,
52  0, 0
53 };
54 
55 static void* ste_cons(Object*) {
56  int nstate = (int)chkarg(1, 1, 1e6);
57  Point_process* pnt = NULL;
58  if (ifarg(2)) {
59  Object* obj = *hoc_objgetarg(2);
60  pnt = ob2pntproc(obj);
61  }
62  StateTransitionEvent* ste = new StateTransitionEvent(nstate, pnt);
63  return ste;
64 }
65 
66 static void ste_destruct(void* v) {
68  delete ste;
69 }
70 
72  class2oc("StateTransitionEvent", ste_cons, ste_destruct,
73  members, NULL, NULL, NULL);
74 }
75 
77  nstate_ = nstate;
78  states_ = new STEState[nstate_];
79  istate_ = 0;
80  pnt_ = pnt;
81  activated_ = -1;
82 }
83 
85  deactivate();
86  delete [] states_;
87 }
88 
90  if (activated_ < 0) { return; }
92  for (int i=0; i < s.ntrans_; ++i) {
94  }
95  activated_ = -1;
96 }
97 
99  if (activated_ >= 0) { deactivate(); }
101  for (int i=0; i < s.ntrans_; ++i) {
102  s.transitions_[i].activate();
103  }
105 }
106 
108  assert(ist >= 0 && ist < nstate_);
109  deactivate();
110  istate_ = ist;
111  activate();
112 }
113 
115  ntrans_ = 0;
116  transitions_ = NULL;
117 }
118 
120  if (transitions_) {
121  delete [] transitions_;
122  }
123 }
124 
126  ++ntrans_;
127  STETransition* st = transitions_;
128  transitions_ = new STETransition[ntrans_];
129  if (st) {
130  int i;
131  for (i=0; i < ntrans_-1; ++i) {
132  transitions_[i].hc_ = st[i].hc_; st[i].hc_ = NULL;
133  transitions_[i].ste_ = st[i].ste_; st[i].ste_ = NULL;
134  transitions_[i].stec_ = st[i].stec_; st[i].stec_ = NULL;
135  transitions_[i].stec_->stet_ = transitions_ + i;
136  transitions_[i].var1_ = st[i].var1_;
137  transitions_[i].var2_ = st[i].var2_;
138  transitions_[i].dest_ = st[i].dest_;
139  transitions_[i].var1_is_time_ = st[i].var1_is_time_;
140  }
141  delete [] st;
142  }
143  return transitions_ + ntrans_ - 1;
144 }
145 
147  hc_ = NULL;
148  ste_ = NULL;
149  stec_ = NULL;
150  var1_is_time_ = false;
151 }
152 
154  if (hc_) {
155  delete hc_;
156  }
157  if (stec_) {
158  delete stec_;
159  }
160 }
161 
163  ste_->deactivate();
164  ste_->istate_ = dest_;
165  if (hc_) {
166  nrn_hoc_lock();
167  hc_->execute();
168  nrn_hoc_unlock();
169  }
170  ste_->activate();
171 }
#define assert(ex)
Definition: hocassrt.h:26
int hoc_is_str_arg(int narg)
Definition: code.cpp:741
bool var1_is_time_
Definition: nrnste.h:28
int hoc_return_type_code
Definition: code.cpp:41
STETransition * transitions_
Definition: nrnste.h:37
void activate()
Definition: netcvode.cpp:5390
void state(int i)
Definition: nrnste.cpp:107
static void ste_destruct(void *v)
Definition: nrnste.cpp:66
StateTransitionEvent * ste_
Definition: nrnste.h:25
static double ste_state(void *v)
Definition: nrnste.cpp:39
#define v
Definition: md1redef.h:4
STECondition * stec_
Definition: nrnste.h:26
void nrn_hoc_lock()
Definition: multicore.cpp:1064
virtual ~StateTransitionEvent()
Definition: nrnste.cpp:84
#define gargstr
Definition: hocdec.h:14
Point_process * pnt_
Definition: nrnste.h:54
virtual ~STEState()
Definition: nrnste.cpp:119
double * hoc_pgetarg(int narg)
Definition: code.cpp:1604
static void * ste_cons(Object *)
Definition: nrnste.cpp:55
double * var1_
Definition: nrnste.h:22
_CONST char * s
Definition: system.cpp:74
static double ste_transition(void *v)
Definition: nrnste.cpp:14
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
Definition: hoc_oop.cpp:1581
static Member_func members[]
Definition: nrnste.cpp:49
int ntrans_
Definition: nrnste.h:36
int
Definition: nrnmusic.cpp:71
STEState()
Definition: nrnste.cpp:114
static int nstate
Definition: simultan.cpp:192
virtual ~STETransition()
Definition: nrnste.cpp:153
void transition(int src, int dest, double *var1, double *var2, HocCommand *)
Definition: netcvode.cpp:5373
int dest_
Definition: nrnste.h:27
int ifarg(int)
Definition: code.cpp:1562
void nrn_hoc_unlock()
Definition: multicore.cpp:1072
void StateTransitionEvent_reg()
Definition: nrnste.cpp:71
Definition: hocdec.h:226
StateTransitionEvent(int nstate, Point_process *)
Definition: nrnste.cpp:76
void deactivate()
Definition: netcvode.cpp:5401
Point_process * ob2pntproc(Object *)
Definition: hocmech.cpp:88
#define i
Definition: md1redef.h:12
double * var2_
Definition: nrnste.h:23
STETransition * add_transition()
Definition: nrnste.cpp:125
Object ** hoc_objgetarg(int)
Definition: code.cpp:1568
return NULL
Definition: cabcode.cpp:461
void event()
Definition: nrnste.cpp:162
double chkarg(int, double low, double high)
Definition: code2.cpp:608
HocCommand * hc_
Definition: nrnste.h:24
STEState * states_
Definition: nrnste.h:53