NEURON
hoclist.h
Go to the documentation of this file.
1 #pragma once
2 
3 #if HOC_L_LIST
4 #define stralloc hoc_l_stralloc
5 #define newitem hoc_l_newitem
6 #define newlist hoc_l_newlist
7 #define freelist hoc_l_freelist
8 #define insertstr hoc_l_insertstr
9 #define insertitem hoc_l_insertitem
10 #define insertlist hoc_l_insertlist
11 #define insertsym hoc_l_insertsym
12 #define insertsec hoc_l_insertsec
13 #define insertobj hoc_l_insertobj
14 #define insertvoid hoc_l_insertvoid
15 #define linsertsym hoc_l_linsertsym
16 #define linsertstr hoc_l_linsertstr
17 #define lappendsym hoc_l_lappendsym
18 #define lappendstr hoc_l_lappendstr
19 #define lappenditem hoc_l_lappenditem
20 #define lappendlst hoc_l_lappendlst
21 #define lappendsec hoc_l_lappendsec
22 #define lappendobj hoc_l_lappendobj
23 #define lappendvoid hoc_l_lappendvoid
24 #define delitems hoc_l_delitems
25 #define movelist hoc_l_movelist
26 #define replacstr hoc_l_replacstr
27 #define Item hoc_Item
28 #define List hoc_List
29 #endif
30 
31 struct Object;
32 struct Section;
33 struct Symbol;
34 struct hoc_Item {
35  union {
38  char* str;
42  void* vd;
43  } element; /* pointer to the actual item */
46  short itemtype;
47 };
49 
50 constexpr auto range_sec(hoc_List* iterable) {
51  struct iterator {
52  hoc_Item* iter;
53  bool operator!=(const iterator& other) const {
54  return iter != other.iter;
55  }
56  void operator++() {
57  iter = iter->next;
58  }
59  Section* operator*() const {
60  return iter->element.sec;
61  }
62  };
63  struct iterable_wrapper {
64  hoc_List* iterable;
65  auto begin() {
66  return iterator{iterable->next};
67  }
68  auto end() {
69  return iterator{iterable};
70  }
71  };
72  return iterable_wrapper{iterable};
73 }
74 
75 #define ITEM0 nullptr
76 #define LIST0 nullptr
77 
78 #define ITERATE(itm, lst) for (itm = (lst)->next; itm != (lst); itm = itm->next)
79 /*
80  * this is convenient way to get the element pointer if you know what type
81  * the item is
82  */
83 #define SYM(q) ((q)->element.sym)
84 #define STR(q) ((q)->element.str)
85 #define ITM(q) ((q)->element.itm)
86 #define LST(q) ((q)->element.lst)
87 #define hocSEC(q) ((q)->element.sec)
88 #define OBJ(q) ((q)->element.obj)
89 #define VOIDITM(q) ((q)->element.vd)
90 
91 /* types not defined in parser */
92 #define ITEM 2
93 #define LIST 3
94 #define VOIDPOINTER 4
95 /*
96  * An item type, STRING is also used as an item type
97  */
98 
99 extern char* hoc_l_stralloc(const char*, char* release);
101 extern hoc_Item* hoc_l_insertstr(hoc_Item*, const char*);
107 extern hoc_Item* hoc_l_linsertstr(hoc_List*, const char*);
109 extern hoc_Item* hoc_l_lappendstr(hoc_List*, const char*);
116 extern void hoc_l_freelist(hoc_List**);
119 extern void hoc_l_delete(hoc_Item*);
122 extern void hoc_l_replacstr(hoc_Item*, const char*);
123 
124 #define Insertstr insertstr
125 #define Insertsym insertsym
126 #define Insertsec insertsec
127 #define Linsertsym linsertsym
128 #define Linsertstr linsertstr
129 #define Lappendsym lappendsym
130 #define Lappendstr lappendstr
131 #define Lappenditem lappenditem
132 #define Lappendlst lappendlst
133 #define Lappendsec lappendsec
hoc_Item * hoc_l_linsertstr(hoc_List *, const char *)
hoc_Item * hoc_l_lappendstr(hoc_List *, const char *)
hoc_Item * hoc_l_lappendlst(hoc_List *, hoc_List *)
char * hoc_l_stralloc(const char *, char *release)
void hoc_l_move(hoc_Item *, hoc_Item *, hoc_Item *)
hoc_Item * hoc_l_insertsec(hoc_Item *, struct Section *)
hoc_Item * hoc_l_insertlist(hoc_Item *, hoc_List *)
hoc_Item * hoc_l_insertitem(hoc_Item *, hoc_Item *)
hoc_Item * hoc_l_lappenditem(hoc_List *, hoc_Item *)
hoc_Item * hoc_l_insertstr(hoc_Item *, const char *)
hoc_Item * hoc_l_linsertsym(hoc_List *, struct Symbol *)
hoc_List * hoc_l_newlist()
hoc_Item * hoc_l_insertvoid(hoc_Item *, void *)
hoc_Item * hoc_l_lappendsec(hoc_List *, struct Section *)
void hoc_l_freelist(hoc_List **)
hoc_Item * hoc_l_lappendobj(hoc_List *, struct Object *)
void hoc_l_delete(hoc_Item *)
hoc_Item * hoc_l_lappendvoid(hoc_List *, void *)
hoc_Item * hoc_l_next(hoc_Item *)
hoc_Item * hoc_l_insertsym(hoc_Item *, struct Symbol *)
void hoc_l_movelist(hoc_Item *, hoc_Item *, hoc_List *)
hoc_Item * hoc_l_prev(hoc_Item *)
void hoc_l_replacstr(hoc_Item *, const char *)
constexpr auto range_sec(hoc_List *iterable)
Definition: hoclist.h:50
hoc_Item * hoc_l_lappendsym(hoc_List *, struct Symbol *)
bool operator!=(unified_allocator< T > const &x, unified_allocator< U > const &y) noexcept
Definition: memory.h:76
Definition: hocdec.h:173
Definition: model.h:47
Object * obj
Definition: hoclist.h:41
void * vd
Definition: hoclist.h:42
Symbol * sym
Definition: hoclist.h:39
hoc_Item * lst
Definition: hoclist.h:37
char * str
Definition: hoclist.h:38
Section * sec
Definition: hoclist.h:40
union hoc_Item::@48 element
short itemtype
Definition: hoclist.h:46
hoc_Item * next
Definition: hoclist.h:44
hoc_Item * itm
Definition: hoclist.h:36
hoc_Item * prev
Definition: hoclist.h:45