NEURON
ndatclas.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include <stdio.h>
3 #include <InterViews/resource.h>
4 #include "nrnoc2iv.h"
5 #include "classreg.h"
6 
7 #include "membfunc.h"
8 #include "parse.hpp"
9 extern Prop* prop_alloc(Prop**, int, Node*);
10 extern void single_prop_free(Prop*);
13 
14 //----------------------------------------------------
15 /* static */ class NrnPropertyImpl {
16  friend class NrnProperty;
19 
20  Prop* p_;
21  int iterator_;
23  bool del_;
24 };
26  p_ = p;
27  iterator_ = -1;
28  sym_ = memb_func[p_->type].sym;
29  del_ = false;
30 }
31 
33  if (del_ && p_) {
34  // printf("NrnProperty freed prop\n");
36  }
37 }
38 
39 //---------------------------------------------------
40 /* static */ class SectionListImpl {
41  friend class SectionList;
43  struct hoc_Item* itr_;
44  struct hoc_Item* list_;
45 };
46 
47 //----------------------------------------------------
48 #if 0
49 /* static */ class NrnSectionImpl {
50  friend NrnSection
51  NrnSectionImpl(Section*);
52  ~NrnSectionImpl();
53 
54  Section* sec_;
55 };
56 NrnSectionImpl::NrnSectionImpl(Section* sec) {
57  sec_ = sec;
59 }
60 NrnSectionImpl::~NrnSectionImpl() {
61  section_unref(sec_);
62 }
63 #endif
64 //----------------------------------------------------
66  npi_ = new NrnPropertyImpl(p);
67 }
68 
71  if (!sym) {
73  }
74  if (sym) {
75  if (sym->type == MECHANISM) {
76  /*EMPTY*/
77  } else if (sym->type == TEMPLATE && sym->u.ctemplate->is_point_) {
79 
80  } else {
81  sym = 0;
82  }
83  }
84  if (sym) {
85  Prop *p, *p0 = 0, *p1;
86  // printf("prop_alloc %s %p type=%d\n", sym->name, sym, sym->subtype);
87  // need to do this with no args
88  hoc_push_frame(sym, 0);
89  p = prop_alloc(&p0, sym->subtype, NULL);
90  hoc_pop_frame();
91  for (; p0 != p; p0 = p1) {
92  p1 = p0->next;
93  single_prop_free(p0);
94  }
95  npi_ = new NrnPropertyImpl(p);
96  npi_->del_ = true;
97  } else {
98  npi_ = NULL;
99  hoc_execerror(name, "is not a Mechanism or Point Process");
100  }
101 }
102 
104  delete npi_;
105 }
106 
108  return npi_->del_;
109 }
110 
111 const char* NrnProperty::name() const {
112  return npi_->sym_->name;
113 }
114 
115 bool NrnProperty::is_point() const {
116  return memb_func[npi_->p_->type].is_point;
117 }
118 
119 int NrnProperty::type() const {
120  return npi_->p_->type;
121 }
122 
124  return npi_->p_;
125 }
126 
128  npi_->iterator_ = -1;
129  return next_var();
130 }
131 
133  if (npi_->iterator_ >= npi_->sym_->s_varn) {
134  return false;
135  } else {
136  return true;
137  }
138 }
139 
141  ++npi_->iterator_;
142  if (more_var()) {
143  return npi_->sym_->u.ppsym[npi_->iterator_];
144  } else {
145  return 0;
146  }
147 }
148 
150  return npi_->sym_->u.ppsym[i];
151 }
152 
153 int NrnProperty::var_type(Symbol* sym) const {
154  return nrn_vartype(sym);
155 }
156 
157 bool NrnProperty::assign(Prop* src, Prop* dest, int vartype) {
158  int n;
159  assert(vartype != NRNPOINTER);
160  if (src && dest && src != dest && src->type == dest->type) {
161  if (src->ob) {
162  Symbol* msym = memb_func[src->type].sym;
163  int i, j, jmax, cnt = msym->s_varn;
164  for (i = 0; i < cnt; ++i) {
165  Symbol* sym = msym->u.ppsym[i];
166  if (vartype == 0 || nrn_vartype(sym) == vartype) {
167  jmax = hoc_total_array_data(sym, 0);
168  n = sym->u.rng.index;
169  double *x, *y;
170  y = dest->ob->u.dataspace[n].pval;
171  x = src->ob->u.dataspace[n].pval;
172  for (j = 0; j < jmax; ++j) {
173  y[j] = x[j];
174  }
175  }
176  }
177  } else {
178  if (vartype == 0) {
179  n = src->param_size;
180  for (int i = 0; i < n; ++i) {
181  dest->param[i] = src->param[i];
182  }
183  } else {
184  Symbol* msym = memb_func[src->type].sym;
185  int i, j, jmax, cnt = msym->s_varn;
186  for (i = 0; i < cnt; ++i) {
187  Symbol* sym = msym->u.ppsym[i];
188  if (nrn_vartype(sym) == vartype) {
189  jmax = hoc_total_array_data(sym, 0);
190  n = sym->u.rng.index;
191  for (j = 0; j < jmax; ++j) {
192  dest->param[n + j] = src->param[n + j];
193  }
194  }
195  }
196  }
197  }
198  return true;
199  } else {
200  return false;
201  }
202 }
204  Symbol* sym;
205  int i, cnt;
206  cnt = npi_->sym_->s_varn;
207  for (i = 0; i < cnt; ++i) {
208  sym = npi_->sym_->u.ppsym[i];
209  if (strcmp(sym->name, name) == 0) {
210  return sym;
211  }
212  }
213  return 0;
214 }
215 int NrnProperty::prop_index(const Symbol* s) const {
216  assert(s);
217  if (s->type != RANGEVAR) {
218  hoc_execerror(s->name, "not a range variable");
219  }
220  return s->u.rng.index;
221 }
222 
223 double* NrnProperty::prop_pval(const Symbol* s, int index) const {
224  if (npi_->p_->ob) {
225  return npi_->p_->ob->u.dataspace[prop_index(s)].pval + index;
226  } else {
227  if (s->subtype == NRNPOINTER) {
228  return npi_->p_->dparam[prop_index(s) + index].pval;
229  } else {
230  return npi_->p_->param + prop_index(s) + index;
231  }
232  }
233 }
234 
235 //--------------------------------------------------
237  sli_ = new SectionListImpl();
238  check_obj_type(ob, "SectionList");
239  sli_->ob_ = ob;
240  ++ob->refcount;
241  sli_->list_ = (struct hoc_Item*) ob->u.this_pointer;
242  sli_->itr_ = sli_->list_;
243 }
246  delete sli_;
247 }
249  sli_->itr_ = sli_->list_->next;
250  return next();
251 }
253  Section* sec;
254  if (sli_->itr_ == sli_->list_) {
255  sec = NULL;
256  } else {
257  sec = hocSEC(sli_->itr_);
258  sli_->itr_ = sli_->itr_->next;
259  }
260  return sec;
261 }
262 
264  Object* ob = sli_->ob_;
265  return ob;
266 }
267 
268 #if 0
269 //---------------------------------------------------
270 NrnSection::NrnSection(Section* sec) {
271  npi_ = new NrnSectionImpl(sec);
272 }
273 NrnSection::~NrnSection() {
274  delete npi_;
275 }
276 void NrnSection::section(Section* sec) {
277  section_ref(sec);
278  section_unref(npi_->sec_);
279  npi_->sec_ = sec;
280 }
281 Section* NrnSection::section() {
282  return npi_->sec_;
283 }
284 
285 Node* NrnSection::node(int inode) { return sec_->pnode[inode]; }
286 
287 bool NrnSection::is_mechanism(type) {
288  return nrn_mechanism(type, node(0)) != (Prop*)0
289 }
290 
291 double* NrnSection::var_pointer(const char* var) {
292  nrn_pushsec(nsi_->sec_);
293  double* pval = hoc_val_pointer(var);
294  nrn_popsec();
295  return pval;
296 }
297 #endif
void nrn_pushsec(Section *sec)
Definition: cabcode.cpp:99
Prop * nrn_mechanism(int type, Node *nd)
Definition: cabcode.cpp:1079
void nrn_popsec(void)
Definition: cabcode.cpp:123
short index
Definition: cabvars.h:10
Memb_func * memb_func
Definition: init.cpp:123
short type
Definition: cabvars.h:9
bool deleteable()
Definition: ndatclas.cpp:107
int prop_index(const Symbol *) const
Definition: ndatclas.cpp:215
Symbol * find(const char *rangevar)
Definition: ndatclas.cpp:203
int var_type(Symbol *) const
Definition: ndatclas.cpp:153
double * prop_pval(const Symbol *, int arrayindex=0) const
Definition: ndatclas.cpp:223
NrnProperty(Prop *)
Definition: ndatclas.cpp:65
virtual ~NrnProperty()
Definition: ndatclas.cpp:103
static bool assign(Prop *src, Prop *dest, int vartype=0)
Definition: ndatclas.cpp:157
Symbol * var(int)
Definition: ndatclas.cpp:149
Symbol * first_var()
Definition: ndatclas.cpp:127
const char * name() const
Definition: ndatclas.cpp:111
int type() const
Definition: ndatclas.cpp:119
Symbol * next_var()
Definition: ndatclas.cpp:140
bool more_var()
Definition: ndatclas.cpp:132
bool is_point() const
Definition: ndatclas.cpp:115
NrnPropertyImpl * npi_
Definition: ndatclas.h:34
Prop * prop() const
Definition: ndatclas.cpp:123
NrnPropertyImpl(Prop *)
Definition: ndatclas.cpp:25
Symbol * sym_
Definition: ndatclas.cpp:22
SectionList(Object *)
Definition: ndatclas.cpp:236
SectionListImpl * sli_
Definition: ndatclas.h:46
virtual ~SectionList()
Definition: ndatclas.cpp:244
Object * nrn_object()
Definition: ndatclas.cpp:263
Section * next()
Definition: ndatclas.cpp:252
Section * begin()
Definition: ndatclas.cpp:248
Object * ob_
Definition: ndatclas.cpp:42
struct hoc_Item * itr_
Definition: ndatclas.cpp:43
struct hoc_Item * list_
Definition: ndatclas.cpp:44
Symbol * hoc_table_lookup(const char *, Symlist *)
Definition: symbol.cpp:61
int nrn_vartype(Symbol *sym)
Definition: eion.cpp:515
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
void hoc_push_frame(Symbol *, int)
size_t hoc_total_array_data(Symbol *s, Objectdata *obd)
Definition: hoc_oop.cpp:94
double * hoc_val_pointer(const char *s)
Definition: code2.cpp:727
void hoc_pop_frame(void)
void hoc_dec_refcount(Object **pobj)
Definition: hoc_oop.cpp:1816
#define assert(ex)
Definition: hocassrt.h:32
#define hocSEC(q)
Definition: hoclist.h:66
double var(InputIterator begin, InputIterator end)
Definition: ivocvect.h:101
#define pval
Definition: md1redef.h:32
#define sec
Definition: md1redef.h:13
#define i
Definition: md1redef.h:12
char * name
Definition: init.cpp:16
Symlist * hoc_top_level_symlist
Definition: symdir.cpp:23
Prop * prop_alloc(Prop **, int, Node *)
Definition: treeset.cpp:694
void single_prop_free(Prop *)
Definition: treeset.cpp:742
Symlist * hoc_built_in_symlist
Definition: ivocmac.cpp:76
static Node * node(Object *)
Definition: netcvode.cpp:340
#define NRNPOINTER
Definition: nocpout.cpp:100
void section_ref(Section *)
Definition: solve.cpp:575
void section_unref(Section *)
Definition: solve.cpp:565
int const size_t const size_t n
Definition: nrngsl.h:11
size_t p
size_t j
check_obj_type(o, "SectionList")
#define cnt
Definition: spt2queue.cpp:19
#define NULL
Definition: sptree.h:16
int is_point
Definition: membfunc.h:53
Symbol * sym
Definition: membfunc.h:38
Definition: section.h:133
Definition: hocdec.h:227
void * this_pointer
Definition: hocdec.h:232
Objectdata * dataspace
Definition: hocdec.h:231
int refcount
Definition: hocdec.h:228
union Object::@39 u
Definition: section.h:214
Datum * dparam
Definition: section.h:220
double * param
Definition: section.h:219
Object * ob
Definition: section.h:225
int param_size
Definition: section.h:218
short type
Definition: section.h:216
struct Prop * next
Definition: section.h:215
Definition: model.h:57
HocStruct Symbol ** ppsym
Definition: hocdec.h:150
short type
Definition: model.h:58
struct Symbol::@37::@38 rng
long subtype
Definition: model.h:59
union Symbol::@18 u
unsigned s_varn
Definition: hocdec.h:158
char * name
Definition: model.h:72
HocStruct cTemplate * ctemplate
Definition: hocdec.h:152
Definition: hocdec.h:84
Symlist * symtable
Definition: hocdec.h:197
int is_point_
Definition: hocdec.h:199
struct hoc_Item * next
Definition: hoclist.h:50
double * pval
Definition: hocdec.h:181
double * pval
Definition: hocdec.h:218