From f1db2b510e1396a932d46ae3a29eb0a9deb8dfcb Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Sun, 24 Sep 2023 11:08:46 +0200 Subject: [PATCH 1/3] Remove `declarePtrList` and `declareList` (#2514) A bunch of code cleanups: * Less usage of declarePtrList * NetConList * Remove GLineRecordList * LineList * HandlerList * More range-based loops * use std::find intensively --- src/ivoc/checkpnt.cpp | 8 - src/ivoc/graph.cpp | 157 ++++-------- src/ivoc/graph.h | 4 +- src/ivoc/nrnsymdiritem.h | 4 +- src/ivoc/ochelp.cpp | 118 +-------- src/ivoc/ocinput.h | 59 ----- src/ivoc/ocpicker.cpp | 41 ++-- src/ivoc/ocpicker.h | 6 +- src/ivoc/scene.cpp | 227 ++++++------------ src/ivoc/scenepic.cpp | 36 ++- src/ivoc/scenevie.h | 6 +- src/ivoc/symdir.cpp | 83 +++---- src/ivoc/xmenu.cpp | 144 ++++++----- src/ivoc/xmenu.h | 9 +- src/nrncvode/cvodeobj.h | 5 +- src/nrncvode/netcvode.cpp | 107 ++++----- src/nrncvode/netcvode.h | 9 +- src/nrncvode/occvode.cpp | 25 +- src/nrncvode/vrecitem.h | 2 - src/nrniv/bbsavestate.cpp | 1 - src/nrniv/glinerec.cpp | 44 ++-- .../callbacks/nrncore_callbacks.cpp | 28 +-- src/nrniv/prcellstate.cpp | 15 +- src/nrniv/pysecname2sec.cpp | 6 +- src/nrniv/savstate.cpp | 21 +- 25 files changed, 386 insertions(+), 779 deletions(-) delete mode 100644 src/ivoc/ocinput.h diff --git a/src/ivoc/checkpnt.cpp b/src/ivoc/checkpnt.cpp index 13d2be314f..4ff1749d85 100644 --- a/src/ivoc/checkpnt.cpp +++ b/src/ivoc/checkpnt.cpp @@ -248,9 +248,6 @@ void PortablePointer::set(void* address, int type, unsigned long s) { } PortablePointer::~PortablePointer() {} -declareList(PPList, PortablePointer) -implementList(PPList, PortablePointer) - class OcCheckpoint { public: OcCheckpoint(); @@ -297,7 +294,6 @@ class OcCheckpoint { int cnt_; int nobj_; Objects* otable_; - PPList* ppl_; bool (OcCheckpoint::*func_)(Symbol*); Symbols* stable_; #if HAVE_XDR @@ -413,7 +409,6 @@ int hoc_readcheckpoint(char* fname) { } OcCheckpoint::OcCheckpoint() { - ppl_ = NULL; func_ = NULL; stable_ = NULL; otable_ = NULL; @@ -430,9 +425,6 @@ OcCheckpoint::OcCheckpoint() { } OcCheckpoint::~OcCheckpoint() { - if (ppl_) { - delete ppl_; - } if (stable_) { delete stable_; } diff --git a/src/ivoc/graph.cpp b/src/ivoc/graph.cpp index e0fdda4e48..b073a0f350 100644 --- a/src/ivoc/graph.cpp +++ b/src/ivoc/graph.cpp @@ -1359,7 +1359,6 @@ void GraphItem::pick(Canvas* c, const Allocation& a, int depth, Hit& h) { } // Graph -implementPtrList(LineList, GraphLine); declareActionCallback(Graph); implementActionCallback(Graph); @@ -1452,8 +1451,8 @@ Graph::Graph(bool b) Graph::~Graph() { // printf("~Graph\n"); - for (long i = 0; i < line_list_.count(); ++i) { - Resource::unref(line_list_.item(i)); + for (auto& item: line_list_) { + Resource::unref(item); } Resource::unref(keep_lines_toggle_); Resource::unref(x_); @@ -1495,36 +1494,31 @@ void Graph::help() { } void Graph::delete_label(GLabel* glab) { - GraphLine* glin = NULL; - GlyphIndex i, cnt; - cnt = line_list_.count(); - for (i = 0; i < cnt; ++i) { - if (line_list_.item(i)->label() == glab) { - glin = line_list_.item(i); - break; - } - } - if (glin) { - line_list_.remove(i); + GraphLine* glin = nullptr; + auto it = std::find_if(line_list_.begin(), line_list_.end(), [&](const auto& e) { + return e->label() == glab; + }); + if (it != line_list_.end()) { + glin = *it; + line_list_.erase(it); glin->unref(); - i = glyph_index(glin); - remove(i); + GlyphIndex index = glyph_index(glin); + remove(index); } if (!glin) { // but possibly a vector line - cnt = count(); - for (i = 0; i < cnt; ++i) { - GraphItem* gi = (GraphItem*) component(i); + for (GlyphIndex index = 0; index < count(); ++index) { + GraphItem* gi = (GraphItem*) component(index); if (gi->is_polyline()) { GPolyLine* gpl = (GPolyLine*) gi->body(); if (gpl->label() == glab) { - remove(i); + remove(index); break; } } } } - i = glyph_index(glab); - remove(i); + GlyphIndex index = glyph_index(glab); + remove(index); } GLabel* Graph::new_proto_label() const { @@ -1532,18 +1526,17 @@ GLabel* Graph::new_proto_label() const { } bool Graph::change_label(GLabel* glab, const char* text, GLabel* gl) { - GlyphIndex i, cnt = line_list_.count(); if (strcmp(glab->text(), text)) { - for (i = 0; i < cnt; ++i) { - if (line_list_.item(i)->label() == glab) { - if (!line_list_.item(i)->change_expr(text, &symlist_)) { + for (auto& line: line_list_) { + if (line->label() == glab) { + if (!line->change_expr(text, &symlist_)) { return false; } } } glab->text(text); } - i = glyph_index(glab); + GlyphIndex i = glyph_index(glab); if (glab->fixtype() != gl->fixtype()) { if (gl->fixed()) { glab->fixed(gl->scale()); @@ -1576,8 +1569,8 @@ void Graph::change_line_color(GPolyLine* glin) { } GlyphIndex Graph::glyph_index(const Glyph* gl) { - GlyphIndex i, cnt = count(); - for (i = 0; i < cnt; ++i) { + GlyphIndex cnt = count(); + for (GlyphIndex i = 0; i < cnt; ++i) { Glyph* g = ((GraphItem*) component(i))->body(); if (g == gl) { return i; @@ -1597,13 +1590,12 @@ std::ostream* Graph::ascii() { } void Graph::draw(Canvas* c, const Allocation& a) const { - long i, cnt = line_list_.count(); // if (!extension_flushed_) { Scene::draw(c, a); //} if (extension_flushed_) { - for (i = 0; i < cnt; ++i) { - line_list_.item(i)->extension()->draw(c, a); + for (auto& item: line_list_) { + item->extension()->draw(c, a); } } if (ascii_) { @@ -1612,7 +1604,7 @@ void Graph::draw(Canvas* c, const Allocation& a) const { } void Graph::ascii_save(std::ostream& o) const { - long line, lcnt = line_list_.count(); + long line, lcnt = line_list_.size(); int i, dcnt; if (lcnt == 0 || !x_ || family_label_) { // tries to print in matrix form is labels and each line the same @@ -1623,8 +1615,8 @@ void Graph::ascii_save(std::ostream& o) const { } if (lcnt) { o << lcnt << " addvar/addexpr lines:"; - for (i = 0; i < lcnt; ++i) { - o << " " << line_list_.item(i)->name(); + for (const auto& line: line_list_) { + o << " " << line->name(); } o << std::endl; } @@ -1730,15 +1722,15 @@ void Graph::ascii_save(std::ostream& o) const { } else { o << "x"; } - for (line = 0; line < lcnt; ++line) { - o << " " << line_list_.item(line)->name(); + for (const auto& item: line_list_) { + o << " " << item->name(); } o << std::endl; dcnt = x_->count(); for (i = 0; i < dcnt; ++i) { o << x_->get_val(i); - for (line = 0; line < lcnt; ++line) { - o << "\t" << line_list_.item(line)->y(i); + for (const auto& item: line_list_) { + o << "\t" << item->y(i); } o << std::endl; } @@ -1810,10 +1802,6 @@ void Graph::wholeplot(Coord& l, Coord& b, Coord& r, Coord& t) const { GraphLine* gl; l = b = 1e9; r = t = -1e9; -#if 0 - cnt = line_list_.count(); - if (!cnt) { -#endif cnt = count(); for (i = 0; i < cnt; ++i) { GraphItem* gi = (GraphItem*) component(i); @@ -1854,19 +1842,6 @@ void Graph::wholeplot(Coord& l, Coord& b, Coord& r, Coord& t) const { t = -1e30; } return; -#if 0 - } - for (i = 0; i < cnt; ++i) { - gl = line_list_.item(i); - l = std::min(l, gl->x_data()->min()); - b = std::min(b, gl->y_data()->min()); - r = std::max(r, gl->x_data()->max()); - t = std::max(t, gl->y_data()->max()); - } - if (l >= r || b >= t) { - Scene::wholeplot(l, b, r, t); - } -#endif } void Graph::axis(DimensionName d, @@ -1919,7 +1894,7 @@ GraphLine* Graph::add_var(const char* expr, ((GraphItem*) component(i))->save(false); glab->color(color); gl->label(glab); - line_list_.append(gl); + line_list_.push_back(gl); gl->ref(); Scene::append(new GPolyLineItem(gl)); return gl; @@ -1955,10 +1930,8 @@ void Graph::begin() { keep_lines(); family_value(); } - long count = line_list_.count(); int hem = hoc_execerror_messages; - for (long i = 0; i < count; ++i) { - GraphLine* gl = line_list_.item(i); + for (auto& gl: line_list_) { gl->erase(); if (family_on_) { ((GPolyLine*) gl)->color(color()); @@ -1987,9 +1960,8 @@ void Graph::plot(float x) { } else { x_->add(x); } - long count = line_list_.count(); - for (long i = 0; i < count; ++i) { - line_list_.item(i)->plot(); + for (auto& item: line_list_) { + item->plot(); } } void Graph::begin_line(const char* s) { @@ -2021,37 +1993,23 @@ void Graph::flush() { // damage_all();//too conservative. plots everything every time } void Graph::fast_flush() { -#if 0 - long i, cnt = line_list_.count(); - for (i=0; i < cnt; ++i) { - modified( - glyph_index( - line_list_.item(i)->extension() - ) - ); - } -#else - long i, cnt = line_list_.count(); - for (i = 0; i < cnt; ++i) { - line_list_.item(i)->extension()->damage(this); + for (auto& item: line_list_) { + item->extension()->damage(this); } -#endif extension_flushed_ = true; } void Graph::extension_start() { x_->running_start(); - long i, cnt = line_list_.count(); - for (i = 0; i < cnt; ++i) { - line_list_.item(i)->extension_start(); + for (auto& item: line_list_) { + item->extension_start(); } extension_flushed_ = false; } void Graph::extension_continue() { x_->running_start(); - long i, cnt = line_list_.count(); - for (i = 0; i < cnt; ++i) { - line_list_.item(i)->extension_continue(); + for (auto& item: line_list_) { + item->extension_continue(); } extension_flushed_ = false; } @@ -2112,28 +2070,21 @@ void Graph::cross_action(char c, Coord x, Coord y) { } } void Graph::erase() { - long count = line_list_.count(); - for (long i = 0; i < count; ++i) { - line_list_.item(i)->erase(); + for (auto& item: line_list_) { + item->erase(); } damage_all(); } void Graph::erase_all() { - int i; -#if 0 - while(count()) { - remove(0); - } -#else - for (i = count() - 1; i >= 0; --i) { + for (int i = count() - 1; i >= 0; --i) { remove(i); } -#endif - while (line_list_.count()) { - Resource::unref(line_list_.item(0)); - line_list_.remove(0); + for (auto& item: line_list_) { + Resource::unref(item); } + line_list_.clear(); + line_list_.shrink_to_fit(); label_n_ = 0; } void Graph::family_value() { @@ -2204,9 +2155,7 @@ void Graph::family(bool i) { } else { family_on_ = false; keep_lines_toggle_->set(TelltaleState::is_chosen, false); - long count = line_list_.count(); - for (long i = 0; i < count; ++i) { - GraphLine* gl = line_list_.item(i); + for (auto& gl: line_list_) { gl->color(gl->save_color()); gl->brush(gl->save_brush()); } @@ -2322,18 +2271,14 @@ void Graph::erase_lines() { } } } - cnt = line_list_.count(); - for (i = 0; i < cnt; ++i) { - GraphLine* gl = line_list_.item(i); + for (auto& gl: line_list_) { gl->label()->erase_flag(false); } cnt = count(); for (i = cnt - 1; i >= 0; --i) { ((GraphItem*) component(i))->erase(this, i, GraphItem::ERASE_LINE); } - cnt = line_list_.count(); - for (i = 0; i < cnt; ++i) { - GraphLine* gl = line_list_.item(i); + for (auto& gl: line_list_) { Scene::append(new GPolyLineItem(gl)); } erase(); diff --git a/src/ivoc/graph.h b/src/ivoc/graph.h index 4b9284d67b..69b2b7b48f 100644 --- a/src/ivoc/graph.h +++ b/src/ivoc/graph.h @@ -23,8 +23,6 @@ class LineExtension; class TelltaleState; struct Object; -declarePtrList(LineList, GraphLine); - // all Glyphs added to Graph must be enclosed in a GraphItem class GraphItem: public MonoGlyph { public: @@ -166,7 +164,7 @@ class Graph: public Scene { // Scene of GraphLines labels and polylines private: Symlist* symlist_; - LineList line_list_; + std::vector line_list_; int loc_; DataVec* x_; bool extension_flushed_; diff --git a/src/ivoc/nrnsymdiritem.h b/src/ivoc/nrnsymdiritem.h index a5f7424235..6f395aacad 100644 --- a/src/ivoc/nrnsymdiritem.h +++ b/src/ivoc/nrnsymdiritem.h @@ -37,8 +37,6 @@ class SymbolItem { int whole_array_; }; -declarePtrList(SymbolList, SymbolItem); - -void nrn_symdir_load_pysec(SymbolList& sl, void*); +void nrn_symdir_load_pysec(std::vector& sl, void*); #endif diff --git a/src/ivoc/ochelp.cpp b/src/ivoc/ochelp.cpp index 347e4435b6..33c6c6974e 100644 --- a/src/ivoc/ochelp.cpp +++ b/src/ivoc/ochelp.cpp @@ -26,51 +26,9 @@ static FILE* help_pipe; extern const char* hoc_current_xopen(); -declareList(CopyStringList, CopyString) -implementList(CopyStringList, CopyString) - -static CopyStringList* filequeue; - void ivoc_help(const char* s) { -#if 1 // printf("online help not currently working\n"); return; -#else - char buf[256]; - strncpy(buf, s + 4, 256); - char* p; - for (p = buf; *p; ++p) { // eliminate trailing newline - if (*p == '\n') { - *p = '\0'; - break; - } - } - for (p = buf; *p; ++p) { // start at first character - if (!isspace(*p)) { - break; - } - } - // queue up the help files if haven't invoked help - if (!help_pipe) { - if (!filequeue) { - filequeue = new CopyStringList(); - } - if (strncmp(p, "?0", 2) == 0) { - Sprintf(buf, "?0 %s", hoc_current_xopen()); - String str(buf); - filequeue->append(str); - return; - } else if (strncmp(p, "?1", 2) == 0) { - filequeue->append(p); - return; - } - } - if (*p) { - Oc::help(p); - } else { - Oc::help("Help_root"); - } -#endif } static void readmore() { @@ -90,86 +48,12 @@ static void readmore() { #if !defined(WIN32) void Oc::help(const char* s) { -#if 1 printf("online help not currently working\n"); -#else - if (help_pipe && ferror(help_pipe)) { - printf( - "error on the help pipe, restarting\n\ -but will be missing this sessions hoc help text\n"); - pclose(help_pipe); - help_pipe = NULL; - } - if (!help_pipe) { - printf("Starting the help system\n"); - char buf[200]; - Sprintf(buf, "%s/ochelp", "$NEURONHOME/bin/$CPU"); - if ((help_pipe = popen(buf, "w")) == (FILE*) 0) { - printf("Could not start %s\n", buf); - } - // printf("help_pipe = %p\n", help_pipe); - readmore(); - if (filequeue) { - for (long i = 0; i < filequeue->count(); ++i) { - fprintf(help_pipe, "%s\n", filequeue->item_ref(i).string()); - } - filequeue->remove_all(); - } - } - if (help_pipe) { - // printf("|%s|\n", s); - if (strncmp(s, "?0", 2) == 0) { - char buf[1024]; - Sprintf(buf, "?0 %s", hoc_current_xopen()); - fprintf(help_pipe, "%s\n", buf); - } else { - fprintf(help_pipe, "%s\n", s); - } - fflush(help_pipe); - } -#endif } #endif #if defined(WIN32) - -void Oc::help(const char* s) { -#if 0 -#ifndef MINGW - static bool ran_ochelp = false; - char buf[1024]; - nrnbbs_connect(); // benign if already connected - if (!nrnbbs_connected()) { - printf("Could not connect to nrnbbs service\n"); - return; - } - if (!ran_ochelp && !nrnbbs_look("ochelp running")) { - ran_ochelp = true; - printf("Starting the help system\n"); - nrnbbs_exec("ochelp"); - }else if (!nrnbbs_look("ochelp running")) { - printf("proper ochelp version not running\n"); - return; - } - - readmore(); - if (filequeue) { - for (long i = 0; i < filequeue->count(); ++i) { -Sprintf(buf,"%s\n", filequeue->item_ref(i).string()); - nrnbbs_post_string("ochelp", buf); - } - filequeue->remove_all(); - } - - if (strncmp(s, "?0", 2) == 0) { - Sprintf(buf,"?0 %s", hoc_current_xopen()); - nrnbbs_post_string("ochelp", buf); - }else{ - nrnbbs_post_string("ochelp", s); - } -#endif // MINGW -#endif -} +void Oc::help(const char* s) {} #endif // WIN32 void Oc::helpmode(bool b) { diff --git a/src/ivoc/ocinput.h b/src/ivoc/ocinput.h deleted file mode 100644 index 74d956d512..0000000000 --- a/src/ivoc/ocinput.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef ocinput_h -#define ocinput_h - -#include -#include -#include - -class HandlerList; - -public -StandardInputHandler: public InputHandler { - public: - StandardInputHandler(Glyph*, Style*); - virtual ~StandardInputHandler(); - - virtual void bind_select(Handler * h) { - bind_press(Event::left, h); - } - virtual void bind_adjust(Handler * h) { - bind_press(Event::middle, h); - } - virtual void bind_menu(Handler * h) { - bind_press(Event::right, h); - } - - virtual void move(const Event& e) { - mouse(0, e); - } - virtual void press(const Event& e) { - mouse(1, e); - } - virtual void drag(const Event& e) { - mouse(2, e); - } - virtual void release(const Event& e) { - mouse(3, e); - } - void mouse(int, const Event&); - - void bind_move(EventButton eb, Handler * h) { - bind(0, eb, h); - } - void bind_press(EventButton eb, Handler * h) { - bind(0, eb, h); - } - void bind_drag(EventButton eb, Handler * h) { - bind(0, eb, h); - } - void bind_release(EventButton eb, Handler * h) { - bind(0, eb, h); - } - void bind(int, EventButton eb, Handler* h) { - bind(0, eb, h); - } - void remove_all(EventButton); - - private: - HandlerList* handlers_[4]; -}; diff --git a/src/ivoc/ocpicker.cpp b/src/ivoc/ocpicker.cpp index 1896d3fe64..76da6bee49 100644 --- a/src/ivoc/ocpicker.cpp +++ b/src/ivoc/ocpicker.cpp @@ -36,20 +36,16 @@ ButtonHandler::~ButtonHandler() { Resource::unref(rband_); } -declarePtrList(HandlerList, ButtonHandler); -implementPtrList(HandlerList, ButtonHandler); - StandardPicker::StandardPicker() { ms_ = unknown; for (int i = 0; i < unknown; ++i) { - handlers_[i] = new HandlerList(1); + handlers_[i] = new std::vector(); } } StandardPicker::~StandardPicker() { for (int i = 0; i < unknown; ++i) { - long cnt = handlers_[i]->count(); - for (long j = 0; j < cnt; j++) { - delete handlers_[i]->item(j); + for (auto& item: *handlers_[i]) { + delete item; } delete handlers_[i]; } @@ -65,15 +61,13 @@ bool StandardPicker::pick(Canvas* c, Glyph* glyph, int depth, Hit& h) { } event(e); - long cnt = handlers_[ms_]->count(); - for (long i = 0; i < cnt; ++i) { - ButtonHandler& b = *handlers_[ms_]->item(i); - if (b.eb_ == Event::any || b.eb_ == mb_) { - if (b.handler_) { - h.target(depth, glyph, 0, b.handler_); + for (const auto& b: *handlers_[ms_]) { + if (b->eb_ == Event::any || b->eb_ == mb_) { + if (b->handler_) { + h.target(depth, glyph, 0, b->handler_); } else { - b.rband_->canvas(c); - h.target(depth, glyph, 0, b.rband_); + b->rband_->canvas(c); + h.target(depth, glyph, 0, b->rband_); } return true; } @@ -109,13 +103,12 @@ void StandardPicker::event(const Event& e) { } void StandardPicker::unbind(int m, EventButton eb) { - long cnt = handlers_[m]->count(); - long i, j; - for (i = 0, j = 0; i < cnt; ++i) { - ButtonHandler& b = *handlers_[m]->item(j); - if (b.eb_ == Event::any || b.eb_ == eb) { - delete handlers_[m]->item(j); - handlers_[m]->remove(j); + long cnt = handlers_[m]->size(); + for (long i = 0, j = 0; i < cnt; ++i) { + ButtonHandler* b = handlers_[m]->at(j); + if (b->eb_ == Event::any || b->eb_ == eb) { + delete b; + handlers_[m]->erase(handlers_[m]->begin() + j); } else { ++j; } @@ -125,7 +118,7 @@ void StandardPicker::unbind(int m, EventButton eb) { void StandardPicker::bind(int m, EventButton eb, OcHandler* h) { unbind(m, eb); if (h) { - handlers_[m]->append(new ButtonHandler(eb, h)); + handlers_[m]->push_back(new ButtonHandler(eb, h)); } } @@ -133,7 +126,7 @@ void StandardPicker::bind_press(EventButton eb, Rubberband* rb) { int m = 1; unbind(m, eb); if (rb) { - handlers_[m]->append(new ButtonHandler(eb, rb)); + handlers_[m]->push_back(new ButtonHandler(eb, rb)); } } diff --git a/src/ivoc/ocpicker.h b/src/ivoc/ocpicker.h index daa2323cbe..c885d12eb6 100644 --- a/src/ivoc/ocpicker.h +++ b/src/ivoc/ocpicker.h @@ -1,15 +1,17 @@ #ifndef ocpicker_h #define ocpicker_h +#include + #include #include #include #include "rubband.h" -class HandlerList; class Canvas; class Allocation; class Hit; +class ButtonHandler; /* steer to the right method in response to a mouse action */ @@ -66,6 +68,6 @@ class StandardPicker { enum { motion, press, drag, release, unknown }; State ms_; EventButton mb_; - HandlerList* handlers_[unknown]; + std::vector* handlers_[unknown]; }; #endif diff --git a/src/ivoc/scene.cpp b/src/ivoc/scene.cpp index 1717c5c895..406846ad73 100644 --- a/src/ivoc/scene.cpp +++ b/src/ivoc/scene.cpp @@ -92,15 +92,8 @@ SceneInfo::SceneInfo(Glyph* g, Coord x, Coord y) { status_ = SceneInfoShowing; } -declareList(SceneInfo_List, SceneInfo); -implementList(SceneInfo_List, SceneInfo); -declarePtrList(XYView_PtrList, XYView); -implementPtrList(XYView_PtrList, XYView); -declarePtrList(Scene_PtrList, Scene); -implementPtrList(Scene_PtrList, Scene); - static const float epsilon = 0.001; -static Scene_PtrList* scene_list; +static std::vector* scene_list; Coord Scene::mbs_; Coord Scene::mbs() const { @@ -112,7 +105,7 @@ static const Color* mb_color_; void Scene::check_allocation(GlyphIndex index) { // will not redraw unless allocation is changed // use damage(index) to do a definite redraw on a constant allocation - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = (*info_)[index]; Requisition s; info.glyph_->request(s); Allocation a_old = info.allocation_; @@ -139,7 +132,7 @@ void Scene::check_allocation(GlyphIndex index) { void Scene::modified(GlyphIndex index) { // will not redraw unless allocation is changed // use damage(index) to do a definite redraw on a constant allocation - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = (*info_)[index]; Requisition s; info.glyph_->request(s); Allocation a_old = info.allocation_; @@ -199,8 +192,8 @@ Scene::Scene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph* bg) tool_ = NOTOOL; background_ = NULL; background(bg); - info_ = new SceneInfo_List(); - views_ = new XYView_PtrList(); + info_ = new std::vector(); + views_ = new std::vector(); x1_orig_ = x1; x2_orig_ = x2; y1_orig_ = y1; @@ -210,7 +203,7 @@ Scene::Scene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph* bg) y1_ = y1; y2_ = y2; if (!scene_list) { - scene_list = new Scene_PtrList; + scene_list = new std::vector(); } if (mbs_ == 0.) { Session::instance()->style()->find_attribute("scene_menu_box_size", mbs_); @@ -224,7 +217,7 @@ Scene::Scene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph* bg) } // printf ("mbs_=%g\n", mbs_); } - scene_list->append(this); + scene_list->push_back(this); picker_ = NULL; mark_ = false; hoc_obj_ptr_ = NULL; @@ -266,15 +259,14 @@ void Scene::help() { } XYView* Scene::sceneview(int i) const { - if (views_->count()) { - return views_->item(i); + if (views_->size() > i) { + return views_->at(i); } else { return NULL; } } void Scene::new_size(Coord x1, Coord y1, Coord x2, Coord y2) { -#if 1 if (x1 == x2) { x1 -= 1.; x2 += 1.; @@ -287,11 +279,10 @@ void Scene::new_size(Coord x1, Coord y1, Coord x2, Coord y2) { y1_ = y1; x2_ = x2; y2_ = y2; -#endif -#if 1 + // resize first view - if (views_->count()) { - XYView* v = views_->item(0); + if (!views_->empty()) { + XYView* v = views_->front(); // v->origin(x1, y1); // v->x_span(x2 - x1); // v->y_span(y2 - y1); @@ -300,34 +291,17 @@ void Scene::new_size(Coord x1, Coord y1, Coord x2, Coord y2) { v->damage_all(); } } -#endif -#if 0 - //resize all views to correspond to the new size - damage_all(); - for (long i = 0; i < views_->count(); ++i) { - XYView* v = views_->item(i); - v->x_span(x2 - x1); - v->y_span(y2 - y1); - v->origin(x1, y1); - } - GlyphIndex count = info_->count(); - for (i=0; i < count; ++i) { - modified(i); - } -#endif notify(); } Scene::~Scene() { // printf("~Scene\n"); - GlyphIndex count = info_->count(); - for (GlyphIndex i = 0; i < count; ++i) { - SceneInfo& info = info_->item_ref(i); - Resource::unref(info.glyph_); + for (auto& item: *info_) { + Resource::unref(item.glyph_); } delete info_; - info_ = NULL; + info_ = nullptr; Resource::unref(background_); if (picker_) { delete picker_; @@ -335,21 +309,11 @@ Scene::~Scene() { // only xyview can manipulate this list. when xyview is deleted it // will remove itself from this list. There is no way to delete scene // without first deleteing all the views. - assert(views_->count() == 0); + assert(views_->empty()); -#if 0 - count = views_->count(); - for (i = 0; i < count; ++i) { - XYView* view = views_->item(i); - Resource::unref(view); - } - views_->remove_all(); -#endif - for (long j = 0; j < scene_list->count(); ++j) { - if (scene_list->item(j) == this) { - scene_list->remove(j); - break; - } + if (auto it = std::find(scene_list->begin(), scene_list->end(), this); + it != scene_list->end()) { + scene_list->erase(it); } delete views_; } @@ -362,29 +326,23 @@ void Scene::wholeplot(Coord& l, Coord& b, Coord& r, Coord& t) const { } int Scene::view_count() const { - return int(views_->count()); + return int(views_->size()); } void Scene::append_view(XYView* v) { - views_->append(v); + views_->push_back(v); // Resource::ref(v); } void Scene::remove_view(XYView* v) { - long count = views_->count(); - for (long i = 0; i < count; ++i) { - if (v == views_->item(i)) { - views_->remove(i); - break; - // Resource::unref(v); - } + if (auto it = std::find(views_->begin(), views_->end(), v); it != views_->end()) { + views_->erase(it); } } void Scene::dismiss() { - long count = views_->count(); - for (long i = count - 1; i >= 0; --i) { - OcViewGlyph* g = views_->item(i)->parent(); + for (auto it = views_->rbegin(); it != views_->rend(); ++it) { + OcViewGlyph* g = (*it)->parent(); if (g && g->has_window()) { g->window()->dismiss(); g->window(NULL); @@ -393,13 +351,11 @@ void Scene::dismiss() { } void Scene::damage(GlyphIndex index) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = info_->at(index); Allocation& a = info.allocation_; - long count = views_->count(); - for (long i = 0; i < count; ++i) { + for (auto& item: *views_) { // printf("damage view\n"); - XYView* view = views_->item(i); - view->damage(info.glyph_, + item->damage(info.glyph_, a, (info.status_ & SceneInfoFixed) != 0, (info.status_ & SceneInfoViewFixed) != 0); @@ -407,11 +363,9 @@ void Scene::damage(GlyphIndex index) { } void Scene::damage(GlyphIndex index, const Allocation& a) { - SceneInfo& info = info_->item_ref(index); - long count = views_->count(); - for (long i = 0; i < count; ++i) { - XYView* view = views_->item(i); - view->damage(info.glyph_, + SceneInfo& info = info_->at(index); + for (auto& item: *views_) { + item->damage(info.glyph_, a, (info.status_ & SceneInfoFixed) != 0, (info.status_ & SceneInfoViewFixed) != 0); @@ -419,24 +373,21 @@ void Scene::damage(GlyphIndex index, const Allocation& a) { } void Scene::damage_all() { - for (long i = 0; i < views_->count(); ++i) { - XYView* v = views_->item(i); - if (v->canvas()) { - v->damage_all(); + for (auto& item: *views_) { + if (item->canvas()) { + item->damage_all(); } } } void Scene::damage(Coord x1, Coord y1, Coord x2, Coord y2) { - long count = views_->count(); - for (long i = 0; i < count; ++i) { - XYView* view = views_->item(i); - view->damage(x1, y1, x2, y2); + for (auto& item: *views_) { + item->damage(x1, y1, x2, y2); } } void Scene::show(GlyphIndex index, bool showing) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = info_->at(index); if (((info.status_ & SceneInfoShowing) == SceneInfoShowing) != showing) { // printf("show %d showing=%d want %d\n", index, (info.status_ & SceneInfoHidden) == 0, // showing); info.pinfo(); @@ -450,11 +401,11 @@ void Scene::show(GlyphIndex index, bool showing) { } bool Scene::showing(GlyphIndex index) const { - return (info_->item_ref(index).status_ & SceneInfoShowing) != 0; + return (info_->at(index).status_ & SceneInfoShowing) != 0; } void Scene::move(GlyphIndex index, Coord x, Coord y) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = info_->at(index); float x1 = info.x_, y1 = info.y_; info.x_ = x; info.y_ = y; @@ -465,21 +416,21 @@ void Scene::move(GlyphIndex index, Coord x, Coord y) { } void Scene::location(GlyphIndex index, Coord& x, Coord& y) const { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = info_->at(index); x = info.x_; y = info.y_; } GlyphIndex Scene::count() const { - return info_->count(); + return info_->size(); } Glyph* Scene::component(GlyphIndex index) const { - return info_->item_ref(index).glyph_; + return info_->at(index).glyph_; } void Scene::allotment(GlyphIndex index, DimensionName res, Allotment& a) const { - a = info_->item_ref(index).allocation_.allotment(res); + a = info_->at(index).allocation_.allotment(res); } void Scene::change(GlyphIndex index) { @@ -487,7 +438,7 @@ void Scene::change(GlyphIndex index) { } void Scene::change_to_fixed(GlyphIndex index, XYView* v) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = info_->at(index); if (info.status_ & SceneInfoViewFixed) { info.status_ &= ~SceneInfoViewFixed; printf("changed to fixed\n"); @@ -499,7 +450,7 @@ void Scene::change_to_fixed(GlyphIndex index, XYView* v) { } void Scene::change_to_vfixed(GlyphIndex index, XYView* v) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = info_->at(index); if (!(info.status_ & SceneInfoViewFixed)) { info.status_ |= SceneInfoViewFixed; info.status_ |= SceneInfoFixed; @@ -512,51 +463,48 @@ void Scene::change_to_vfixed(GlyphIndex index, XYView* v) { void Scene::append(Glyph* glyph) { SceneInfo info(glyph); - info_->append(info); + info_->push_back(info); Resource::ref(glyph); - // modified(info_->count() - 1); } void Scene::append_fixed(Glyph* glyph) { SceneInfo info(glyph); info.status_ |= SceneInfoFixed; - info_->append(info); + info_->push_back(info); Resource::ref(glyph); - // modified(info_->count() - 1); } void Scene::append_viewfixed(Glyph* glyph) { // printf("Scene::append_viewfixed\n"); SceneInfo info(glyph); info.status_ |= SceneInfoFixed | SceneInfoViewFixed; - info_->append(info); + info_->push_back(info); Resource::ref(glyph); - // modified(info_->count() - 1); } void Scene::prepend(Glyph* glyph) { SceneInfo info(glyph); - info_->prepend(info); + info_->insert(info_->begin(), info); Resource::ref(glyph); // modified(0); } void Scene::insert(GlyphIndex index, Glyph* glyph) { SceneInfo info(glyph); - info_->insert(index, info); + info_->insert(info_->begin() + index, info); Resource::ref(glyph); // modified(index); } void Scene::remove(GlyphIndex index) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = info_->at(index); damage(index); Resource::unref(info.glyph_); - info_->remove(index); + info_->erase(info_->begin() + index); } void Scene::replace(GlyphIndex index, Glyph* glyph) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = info_->at(index); damage(index); Resource::ref(glyph); Resource::unref(info.glyph_); @@ -565,10 +513,8 @@ void Scene::replace(GlyphIndex index, Glyph* glyph) { } GlyphIndex Scene::glyph_index(const Glyph* g) { - GlyphIndex i, cnt = info_->count(); - ; - for (i = 0; i < cnt; ++i) { - if (info_->item_ref(i).glyph_ == g) { + for (std::size_t i = 0; i < info_->size(); ++i) { + if ((*info_)[i].glyph_ == g) { return i; } } @@ -590,8 +536,7 @@ void Scene::request(Requisition& req) const { void Scene::allocate(Canvas* c, const Allocation& a, Extension& ext) { // printf("Scene::allocate\n"); - GlyphIndex count = info_->count(); - for (GlyphIndex index = 0; index < count; ++index) { + for (GlyphIndex index = 0; index < info_->size(); ++index) { check_allocation(index); } ext.set(c, a); @@ -630,18 +575,14 @@ void Scene::draw(Canvas* canvas, const Allocation& a) const { canvas->pop_transform(); } } - GlyphIndex count = info_->count(); bool are_fixed = false; - for (GlyphIndex index = 0; index < count; ++index) { - SceneInfo& info = info_->item_ref(index); + for (auto& info: *info_) { if (info.status_ & SceneInfoFixed) { are_fixed = true; } else if (info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) { Allocation& a = info.allocation_; Extension b; b.set(canvas, a); - // printf("%d alloc %g %g %g %g\n", index, a.left(), a.bottom(), a.right(), a.top()); - // printf("%d exten %g %g %g %g\n", index, b.left(), b.bottom(), b.right(), b.top()); if (canvas->damaged(b)) { info.glyph_->draw(canvas, a); } @@ -656,8 +597,7 @@ void Scene::draw(Canvas* canvas, const Allocation& a) const { const Transformer& tv = XYView::current_draw_view()->s2o(); canvas->transform(tv); IfIdraw(pict(tv)); - for (GlyphIndex index = 0; index < count; ++index) { - SceneInfo& info = info_->item_ref(index); + for (auto& info: *info_) { if ((info.status_ & SceneInfoFixed) && info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) { Allocation a = info.allocation_; @@ -689,10 +629,8 @@ void Scene::print(Printer* canvas, const Allocation& a) const { if (background_ != NULL) { background_->print(canvas, a); } - GlyphIndex count = info_->count(); bool are_fixed = false; - for (GlyphIndex index = 0; index < count; ++index) { - SceneInfo& info = info_->item_ref(index); + for (auto& info: *info_) { if (info.status_ & SceneInfoFixed) { are_fixed = true; } else if (info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) { @@ -712,8 +650,7 @@ void Scene::print(Printer* canvas, const Allocation& a) const { // view_transform(canvas, 2, tv); const Transformer& tv = XYView::current_draw_view()->s2o(); canvas->transform(tv); - for (GlyphIndex index = 0; index < count; ++index) { - SceneInfo& info = info_->item_ref(index); + for (auto& info: *info_) { if ((info.status_ & SceneInfoFixed) && info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) { Allocation a = info.allocation_; @@ -756,30 +693,14 @@ void Scene::pick(Canvas* c, const Allocation& a, int depth, Hit& h) { if (background_ != NULL) { background_->pick(c, a, depth, h); } - GlyphIndex count = info_->count(); -#if 0 - for (GlyphIndex index = 0; index < count; ++index) { - SceneInfo& info = info_->item_ref(index); - if (info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) { - Allocation& a = info.allocation_; - if ( - h.right() >= a.left() && h.left() < a.right() - && h.top() >= a.bottom() && h.bottom() < a.top() - ) { - h.begin(depth, this, index); - info.glyph_->pick(c, a, depth + 1, h); - h.end(); - } - } - } -#else + GlyphIndex count = info_->size(); // pick with some extra epsilon in canvas coords Coord epsx = XYView::current_pick_view()->x_pick_epsilon(); Coord epsy = XYView::current_pick_view()->y_pick_epsilon(); bool are_fixed = false; for (GlyphIndex index = 0; index < count; ++index) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = (*info_)[index]; if (info.status_ & SceneInfoFixed) { are_fixed = true; } else if (info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) { @@ -800,7 +721,7 @@ void Scene::pick(Canvas* c, const Allocation& a, int depth, Hit& h) { float scx, scy, tmp; tv.matrix(scx, tmp, tmp, scy, tmp, tmp); for (GlyphIndex index = 0; index < count; ++index) { - SceneInfo& info = info_->item_ref(index); + SceneInfo& info = (*info_)[index]; if ((info.status_ & SceneInfoFixed) && info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) { Allocation a = info.allocation_; @@ -828,13 +749,12 @@ void Scene::pick(Canvas* c, const Allocation& a, int depth, Hit& h) { } } } -#endif } long Scene::scene_list_index(Scene* s) { - long i, cnt = scene_list->count(); - for (i = 0; i < cnt; ++i) { - if (s == scene_list->item(i)) { + std::size_t cnt = scene_list->size(); + for (std::size_t i = 0; i < cnt; ++i) { + if (s == scene_list->at(i)) { return i; } } @@ -847,19 +767,16 @@ void Scene::save_all(std::ostream& o) { if (!scene_list) { return; } - long count = scene_list->count(); - if (count) { - Sprintf(buf, "objectvar scene_vector_[%ld]", count); + if (!scene_list->empty()) { + Sprintf(buf, "objectvar scene_vector_[%ld]", scene_list->size()); o << buf << std::endl; } - for (long i = 0; i < count; ++i) { - Scene* s = scene_list->item(i); - s->mark(false); + for (auto& scene: *scene_list) { + scene->mark(false); } } void Scene::save_class(std::ostream& o, const char* s) { - long count = views_->count(); // PrintableWindow* w = (PrintableWindow*)canvas()->window(); o << "save_window_ = new " << s << "(0)" << std::endl; char buf[256]; @@ -881,8 +798,8 @@ void Scene::save_phase1(std::ostream&) {} void Scene::save_phase2(std::ostream&) {} void Scene::printfile(const char* fname) { - if (view_count()) { - views_->item(0)->printfile(fname); + if (!views_->empty()) { + views_->front()->printfile(fname); } } diff --git a/src/ivoc/scenepic.cpp b/src/ivoc/scenepic.cpp index e9ec48f6d3..9b4b29d172 100644 --- a/src/ivoc/scenepic.cpp +++ b/src/ivoc/scenepic.cpp @@ -85,9 +85,6 @@ GlyphIndex ButtonItemInfo::menu_index() { return -1; } -declarePtrList(ButtonItemInfoList, ButtonItemInfo) -implementPtrList(ButtonItemInfoList, ButtonItemInfo) - /*static*/ class SceneMover: public OcHandler { public: SceneMover(); @@ -193,7 +190,7 @@ ScenePicker* Scene::picker() { Scene* scene_; TelltaleGroup* tg_; CopyString sel_name_; - ButtonItemInfoList* bil_; + std::vector* bil_; static DismissableWindow* window_; }; @@ -276,7 +273,7 @@ MenuItem* ScenePicker::add_menu(const char* name, MenuItem* mi, Menu* m) { mm = spi_->menu_->menu(); } mm->append_item(mi); - spi_->bil_->append(new ButtonItemInfo(name, mi->action(), mi->state(), mi, mm)); + spi_->bil_->push_back(new ButtonItemInfo(name, mi->action(), mi->state(), mi, mm)); return mi; } @@ -294,7 +291,7 @@ Button* ScenePicker::radio_button(const char* name, Action* a) { Button* mi = WidgetKit::instance()->radio_button(spi_->tg_, name, new RadioSelect(name, a, spi_->scene_)); - spi_->bil_->append(new ButtonItemInfo(name, mi->action(), mi->state())); + spi_->bil_->push_back(new ButtonItemInfo(name, mi->action(), mi->state())); return mi; } MenuItem* ScenePicker::add_radio_menu(const char* name, @@ -312,10 +309,9 @@ MenuItem* ScenePicker::add_radio_menu(const char* name, OcHandler* h, int tool, } long ScenePickerImpl::info_index(const char* name) { - long i, cnt; - cnt = bil_->count(); - for (i = 0; i < cnt; ++i) { - ButtonItemInfo* b = bil_->item(i); + std::size_t cnt = bil_->size(); + for (std::size_t i = 0; i < cnt; ++i) { + ButtonItemInfo* b = bil_->at(i); if (strcmp(b->name_.string(), name) == 0) { return i; } @@ -337,7 +333,7 @@ void ScenePicker::exec_item(const char* name) { } i = spi_->info_index(name); if (i > -1) { - ButtonItemInfo* b = spi_->bil_->item(i); + ButtonItemInfo* b = spi_->bil_->at(i); TelltaleState* t = b->s_; bool chosen = t->test(TelltaleState::is_chosen); bool act = !chosen; @@ -355,11 +351,10 @@ void ScenePicker::exec_item(const char* name) { } void ScenePicker::remove_item(const char* name) { - long i; - i = spi_->info_index(name); + long i = spi_->info_index(name); if (i > -1) { - ButtonItemInfo* b = spi_->bil_->item(i); - spi_->bil_->remove(i); + ButtonItemInfo* b = spi_->bil_->at(i); + spi_->bil_->erase(spi_->bil_->begin() + i); GlyphIndex j = b->menu_index(); if (j > -1) { b->parent_->remove_item(j); @@ -375,11 +370,11 @@ void ScenePicker::insert_item(const char* insert, const char* name, MenuItem* mi long i; i = spi_->info_index(insert); if (i > -1) { - ButtonItemInfo* b = spi_->bil_->item(i); + ButtonItemInfo* b = spi_->bil_->at(i); GlyphIndex j = b->menu_index(); if (j > -1) { b->parent_->insert_item(j, mi); - spi_->bil_->insert(i, + spi_->bil_->insert(spi_->bil_->begin() + i, new ButtonItemInfo(name, mi->action(), mi->state(), mi, b->parent_)); } } @@ -408,14 +403,15 @@ ScenePickerImpl::ScenePickerImpl(Scene* scene) tg_ = new TelltaleGroup(); tg_->ref(); scene_ = scene; // not ref'ed since picker deleted when scene is deleted - bil_ = new ButtonItemInfoList(20); + bil_ = new std::vector(); + bil_->reserve(20); } ScenePickerImpl::~ScenePickerImpl() { Resource::unref(menu_); Resource::unref(tg_); - for (long i = bil_->count() - 1; i >= 0; --i) { - delete bil_->item(i); + for (auto it = bil_->rbegin(); it != bil_->rend(); ++it) { + delete *it; } delete bil_; } diff --git a/src/ivoc/scenevie.h b/src/ivoc/scenevie.h index ffffc88fb6..51de7ebaf7 100644 --- a/src/ivoc/scenevie.h +++ b/src/ivoc/scenevie.h @@ -74,11 +74,11 @@ with the common append/move. #include #include "apwindow.h" #include "ocglyph.h" +#include #undef Scene class Scene; -class SceneInfo_List; class SceneInfo; class XYView; class XYView_PtrList; @@ -330,8 +330,8 @@ class Scene: public Glyph, public Observable { private: Coord x1_, y1_, x2_, y2_; - SceneInfo_List* info_; - XYView_PtrList* views_; + std::vector* info_; + std::vector* views_; Glyph* background_; ScenePicker* picker_; int tool_; diff --git a/src/ivoc/symdir.cpp b/src/ivoc/symdir.cpp index 819c2e7897..46c55efbd9 100644 --- a/src/ivoc/symdir.cpp +++ b/src/ivoc/symdir.cpp @@ -19,7 +19,6 @@ extern Symlist *hoc_built_in_symlist, *hoc_top_level_symlist; #include "symdir.h" #include "nrnsymdiritem.h" -implementPtrList(SymbolList, SymbolItem); const char* concat(const char* s1, const char* s2) { static char* tmp = 0; @@ -43,7 +42,7 @@ class SymDirectoryImpl: public Observer { Object* obj_; cTemplate* t_; - SymbolList symbol_list_; + std::vector symbol_lists_; CopyString path_; void load(int type); @@ -76,16 +75,15 @@ static int compare_entries(const void* k1, const void* k2) { }; void SymDirectoryImpl::sort() { - long cnt, i; - cnt = symbol_list_.count(); + std::size_t cnt = symbol_lists_.size(); SymbolItem** slist = new SymbolItem*[cnt]; - for (i = 0; i < cnt; ++i) { - slist[i] = symbol_list_.item(i); + for (std::size_t i = 0; i < cnt; ++i) { + slist[i] = symbol_lists_[i]; } qsort(slist, cnt, sizeof(SymbolItem*), compare_entries); - symbol_list_.remove_all(); - for (i = 0; i < cnt; ++i) { - symbol_list_.append(slist[i]); + symbol_lists_.clear(); + for (std::size_t i = 0; i < cnt; ++i) { + symbol_lists_.push_back(slist[i]); } delete[] slist; } @@ -161,14 +159,14 @@ SymDirectory::SymDirectory(Object* ob) { } bool SymDirectory::is_pysec(int index) const { - SymbolItem* si = impl_->symbol_list_.item(index); + SymbolItem* si = impl_->symbol_lists_.at(index); return si->pysec_ ? true : false; } SymDirectory* SymDirectory::newsymdir(int index) { - SymbolItem* si = impl_->symbol_list_.item(index); + SymbolItem* si = impl_->symbol_lists_.at(index); SymDirectory* d = new SymDirectory(); if (si->pysec_type_ == PYSECOBJ) { - nrn_symdir_load_pysec(d->impl_->symbol_list_, si->pysec_); + nrn_symdir_load_pysec(d->impl_->symbol_lists_, si->pysec_); } else { d->impl_->sec_ = (Section*) si->pysec_; section_ref(d->impl_->sec_); @@ -201,11 +199,11 @@ SymDirectory::SymDirectory(int type) { } SymDirectory::~SymDirectory() { - long cnt = count(); - for (long i = 0; i < cnt; ++i) { - delete impl_->symbol_list_.item(i); + for (auto& item: impl_->symbol_lists_) { + delete item; } - impl_->symbol_list_.remove_all(); + impl_->symbol_lists_.clear(); + impl_->symbol_lists_.shrink_to_fit(); if (impl_->obj_) { ObjObservable::Detach(impl_->obj_, impl_); } @@ -218,11 +216,11 @@ SymDirectory::~SymDirectory() { delete impl_; } void SymDirectoryImpl::disconnect(Observable*) { - long cnt = symbol_list_.count(); - for (long i = 0; i < cnt; ++i) { - delete symbol_list_.item(i); + for (auto& item: symbol_lists_) { + delete item; } - symbol_list_.remove_all(); + symbol_lists_.clear(); + symbol_lists_.shrink_to_fit(); obj_ = NULL; } @@ -292,26 +290,26 @@ double* SymDirectory::variable(int index) { } int SymDirectory::whole_vector(int index) { - return impl_->symbol_list_.item(index)->whole_vector(); + return impl_->symbol_lists_.at(index)->whole_vector(); } const String& SymDirectory::path() const { return impl_->path_; } int SymDirectory::count() const { - return impl_->symbol_list_.count(); + return impl_->symbol_lists_.size(); } const String& SymDirectory::name(int index) const { - return impl_->symbol_list_.item(index)->name(); + return impl_->symbol_lists_.at(index)->name(); } int SymDirectory::array_index(int i) const { - return impl_->symbol_list_.item(i)->array_index(); + return impl_->symbol_lists_.at(i)->array_index(); } int SymDirectory::index(const String& name) const { long cnt = count(); for (long i = 0; i < cnt; ++i) { - if (name == impl_->symbol_list_.item(i)->name()) { + if (name == impl_->symbol_lists_[i]->name()) { return i; } } @@ -323,20 +321,20 @@ void SymDirectory::whole_name(int index, CopyString& s) const { s = concat(s1.string(), s2.string()); } bool SymDirectory::is_directory(int index) const { - return impl_->symbol_list_.item(index)->is_directory(); + return impl_->symbol_lists_.at(index)->is_directory(); } bool SymDirectory::match(const String&, const String&) { return true; } Symbol* SymDirectory::symbol(int index) const { - return impl_->symbol_list_.item(index)->symbol(); + return impl_->symbol_lists_.at(index)->symbol(); } Object* SymDirectory::object() const { return impl_->obj_; } Object* SymDirectory::obj(int index) { - return impl_->symbol_list_.item(index)->object(); + return impl_->symbol_lists_.at(index)->object(); } // SymbolItem @@ -436,7 +434,7 @@ void SymDirectoryImpl::load(int type) { break; case PYSEC: path_ = "_pysec."; - nrn_symdir_load_pysec(symbol_list_, NULL); + nrn_symdir_load_pysec(symbol_lists_, NULL); break; default: load(type, hoc_symlist); @@ -515,7 +513,7 @@ void SymDirectoryImpl::load_section() { double x = nrn_arc_position(sec, sec->pnode[0]); Sprintf(xarg, "( %g )", x); Sprintf(buf, "v%s", xarg); - symbol_list_.append(new SymbolItem(buf)); + symbol_lists_.push_back(new SymbolItem(buf)); nrn_pushsec(sec); Node* nd = sec->pnode[i]; for (Prop* p = nd->prop; p; p = p->next) { @@ -536,15 +534,15 @@ void SymDirectoryImpl::load_mechanism(Prop* p, int type, const char* xarg) { int n = hoc_total_array_data(sym, 0); if (n > 5) { Sprintf(buf, "%s[all]%s", sym->name, xarg); - symbol_list_.append(new SymbolItem(buf, n)); + symbol_lists_.push_back(new SymbolItem(buf, n)); } Sprintf(buf, "%s[%d]%s", sym->name, 0, xarg); - symbol_list_.append(new SymbolItem(buf)); + symbol_lists_.push_back(new SymbolItem(buf)); Sprintf(buf, "%s[%d]%s", sym->name, n - 1, xarg); - symbol_list_.append(new SymbolItem(buf)); + symbol_lists_.push_back(new SymbolItem(buf)); } else { Sprintf(buf, "%s%s", sym->name, xarg); - symbol_list_.append(new SymbolItem(buf)); + symbol_lists_.push_back(new SymbolItem(buf)); } } } @@ -562,30 +560,29 @@ void SymDirectoryImpl::append(Symbol* sym, Objectdata* od, Object* o) { } } if (n > 5 && sym->type == VAR) { - symbol_list_.append(new SymbolItem(sym, od, 0, n)); + symbol_lists_.push_back(new SymbolItem(sym, od, 0, n)); } for (i = 0; i < n; ++i) { - symbol_list_.append(new SymbolItem(sym, od, i)); + symbol_lists_.push_back(new SymbolItem(sym, od, i)); if (i > 5) { break; } } if (i < n - 1) { - symbol_list_.append(new SymbolItem(sym, od, n - 1)); + symbol_lists_.push_back(new SymbolItem(sym, od, n - 1)); } } else { - symbol_list_.append(new SymbolItem(sym, od, 0)); + symbol_lists_.push_back(new SymbolItem(sym, od, 0)); } } void SymDirectoryImpl::append(Object* ob) { - symbol_list_.append(new SymbolItem(ob)); + symbol_lists_.push_back(new SymbolItem(ob)); } void SymDirectoryImpl::un_append(Object* ob) { - long i, cnt = symbol_list_.count(); - for (i = 0; i < cnt; ++i) { - if (symbol_list_.item(i)->object() == ob) { - symbol_list_.item(i)->no_object(); + for (auto& symbol: symbol_lists_) { + if (symbol->object() == ob) { + symbol->no_object(); break; } } diff --git a/src/ivoc/xmenu.cpp b/src/ivoc/xmenu.cpp index dfc99da764..58407fad47 100644 --- a/src/ivoc/xmenu.cpp +++ b/src/ivoc/xmenu.cpp @@ -570,8 +570,7 @@ void HocButton::print(Printer* pr, const Allocation& a) const { l_->print(pr, a); } -implementPtrList(HocPanelList, HocPanel); -static HocPanelList* hoc_panel_list; +static std::vector* hoc_panel_list; static HocPanel* curHocPanel; static HocValEditor* last_fe_constructed_; static void checkOpenPanel() { @@ -580,40 +579,38 @@ static void checkOpenPanel() { } } -declarePtrList(HocMenuList, HocMenu) -implementPtrList(HocMenuList, HocMenu) /*static*/ class MenuStack { public: bool isEmpty() { - return l_.count() == 0; + return l_.empty(); } void push(HocMenu* m); void pop() { - if (l_.count()) { - l_.item(0)->unref(); - l_.remove(0); + if (!l_.empty()) { + l_.front()->unref(); + l_.erase(l_.begin()); } } Menu* top() { - return (l_.count()) ? l_.item(0)->menu() : NULL; + return (l_.empty()) ? nullptr : l_.front()->menu(); } HocItem* hoc_item() { - return (l_.count()) ? l_.item(0) : NULL; + return (l_.empty()) ? nullptr : l_.front(); } void clean(); private: - HocMenuList l_; + std::vector l_; }; void MenuStack::push(HocMenu* m) { m->ref(); - l_.prepend(m); + l_.insert(l_.begin(), m); } void MenuStack::clean() { - for (long i = 0; i < l_.count(); i++) { - l_.item(i)->unref(); + for (auto& item: l_) { + item->unref(); } - l_.remove_all(); + l_.clear(); } static MenuStack* menuStack; static Menu* hocmenubar; @@ -953,16 +950,17 @@ void HocPanel::save_all(std::ostream&) { long i, cnt; HocDataPaths* data_paths = new HocDataPaths(); - cnt = hoc_panel_list->count(); - if (hoc_panel_list) - for (i = 0; i < cnt; ++i) { - hoc_panel_list->item(i)->data_path(data_paths, true); + if (hoc_panel_list) { + for (auto& item: *hoc_panel_list) { + item->data_path(data_paths, true); } + } data_paths->search(); - if (hoc_panel_list) - for (i = 0; i < cnt; ++i) { - hoc_panel_list->item(i)->data_path(data_paths, false); + if (hoc_panel_list) { + for (auto& item: *hoc_panel_list) { + item->data_path(data_paths, false); } + } delete data_paths; } @@ -992,15 +990,12 @@ void HocPanel::map_window(int scroll) { } // HocPanel - -implementPtrList(HocUpdateItemList, HocUpdateItem); -implementPtrList(HocItemList, HocItem); - static void var_freed(void* pd, int size) { - if (hoc_panel_list) - for (long i = hoc_panel_list->count() - 1; i >= 0; --i) { - hoc_panel_list->item(i)->check_valid_pointers(pd, size); + if (hoc_panel_list) { + for (auto it = hoc_panel_list->rbegin(); it != hoc_panel_list->rend(); ++it) { + (*it)->check_valid_pointers(pd, size); } + } } HocPanel::HocPanel(const char* name, bool h) @@ -1020,11 +1015,11 @@ HocPanel::HocPanel(const char* name, bool h) wk.background()), wk.style())); if (!hoc_panel_list) { - hoc_panel_list = new HocPanelList; + hoc_panel_list = new std::vector; Oc oc; oc.notify_freed(var_freed); } - hoc_panel_list->append(this); + hoc_panel_list->push_back(this); item_append(new HocItem(name)); left_ = -1000.; bottom_ = -1000.; @@ -1032,22 +1027,21 @@ HocPanel::HocPanel(const char* name, bool h) } HocPanel::~HocPanel() { - long i; box_->unref(); - for (i = 0; i < ilist_.count(); i++) { - ilist_.item(i)->HocItem::unref(); + for (auto& item: ilist_) { + item->HocItem::unref(); } - for (i = 0; i < elist_.count(); i++) { - elist_.item(i)->HocItem::unref(); + for (auto& item: elist_) { + item->HocItem::unref(); } - for (i = 0; i < hoc_panel_list->count(); ++i) { - if (hoc_panel_list->item(i) == this) { - hoc_panel_list->remove(i); - break; - } + if (auto it = std::find(hoc_panel_list->begin(), hoc_panel_list->end(), this); + it != hoc_panel_list->end()) { + hoc_panel_list->erase(it); } - ilist_.remove_all(); - elist_.remove_all(); + ilist_.clear(); + ilist_.shrink_to_fit(); + elist_.clear(); + elist_.shrink_to_fit(); // printf("~HocPanel\n"); } @@ -1062,30 +1056,26 @@ void HocUpdateItem::check_pointer(void*, int) {} void HocUpdateItem::data_path(HocDataPaths*, bool) {} // ones that get updated on every doEvents() -HocUpdateItemList* HocPanel::update_list_; +std::vector* HocPanel::update_list_; void HocPanel::keep_updated() { static int cnt = 0; if (update_list_ && (++cnt % 10 == 0)) { - long i, cnt = update_list_->count(); - if (cnt) - for (i = 0; i < cnt; ++i) { - update_list_->item(i)->update_hoc_item(); - } + for (auto& item: *update_list_) { + item->update_hoc_item(); + } } } void HocPanel::keep_updated(HocUpdateItem* hui, bool add) { if (!update_list_) { - update_list_ = new HocUpdateItemList(); + update_list_ = new std::vector(); } if (add) { - update_list_->append(hui); + update_list_->push_back(hui); } else { - for (long i = 0; i < update_list_->count(); ++i) { - if (update_list_->item(i) == hui) { - update_list_->remove(i); - break; - } + if (auto it = std::find(update_list_->begin(), update_list_->end(), hui); + it != update_list_->end()) { + update_list_->erase(it); } } } @@ -1120,11 +1110,11 @@ PolyGlyph* HocPanel::box() { } const char* HocPanel::getName() { - return ilist_.item(0)->getStr(); + return ilist_.front()->getStr(); } HocItem* HocPanel::hoc_item() { - return ilist_.item(0); + return ilist_.front(); } void HocPanel::pushButton(const char* name, const char* action, bool activate, Object* pyact) { @@ -1184,7 +1174,7 @@ void HocPanel::label(const char* name) { void HocPanel::var_label(char** name, Object* pyvar) { HocVarLabel* l = new HocVarLabel(name, box(), pyvar); item_append(l); - elist_.append(l); + elist_.push_back(l); l->ref(); } @@ -1214,7 +1204,7 @@ void HocPanel::slider(neuron::container::data_handle pd, wk->end_style(); } item_append(s); - elist_.append(s); + elist_.push_back(s); s->ref(); } @@ -1345,7 +1335,7 @@ void HocPanel::valueEd(const char* name, fe = new HocValEditor(name, variable, vel, act, pd, canrun, hoc_item(), pyvar); } ih_->append_input_handler(fe->field_editor()); - elist_.append(fe); + elist_.push_back(fe); fe->ref(); act->setFieldSEditor(fe); // so button can change the editor LayoutKit* lk = LayoutKit::instance(); @@ -1382,12 +1372,13 @@ void HocPanel::save(std::ostream& o) { void HocPanel::write(std::ostream& o) { Oc oc; char buf[200]; - long i; // o << "xpanel(\"" << getName() << "\")" << std::endl; Sprintf(buf, "xpanel(\"%s\", %d)", getName(), horizontal_); o << buf << std::endl; - for (i = 1; i < ilist_.count(); i++) { - ilist_.item(i)->write(o); + if (ilist_.size() > 1) { + for (std::size_t i = 1; i < ilist_.size(); ++i) { + ilist_[i]->write(o); + } } if (has_window()) { Sprintf(buf, "xpanel(%g,%g)", window()->save_left(), window()->save_bottom()); @@ -1399,7 +1390,7 @@ void HocPanel::write(std::ostream& o) { void HocPanel::item_append(HocItem* hi) { hi->ref(); - ilist_.append(hi); + ilist_.push_back(hi); } // HocItem @@ -2286,22 +2277,23 @@ void Oc::notifyHocValue() { // printf("notifyHocValue %d\n", ++j); ParseTopLevel ptl; ptl.save(); - if (hoc_panel_list) - for (long i = hoc_panel_list->count() - 1; i >= 0; --i) { - hoc_panel_list->item(i)->notifyHocValue(); + if (hoc_panel_list) { + for (auto it = hoc_panel_list->rbegin(); it != hoc_panel_list->rend(); ++it) { + (*it)->notifyHocValue(); } + } ptl.restore(); } void HocPanel::notifyHocValue() { - for (long i = elist_.count() - 1; i >= 0; --i) { - elist_.item(i)->update_hoc_item(); + for (auto it = elist_.rbegin(); it != elist_.rend(); ++it) { + (*it)->update_hoc_item(); } } void HocPanel::check_valid_pointers(void* v, int size) { - for (long i = elist_.count() - 1; i >= 0; --i) { - elist_.item(i)->check_pointer(v, size); + for (auto it = elist_.rbegin(); it != elist_.rend(); ++it) { + (*it)->check_pointer(v, size); } } @@ -2328,8 +2320,8 @@ void HocVarLabel::check_pointer(void* v, int) { } void HocPanel::data_path(HocDataPaths* hdp, bool append) { - for (long i = elist_.count() - 1; i >= 0; --i) { - elist_.item(i)->data_path(hdp, append); + for (auto it = elist_.rbegin(); it != elist_.rend(); ++it) { + (*it)->data_path(hdp, append); } } @@ -2826,7 +2818,7 @@ void HocPanel::stateButton(neuron::container::data_handle pd, box()->append(button); HocStateButton* hsb = new HocStateButton(pd, name, button, act, style, hoc_item(), pyvar); item_append(hsb); - elist_.append(hsb); + elist_.push_back(hsb); hsb->ref(); } @@ -2989,7 +2981,7 @@ MenuItem* HocPanel::menuStateItem(neuron::container::data_handle pd, HocAction* act = new HocAction(action, pyact); HocStateMenuItem* hsb = new HocStateMenuItem(pd, name, mi, act, hoc_item(), pyvar); item_append(hsb); - elist_.append(hsb); + elist_.push_back(hsb); hsb->ref(); return mi; } diff --git a/src/ivoc/xmenu.h b/src/ivoc/xmenu.h index ccf6c215d7..81eb9d1e85 100644 --- a/src/ivoc/xmenu.h +++ b/src/ivoc/xmenu.h @@ -42,9 +42,6 @@ class ValEdLabel; class ScenePicker; struct HocSymExtension; -declarePtrList(HocUpdateItemList, HocUpdateItem) -declarePtrList(HocItemList, HocItem) -declarePtrList(HocPanelList, HocPanel) class HocPanel: public OcGlyph { public: @@ -122,9 +119,9 @@ class HocPanel: public OcGlyph { private: PolyGlyph* box_; - HocUpdateItemList elist_; - HocItemList ilist_; - static HocUpdateItemList* update_list_; + std::vector elist_; + std::vector ilist_; + static std::vector* update_list_; bool horizontal_; InputHandler* ih_; }; diff --git a/src/nrncvode/cvodeobj.h b/src/nrncvode/cvodeobj.h index 5f50cbc532..19933ff057 100644 --- a/src/nrncvode/cvodeobj.h +++ b/src/nrncvode/cvodeobj.h @@ -15,7 +15,6 @@ class TQueue; typedef std::vector PreSynList; struct BAMech; struct NrnThread; -class PlayRecList; class PlayRecord; class STEList; class HTList; @@ -81,8 +80,8 @@ class CvodeThreadData { int neq_v_; // for daspk, number of voltage states for this thread int nonvint_offset_; // synonym for neq_v_. Beginning of this threads nonvint variables. int nonvint_extra_offset_; // extra states (probably Python). Not scattered or gathered. - PlayRecList* record_; - PlayRecList* play_; + std::vector* play_; + std::vector* record_; }; class Cvode { diff --git a/src/nrncvode/netcvode.cpp b/src/nrncvode/netcvode.cpp index f0a511a322..53da0e10b4 100644 --- a/src/nrncvode/netcvode.cpp +++ b/src/nrncvode/netcvode.cpp @@ -95,7 +95,7 @@ extern Symlist* hoc_built_in_symlist; extern Symlist* hoc_top_level_symlist; extern TQueue* net_cvode_instance_event_queue(NrnThread*); extern hoc_Item* net_cvode_instance_psl(); -extern PlayRecList* net_cvode_instance_prl(); +extern std::vector* net_cvode_instance_prl(); extern void nrn_update_ps2nt(); extern void nrn_use_busywait(int); void* nrn_interthread_enqueue(NrnThread*); @@ -300,7 +300,7 @@ hoc_Item* net_cvode_instance_psl() { return net_cvode_instance->psl_; } -PlayRecList* net_cvode_instance_prl() { +std::vector* net_cvode_instance_prl() { return net_cvode_instance->playrec_list(); } @@ -1213,9 +1213,12 @@ NetCvode::NetCvode(bool single) { matrix_change_cnt_ = -1; playrec_change_cnt_ = 0; alloc_list(); - prl_ = new PlayRecList(10); - fixed_play_ = new PlayRecList(10); - fixed_record_ = new PlayRecList(10); + prl_ = new std::vector(); + prl_->reserve(10); + fixed_play_ = new std::vector(); + fixed_play_->reserve(10); + fixed_record_ = new std::vector(); + fixed_record_->reserve(10); vec_event_store_ = nullptr; if (!record_init_items_) { record_init_items_ = new TQList(); @@ -1248,8 +1251,8 @@ NetCvode::~NetCvode() { delete std::exchange(pst_, nullptr); delete std::exchange(fixed_play_, nullptr); delete std::exchange(fixed_record_, nullptr); - while (prl_->count()) { - delete prl_->item(prl_->count() - 1); + for (auto& item: *prl_) { + delete item; } delete std::exchange(prl_, nullptr); unused_presyn = nullptr; @@ -4189,8 +4192,7 @@ void record_init_clear(const TQItem* q, int) { } void NetCvode::record_init() { - int i, cnt = prl_->count(); - if (cnt) { + if (!prl_->empty()) { // there may be some events on the queue descended from // finitialize that need to be removed record_init_items_->clear(); @@ -4200,15 +4202,14 @@ void NetCvode::record_init() { } record_init_items_->clear(); } - for (i = 0; i < cnt; ++i) { - prl_->item(i)->record_init(); + for (auto& item: *prl_) { + item->record_init(); } } void NetCvode::play_init() { - int i, cnt = prl_->count(); - for (i = 0; i < cnt; ++i) { - prl_->item(i)->play_init(); + for (auto& item: *prl_) { + item->play_init(); } } @@ -5615,9 +5616,7 @@ void Cvode::check_deliver(NrnThread* nt) { void NetCvode::fixed_record_continuous(neuron::model_sorted_token const& cache_token, NrnThread& nt) { nrn_ba(cache_token, nt, BEFORE_STEP); - auto const cnt = fixed_record_->count(); - for (int i = 0; i < cnt; ++i) { // should be made more efficient - PlayRecord* pr = fixed_record_->item(i); + for (auto& pr: *fixed_record_) { if (pr->ith_ == nt.id) { pr->continuous(nt._t); } @@ -5625,10 +5624,7 @@ void NetCvode::fixed_record_continuous(neuron::model_sorted_token const& cache_t } void NetCvode::fixed_play_continuous(NrnThread* nt) { - int i, cnt; - cnt = fixed_play_->count(); - for (i = 0; i < cnt; ++i) { - PlayRecord* pr = fixed_play_->item(i); + for (auto& pr: *fixed_play_) { if (pr->ith_ == nt->id) { pr->continuous(nt->_t); } @@ -5723,12 +5719,9 @@ void nrnthread_get_trajectory_requests(int tid, pvars = NULL; if (tid < nrn_nthread) { NrnThread& nt = nrn_threads[tid]; - PlayRecList* fr = net_cvode_instance->fixed_record_; - int cntp; - cntp = fr->count(); + auto* fr = net_cvode_instance->fixed_record_; // allocate - for (int i = 0; i < cntp; ++i) { - PlayRecord* pr = fr->item(i); + for (auto& pr: *fr) { if (pr->ith_ == tid) { if (pr->type() == TvecRecordType || pr->type() == YvecRecordType) { n_pr++; @@ -5777,9 +5770,8 @@ void nrnthread_get_trajectory_requests(int tid, // everything allocated, start over and fill n_pr = 0; n_trajec = 0; - for (int i = 0; i < cntp; ++i) { + for (auto& pr: *fr) { int err = 0; - PlayRecord* pr = fr->item(i); if (pr->ith_ == tid) { if (1) { // buffered or per time step value return IvocVect* v = NULL; @@ -6123,44 +6115,31 @@ void NetCvode::deliver_net_events(NrnThread* nt) { // for default method nt->_t = tsav; } -implementPtrList(PlayRecList, PlayRecord) - void NetCvode::playrec_add(PlayRecord* pr) { // called by PlayRecord constructor // printf("NetCvode::playrec_add %p\n", pr); playrec_change_cnt_ = 0; - prl_->append(pr); + prl_->push_back(pr); } void NetCvode::playrec_remove(PlayRecord* pr) { // called by PlayRecord destructor // printf("NetCvode::playrec_remove %p\n", pr); playrec_change_cnt_ = 0; - int i, cnt = prl_->count(); - for (i = 0; i < cnt; ++i) { - if (prl_->item(i) == pr) { - prl_->remove(i); - break; - } + if (auto it = std::find(prl_->begin(), prl_->end(), pr); it != prl_->end()) { + prl_->erase(it); } - cnt = fixed_play_->count(); - for (i = 0; i < cnt; ++i) { - if (fixed_play_->item(i) == pr) { - fixed_play_->remove(i); - break; - } + if (auto it = std::find(fixed_play_->begin(), fixed_play_->end(), pr); + it != fixed_play_->end()) { + fixed_play_->erase(it); } - cnt = fixed_record_->count(); - for (i = 0; i < cnt; ++i) { - if (fixed_record_->item(i) == pr) { - fixed_record_->remove(i); - break; - } + if (auto it = std::find(fixed_record_->begin(), fixed_record_->end(), pr); + it != fixed_record_->end()) { + fixed_record_->erase(it); } } int NetCvode::playrec_item(PlayRecord* pr) { - int i, cnt = prl_->count(); - for (i = 0; i < cnt; ++i) { - if (prl_->item(i) == pr) { + for (std::size_t i = 0; i < prl_->size(); ++i) { + if ((*prl_)[i] == pr) { return i; } } @@ -6168,15 +6147,13 @@ int NetCvode::playrec_item(PlayRecord* pr) { } PlayRecord* NetCvode::playrec_item(int i) { - assert(i < prl_->count()); - return prl_->item(i); + return prl_->at(i); } PlayRecord* NetCvode::playrec_uses(void* v) { - int i, cnt = prl_->count(); - for (i = 0; i < cnt; ++i) { - if (prl_->item(i)->uses(v)) { - return prl_->item(i); + for (auto& item: *prl_) { + if (item->uses(v)) { + return item; } } return nullptr; @@ -6216,7 +6193,7 @@ void PlayRecord::record_add(Cvode* cv) { if (cv) { cv->record_add(this); } - net_cvode_instance->fixed_record_->append(this); + net_cvode_instance->fixed_record_->push_back(this); } void PlayRecord::play_add(Cvode* cv) { @@ -6224,7 +6201,7 @@ void PlayRecord::play_add(Cvode* cv) { if (cv) { cv->play_add(this); } - net_cvode_instance->fixed_play_->append(this); + net_cvode_instance->fixed_play_->push_back(this); } void PlayRecord::pr() { @@ -6446,10 +6423,9 @@ void NetCvode::vec_remove() { } void NetCvode::playrec_setup() { - long i, j, prlc; - prlc = prl_->count(); - fixed_record_->remove_all(); - fixed_play_->remove_all(); + long i, j; + fixed_record_->clear(); + fixed_play_->clear(); if (gcv_) { gcv_->delete_prl(); } else { @@ -6458,8 +6434,7 @@ void NetCvode::playrec_setup() { } } std::vector to_delete{}; - for (long iprl = 0; iprl < prlc; ++iprl) { - PlayRecord* pr = prl_->item(iprl); + for (auto& pr: *prl_) { if (!pr->pd_) { // Presumably the recorded value was invalidated elsewhere, e.g. it // was a voltage of a deleted node, or a range variable of a deleted diff --git a/src/nrncvode/netcvode.h b/src/nrncvode/netcvode.h index 2186c342ce..afddcf998e 100644 --- a/src/nrncvode/netcvode.h +++ b/src/nrncvode/netcvode.h @@ -23,7 +23,6 @@ class SelfEvent; using SelfEventPool = MutexPool; struct hoc_Item; class PlayRecord; -class PlayRecList; class IvocVect; struct BAMechList; class HTList; @@ -128,13 +127,13 @@ class NetCvode { void playrec_remove(PlayRecord*); int playrec_item(PlayRecord*); PlayRecord* playrec_item(int); - PlayRecList* playrec_list() { + std::vector* playrec_list() { return prl_; } void simgraph_remove(); // fixed step continuous play and record - PlayRecList* fixed_play_; - PlayRecList* fixed_record_; + std::vector* fixed_play_; + std::vector* fixed_record_; void vecrecord_add(); // hoc interface functions void vec_remove(); void record_init(); @@ -242,7 +241,7 @@ class NetCvode { PreSynTable* pst_; int pst_cnt_; int playrec_change_cnt_; - PlayRecList* prl_; + std::vector* prl_; IvocVect* vec_event_store_; HocDataPaths create_hdp(int style); diff --git a/src/nrncvode/occvode.cpp b/src/nrncvode/occvode.cpp index cf962fe9c9..bb2ec2db02 100644 --- a/src/nrncvode/occvode.cpp +++ b/src/nrncvode/occvode.cpp @@ -1038,9 +1038,10 @@ void Cvode::delete_prl() { void Cvode::record_add(PlayRecord* pr) { CvodeThreadData& z = CTD(pr->ith_); if (!z.record_) { - z.record_ = new PlayRecList(1); + z.record_ = new std::vector(); + z.record_->reserve(1); } - z.record_->append(pr); + z.record_->push_back(pr); } void Cvode::record_continuous() { @@ -1055,8 +1056,8 @@ void Cvode::record_continuous() { before_after(sorted_token, z.before_step_, nt); } if (z.record_) { - for (long i = 0; i < z.record_->count(); ++i) { - z.record_->item(i)->continuous(t_); + for (auto& item: *(z.record_)) { + item->continuous(t_); } } } @@ -1069,8 +1070,8 @@ void Cvode::record_continuous_thread(NrnThread* nt) { before_after(nrn_ensure_model_data_are_sorted(), z.before_step_, nt); } if (z.record_) { - for (long i = 0; i < z.record_->count(); ++i) { - z.record_->item(i)->continuous(t_); + for (auto& item: *(z.record_)) { + item->continuous(t_); } } } @@ -1078,9 +1079,9 @@ void Cvode::record_continuous_thread(NrnThread* nt) { void Cvode::play_add(PlayRecord* pr) { CvodeThreadData& z = CTD(pr->ith_); if (!z.play_) { - z.play_ = new PlayRecList(1); + z.play_ = new std::vector(); } - z.play_->append(pr); + z.play_->push_back(pr); } void Cvode::play_continuous(double tt) { @@ -1090,8 +1091,8 @@ void Cvode::play_continuous(double tt) { for (int i = 0; i < nrn_nthread; ++i) { CvodeThreadData& z = ctd_[i]; if (z.play_) { - for (long i = 0; i < z.play_->count(); ++i) { - z.play_->item(i)->continuous(tt); + for (auto& item: *(z.play_)) { + item->continuous(tt); } } } @@ -1100,8 +1101,8 @@ void Cvode::play_continuous(double tt) { void Cvode::play_continuous_thread(double tt, NrnThread* nt) { CvodeThreadData& z = CTD(nt->id); if (z.play_) { - for (long i = 0; i < z.play_->count(); ++i) { - z.play_->item(i)->continuous(tt); + for (auto& item: *(z.play_)) { + item->continuous(tt); } } } diff --git a/src/nrncvode/vrecitem.h b/src/nrncvode/vrecitem.h index 879a73af1b..6d30a0ec17 100644 --- a/src/nrncvode/vrecitem.h +++ b/src/nrncvode/vrecitem.h @@ -95,8 +95,6 @@ class PlayRecord: public Observer { int ith_; // The thread index }; -declarePtrList(PlayRecList, PlayRecord) - class PlayRecordSave { public: PlayRecordSave(PlayRecord*); diff --git a/src/nrniv/bbsavestate.cpp b/src/nrniv/bbsavestate.cpp index 43f3bc8f70..3fd6cc30c0 100644 --- a/src/nrniv/bbsavestate.cpp +++ b/src/nrniv/bbsavestate.cpp @@ -208,7 +208,6 @@ extern NetCvode* net_cvode_instance; extern TQueue* net_cvode_instance_event_queue(NrnThread*); extern cTemplate** nrn_pnt_template_; extern hoc_Item* net_cvode_instance_psl(); -extern PlayRecList* net_cvode_instance_prl(); extern void nrn_netcon_event(NetCon*, double); extern double t; typedef void (*PFIO)(int, Object*); diff --git a/src/nrniv/glinerec.cpp b/src/nrniv/glinerec.cpp index 0fabbdb589..001550bd10 100644 --- a/src/nrniv/glinerec.cpp +++ b/src/nrniv/glinerec.cpp @@ -26,11 +26,7 @@ extern NetCvode* net_cvode_instance; -class GLineRecordList; - -declarePtrList(GLineRecordList, GLineRecord) -implementPtrList(GLineRecordList, GLineRecord) -static GLineRecordList* grl; +static std::vector* grl; // Since GraphLine is not an observable, its destructor calls this. // So ivoc will work, a stub is placed in ivoc/datapath.cpp @@ -38,11 +34,9 @@ void graphLineRecDeleted(GraphLine* gl) { if (!grl) { return; } - int i, cnt = grl->count(); - for (i = 0; i < cnt; ++i) { - GLineRecord* r = grl->item(i); - if (r->uses(gl)) { - delete r; + for (auto& item: *grl) { + if (item->uses(gl)) { + delete item; return; } } @@ -52,25 +46,22 @@ void NetCvode::simgraph_remove() { if (!grl) { return; } - while (grl->count()) { - delete grl->item(grl->count() - 1); + for (auto& item: *grl) { + delete item; } } void Graph::simgraph() { - int i, cnt; if (!grl) { - grl = new GLineRecordList(); + grl = new std::vector(); } - cnt = line_list_.count(); - for (i = 0; i < cnt; ++i) { - GraphLine* gl = line_list_.item(i); + for (auto& gl: line_list_) { PlayRecord* pr = net_cvode_instance->playrec_uses(gl); if (pr) { delete pr; } GLineRecord* r = new GLineRecord(gl); - grl->append(r); + grl->push_back(r); } } @@ -162,21 +153,18 @@ void GraphVector::record_uninstall() {} GLineRecord::~GLineRecord() { if (v_) { delete v_; - v_ = NULL; + v_ = nullptr; } - for (GLineRecordEData::iterator it = pd_and_vec_.begin(); it != pd_and_vec_.end(); ++it) { - if ((*it).second) { - delete (*it).second; + for (auto& [_, vec]: pd_and_vec_) { + if (vec) { + delete vec; } } - for (int i = grl->count() - 1; i >= 0; --i) { - if (grl->item(i) == this) { - gl_->simgraph_activate(false); - grl->remove(i); - return; - } + if (auto it = std::find(grl->rbegin(), grl->rend(), this); it != grl->rend()) { + gl_->simgraph_activate(false); + grl->erase(std::next(it).base()); // Reverse iterator need that } } diff --git a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp index 0419b282db..05d0f90e56 100644 --- a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp +++ b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp @@ -630,10 +630,10 @@ int nrnthread_dat2_vecplay(int tid, std::vector& indices) { // add the index of each instance in fixed_play_ for thread tid. // error if not a VecPlayContinuous with no discon vector - PlayRecList* fp = net_cvode_instance->fixed_play_; - for (int i = 0; i < fp->count(); ++i) { - if (fp->item(i)->type() == VecPlayContinuousType) { - VecPlayContinuous* vp = (VecPlayContinuous*) fp->item(i); + int i = 0; + for (auto& item: *net_cvode_instance->fixed_play_) { + if (item->type() == VecPlayContinuousType) { + auto* vp = static_cast(item); if (vp->discon_indices_ == NULL) { if (vp->ith_ == nt.id) { assert(vp->y_ && vp->t_); @@ -645,6 +645,7 @@ int nrnthread_dat2_vecplay(int tid, std::vector& indices) { } else { assert(0); } + ++i; } return 1; @@ -666,9 +667,9 @@ int nrnthread_dat2_vecplay_inst(int tid, } NrnThread& nt = nrn_threads[tid]; - PlayRecList* fp = net_cvode_instance->fixed_play_; - if (fp->item(i)->type() == VecPlayContinuousType) { - auto* const vp = static_cast(fp->item(i)); + auto* fp = net_cvode_instance->fixed_play_; + if (fp->at(i)->type() == VecPlayContinuousType) { + auto* const vp = static_cast(fp->at(i)); if (!vp->discon_indices_) { if (vp->ith_ == nt.id) { auto* pd = static_cast(vp->pd_); @@ -709,9 +710,9 @@ void core2nrn_vecplay(int tid, int i, int last_index, int discon_index, int ubou if (tid >= nrn_nthread) { return; } - PlayRecList* fp = net_cvode_instance->fixed_play_; - assert(fp->item(i)->type() == VecPlayContinuousType); - VecPlayContinuous* vp = (VecPlayContinuous*) fp->item(i); + auto* fp = net_cvode_instance->fixed_play_; + assert(fp->at(i)->type() == VecPlayContinuousType); + VecPlayContinuous* vp = (VecPlayContinuous*) fp->at(i); vp->last_index_ = last_index; vp->discon_index_ = discon_index; vp->ubound_index_ = ubound_index; @@ -719,10 +720,9 @@ void core2nrn_vecplay(int tid, int i, int last_index, int discon_index, int ubou /** start the vecplay events **/ void core2nrn_vecplay_events() { - PlayRecList* fp = net_cvode_instance->fixed_play_; - for (int i = 0; i < fp->count(); ++i) { - if (fp->item(i)->type() == VecPlayContinuousType) { - VecPlayContinuous* vp = (VecPlayContinuous*) fp->item(i); + for (auto& item: *net_cvode_instance->fixed_play_) { + if (item->type() == VecPlayContinuousType) { + auto* vp = static_cast(item); NrnThread* nt = nrn_threads + vp->ith_; vp->e_->send(vp->t_->elem(vp->ubound_index_), net_cvode_instance, nt); } diff --git a/src/nrniv/prcellstate.cpp b/src/nrniv/prcellstate.cpp index 673f16263f..eb7b5e4822 100644 --- a/src/nrniv/prcellstate.cpp +++ b/src/nrniv/prcellstate.cpp @@ -11,10 +11,6 @@ void nrn_prcellstate(int gid, const char* filesuffix); -declarePtrList(NetConList, NetCon); // NetCons in same order as Point_process -implementPtrList(NetConList, NetCon); // and there may be several per pp. - - static void pr_memb(int type, Memb_list* ml, int* cellnodes, @@ -51,9 +47,10 @@ static void pr_netcon(NrnThread& nt, FILE* f, const std::map& pnt2in // List of NetCon for each of the NET_RECEIVE point process instances // ... all NetCon list in the hoc NetCon cTemplate - NetConList** nclist = new NetConList*[pnt2index.size()]; + std::vector** nclist = new std::vector*[pnt2index.size()]; for (size_t i = 0; i < pnt2index.size(); ++i) { - nclist[i] = new NetConList(1); + nclist[i] = new std::vector(); + nclist[i]->reserve(1); } int nc_cnt = 0; Symbol* ncsym = hoc_lookup("NetCon"); @@ -64,15 +61,15 @@ static void pr_netcon(NrnThread& nt, FILE* f, const std::map& pnt2in Point_process* pp = nc->target_; const auto& it = pnt2index.find(pp); if (it != pnt2index.end()) { - nclist[it->second]->append(nc); + nclist[it->second]->push_back(nc); ++nc_cnt; } } fprintf(f, "netcons %d\n", nc_cnt); fprintf(f, " pntindex srcgid active delay weights\n"); for (size_t i = 0; i < pnt2index.size(); ++i) { - for (int j = 0; j < nclist[i]->count(); ++j) { - NetCon* nc = nclist[i]->item(j); + for (int j = 0; j < nclist[i]->size(); ++j) { + NetCon* nc = nclist[i]->at(j); int srcgid = -3; srcgid = (nc->src_) ? nc->src_->gid_ : -3; if (srcgid < 0 && nc->src_ && nc->src_->osrc_) { diff --git a/src/nrniv/pysecname2sec.cpp b/src/nrniv/pysecname2sec.cpp index 5af4adcf02..a47be3e2f4 100644 --- a/src/nrniv/pysecname2sec.cpp +++ b/src/nrniv/pysecname2sec.cpp @@ -245,7 +245,7 @@ void nrnpy_pysecname2sec_remove(Section* sec) { #endif } -void nrn_symdir_load_pysec(SymbolList& sl, void* v) { +void nrn_symdir_load_pysec(std::vector& sl, void* v) { activate(); if (!v) { // top level items are any of the four types @@ -255,7 +255,7 @@ void nrn_symdir_load_pysec(SymbolList& sl, void* v) { SymbolItem* si = new SymbolItem(it->first.c_str(), 0); si->pysec_type_ = cs.first == CELLTYPE ? PYSECOBJ : PYSECNAME; si->pysec_ = (Section*) cs.second; - sl.append(si); + sl.push_back(si); } } } else { @@ -267,7 +267,7 @@ void nrn_symdir_load_pysec(SymbolList& sl, void* v) { SymbolItem* si = new SymbolItem(it->first.c_str(), 0); si->pysec_type_ = PYSECNAME; si->pysec_ = (Section*) cs.second; - sl.append(si); + sl.push_back(si); } } } diff --git a/src/nrniv/savstate.cpp b/src/nrniv/savstate.cpp index d2af0a8ed0..0e2df0f2dc 100644 --- a/src/nrniv/savstate.cpp +++ b/src/nrniv/savstate.cpp @@ -24,7 +24,7 @@ extern ReceiveFunc* pnt_receive; extern NetCvode* net_cvode_instance; extern TQueue* net_cvode_instance_event_queue(NrnThread*); extern hoc_Item* net_cvode_instance_psl(); -extern PlayRecList* net_cvode_instance_prl(); +extern std::vector* net_cvode_instance_prl(); extern double t; extern short* nrn_is_artificial_; static void tqcallback(const TQItem* tq, int i); @@ -479,8 +479,8 @@ void SaveState::alloc() { allocacell(acell_[j], i); ++j; } - PlayRecList* prl = net_cvode_instance_prl(); - nprs_ = prl->count(); + std::vector* prl = net_cvode_instance_prl(); + nprs_ = prl->size(); if (nprs_) { prs_ = new PlayRecordSave*[nprs_]; } @@ -627,11 +627,10 @@ void SaveState::save() { ++j; } if (nprs_) { - PlayRecList* prl = net_cvode_instance_prl(); - int i; - assert(nprs_ == prl->count()); - for (i = 0; i < nprs_; ++i) { - prs_[i] = prl->item(i)->savestate_save(); + std::vector* prl = net_cvode_instance_prl(); + assert(nprs_ == prl->size()); + for (std::size_t i = 0; i < nprs_; ++i) { + prs_[i] = (*prl)[i]->savestate_save(); } } savenet(); @@ -711,10 +710,10 @@ void SaveState::restore(int type) { if (type == 1) { return; } - PlayRecList* prl = net_cvode_instance_prl(); - // during a local step the PlayRecList is augmented with GLineRecord + std::vector* prl = net_cvode_instance_prl(); + // during a local step prl is augmented with GLineRecord // assert(nprs_ == prl->count()); - assert(nprs_ <= prl->count()); + assert(nprs_ <= prl->size()); int i; for (i = 0; i < nprs_; ++i) { prs_[i]->savestate_restore(); From 40ae342d5231dd8412b4c7d4d2626711f25445f2 Mon Sep 17 00:00:00 2001 From: nrnhines Date: Sun, 24 Sep 2023 15:45:53 -0400 Subject: [PATCH 2/3] typo when setting NRN_COVERAGE_FLAGS (#2530) * NRN_COVERAGE_LIB does not need to be set to gcov anymore. --- cmake/Coverage.cmake | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmake/Coverage.cmake b/cmake/Coverage.cmake index c02d691aeb..aa2bae3bf5 100644 --- a/cmake/Coverage.cmake +++ b/cmake/Coverage.cmake @@ -35,8 +35,7 @@ if(NRN_ENABLE_COVERAGE) message(WARNING "Using CMAKE_BUILD_TYPE=Debug is recommended with NRN_ENABLE_COVERAGE") endif() set(NRN_COVERAGE_FLAGS_UNQUOTED --coverage -fno-inline) - string(JOIN " " NRN_COVERAGE_FLAGS ${NRN_COVERAGE_FLAGS}) - set(NRN_COVERAGE_LIB gcov) + string(JOIN " " NRN_COVERAGE_FLAGS ${NRN_COVERAGE_FLAGS_UNQUOTED}) set(NRN_COVERAGE_LINK_FLAGS --coverage) if(NRN_COVERAGE_FILES) @@ -60,11 +59,11 @@ if(NRN_ENABLE_COVERAGE) "${NRN_COVERAGE_FLAGS}" CACHE INTERNAL "Remind that this is always in effect from now on" FORCE) list(APPEND NRN_COMPILE_FLAGS ${NRN_COVERAGE_FLAGS_UNQUOTED}) - list(APPEND NRN_LINK_FLAGS ${NRN_COVERAGE_LINK_FLAGS}) list(APPEND CORENRN_EXTRA_CXX_FLAGS ${NRN_COVERAGE_FLAGS_UNQUOTED}) list(APPEND CORENRN_EXTRA_MECH_CXX_FLAGS ${NRN_COVERAGE_FLAGS_UNQUOTED}) - list(APPEND CORENRN_EXTRA_LINK_FLAGS ${NRN_COVERAGE_LINK_FLAGS}) endif() + list(APPEND NRN_LINK_FLAGS ${NRN_COVERAGE_LINK_FLAGS}) + list(APPEND CORENRN_EXTRA_LINK_FLAGS ${NRN_COVERAGE_LINK_FLAGS}) list(APPEND NRN_COMPILE_DEFS NRN_COVERAGE_ENABLED) else() unset(NRN_COVERAGE_FLAGS) From b4fdb4caa875514d551e3cfb2601f24c977c6c92 Mon Sep 17 00:00:00 2001 From: Pramod Kumbhar Date: Mon, 25 Sep 2023 14:51:13 -0400 Subject: [PATCH 3/3] Update Installer links and changelog with 8.2.3 release (#2502) (#2516) --- docs/changelog.md | 20 ++++++++++++++++++++ docs/index.rst | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index abc5ee7381..ab3b1002c5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,25 @@ # NEURON 8.2 +## 8.2.3 +_Release Date_ : 15-09-2023 + +### What's New + +- The primary purpose of 8.2.3 is to fix the HOC cursor control problems of + the wheel and windows installed versions. +- Many fragments from current master to allow building of installers. + with current compiler toolchains and github actions. + + +### Bug Fixes + +- Fix MacOS linux wheel HOC backspace. +- Fix Windows HOC cursor issues. +- Fix Windows 11 HOC icon. +- Fix Windows and MacOS segfault on multiline HOC statements input from terminal. +- Fix build issues with current compiler toolchains and github actions. +- Deal with .inputrc if missing on Windows + ## 8.2.2 _Release Date_ : 15-12-2022 diff --git a/docs/index.rst b/docs/index.rst index 716e1daafa..3ce69c7774 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -97,7 +97,7 @@ Installation pip3 install neuron - Alternatively, you can use the `PKG installer `_. + Alternatively, you can use the `PKG installer `_. For troubleshooting, see the `detailed installation instructions `_. @@ -115,7 +115,7 @@ Installation .. tab-item:: Windows - `Download the Windows Installer `_. + `Download the Windows Installer `_. You can also install the Linux wheel via the Windows Subsystem for Linux (WSL). See `instructions `_.