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 <code.h>
9 #include <objcmd.h>
10 #include <nrnste.h>
11 #include <netcon.h>
12 
13 static double ste_transition(void* v) {
14  auto* const ste = static_cast<StateTransitionEvent*>(v);
15  int src = (int) chkarg(1, 0, ste->nstate() - 1);
16  int dest = (int) chkarg(2, 0, ste->nstate() - 1);
17  auto var1 = hoc_hgetarg<double>(3);
18  auto var2 = hoc_hgetarg<double>(4);
19  std::unique_ptr<HocCommand> hc{};
20  if (ifarg(5)) {
21  Object* obj = NULL;
22  if (hoc_is_str_arg(5)) {
23  char* stmt = NULL;
24  stmt = gargstr(5);
25  if (ifarg(6)) {
26  obj = *hoc_objgetarg(6);
27  }
28  hc = std::make_unique<HocCommand>(stmt, obj);
29  } else {
30  obj = *hoc_objgetarg(5);
31  hc = std::make_unique<HocCommand>(obj);
32  }
33  }
34  ste->transition(src, dest, std::move(var1), std::move(var2), std::move(hc));
35  return 1.;
36 }
37 
38 static double ste_state(void* v) {
41  int state = ste->state();
42  if (ifarg(1)) {
43  ste->state((int) chkarg(1, 0, ste->nstate() - 1));
44  }
45  return (double) state;
46 }
47 
48 static Member_func members[] = {{"transition", ste_transition},
49  {"state", ste_state},
50  {nullptr, nullptr}};
51 
52 static void* ste_cons(Object*) {
53  int nstate = (int) chkarg(1, 1, 1e6);
54  Point_process* pnt = NULL;
55  if (ifarg(2)) {
56  Object* obj = *hoc_objgetarg(2);
57  pnt = ob2pntproc(obj);
58  }
60  return ste;
61 }
62 
63 static void ste_destruct(void* v) {
65  delete ste;
66 }
67 
69  class2oc("StateTransitionEvent", ste_cons, ste_destruct, members, nullptr, nullptr);
70 }
71 
73  : pnt_{pnt} {
74  states_.resize(nstate);
75 }
76 
78  deactivate();
79 }
80 
82  if (activated_ < 0) {
83  return;
84  }
86  for (auto& st: s.transitions_) {
87  st.deactivate();
88  }
89  activated_ = -1;
90 }
91 
93  if (activated_ >= 0) {
94  deactivate();
95  }
97  for (auto& st: s.transitions_) {
98  st.activate();
99  }
101 }
102 
104  assert(ist >= 0 && ist < states_.size());
105  deactivate();
106  istate_ = ist;
107  activate();
108 }
109 
111  : stec_{std::make_unique<STECondition>(pnt, nullptr)} {}
112 
114  transitions_.emplace_back(pnt);
115  // update in case of reallocation of transitions_
116  for (auto& st: transitions_) {
117  st.stec_->stet_ = &st;
118  }
119  return transitions_.back();
120 }
121 
123  ste_->deactivate();
124  ste_->istate_ = dest_;
125  if (hc_) {
126  nrn_hoc_lock();
127  hc_->execute();
128  nrn_hoc_unlock();
129  }
130  ste_->activate();
131 }
void class2oc(const char *, ctor_f *cons, dtor_f *destruct, Member_func *, Member_ret_obj_func *, Member_ret_str_func *)
Definition: hoc_oop.cpp:1631
char * gargstr(int narg)
Definition: code2.cpp:227
HocReturnType hoc_return_type_code
Definition: code.cpp:42
#define v
Definition: md1redef.h:11
double chkarg(int, double low, double high)
Definition: code2.cpp:626
void nrn_hoc_unlock()
Definition: multicore.cpp:827
int hoc_is_str_arg(int narg)
Definition: code.cpp:872
void nrn_hoc_lock()
Definition: multicore.cpp:819
#define assert(ex)
Definition: hocassrt.h:24
Point_process * ob2pntproc(Object *ob)
Definition: hocmech.cpp:99
Object ** hoc_objgetarg(int)
Definition: code.cpp:1614
void move(Item *q1, Item *q2, Item *q3)
Definition: list.cpp:200
s
Definition: multisend.cpp:521
int ifarg(int)
Definition: code.cpp:1607
static void ste_destruct(void *v)
Definition: nrnste.cpp:63
static Member_func members[]
Definition: nrnste.cpp:48
static double ste_state(void *v)
Definition: nrnste.cpp:38
void StateTransitionEvent_reg()
Definition: nrnste.cpp:68
static void * ste_cons(Object *)
Definition: nrnste.cpp:52
static double ste_transition(void *v)
Definition: nrnste.cpp:13
static int nstate
Definition: simultan.cpp:226
#define NULL
Definition: spdefs.h:105
Definition: hocdec.h:173
A point process is computed just like regular mechanisms.
Definition: section_fwd.hpp:77
STETransition & add_transition(Point_process *pnt)
Definition: nrnste.cpp:113
std::vector< STETransition > transitions_
Definition: nrnste.h:35
StateTransitionEvent * ste_
Definition: nrnste.h:27
std::unique_ptr< HocCommand > hc_
Definition: nrnste.h:26
void event()
Definition: nrnste.cpp:122
int dest_
Definition: nrnste.h:29
STETransition(Point_process *pnt)
Definition: nrnste.cpp:110
std::vector< STEState > states_
Definition: nrnste.h:57
void state(int i)
Definition: nrnste.cpp:103
StateTransitionEvent(int nstate, Point_process *)
Definition: nrnste.cpp:72