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 <stdio.h>
17 #include <OS/list.h>
18 #include <nrnoc2iv.h>
19 #include <classreg.h>
20 #include <objcmd.h>
21 
22 class FInitialHandler;
25 
27 public:
28  FInitialHandler(int, const char*, Object*, Object* pyact=NULL);
29  virtual ~FInitialHandler();
31  int type_;
32  static FIHList* fihlist_[4];
33 };
34 
35 void nrn_fihexec(int type);
36 void nrn_fihexec(int type) {
37  FIHList* fl = FInitialHandler::fihlist_[type];
38  if (fl) {
39  int i, cnt;
40  cnt = fl->count();
41  for (i=0; i < cnt; ++i) {
42  FInitialHandler* f = fl->item(i);
43  f->stmt_->execute();
44  }
45  }
46 }
47 
48 static double allprint(void* v) {
49  int type, i, cnt;
50  for (type=0; type < 4; ++type) {
51  FIHList* fl = FInitialHandler::fihlist_[type];
52  if (fl && fl->count() > 0) {
53  cnt = fl->count();
54  Printf("Type %d FInitializeHandler statements\n", type);
55  for (i=0; i < cnt; ++i) {
56  FInitialHandler* f = fl->item(i);
57  if (f->stmt_->pyobject()) {
58 Printf("\t%s\n", hoc_object_name(f->stmt_->pyobject()));
59  }else if (f->stmt_->object()) {
60 Printf("\t%s.%s\n", hoc_object_name(f->stmt_->object()), f->stmt_->name());
61  }else{
62  Printf("\t%s\n", f->stmt_->name());
63  }
64  }
65  }
66  }
67  return 0.;
68 }
69 
70 static Member_func members[] = {
71  "allprint", allprint,
72  0, 0
73 };
74 
75 static void* finithnd_cons(Object*) {
76  int type = 1; // default is after INITIAL blocks are called
77  int ia = 1;
78  if (hoc_is_double_arg(ia)) {
79  type = (int)chkarg(ia, 0, 3);
80  ++ia;
81  }
82  char* s = NULL;
83  Object* pyact = NULL;
84  if (hoc_is_object_arg(ia)) {
85  pyact = *hoc_objgetarg(ia);
86  if (!pyact) {
87  hoc_execerror("arg is None", 0);
88  }
89  }else{
90  s =gargstr(ia);
91  }
92  ++ia;
93  Object* obj = NULL;
94  if (ifarg(ia)) {
95  obj = *hoc_objgetarg(ia);
96  }
97  FInitialHandler* f = new FInitialHandler(type, s, obj, pyact);
98  return f;
99 }
100 
101 static void finithnd_destruct(void* v) {
103  delete f;
104 }
105 
107  class2oc("FInitializeHandler", finithnd_cons, finithnd_destruct,
108  members, NULL, NULL, NULL);
109 }
110 
111 FIHList* FInitialHandler::fihlist_[4];
112 
113 FInitialHandler::FInitialHandler(int i, const char* s, Object* obj, Object* pyact) {
114  if (!fihlist_[i]) {
115  fihlist_[i] = new FIHList(10);
116  }
117  type_ = i;
118  if (pyact) {
119  stmt_ = new HocCommand(pyact);
120  }else{
121  stmt_ = new HocCommand(s, obj);
122  }
123  fihlist_[i]->append(this);
124 }
125 
127  delete stmt_;
128  int i, cnt;
129  cnt = fihlist_[type_]->count();
130  for (i=0; i < cnt; ++i) {
131  if (fihlist_[type_]->item(i) == this) {
132  fihlist_[type_]->remove(i);
133  return;
134  }
135  }
136 }
137 
138 
#define Printf
Definition: model.h:252
static FIHList * fihlist_[4]
Definition: finithnd.cpp:32
short type
Definition: cabvars.h:10
virtual ~FInitialHandler()
Definition: finithnd.cpp:126
int hoc_is_double_arg(int narg)
Definition: code.cpp:733
char * hoc_object_name(Object *ob)
Definition: hoc_oop.cpp:84
#define v
Definition: md1redef.h:4
#define gargstr
Definition: hocdec.h:14
const char * name()
Definition: objcmd.cpp:84
#define implementPtrList(PtrList, T)
_CONST char * s
Definition: system.cpp:74
int execute(bool notify=true)
Definition: objcmd.cpp:105
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
void FInitializeHandler_reg()
Definition: finithnd.cpp:106
static Member_func members[]
Definition: finithnd.cpp:70
int
Definition: nrnmusic.cpp:71
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:741
#define cnt
Definition: spt2queue.cpp:19
static double allprint(void *v)
Definition: finithnd.cpp:48
int ifarg(int)
Definition: code.cpp:1562
void nrn_fihexec(int type)
Definition: finithnd.cpp:36
Definition: hocdec.h:226
static void finithnd_destruct(void *v)
Definition: finithnd.cpp:101
#define i
Definition: md1redef.h:12
static void * finithnd_cons(Object *)
Definition: finithnd.cpp:75
int hoc_is_object_arg(int narg)
Definition: code.cpp:745
Object * object()
Definition: objcmd.h:29
declarePtrList(FIHList, FInitialHandler) implementPtrList(FIHList
Object ** hoc_objgetarg(int)
Definition: code.cpp:1568
FInitialHandler(int, const char *, Object *, Object *pyact=NULL)
Definition: finithnd.cpp:113
return NULL
Definition: cabcode.cpp:461
double chkarg(int, double low, double high)
Definition: code2.cpp:608
Object * pyobject()
Definition: objcmd.h:30
HocCommand * stmt_
Definition: finithnd.cpp:30