NEURON
finithnd.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 /*
4 statements that are called during finitialize()
5 Type 1 is the default.
6 Type 0 are called after v is set but before INITIAL blocks are called.
7  This is also after clearing the event queue and playing the time 0 values.
8 Type 1 are after INITIAL blocks (and linmod and init_net_events) but
9  before variable step re_init or fcurrent();
10 Type 2 are just before return. ie after vector initial record and delivery
11  of events at t=0;
12 Type 3 are at the very beginning of finitialize. ie structure changes
13  are allowed.
14 */
15 
16 #include <vector>
17 #include <cstdio>
18 #include <nrnoc2iv.h>
19 #include <classreg.h>
20 #include <objcmd.h>
21 #include "utils/enumerate.h"
22 
24  public:
25  FInitialHandler(int, const char*, Object*, Object* pyact = NULL);
26  virtual ~FInitialHandler();
28  int type_;
29  static std::vector<FInitialHandler*> fihlist_[4];
30 };
31 
32 void nrn_fihexec(int type);
33 void nrn_fihexec(int type) {
34  for (auto& f: FInitialHandler::fihlist_[type]) {
35  f->stmt_->execute();
36  }
37 }
38 
39 static double allprint(void* v) {
40  for (int type = 0; type < 4; ++type) {
41  std::vector<FInitialHandler*> fl = FInitialHandler::fihlist_[type];
42  if (!fl.empty()) {
43  Printf("Type %d FInitializeHandler statements\n", type);
44  for (auto& f: fl) {
45  if (f->stmt_->pyobject()) {
46  Printf("\t%s\n", hoc_object_name(f->stmt_->pyobject()));
47  } else if (f->stmt_->object()) {
48  Printf("\t%s.%s\n", hoc_object_name(f->stmt_->object()), f->stmt_->name());
49  } else {
50  Printf("\t%s\n", f->stmt_->name());
51  }
52  }
53  }
54  }
55  return 0.;
56 }
57 
58 static Member_func members[] = {{"allprint", allprint}, {nullptr, nullptr}};
59 
60 static void* finithnd_cons(Object*) {
61  int type = 1; // default is after INITIAL blocks are called
62  int ia = 1;
63  if (hoc_is_double_arg(ia)) {
64  type = (int) chkarg(ia, 0, 3);
65  ++ia;
66  }
67  char* s = NULL;
68  Object* pyact = NULL;
69  if (hoc_is_object_arg(ia)) {
70  pyact = *hoc_objgetarg(ia);
71  if (!pyact) {
72  hoc_execerror("arg is None", 0);
73  }
74  } else {
75  s = gargstr(ia);
76  }
77  ++ia;
78  Object* obj = NULL;
79  if (ifarg(ia)) {
80  obj = *hoc_objgetarg(ia);
81  }
82  FInitialHandler* f = new FInitialHandler(type, s, obj, pyact);
83  return f;
84 }
85 
86 static void finithnd_destruct(void* v) {
88  delete f;
89 }
90 
92  class2oc("FInitializeHandler", finithnd_cons, finithnd_destruct, members, nullptr, nullptr);
93 }
94 
95 std::vector<FInitialHandler*> FInitialHandler::fihlist_[4];
96 
97 FInitialHandler::FInitialHandler(int i, const char* s, Object* obj, Object* pyact) {
98  type_ = i;
99  if (pyact) {
100  stmt_ = new HocCommand(pyact);
101  } else {
102  stmt_ = new HocCommand(s, obj);
103  }
104  fihlist_[i].push_back(this);
105 }
106 
108  delete stmt_;
109  erase_first(fihlist_[type_], this);
110 }
HocCommand * stmt_
Definition: finithnd.cpp:27
FInitialHandler(int, const char *, Object *, Object *pyact=NULL)
Definition: finithnd.cpp:97
virtual ~FInitialHandler()
Definition: finithnd.cpp:107
static std::vector< FInitialHandler * > fihlist_[4]
Definition: finithnd.cpp:29
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
#define v
Definition: md1redef.h:11
#define i
Definition: md1redef.h:19
void erase_first(T &&iterable, value_type &&value)
Definition: enumerate.h:22
double chkarg(int, double low, double high)
Definition: code2.cpp:626
static void finithnd_destruct(void *v)
Definition: finithnd.cpp:86
static Member_func members[]
Definition: finithnd.cpp:58
static void * finithnd_cons(Object *)
Definition: finithnd.cpp:60
static double allprint(void *v)
Definition: finithnd.cpp:39
void nrn_fihexec(int type)
Definition: finithnd.cpp:33
void FInitializeHandler_reg()
Definition: finithnd.cpp:91
int hoc_is_object_arg(int narg)
Definition: code.cpp:876
int hoc_is_double_arg(int narg)
Definition: code.cpp:864
char * hoc_object_name(Object *ob)
Definition: hoc_oop.cpp:73
Object ** hoc_objgetarg(int)
Definition: code.cpp:1614
void hoc_execerror(const char *s1, const char *s2)
Definition: nrnoc_aux.cpp:39
s
Definition: multisend.cpp:521
int ifarg(int)
Definition: code.cpp:1607
short type
Definition: cabvars.h:10
#define NULL
Definition: spdefs.h:105
Definition: hocdec.h:173
int Printf(const char *fmt, Args... args)
Definition: logger.hpp:18