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[] = {"transition", ste_transition, "state", ste_state, 0, 0};
50 
51 static void* ste_cons(Object*) {
52  int nstate = (int) chkarg(1, 1, 1e6);
53  Point_process* pnt = NULL;
54  if (ifarg(2)) {
55  Object* obj = *hoc_objgetarg(2);
56  pnt = ob2pntproc(obj);
57  }
59  return ste;
60 }
61 
62 static void ste_destruct(void* v) {
64  delete ste;
65 }
66 
68  class2oc("StateTransitionEvent", ste_cons, ste_destruct, members, NULL, NULL, NULL);
69 }
70 
72  nstate_ = nstate;
73  states_ = new STEState[nstate_];
74  istate_ = 0;
75  pnt_ = pnt;
76  activated_ = -1;
77 }
78 
80  deactivate();
81  delete[] states_;
82 }
83 
85  if (activated_ < 0) {
86  return;
87  }
89  for (int i = 0; i < s.ntrans_; ++i) {
91  }
92  activated_ = -1;
93 }
94 
96  if (activated_ >= 0) {
97  deactivate();
98  }
99  STEState& s = states_[istate_];
100  for (int i = 0; i < s.ntrans_; ++i) {
101  s.transitions_[i].activate();
102  }
104 }
105 
107  assert(ist >= 0 && ist < nstate_);
108  deactivate();
109  istate_ = ist;
110  activate();
111 }
112 
114  ntrans_ = 0;
115  transitions_ = NULL;
116 }
117 
119  if (transitions_) {
120  delete[] transitions_;
121  }
122 }
123 
125  ++ntrans_;
128  if (st) {
129  int i;
130  for (i = 0; i < ntrans_ - 1; ++i) {
131  transitions_[i].hc_ = st[i].hc_;
132  st[i].hc_ = NULL;
133  transitions_[i].ste_ = st[i].ste_;
134  st[i].ste_ = NULL;
135  transitions_[i].stec_ = st[i].stec_;
136  st[i].stec_ = NULL;
138  transitions_[i].var1_ = st[i].var1_;
139  transitions_[i].var2_ = st[i].var2_;
140  transitions_[i].dest_ = st[i].dest_;
142  }
143  delete[] st;
144  }
145  return transitions_ + ntrans_ - 1;
146 }
147 
149  hc_ = NULL;
150  ste_ = NULL;
151  stec_ = NULL;
152  var1_is_time_ = false;
153 }
154 
156  if (hc_) {
157  delete hc_;
158  }
159  if (stec_) {
160  delete stec_;
161  }
162 }
163 
165  ste_->deactivate();
166  ste_->istate_ = dest_;
167  if (hc_) {
168  nrn_hoc_lock();
169  hc_->execute();
170  nrn_hoc_unlock();
171  }
172  ste_->activate();
173 }
int execute(bool notify=true)
Definition: objcmd.cpp:102
STETransition * stet_
Definition: netcon.h:252
virtual ~STEState()
Definition: nrnste.cpp:118
STETransition * add_transition()
Definition: nrnste.cpp:124
STEState()
Definition: nrnste.cpp:113
int ntrans_
Definition: nrnste.h:38
STETransition * transitions_
Definition: nrnste.h:39
virtual ~STETransition()
Definition: nrnste.cpp:155
STECondition * stec_
Definition: nrnste.h:28
StateTransitionEvent * ste_
Definition: nrnste.h:27
void deactivate()
Definition: netcvode.cpp:5569
void event()
Definition: nrnste.cpp:164
HocCommand * hc_
Definition: nrnste.h:26
void activate()
Definition: netcvode.cpp:5558
bool var1_is_time_
Definition: nrnste.h:30
double * var2_
Definition: nrnste.h:25
int dest_
Definition: nrnste.h:29
double * var1_
Definition: nrnste.h:24
Point_process * pnt_
Definition: nrnste.h:60
STEState * states_
Definition: nrnste.h:59
virtual ~StateTransitionEvent()
Definition: nrnste.cpp:79
void transition(int src, int dest, double *var1, double *var2, HocCommand *)
Definition: netcvode.cpp:5540
void state(int i)
Definition: nrnste.cpp:106
StateTransitionEvent(int nstate, Point_process *)
Definition: nrnste.cpp:71
Point_process * ob2pntproc(Object *)
Definition: hocmech.cpp:88
double chkarg(int, double low, double high)
Definition: code2.cpp:638
void nrn_hoc_unlock()
Definition: multicore.cpp:1127
int hoc_is_str_arg(int narg)
Definition: code.cpp:752
void nrn_hoc_lock()
Definition: multicore.cpp:1119
double * hoc_pgetarg(int narg)
Definition: code.cpp:1623
#define assert(ex)
Definition: hocassrt.h:32
#define gargstr
Definition: hocdec.h:14
Object ** hoc_objgetarg(int)
Definition: code.cpp:1587
int ifarg(int)
Definition: code.cpp:1581
#define v
Definition: md1redef.h:4
#define i
Definition: md1redef.h:12
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:1560
static void ste_destruct(void *v)
Definition: nrnste.cpp:62
static Member_func members[]
Definition: nrnste.cpp:49
static double ste_state(void *v)
Definition: nrnste.cpp:39
void StateTransitionEvent_reg()
Definition: nrnste.cpp:67
int hoc_return_type_code
Definition: code.cpp:42
static void * ste_cons(Object *)
Definition: nrnste.cpp:51
static double ste_transition(void *v)
Definition: nrnste.cpp:14
static int nstate
Definition: simultan.cpp:221
#define NULL
Definition: sptree.h:16
Definition: hocdec.h:227