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;
58  section_ref(sec);
59 }
60 NrnSectionImpl::~NrnSectionImpl() {
61  section_unref(sec_);
62 }
63 #endif
64 //----------------------------------------------------
66  npi_ = new NrnPropertyImpl(p);
67 }
68 
70  Symbol* sym = hoc_table_lookup(name, hoc_built_in_symlist);
71  if (!sym) {
72  sym = hoc_table_lookup(name, hoc_top_level_symlist);
73  }
74  if(sym) {
75  if (sym->type == MECHANISM) {
76  /*EMPTY*/
77  }else if (sym->type == TEMPLATE && sym->u.ctemplate->is_point_){
78  sym = hoc_table_lookup(name, sym->u.ctemplate->symtable);
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 
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 }
245  hoc_dec_refcount(&sli_->ob_);
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
Section * next()
Definition: ndatclas.cpp:252
int var_type(Symbol *) const
Definition: ndatclas.cpp:153
Definition: hocdec.h:84
int param_size
Definition: section.h:217
size_t hoc_total_array_data(Symbol *s, Objectdata *obd)
Definition: hoc_oop.cpp:106
double * param
Definition: section.h:218
#define assert(ex)
Definition: hocassrt.h:26
short type
Definition: cabvars.h:10
Symbol * var(int)
Definition: ndatclas.cpp:149
#define hocSEC(q)
Definition: hoclist.h:66
Symlist * hoc_top_level_symlist
Definition: symbol.cpp:41
NrnPropertyImpl(Prop *)
Definition: ndatclas.cpp:25
short type
Definition: model.h:58
int prop_index(const Symbol *) const
Definition: ndatclas.cpp:215
Symlist * symtable
Definition: hocdec.h:196
Symlist * hoc_built_in_symlist
Definition: symbol.cpp:39
#define NRNPOINTER
Definition: nocpout.cpp:100
void * this_pointer
Definition: hocdec.h:231
size_t p
check_obj_type(o, "SectionList")
char * name
Definition: model.h:72
double * prop_pval(const Symbol *, int arrayindex=0) const
Definition: ndatclas.cpp:223
Object * ob
Definition: section.h:224
Memb_func * memb_func
Definition: init.cpp:161
Item * next(Item *item)
Definition: list.cpp:95
bool deleteable()
Definition: ndatclas.cpp:107
inode
Definition: multicore.cpp:985
NrnProperty(Prop *)
Definition: ndatclas.cpp:65
virtual ~SectionList()
Definition: ndatclas.cpp:244
short type
Definition: section.h:215
unsigned s_varn
Definition: hocdec.h:157
Symbol * sym
Definition: membfunc.h:38
int refcount
Definition: hocdec.h:227
int nrn_vartype(Symbol *sym)
Definition: eion.cpp:488
struct hoc_Item * list_
Definition: ndatclas.cpp:44
int const size_t const size_t n
Definition: nrngsl.h:12
HocStruct Symbol ** ppsym
Definition: hocdec.h:149
double * pval
Definition: hocdec.h:217
_CONST char * s
Definition: system.cpp:74
Objectdata * dataspace
Definition: hocdec.h:230
Prop * prop_alloc(Prop **, int, Node *)
Definition: treeset.cpp:688
void nrn_pushsec(Section *sec)
Definition: cabcode.cpp:97
Symbol * first_var()
Definition: ndatclas.cpp:127
SectionList(Object *)
Definition: ndatclas.cpp:236
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:741
#define cnt
Definition: spt2queue.cpp:19
void hoc_dec_refcount(Object **pobj)
Definition: hoc_oop.cpp:1986
size_t j
Definition: model.h:57
static bool assign(Prop *src, Prop *dest, int vartype=0)
Definition: ndatclas.cpp:157
Definition: section.h:213
char * name
Definition: init.cpp:16
Prop * nrn_mechanism(int type, Node *nd)
Definition: cabcode.cpp:1079
int is_point_
Definition: hocdec.h:198
int type() const
Definition: ndatclas.cpp:119
void section_ref(Section *)
Definition: solve.cpp:563
long subtype
Definition: model.h:59
struct Symbol::@52::@53 rng
void single_prop_free(Prop *)
Definition: treeset.cpp:736
Object * nrn_object()
Definition: ndatclas.cpp:263
Symbol * next_var()
Definition: ndatclas.cpp:140
Definition: hocdec.h:226
HocStruct cTemplate * ctemplate
Definition: hocdec.h:151
void hoc_push_frame(Symbol *, int)
Symbol * sym_
Definition: ndatclas.cpp:22
const char * name() const
Definition: ndatclas.cpp:111
Symbol * hoc_table_lookup(const char *, Symlist *)
Definition: symbol.cpp:60
double * hoc_val_pointer(const char *s)
Definition: code2.cpp:699
#define i
Definition: md1redef.h:12
int is_point
Definition: membfunc.h:53
struct Prop * next
Definition: section.h:214
bool more_var()
Definition: ndatclas.cpp:132
sec
Definition: solve.cpp:885
void nrn_popsec(void)
Definition: cabcode.cpp:122
union Symbol::@18 u
struct hoc_Item * itr_
Definition: ndatclas.cpp:43
union Object::@54 u
static Node * node(Object *)
Definition: netcvode.cpp:318
void section_unref(Section *)
Definition: solve.cpp:552
Definition: section.h:132
Prop * prop() const
Definition: ndatclas.cpp:123
bool is_point() const
Definition: ndatclas.cpp:115
void hoc_pop_frame(void)
Symbol * find(const char *rangevar)
Definition: ndatclas.cpp:203
#define pval
Definition: md1redef.h:32
double var(InputIterator begin, InputIterator end)
Definition: ivocvect.h:93
return NULL
Definition: cabcode.cpp:461
Section * begin()
Definition: ndatclas.cpp:248
virtual ~NrnProperty()
Definition: ndatclas.cpp:103
short index
Definition: cabvars.h:11
Object * ob_
Definition: ndatclas.cpp:42