trunk/src/emu/netlist/nl_base.h
| r30606 | r30607 | |
| 369 | 369 | // netlist_core_terminal_t |
| 370 | 370 | // ---------------------------------------------------------------------------------------- |
| 371 | 371 | |
| 372 | | class netlist_core_terminal_t : public netlist_owned_object_t, public plinked_list_element<netlist_core_terminal_t> |
| 372 | class netlist_core_terminal_t : public netlist_owned_object_t, public plinkedlist_element_t<netlist_core_terminal_t> |
| 373 | 373 | { |
| 374 | 374 | NETLIST_PREVENT_COPYING(netlist_core_terminal_t) |
| 375 | 375 | public: |
| 376 | 376 | |
| 377 | | typedef netlist_list_t<netlist_core_terminal_t *> list_t; |
| 377 | typedef plinearlist_t<netlist_core_terminal_t *> list_t; |
| 378 | 378 | |
| 379 | 379 | /* needed here ... */ |
| 380 | 380 | |
| r30606 | r30607 | |
| 429 | 429 | NETLIST_PREVENT_COPYING(netlist_terminal_t) |
| 430 | 430 | public: |
| 431 | 431 | |
| 432 | | typedef netlist_list_t<netlist_terminal_t *> list_t; |
| 432 | typedef plinearlist_t<netlist_terminal_t *> list_t; |
| 433 | 433 | |
| 434 | 434 | ATTR_COLD netlist_terminal_t(); |
| 435 | 435 | |
| r30606 | r30607 | |
| 554 | 554 | NETLIST_PREVENT_COPYING(netlist_net_t) |
| 555 | 555 | public: |
| 556 | 556 | |
| 557 | | typedef netlist_list_t<netlist_net_t *> list_t; |
| 557 | typedef plinearlist_t<netlist_net_t *> list_t; |
| 558 | 558 | |
| 559 | 559 | ATTR_COLD netlist_net_t(const family_t afamily); |
| 560 | 560 | ATTR_COLD virtual ~netlist_net_t(); |
| r30606 | r30607 | |
| 592 | 592 | |
| 593 | 593 | ATTR_COLD void move_connections(netlist_net_t *new_net); |
| 594 | 594 | |
| 595 | | netlist_list_t<netlist_core_terminal_t *> m_core_terms; // save post-start m_list ... |
| 595 | plinearlist_t<netlist_core_terminal_t *> m_core_terms; // save post-start m_list ... |
| 596 | 596 | |
| 597 | 597 | protected: //FIXME: needed by current solver code |
| 598 | 598 | |
| r30606 | r30607 | |
| 606 | 606 | private: |
| 607 | 607 | |
| 608 | 608 | netlist_core_terminal_t * RESTRICT m_railterminal; |
| 609 | | plinked_list<netlist_core_terminal_t> m_list_active; |
| 609 | plinkedlist_t<netlist_core_terminal_t> m_list_active; |
| 610 | 610 | |
| 611 | 611 | netlist_time m_time; |
| 612 | 612 | INT32 m_active; |
| r30606 | r30607 | |
| 627 | 627 | NETLIST_PREVENT_COPYING(netlist_logic_net_t) |
| 628 | 628 | public: |
| 629 | 629 | |
| 630 | | typedef netlist_list_t<netlist_logic_net_t *> list_t; |
| 630 | typedef plinearlist_t<netlist_logic_net_t *> list_t; |
| 631 | 631 | |
| 632 | 632 | ATTR_COLD netlist_logic_net_t(); |
| 633 | 633 | ATTR_COLD virtual ~netlist_logic_net_t() { }; |
| r30606 | r30607 | |
| 694 | 694 | NETLIST_PREVENT_COPYING(netlist_analog_net_t) |
| 695 | 695 | public: |
| 696 | 696 | |
| 697 | | typedef netlist_list_t<netlist_analog_net_t *> list_t; |
| 697 | typedef plinearlist_t<netlist_analog_net_t *> list_t; |
| 698 | 698 | |
| 699 | 699 | ATTR_COLD netlist_analog_net_t(); |
| 700 | 700 | ATTR_COLD virtual ~netlist_analog_net_t() { }; |
| r30606 | r30607 | |
| 927 | 927 | NETLIST_PREVENT_COPYING(netlist_core_device_t) |
| 928 | 928 | public: |
| 929 | 929 | |
| 930 | | typedef netlist_list_t<netlist_core_device_t *> list_t; |
| 930 | typedef plinearlist_t<netlist_core_device_t *> list_t; |
| 931 | 931 | |
| 932 | 932 | ATTR_COLD netlist_core_device_t(const family_t afamily, const netlist_logic_family_desc_t *family_desc); |
| 933 | 933 | |
| r30606 | r30607 | |
| 1033 | 1033 | |
| 1034 | 1034 | ATTR_COLD void connect(netlist_core_terminal_t &t1, netlist_core_terminal_t &t2); |
| 1035 | 1035 | |
| 1036 | | netlist_list_t<pstring, 20> m_terminals; |
| 1036 | plinearlist_t<pstring, 20> m_terminals; |
| 1037 | 1037 | |
| 1038 | 1038 | protected: |
| 1039 | 1039 | |
| r30606 | r30607 | |
| 1077 | 1077 | // netlist_base_t |
| 1078 | 1078 | // ---------------------------------------------------------------------------------------- |
| 1079 | 1079 | |
| 1080 | | template <class _C> |
| 1081 | | class netlist_tagmap_t : public netlist_list_t<_C> |
| 1082 | | { |
| 1083 | | public: |
| 1084 | | _C find(const pstring name) const |
| 1085 | | { |
| 1086 | | for (int i=0; i < this->count(); i++) |
| 1087 | | if (get_name((*this)[i]) == name) |
| 1088 | | return (*this)[i]; |
| 1089 | | return _C(NULL); |
| 1090 | | } |
| 1091 | 1080 | |
| 1092 | | void remove_by_name(const pstring name) |
| 1093 | | { |
| 1094 | | netlist_list_t<_C>::remove(find(name)); |
| 1095 | | } |
| 1096 | | |
| 1097 | | bool add(_C dev, bool allow_duplicate) |
| 1098 | | { |
| 1099 | | if (allow_duplicate) |
| 1100 | | netlist_list_t<_C>::add(dev); |
| 1101 | | else |
| 1102 | | { |
| 1103 | | if (!(this->find(get_name(dev)) == _C(NULL))) |
| 1104 | | return false; |
| 1105 | | netlist_list_t<_C>::add(dev); |
| 1106 | | } |
| 1107 | | return true; |
| 1108 | | } |
| 1109 | | |
| 1110 | | private: |
| 1111 | | template <typename T> static const pstring get_name(T &elem) { return elem.name(); } |
| 1112 | | template <typename T> static const pstring get_name(T *elem) { return elem->name(); } |
| 1113 | | |
| 1114 | | }; |
| 1115 | | |
| 1116 | 1081 | class netlist_base_t : public netlist_object_t, public pstate_manager_t |
| 1117 | 1082 | { |
| 1118 | 1083 | NETLIST_PREVENT_COPYING(netlist_base_t) |
| r30606 | r30607 | |
| 1155 | 1120 | ATTR_COLD void log(const char *format, ...) const ATTR_PRINTF(2,3); |
| 1156 | 1121 | |
| 1157 | 1122 | template<class _C> |
| 1158 | | netlist_list_t<_C *> get_device_list() |
| 1123 | plinearlist_t<_C *> get_device_list() |
| 1159 | 1124 | { |
| 1160 | | netlist_list_t<_C *> tmp; |
| 1125 | plinearlist_t<_C *> tmp; |
| 1161 | 1126 | for (netlist_device_t * const *entry = m_devices.first(); entry != NULL; entry = m_devices.next(entry)) |
| 1162 | 1127 | { |
| 1163 | 1128 | _C *dev = dynamic_cast<_C *>(*entry); |
| r30606 | r30607 | |
| 1198 | 1163 | return ret; |
| 1199 | 1164 | } |
| 1200 | 1165 | |
| 1201 | | netlist_tagmap_t<netlist_device_t *> m_devices; |
| 1166 | pnamedlist_t<netlist_device_t *> m_devices; |
| 1202 | 1167 | netlist_net_t::list_t m_nets; |
| 1203 | 1168 | |
| 1204 | 1169 | protected: |
| r30606 | r30607 | |
| 1433 | 1398 | class netlist_factory_t |
| 1434 | 1399 | { |
| 1435 | 1400 | public: |
| 1436 | | typedef netlist_list_t<net_device_t_base_factory *> list_t; |
| 1401 | typedef plinearlist_t<net_device_t_base_factory *> list_t; |
| 1437 | 1402 | |
| 1438 | 1403 | ATTR_COLD netlist_factory_t(); |
| 1439 | 1404 | ATTR_COLD ~netlist_factory_t(); |
trunk/src/emu/netlist/plists.h
| r0 | r30607 | |
| 1 | // license:GPL-2.0+ |
| 2 | // copyright-holders:Couriersud |
| 3 | /* |
| 4 | * plists.h |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #ifndef PLISTS_H_ |
| 11 | #define PLISTS_H_ |
| 12 | |
| 13 | #include "nl_config.h" |
| 14 | #include "pstring.h" |
| 15 | |
| 16 | // ---------------------------------------------------------------------------------------- |
| 17 | // plinearlist_t: a simple list |
| 18 | // ---------------------------------------------------------------------------------------- |
| 19 | |
| 20 | template <class _ListClass, int _NumElem = 0> |
| 21 | class plinearlist_t |
| 22 | { |
| 23 | public: |
| 24 | |
| 25 | ATTR_COLD plinearlist_t(int numElements = _NumElem) |
| 26 | { |
| 27 | m_num_elements = numElements; |
| 28 | if (m_num_elements == 0) |
| 29 | m_list = NULL; |
| 30 | else |
| 31 | m_list = new _ListClass[m_num_elements]; |
| 32 | m_count = 0; |
| 33 | } |
| 34 | |
| 35 | ATTR_COLD plinearlist_t(const plinearlist_t &rhs) |
| 36 | { |
| 37 | m_num_elements = rhs.capacity(); |
| 38 | if (m_num_elements == 0) |
| 39 | m_list = NULL; |
| 40 | else |
| 41 | m_list = new _ListClass[m_num_elements]; |
| 42 | m_count = 0; |
| 43 | for (int i=0; i<rhs.count(); i++) |
| 44 | { |
| 45 | this->add(rhs[i]); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | ATTR_COLD plinearlist_t &operator=(const plinearlist_t &rhs) |
| 50 | { |
| 51 | this->clear(); |
| 52 | for (int i=0; i<rhs.count(); i++) |
| 53 | { |
| 54 | this->add(rhs[i]); |
| 55 | } |
| 56 | return *this; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | ATTR_COLD ~plinearlist_t() |
| 61 | { |
| 62 | if (m_list != NULL) |
| 63 | delete[] m_list; |
| 64 | } |
| 65 | |
| 66 | ATTR_HOT inline void add(const _ListClass &elem) |
| 67 | { |
| 68 | if (m_count >= m_num_elements){ |
| 69 | int new_size = m_num_elements * 2; |
| 70 | if (new_size < 32) |
| 71 | new_size = 32; |
| 72 | resize(new_size); |
| 73 | } |
| 74 | |
| 75 | m_list[m_count++] = elem; |
| 76 | } |
| 77 | |
| 78 | ATTR_HOT inline void resize(const int new_size) |
| 79 | { |
| 80 | int cnt = count(); |
| 81 | if (new_size > 0) |
| 82 | { |
| 83 | _ListClass *m_new = new _ListClass[new_size]; |
| 84 | _ListClass *pd = m_new; |
| 85 | |
| 86 | if (cnt > new_size) |
| 87 | cnt = new_size; |
| 88 | for (_ListClass *ps = m_list; ps < m_list + cnt; ps++, pd++) |
| 89 | *pd = *ps; |
| 90 | if (m_list != NULL) |
| 91 | delete[] m_list; |
| 92 | m_list = m_new; |
| 93 | m_count = cnt; |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | if (m_list != NULL) |
| 98 | delete[] m_list; |
| 99 | m_list = NULL; |
| 100 | m_count = 0; |
| 101 | } |
| 102 | m_num_elements = new_size; |
| 103 | } |
| 104 | |
| 105 | ATTR_HOT inline void remove(const _ListClass &elem) |
| 106 | { |
| 107 | for (int i = 0; i < m_count; i++) |
| 108 | { |
| 109 | if (m_list[i] == elem) |
| 110 | { |
| 111 | m_count --; |
| 112 | while (i < m_count) |
| 113 | { |
| 114 | m_list[i] = m_list[i+1]; |
| 115 | i++; |
| 116 | } |
| 117 | return; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | ATTR_HOT inline void remove_at(const int pos) |
| 123 | { |
| 124 | assert((pos>=0) && (pos<m_count)); |
| 125 | m_count--; |
| 126 | for (int i = pos; i < m_count; i++) |
| 127 | { |
| 128 | m_list[i] = m_list[i+1]; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | ATTR_HOT inline bool contains(const _ListClass &elem) const |
| 133 | { |
| 134 | for (_ListClass *i = m_list; i < m_list + m_count; i++) |
| 135 | { |
| 136 | if (*i == elem) |
| 137 | return true; |
| 138 | } |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | ATTR_HOT inline int indexof(const _ListClass &elem) const |
| 143 | { |
| 144 | for (int i = 0; i < m_count; i++) |
| 145 | { |
| 146 | if (m_list[i] == elem) |
| 147 | return i; |
| 148 | } |
| 149 | return -1; |
| 150 | } |
| 151 | |
| 152 | ATTR_HOT inline const _ListClass *first() const { return ((m_count > 0) ? &m_list[0] : NULL ); } |
| 153 | ATTR_HOT inline const _ListClass *next(const _ListClass *lc) const { return ((lc < last()) ? lc + 1 : NULL ); } |
| 154 | ATTR_HOT inline const _ListClass *last() const { return &m_list[m_count -1]; } |
| 155 | ATTR_HOT inline int count() const { return m_count; } |
| 156 | ATTR_HOT inline bool is_empty() const { return (m_count == 0); } |
| 157 | ATTR_HOT inline void clear() { m_count = 0; } |
| 158 | ATTR_HOT inline int capacity() const { return m_num_elements; } |
| 159 | |
| 160 | ATTR_COLD void clear_and_free() |
| 161 | { |
| 162 | for (_ListClass *i = m_list; i < m_list + m_count; i++) |
| 163 | { |
| 164 | delete *i; |
| 165 | } |
| 166 | clear(); |
| 167 | } |
| 168 | |
| 169 | ATTR_HOT inline _ListClass& operator[](const int & index) { return m_list[index]; } |
| 170 | ATTR_HOT inline const _ListClass& operator[](const int & index) const { return m_list[index]; } |
| 171 | |
| 172 | private: |
| 173 | int m_count; |
| 174 | _ListClass * m_list; |
| 175 | int m_num_elements; |
| 176 | }; |
| 177 | |
| 178 | // ---------------------------------------------------------------------------------------- |
| 179 | // pnamedlist_t: a simple list |
| 180 | // ---------------------------------------------------------------------------------------- |
| 181 | |
| 182 | template <class _C> |
| 183 | class pnamedlist_t : public plinearlist_t<_C> |
| 184 | { |
| 185 | public: |
| 186 | _C find(const pstring name) const |
| 187 | { |
| 188 | for (int i=0; i < this->count(); i++) |
| 189 | if (get_name((*this)[i]) == name) |
| 190 | return (*this)[i]; |
| 191 | return _C(NULL); |
| 192 | } |
| 193 | |
| 194 | void remove_by_name(const pstring name) |
| 195 | { |
| 196 | plinearlist_t<_C>::remove(find(name)); |
| 197 | } |
| 198 | |
| 199 | bool add(_C dev, bool allow_duplicate) |
| 200 | { |
| 201 | if (allow_duplicate) |
| 202 | plinearlist_t<_C>::add(dev); |
| 203 | else |
| 204 | { |
| 205 | if (!(this->find(get_name(dev)) == _C(NULL))) |
| 206 | return false; |
| 207 | plinearlist_t<_C>::add(dev); |
| 208 | } |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | private: |
| 213 | template <typename T> static const pstring get_name(T &elem) { return elem.name(); } |
| 214 | template <typename T> static const pstring get_name(T *elem) { return elem->name(); } |
| 215 | |
| 216 | }; |
| 217 | |
| 218 | |
| 219 | // ---------------------------------------------------------------------------------------- |
| 220 | // pstack_t: a simple stack |
| 221 | // ---------------------------------------------------------------------------------------- |
| 222 | |
| 223 | template <class _StackClass, int _NumElem = 128> |
| 224 | class pstack_t |
| 225 | { |
| 226 | public: |
| 227 | |
| 228 | ATTR_COLD pstack_t(int numElements = _NumElem) |
| 229 | : m_list(numElements) |
| 230 | { |
| 231 | } |
| 232 | |
| 233 | ATTR_COLD pstack_t(const pstack_t &rhs) |
| 234 | : m_list(rhs.m_list) |
| 235 | { |
| 236 | } |
| 237 | |
| 238 | ATTR_COLD pstack_t &operator=(const pstack_t &rhs) |
| 239 | { |
| 240 | m_list = rhs.m_list; |
| 241 | return *this; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | ATTR_COLD ~pstack_t() |
| 246 | { |
| 247 | } |
| 248 | |
| 249 | ATTR_HOT inline void push(const _StackClass &elem) |
| 250 | { |
| 251 | m_list.add(elem); |
| 252 | } |
| 253 | |
| 254 | ATTR_HOT inline _StackClass peek() const |
| 255 | { |
| 256 | return m_list[m_list.count() - 1]; |
| 257 | } |
| 258 | |
| 259 | ATTR_HOT inline _StackClass pop() |
| 260 | { |
| 261 | _StackClass ret = peek(); |
| 262 | m_list.remove_at(m_list.count() - 1); |
| 263 | return ret; |
| 264 | } |
| 265 | |
| 266 | ATTR_HOT inline int count() const { return m_list.count(); } |
| 267 | ATTR_HOT inline bool empty() const { return (m_list.count() == 0); } |
| 268 | ATTR_HOT inline void reset() { m_list.reset(); } |
| 269 | ATTR_HOT inline int capacity() const { return m_list.capacity(); } |
| 270 | |
| 271 | private: |
| 272 | plinearlist_t<_StackClass, _NumElem> m_list; |
| 273 | }; |
| 274 | |
| 275 | template <class _ListClass> |
| 276 | struct plinkedlist_element_t |
| 277 | { |
| 278 | plinkedlist_element_t() : m_next(NULL) {} |
| 279 | _ListClass * m_next; |
| 280 | |
| 281 | }; |
| 282 | |
| 283 | // ---------------------------------------------------------------------------------------- |
| 284 | // plinkedlist_t: a simple linked list |
| 285 | // ---------------------------------------------------------------------------------------- |
| 286 | |
| 287 | template <class _ListClass> |
| 288 | class plinkedlist_t |
| 289 | { |
| 290 | public: |
| 291 | |
| 292 | plinkedlist_t() : m_head(NULL) {} |
| 293 | |
| 294 | ATTR_HOT inline void insert(const _ListClass &before, _ListClass &elem) |
| 295 | { |
| 296 | if (m_head == &before) |
| 297 | { |
| 298 | elem.m_next = m_head; |
| 299 | m_head = elem; |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | _ListClass *p = m_head; |
| 304 | while (p != NULL) |
| 305 | { |
| 306 | if (p->m_next == &before) |
| 307 | { |
| 308 | elem->m_next = &before; |
| 309 | p->m_next = &elem; |
| 310 | return; |
| 311 | } |
| 312 | p = p->m_next; |
| 313 | } |
| 314 | assert_always(false, "element not found"); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | ATTR_HOT inline void insert(_ListClass &elem) |
| 319 | { |
| 320 | elem.m_next = m_head; |
| 321 | m_head = &elem; |
| 322 | } |
| 323 | |
| 324 | ATTR_HOT inline void add(_ListClass &elem) |
| 325 | { |
| 326 | _ListClass **p = &m_head; |
| 327 | while (*p != NULL) |
| 328 | { |
| 329 | p = &((*p)->m_next); |
| 330 | } |
| 331 | *p = &elem; |
| 332 | elem.m_next = NULL; |
| 333 | } |
| 334 | |
| 335 | ATTR_HOT inline void remove(const _ListClass &elem) |
| 336 | { |
| 337 | _ListClass **p = &m_head; |
| 338 | while (*p != &elem) |
| 339 | { |
| 340 | assert(*p != NULL); |
| 341 | p = &((*p)->m_next); |
| 342 | } |
| 343 | (*p) = elem.m_next; |
| 344 | } |
| 345 | |
| 346 | |
| 347 | ATTR_HOT static inline _ListClass *next(const _ListClass &elem) { return elem.m_next; } |
| 348 | ATTR_HOT static inline _ListClass *next(const _ListClass *elem) { return elem->m_next; } |
| 349 | ATTR_HOT inline _ListClass *first() const { return m_head; } |
| 350 | ATTR_HOT inline void clear() { m_head = NULL; } |
| 351 | ATTR_HOT inline bool is_empty() const { return (m_head == NULL); } |
| 352 | |
| 353 | private: |
| 354 | _ListClass *m_head; |
| 355 | }; |
| 356 | |
| 357 | #endif /* PLISTS_H_ */ |
trunk/src/emu/netlist/nl_lists.h
| r30606 | r30607 | |
| 12 | 12 | |
| 13 | 13 | #include "nl_config.h" |
| 14 | 14 | |
| 15 | | // ---------------------------------------------------------------------------------------- |
| 16 | | // netlist_list_t: a simple list |
| 17 | | // ---------------------------------------------------------------------------------------- |
| 18 | 15 | |
| 19 | | |
| 20 | | template <class _ListClass, int _NumElem = 128> |
| 21 | | class netlist_list_t |
| 22 | | { |
| 23 | | public: |
| 24 | | |
| 25 | | ATTR_COLD netlist_list_t(int numElements = _NumElem) |
| 26 | | { |
| 27 | | m_num_elements = numElements; |
| 28 | | m_list = new _ListClass[m_num_elements]; |
| 29 | | m_count = 0; |
| 30 | | } |
| 31 | | |
| 32 | | ATTR_COLD netlist_list_t(const netlist_list_t &rhs) |
| 33 | | { |
| 34 | | m_num_elements = rhs.capacity(); |
| 35 | | m_list = new _ListClass[m_num_elements]; |
| 36 | | m_count = 0; |
| 37 | | for (int i=0; i<rhs.count(); i++) |
| 38 | | { |
| 39 | | this->add(rhs[i]); |
| 40 | | } |
| 41 | | } |
| 42 | | |
| 43 | | ATTR_COLD netlist_list_t &operator=(const netlist_list_t &rhs) |
| 44 | | { |
| 45 | | this->clear(); |
| 46 | | for (int i=0; i<rhs.count(); i++) |
| 47 | | { |
| 48 | | this->add(rhs[i]); |
| 49 | | } |
| 50 | | return *this; |
| 51 | | } |
| 52 | | |
| 53 | | |
| 54 | | ATTR_COLD ~netlist_list_t() |
| 55 | | { |
| 56 | | delete[] m_list; |
| 57 | | } |
| 58 | | |
| 59 | | ATTR_HOT inline void add(const _ListClass &elem) |
| 60 | | { |
| 61 | | if (m_count >= m_num_elements) |
| 62 | | resize(m_num_elements * 2); |
| 63 | | |
| 64 | | m_list[m_count++] = elem; |
| 65 | | } |
| 66 | | |
| 67 | | ATTR_HOT inline void resize(const int new_size) |
| 68 | | { |
| 69 | | int cnt = count(); |
| 70 | | _ListClass *m_new = new _ListClass[new_size]; |
| 71 | | _ListClass *pd = m_new; |
| 72 | | |
| 73 | | for (_ListClass *ps = m_list; ps < m_list + cnt; ps++, pd++) |
| 74 | | *pd = *ps; |
| 75 | | delete[] m_list; |
| 76 | | m_list = m_new; |
| 77 | | m_count = cnt; |
| 78 | | m_num_elements = new_size; |
| 79 | | } |
| 80 | | |
| 81 | | ATTR_HOT inline void remove(const _ListClass &elem) |
| 82 | | { |
| 83 | | for (int i = 0; i < m_count; i++) |
| 84 | | { |
| 85 | | if (m_list[i] == elem) |
| 86 | | { |
| 87 | | m_count --; |
| 88 | | while (i < m_count) |
| 89 | | { |
| 90 | | m_list[i] = m_list[i+1]; |
| 91 | | i++; |
| 92 | | } |
| 93 | | return; |
| 94 | | } |
| 95 | | } |
| 96 | | } |
| 97 | | |
| 98 | | ATTR_HOT inline void remove_at(const int pos) |
| 99 | | { |
| 100 | | assert((pos>=0) && (pos<m_count)); |
| 101 | | m_count--; |
| 102 | | for (int i = pos; i < m_count; i++) |
| 103 | | { |
| 104 | | m_list[i] = m_list[i+1]; |
| 105 | | } |
| 106 | | } |
| 107 | | |
| 108 | | ATTR_HOT inline bool contains(const _ListClass &elem) const |
| 109 | | { |
| 110 | | for (_ListClass *i = m_list; i < m_list + m_count; i++) |
| 111 | | { |
| 112 | | if (*i == elem) |
| 113 | | return true; |
| 114 | | } |
| 115 | | return false; |
| 116 | | } |
| 117 | | |
| 118 | | ATTR_HOT inline int indexof(const _ListClass &elem) const |
| 119 | | { |
| 120 | | for (int i = 0; i < m_count; i++) |
| 121 | | { |
| 122 | | if (m_list[i] == elem) |
| 123 | | return i; |
| 124 | | } |
| 125 | | return -1; |
| 126 | | } |
| 127 | | |
| 128 | | ATTR_HOT inline const _ListClass *first() const { return ((m_count > 0) ? &m_list[0] : NULL ); } |
| 129 | | ATTR_HOT inline const _ListClass *next(const _ListClass *lc) const { return ((lc < last()) ? lc + 1 : NULL ); } |
| 130 | | ATTR_HOT inline const _ListClass *last() const { return &m_list[m_count -1]; } |
| 131 | | ATTR_HOT inline int count() const { return m_count; } |
| 132 | | ATTR_HOT inline bool is_empty() const { return (m_count == 0); } |
| 133 | | ATTR_HOT inline void clear() { m_count = 0; } |
| 134 | | ATTR_HOT inline int capacity() const { return m_num_elements; } |
| 135 | | |
| 136 | | ATTR_COLD void clear_and_free() |
| 137 | | { |
| 138 | | for (_ListClass *i = m_list; i < m_list + m_count; i++) |
| 139 | | { |
| 140 | | delete *i; |
| 141 | | } |
| 142 | | clear(); |
| 143 | | } |
| 144 | | |
| 145 | | ATTR_HOT inline _ListClass& operator[](const int & index) { return m_list[index]; } |
| 146 | | ATTR_HOT inline const _ListClass& operator[](const int & index) const { return m_list[index]; } |
| 147 | | |
| 148 | | private: |
| 149 | | int m_count; |
| 150 | | _ListClass * m_list; |
| 151 | | int m_num_elements; |
| 152 | | }; |
| 153 | | |
| 154 | 16 | // ---------------------------------------------------------------------------------------- |
| 155 | 17 | // timed queue |
| 156 | 18 | // ---------------------------------------------------------------------------------------- |
| r30606 | r30607 | |
| 255 | 117 | |
| 256 | 118 | }; |
| 257 | 119 | |
| 258 | | // ---------------------------------------------------------------------------------------- |
| 259 | | // netlist_stack_t: a simple stack |
| 260 | | // ---------------------------------------------------------------------------------------- |
| 261 | | |
| 262 | | |
| 263 | | template <class _StackClass, int _NumElem = 128> |
| 264 | | class netlist_stack_t |
| 265 | | { |
| 266 | | public: |
| 267 | | |
| 268 | | ATTR_COLD netlist_stack_t(int numElements = _NumElem) |
| 269 | | : m_list(numElements) |
| 270 | | { |
| 271 | | } |
| 272 | | |
| 273 | | ATTR_COLD netlist_stack_t(const netlist_stack_t &rhs) |
| 274 | | : m_list(rhs.m_list) |
| 275 | | { |
| 276 | | } |
| 277 | | |
| 278 | | ATTR_COLD netlist_stack_t &operator=(const netlist_stack_t &rhs) |
| 279 | | { |
| 280 | | m_list = rhs.m_list; |
| 281 | | return *this; |
| 282 | | } |
| 283 | | |
| 284 | | |
| 285 | | ATTR_COLD ~netlist_stack_t() |
| 286 | | { |
| 287 | | } |
| 288 | | |
| 289 | | ATTR_HOT inline void push(const _StackClass &elem) |
| 290 | | { |
| 291 | | m_list.add(elem); |
| 292 | | } |
| 293 | | |
| 294 | | ATTR_HOT inline _StackClass peek() const |
| 295 | | { |
| 296 | | return m_list[m_list.count() - 1]; |
| 297 | | } |
| 298 | | |
| 299 | | ATTR_HOT inline _StackClass pop() |
| 300 | | { |
| 301 | | _StackClass ret = peek(); |
| 302 | | m_list.remove_at(m_list.count() - 1); |
| 303 | | return ret; |
| 304 | | } |
| 305 | | |
| 306 | | ATTR_HOT inline int count() const { return m_list.count(); } |
| 307 | | ATTR_HOT inline bool empty() const { return (m_list.count() == 0); } |
| 308 | | ATTR_HOT inline void reset() { m_list.reset(); } |
| 309 | | ATTR_HOT inline int capacity() const { return m_list.capacity(); } |
| 310 | | |
| 311 | | private: |
| 312 | | netlist_list_t<_StackClass, _NumElem> m_list; |
| 313 | | }; |
| 314 | | |
| 315 | | template <class _ListClass> |
| 316 | | struct plinked_list_element |
| 317 | | { |
| 318 | | plinked_list_element() : m_next(NULL) {} |
| 319 | | _ListClass * m_next; |
| 320 | | |
| 321 | | }; |
| 322 | | |
| 323 | | template <class _ListClass> |
| 324 | | class plinked_list |
| 325 | | { |
| 326 | | public: |
| 327 | | |
| 328 | | plinked_list() : m_head(NULL) {} |
| 329 | | |
| 330 | | ATTR_HOT inline void insert(const _ListClass &before, _ListClass &elem) |
| 331 | | { |
| 332 | | if (m_head == &before) |
| 333 | | { |
| 334 | | elem.m_next = m_head; |
| 335 | | m_head = elem; |
| 336 | | } |
| 337 | | else |
| 338 | | { |
| 339 | | _ListClass *p = m_head; |
| 340 | | while (p != NULL) |
| 341 | | { |
| 342 | | if (p->m_next == &before) |
| 343 | | { |
| 344 | | elem->m_next = &before; |
| 345 | | p->m_next = &elem; |
| 346 | | return; |
| 347 | | } |
| 348 | | p = p->m_next; |
| 349 | | } |
| 350 | | assert_always(false, "element not found"); |
| 351 | | } |
| 352 | | } |
| 353 | | |
| 354 | | ATTR_HOT inline void insert(_ListClass &elem) |
| 355 | | { |
| 356 | | elem.m_next = m_head; |
| 357 | | m_head = &elem; |
| 358 | | } |
| 359 | | |
| 360 | | ATTR_HOT inline void add(_ListClass &elem) |
| 361 | | { |
| 362 | | _ListClass **p = &m_head; |
| 363 | | while (*p != NULL) |
| 364 | | { |
| 365 | | p = &((*p)->m_next); |
| 366 | | } |
| 367 | | *p = &elem; |
| 368 | | elem.m_next = NULL; |
| 369 | | } |
| 370 | | |
| 371 | | ATTR_HOT inline void remove(const _ListClass &elem) |
| 372 | | { |
| 373 | | _ListClass **p = &m_head; |
| 374 | | while (*p != &elem) |
| 375 | | { |
| 376 | | assert(*p != NULL); |
| 377 | | p = &((*p)->m_next); |
| 378 | | } |
| 379 | | (*p) = elem.m_next; |
| 380 | | } |
| 381 | | |
| 382 | | |
| 383 | | ATTR_HOT static inline _ListClass *next(const _ListClass &elem) { return elem.m_next; } |
| 384 | | ATTR_HOT static inline _ListClass *next(const _ListClass *elem) { return elem->m_next; } |
| 385 | | ATTR_HOT inline _ListClass *first() const { return m_head; } |
| 386 | | ATTR_HOT inline void clear() { m_head = NULL; } |
| 387 | | ATTR_HOT inline bool is_empty() const { return (m_head == NULL); } |
| 388 | | |
| 389 | | private: |
| 390 | | _ListClass *m_head; |
| 391 | | }; |
| 392 | | |
| 393 | 120 | #endif /* NLLISTS_H_ */ |