From 846634fbf9ddbb524f064cdc83ec6876d551ceeb Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Mon, 9 Oct 2023 22:25:41 +0200 Subject: [PATCH] No more CopyString when Interviews is not used (#2483) * Remove CopyString and replace it with std::string * Simplify xmenu.cpp --- src/ivoc/apwindow.cpp | 2 +- src/ivoc/apwindow.h | 4 +- src/ivoc/datapath.cpp | 55 ++++++++------------ src/ivoc/datapath.h | 4 +- src/ivoc/graph.cpp | 50 ++++++++---------- src/ivoc/graph.h | 8 +-- src/ivoc/nrnsymdiritem.h | 4 +- src/ivoc/objcmd.cpp | 17 +++--- src/ivoc/objcmd.h | 4 +- src/ivoc/ocfile.cpp | 8 +-- src/ivoc/ocfile.h | 6 +-- src/ivoc/ocpointer.cpp | 7 ++- src/ivoc/ocpointer.h | 2 +- src/ivoc/strfun.cpp | 24 ++++----- src/ivoc/symchoos.cpp | 40 +++++++------- src/ivoc/symchoos.h | 2 +- src/ivoc/symdir.cpp | 32 ++++++------ src/ivoc/symdir.h | 14 ++--- src/ivoc/xmenu.cpp | 107 +++++++++++++------------------------- src/ivoc/xmenu.h | 10 ++-- src/ivos/OS/_defines.h | 1 - src/ivos/OS/_undefs.h | 1 - src/ivos/OS/string.h | 24 --------- src/ivos/string.cpp | 63 ---------------------- src/nrncvode/netcvode.cpp | 4 +- src/nrniv/kschan.cpp | 34 ++++++------ src/nrniv/kschan.h | 8 +-- src/nrniv/nrnmenu.cpp | 13 ++--- src/nrniv/nrnmenu.h | 2 +- src/nrniv/shape.cpp | 23 +++----- src/nrniv/shape.h | 2 +- src/nrniv/shapeplt.cpp | 2 +- src/nrniv/spaceplt.cpp | 8 +-- 33 files changed, 214 insertions(+), 371 deletions(-) diff --git a/src/ivoc/apwindow.cpp b/src/ivoc/apwindow.cpp index e4733b7827..71c07bcf36 100644 --- a/src/ivoc/apwindow.cpp +++ b/src/ivoc/apwindow.cpp @@ -452,7 +452,7 @@ void PrintableWindow::type(const char* s) { type_ = s; } const char* PrintableWindow::type() const { - return type_.string(); + return type_.c_str(); } // StandardWindow diff --git a/src/ivoc/apwindow.h b/src/ivoc/apwindow.h index a478212f86..5c173056a0 100644 --- a/src/ivoc/apwindow.h +++ b/src/ivoc/apwindow.h @@ -1,6 +1,8 @@ #ifndef dismiswin_h #define dismiswin_h +#include + #include #include @@ -103,7 +105,7 @@ class PrintableWindow: public DismissableWindow, public Observable { virtual void default_geometry(); private: - CopyString type_; + std::string type_; static OcGlyphContainer* intercept_; bool mappable_; bool xplace_; diff --git a/src/ivoc/datapath.cpp b/src/ivoc/datapath.cpp index eba19af7ba..8450b3c649 100644 --- a/src/ivoc/datapath.cpp +++ b/src/ivoc/datapath.cpp @@ -22,24 +22,16 @@ extern Objectdata* hoc_top_level_data; /*static*/ class PathValue { public: PathValue(); - ~PathValue(); - CopyString* path; + ~PathValue() = default; + std::string path{}; Symbol* sym; double original; char* str; }; PathValue::PathValue() { - path = NULL; str = NULL; sym = NULL; } -PathValue::~PathValue() { - if (path) { - delete path; - } -} - -using StringList = std::vector; class HocDataPathImpl { private: @@ -62,7 +54,7 @@ class HocDataPathImpl { private: std::map table_; - StringList strlist_; + std::vector strlist_; int size_, count_, found_so_far_; int pathstyle_; }; @@ -110,14 +102,14 @@ void HocDataPaths::search() { } } -String* HocDataPaths::retrieve(double* pd) const { +std::string HocDataPaths::retrieve(double* pd) const { assert(impl_->pathstyle_ != 2); // printf("HocDataPaths::retrieve\n"); auto const it = impl_->table_.find(pd); if (it != impl_->table_.end()) { return it->second->path; } - return nullptr; + return {}; } Symbol* HocDataPaths::retrieve_sym(double* pd) const { @@ -139,13 +131,13 @@ void HocDataPaths::append(char** pd) { } } -String* HocDataPaths::retrieve(char** pd) const { +std::string HocDataPaths::retrieve(char** pd) const { // printf("HocDataPaths::retrieve\n"); auto const it = impl_->table_.find(pd); if (it != impl_->table_.end()) { return it->second->path; } - return nullptr; + return {}; } /*------------------------------*/ @@ -205,20 +197,20 @@ PathValue* HocDataPathImpl::found_v(void* v, const char* buf, Symbol* sym) { PathValue* pv; if (pathstyle_ != 2) { char path[500]; - CopyString cs(""); + std::string cs{}; for (const auto& str: strlist_) { - Sprintf(path, "%s%s.", cs.string(), str); + Sprintf(path, "%s%s.", cs.c_str(), str.c_str()); cs = path; } - Sprintf(path, "%s%s", cs.string(), buf); + Sprintf(path, "%s%s", cs.c_str(), buf); const auto& it = table_.find(v); if (it == table_.end()) { hoc_warning("table lookup failed for pointer for-", path); return nullptr; } pv = it->second; - if (!pv->path) { - pv->path = new CopyString(path); + if (pv->path.empty()) { + pv->path = path; pv->sym = sym; ++found_so_far_; } @@ -258,7 +250,7 @@ void HocDataPathImpl::search(Objectdata* od, Symlist* sl) { Symbol* sym; int i, total; char buf[200]; - CopyString cs(""); + std::string cs{}; if (sl) for (sym = sl->first; sym; sym = sym->next) { if (sym->cpublic != 2) { @@ -278,7 +270,7 @@ void HocDataPathImpl::search(Objectdata* od, Symlist* sl) { if (pd[i] == sentinal) { Sprintf(buf, "%s%s", sym->name, hoc_araystr(sym, i, od)); cs = buf; - found(pd + i, cs.string(), sym); + found(pd + i, cs.c_str(), sym); } } } break; @@ -287,7 +279,7 @@ void HocDataPathImpl::search(Objectdata* od, Symlist* sl) { if (*pstr == NULL) { Sprintf(buf, "%s", sym->name); cs = buf; - found(pstr, cs.string(), sym); + found(pstr, cs.c_str(), sym); } } break; case OBJECTVAR: { @@ -304,7 +296,7 @@ void HocDataPathImpl::search(Objectdata* od, Symlist* sl) { if (obp[i]->u.dataspace != od) { Sprintf(buf, "%s%s", sym->name, hoc_araystr(sym, i, od)); cs = buf; - strlist_.push_back((char*) cs.string()); + strlist_.push_back(cs); obp[i]->recurse = 1; search(obp[i]->u.dataspace, obp[i]->ctemplate->symtable); obp[i]->recurse = 0; @@ -315,7 +307,7 @@ void HocDataPathImpl::search(Objectdata* od, Symlist* sl) { if (t->is_point_) { Sprintf(buf, "%s%s", sym->name, hoc_araystr(sym, i, od)); cs = buf; - strlist_.push_back((char*) cs.string()); + strlist_.push_back(cs); search((Point_process*) obp[i]->u.this_pointer, sym); strlist_.pop_back(); } @@ -330,7 +322,7 @@ void HocDataPathImpl::search(Objectdata* od, Symlist* sl) { if (pitm[i]) { Sprintf(buf, "%s%s", sym->name, hoc_araystr(sym, i, od)); cs = buf; - strlist_.push_back((char*) cs.string()); + strlist_.push_back(cs); search(hocSEC(pitm[i])); strlist_.pop_back(); } @@ -343,7 +335,7 @@ void HocDataPathImpl::search(Objectdata* od, Symlist* sl) { Object* obj = OBJ(q); Sprintf(buf, "%s[%d]", sym->name, obj->index); cs = buf; - strlist_.push_back((char*) cs.string()); + strlist_.push_back(cs); if (!t->constructor) { search(obj->u.dataspace, t->symtable); } else { @@ -361,14 +353,14 @@ void HocDataPathImpl::search(Objectdata* od, Symlist* sl) { void HocDataPathImpl::search_vectors() { char buf[200]; - CopyString cs(""); + std::string cs{}; cTemplate* t = sym_vec->u.ctemplate; hoc_Item* q; ITERATE(q, t->olist) { Object* obj = OBJ(q); Sprintf(buf, "%s[%d]", sym_vec->name, obj->index); cs = buf; - strlist_.push_back((char*) cs.string()); + strlist_.push_back(cs); Vect* vec = (Vect*) obj->u.this_pointer; int size = vec->size(); double* pd = vector_vec(vec); @@ -384,14 +376,14 @@ void HocDataPathImpl::search_vectors() { void HocDataPathImpl::search_pysec() { #if USE_PYTHON - CopyString cs(""); + std::string cs{}; hoc_Item* qsec; // ForAllSections(sec) ITERATE(qsec, section_list) { Section* sec = hocSEC(qsec); if (sec->prop && sec->prop->dparam[PROP_PY_INDEX].get()) { cs = secname(sec); - strlist_.push_back((char*) cs.string()); + strlist_.push_back(cs); search(sec); strlist_.pop_back(); } @@ -418,7 +410,6 @@ void HocDataPathImpl::search(Section* sec) { } void HocDataPathImpl::search(Node* nd, double x) { char buf[100]; - CopyString cs(""); if (NODEV(nd) == sentinal) { Sprintf(buf, "v(%g)", x); // the conversion below yields a pointer that is potentially invalidated diff --git a/src/ivoc/datapath.h b/src/ivoc/datapath.h index 1e8d96920a..0f88d6e6d4 100644 --- a/src/ivoc/datapath.h +++ b/src/ivoc/datapath.h @@ -15,8 +15,8 @@ class HocDataPaths { void append(double*); void append(char**); void search(); - String* retrieve(double*) const; - String* retrieve(char**) const; + std::string retrieve(double*) const; + std::string retrieve(char**) const; Symbol* retrieve_sym(double*) const; int style(); diff --git a/src/ivoc/graph.cpp b/src/ivoc/graph.cpp index b073a0f350..3868bc0707 100644 --- a/src/ivoc/graph.cpp +++ b/src/ivoc/graph.cpp @@ -1369,7 +1369,6 @@ Graph::Graph(bool b) loc_ = 0; x_expr_ = NULL; x_pval_ = {}; - var_name_ = NULL; rvp_ = NULL; cross_action_ = NULL; vector_copy_ = false; @@ -1463,20 +1462,13 @@ Graph::~Graph() { Resource::unref(sc_); Resource::unref(current_polyline_); Resource::unref(family_label_); - if (var_name_) { - delete var_name_; - } if (cross_action_) { delete cross_action_; } } void Graph::name(char* s) { - if (var_name_) { - *var_name_ = s; - } else { - var_name_ = new CopyString(s); - } + var_name_ = s; } void Graph::help() { @@ -2363,14 +2355,14 @@ void Graph::save_phase2(std::ostream& o) { Sprintf(buf, "save_window_.family(\"%s\")", family_label_->text()); o << buf << std::endl; } - if (var_name_) { - if ((var_name_->string())[var_name_->length() - 1] == '.') { - Sprintf(buf, "%sappend(save_window_)", var_name_->string()); + if (!var_name_.empty()) { + if (var_name_.back() == '.') { + Sprintf(buf, "%sappend(save_window_)", var_name_.c_str()); } else { - Sprintf(buf, "%s = save_window_", var_name_->string()); + Sprintf(buf, "%s = save_window_", var_name_.c_str()); } o << buf << std::endl; - Sprintf(buf, "save_window_.save_name(\"%s\")", var_name_->string()); + Sprintf(buf, "save_window_.save_name(\"%s\")", var_name_.c_str()); o << buf << std::endl; } if (x_expr_) { @@ -2429,7 +2421,7 @@ void Graph::choose_sym() { neuron::container::data_handle pd_handle{pd}; if (sc_->selected_vector_count()) { - Sprintf(buf, "%s", sc_->selected()->string()); + Sprintf(buf, "%s", sc_->selected().c_str()); GraphVector* gv = new GraphVector(buf); gv->color(color()); gv->brush(brush()); @@ -2444,19 +2436,19 @@ void Graph::choose_sym() { flush(); break; } else if (pd) { - add_var(sc_->selected()->string(), color(), brush(), 1, 2); + add_var(sc_->selected().c_str(), color(), brush(), 1, 2); break; } else { - CopyString s(*sc_->selected()); + auto s = sc_->selected(); // above required due to bug in mswindows version in which // sc_->selected seems volatile under some kinds of hoc // executions. - Sprintf(buf, "hoc_ac_ = %s\n", s.string()); + Sprintf(buf, "hoc_ac_ = %s\n", s.c_str()); if (oc.run(buf) == 0) { - add_var(s.string(), color(), brush(), 0, 2); + add_var(s.c_str(), color(), brush(), 0, 2); break; } - hoc_warning(s.string(), "is not an expression."); + hoc_warning(s.c_str(), "is not an expression."); } } // sc_->unref(); @@ -2475,12 +2467,12 @@ void Graph::family_label_chooser() { } while (fsc_->post_for_aligned(XYView::current_pick_view()->canvas()->window(), .5, 1.)) { char buf[256]; - Sprintf(buf, "hoc_ac_ = %s\n", fsc_->selected()->string()); + Sprintf(buf, "hoc_ac_ = %s\n", fsc_->selected().c_str()); if (oc.run(buf) == 0) { - family(fsc_->selected()->string()); + family(fsc_->selected().c_str()); break; } - hoc_warning(sc_->selected()->string(), "is not an expression."); + hoc_warning(sc_->selected().c_str(), "is not an expression."); } } @@ -3010,7 +3002,7 @@ GLabel::~GLabel() { } Glyph* GLabel::clone() const { - return new GLabel(text_.string(), color_, fixtype_, scale_, x_align_, y_align_); + return new GLabel(text_.c_str(), color_, fixtype_, scale_, x_align_, y_align_); } void GLabel::save(std::ostream& o, Coord x, Coord y) { @@ -3022,7 +3014,7 @@ void GLabel::save(std::ostream& o, Coord x, Coord y) { "save_window_.label(%g, %g, \"%s\", %d, %g, %g, %g, %d)", x, y, - text_.string(), + text_.c_str(), fixtype_, scale_, x_align_, @@ -3050,7 +3042,7 @@ void GLabel::align(float x, float y) { void GLabel::color(const Color* c) { Resource::unref(label_); WidgetKit& kit = *WidgetKit::instance(); - label_ = new Label(text_, kit.font(), c); + label_ = new Label(text_.c_str(), kit.font(), c); label_->ref(); Resource::ref(c); Resource::unref(color_); @@ -3064,7 +3056,7 @@ void GLabel::text(const char* t) { Resource::unref(label_); WidgetKit& kit = *WidgetKit::instance(); text_ = t; - label_ = new Label(text_, kit.font(), color_); + label_ = new Label(text_.c_str(), kit.font(), color_); label_->ref(); } @@ -3106,7 +3098,7 @@ void GLabel::draw(Canvas* c, const Allocation& a1) const { // printf("transformer %g %g %g %g %g %g\n", a00, a01, a10, a11, a20, a21); label_->draw(c, a2); c->pop_transform(); - IfIdraw(text(c, text_.string(), t, NULL, color())); + IfIdraw(text(c, text_.c_str(), t, NULL, color())); } // DataVec------------------ @@ -3288,7 +3280,7 @@ GraphVector::~GraphVector() { } const char* GraphVector::name() const { - return name_.string(); + return name_.c_str(); } void GraphVector::save(std::ostream&) {} diff --git a/src/ivoc/graph.h b/src/ivoc/graph.h index 69b2b7b48f..72e58b5874 100644 --- a/src/ivoc/graph.h +++ b/src/ivoc/graph.h @@ -170,7 +170,7 @@ class Graph: public Scene { // Scene of GraphLines labels and polylines bool extension_flushed_; SymChooser* sc_; static SymChooser* fsc_; - CopyString* var_name_; + std::string var_name_; GPolyLine* current_polyline_; const Color* color_; @@ -396,7 +396,7 @@ class GraphVector: public GPolyLine, public Observer { // fixed x and vector of private: DataPointers* dp_; - CopyString name_; + std::string name_; bool disconnect_defer_; }; @@ -447,7 +447,7 @@ class GLabel: public Glyph { return scale_; } const char* text() const { - return text_.string(); + return text_.c_str(); } int fixtype() const { return fixtype_; @@ -480,7 +480,7 @@ class GLabel: public Glyph { int fixtype_; float scale_; float x_align_, y_align_; - CopyString text_; + std::string text_; Glyph* label_; const Color* color_; GPolyLine* gpl_; diff --git a/src/ivoc/nrnsymdiritem.h b/src/ivoc/nrnsymdiritem.h index 6f395aacad..f9b48341b7 100644 --- a/src/ivoc/nrnsymdiritem.h +++ b/src/ivoc/nrnsymdiritem.h @@ -19,7 +19,7 @@ class SymbolItem { return ob_; } void no_object(); - const String& name() const { + const std::string& name() const { return name_; } bool is_directory() const; @@ -30,7 +30,7 @@ class SymbolItem { int pysec_type_; /* PYSECOBJ (cell prefix) or PYSECNAME (Section) */ void* pysec_; /* Name2Section* or Section* */ private: - CopyString name_; + std::string name_; Symbol* symbol_; int index_; Object* ob_; diff --git a/src/ivoc/objcmd.cpp b/src/ivoc/objcmd.cpp index 92384c1636..9b30de6fa1 100644 --- a/src/ivoc/objcmd.cpp +++ b/src/ivoc/objcmd.cpp @@ -31,12 +31,11 @@ HocCommand::HocCommand(Object* pobj) { } po_ = pobj; hoc_obj_ref(po_); - s_ = NULL; obj_ = NULL; } void HocCommand::init(const char* cmd, Object* obj) { - s_ = new CopyString(cmd); + s_ = std::make_unique(cmd); obj_ = obj; po_ = NULL; if (obj_) { @@ -46,17 +45,13 @@ void HocCommand::init(const char* cmd, Object* obj) { void HocCommand::update(Observable*) { // obj_ has been freed obj_ = NULL; - delete s_; - s_ = new CopyString(""); + s_ = std::make_unique(""); } HocCommand::~HocCommand() { if (obj_) { nrn_notify_pointer_disconnect(this); } - if (s_) { - delete s_; - } if (po_) { hoc_obj_unref(po_); } @@ -66,9 +61,9 @@ void HocCommand::help() { #if HAVE_IV char buf[200]; if (obj_) { - Sprintf(buf, "%s %s", s_->string(), obj_->ctemplate->sym->name); + Sprintf(buf, "%s %s", s_->c_str(), obj_->ctemplate->sym->name); } else { - Sprintf(buf, "%s", s_->string()); + Sprintf(buf, "%s", s_->c_str()); } Oc::help(buf); #endif @@ -77,7 +72,7 @@ void HocCommand::help() { const char* ccc = "PythonObject"; const char* HocCommand::name() { if (po_ == NULL) { - return s_->string(); + return s_->c_str(); } else { return ccc; } @@ -106,7 +101,7 @@ int HocCommand::execute(bool notify) { return 0; } char buf[256]; - Sprintf(buf, "{%s}\n", s_->string()); + Sprintf(buf, "{%s}\n", s_->c_str()); err = hoc_obj_run(buf, obj_); } #if HAVE_IV diff --git a/src/ivoc/objcmd.h b/src/ivoc/objcmd.h index b3bfd1985e..a9742b59d1 100644 --- a/src/ivoc/objcmd.h +++ b/src/ivoc/objcmd.h @@ -1,6 +1,8 @@ #ifndef objcmd_h #define objcmd_h +#include + #include #include #if HAVE_IV @@ -39,7 +41,7 @@ class HocCommand: public Observer { private: Object* obj_; - CopyString* s_; + std::unique_ptr s_{}; Object* po_; }; diff --git a/src/ivoc/ocfile.cpp b/src/ivoc/ocfile.cpp index bf7cca386e..ee5b24da7b 100644 --- a/src/ivoc/ocfile.cpp +++ b/src/ivoc/ocfile.cpp @@ -311,7 +311,7 @@ void OcFile::close() { } void OcFile::set_name(const char* s) { close(); - if (s != filename_.string()) { + if (s != filename_.c_str()) { filename_ = s; } } @@ -329,7 +329,7 @@ void OcFile::binary_mode() { // printf("can't switch to binary mode. No setmode\n"); mode_[1] = 'b'; mode_[2] = '\0'; - file_ = freopen(filename_.string(), mode_, file()); + file_ = freopen(filename_.c_str(), mode_, file()); #else setmode(fileno(file()), O_BINARY); #endif @@ -471,13 +471,13 @@ void OcFile::file_chooser_style(const char* type, const char* OcFile::dir() { #if HAVE_IV if (fc_) { - dirname_ = *fc_->dir(); + dirname_ = *fc_->dir()->string(); } else #endif { dirname_ = ""; } - return dirname_.string(); + return dirname_.c_str(); } bool OcFile::file_chooser_popup() { diff --git a/src/ivoc/ocfile.h b/src/ivoc/ocfile.h index f7269adcbb..ffcb571b3a 100644 --- a/src/ivoc/ocfile.h +++ b/src/ivoc/ocfile.h @@ -13,7 +13,7 @@ class OcFile { bool open(const char* filename, const char* type); void set_name(const char* s); const char* get_name() { - return filename_.string(); + return filename_.c_str(); } const char* dir(); void close(); @@ -48,8 +48,8 @@ class OcFile { #if HAVE_IV int chooser_type_; #endif - CopyString filename_; - CopyString dirname_; + std::string filename_; + std::string dirname_; FILE* file_; #ifdef WIN32 bool binary_; diff --git a/src/ivoc/ocpointer.cpp b/src/ivoc/ocpointer.cpp index b1edf7be92..a1cc1b04f9 100644 --- a/src/ivoc/ocpointer.cpp +++ b/src/ivoc/ocpointer.cpp @@ -117,13 +117,12 @@ void OcPointer_reg() { sv->u.ctemplate->steer = steer_val; } -StmtInfo::StmtInfo(const char* s) { - stmt_ = new CopyString(s); +StmtInfo::StmtInfo(const char* s) + : stmt_(s) { parse(); } StmtInfo::~StmtInfo() { - delete stmt_; hoc_free_list(&symlist_); } @@ -134,7 +133,7 @@ void StmtInfo::parse() { symlist_ = NULL; ParseTopLevel ptl; bool see_arg = false; - for (s = stmt_->string(), d = buf; *s; ++s, ++d) { + for (s = stmt_.c_str(), d = buf; *s; ++s, ++d) { if (*s == '$' && s[1] == '1') { strcpy(d, "hoc_ac_"); s++; diff --git a/src/ivoc/ocpointer.h b/src/ivoc/ocpointer.h index 09529bc325..8e51c13f1f 100644 --- a/src/ivoc/ocpointer.h +++ b/src/ivoc/ocpointer.h @@ -24,7 +24,7 @@ class StmtInfo { virtual ~StmtInfo(); void play_one(double); void parse(); - CopyString* stmt_; + std::string stmt_{}; Symlist* symlist_; Symbol* symstmt_; }; diff --git a/src/ivoc/strfun.cpp b/src/ivoc/strfun.cpp index f9c1618d93..ccf188ef41 100644 --- a/src/ivoc/strfun.cpp +++ b/src/ivoc/strfun.cpp @@ -63,13 +63,13 @@ static double l_head(void*) { } static double l_tail(void*) { - CopyString text(gargstr(1)); + std::string text(gargstr(1)); Regexp r(gargstr(2)); - r.Search(text.string(), text.length(), 0, text.length()); + r.Search(text.c_str(), text.size(), 0, text.size()); int i = r.EndOfMatch(); char** tail = hoc_pgargstr(3); if (i >= 0) { - hoc_assign_str(tail, text.string() + i); + hoc_assign_str(tail, text.c_str() + i); } else { hoc_assign_str(tail, ""); } @@ -78,16 +78,16 @@ static double l_tail(void*) { } static double l_left(void*) { - CopyString text(gargstr(1)); - CopyString newtext = text.left(int(chkarg(2, 0, strlen(gargstr(1))))); - hoc_assign_str(hoc_pgargstr(1), newtext.string()); + std::string text(gargstr(1)); + std::string newtext = text.substr(0, int(chkarg(2, 0, strlen(gargstr(1))))); + hoc_assign_str(hoc_pgargstr(1), newtext.c_str()); return 1.; } static double l_right(void*) { - CopyString text(gargstr(1)); - CopyString newtext = text.right(int(chkarg(2, 0, strlen(gargstr(1))))); - hoc_assign_str(hoc_pgargstr(1), newtext.string()); + std::string text(gargstr(1)); + std::string newtext = text.substr(int(chkarg(2, 0, strlen(gargstr(1))))); + hoc_assign_str(hoc_pgargstr(1), newtext.c_str()); return 1.; } @@ -359,7 +359,7 @@ IvocAliases::~IvocAliases() { } Symbol* IvocAliases::lookup(const char* name) { String s(name); - const auto& it = symtab_.find(s); + const auto& it = symtab_.find(s.string()); if (it != symtab_.end()) { return it->second; } @@ -375,13 +375,13 @@ Symbol* IvocAliases::install(const char* name) { sp->extra = 0; sp->arayinfo = 0; String s(sp->name); - symtab_.emplace(s, sp); + symtab_.emplace(s.string(), sp); return sp; } void IvocAliases::remove(Symbol* sym) { hoc_free_symspace(sym); String s(sym->name); - auto it = symtab_.find(s); + auto it = symtab_.find(s.string()); symtab_.erase(it); free(sym->name); free(sym); diff --git a/src/ivoc/symchoos.cpp b/src/ivoc/symchoos.cpp index ab5de02edb..ea9048bf58 100644 --- a/src/ivoc/symchoos.cpp +++ b/src/ivoc/symchoos.cpp @@ -81,7 +81,7 @@ class SymChooserImpl { int* filter_map_; SymDirectory** dir_; SymChooserAction* action_; - const String* selected_; + std::string selected_; CopyString last_selected_; int last_index_; Style* style_; @@ -200,7 +200,7 @@ static double text(void* v) { #if HAVE_IV IFGUI SymChooser* sc = (SymChooser*) v; - hoc_assign_str(hoc_pgargstr(1), sc->selected()->string()); + hoc_assign_str(hoc_pgargstr(1), sc->selected().c_str()); ENDGUI return 0.; #else @@ -247,7 +247,7 @@ SymChooser::~SymChooser() { delete impl_; } -const String* SymChooser::selected() const { +const std::string& SymChooser::selected() const { return impl_->selected_; } @@ -506,7 +506,7 @@ void SymChooserImpl::load(int bindex) { filter_map_ = index; // printf("loading %d\n", bindex); for (int i = 0; i < dircount; i++) { - const String& f = d.name(i); + const String& f = d.name(i).c_str(); bool is_dir = d.is_directory(i); if ((is_dir && filtered(f, directory_filter_)) || (!is_dir && filtered(f, filter_))) { Glyph* name = kit.label(f); @@ -529,7 +529,7 @@ void SymChooserImpl::load(int bindex) { // to avoid a premature browser request which ends up showing an // empty list. fbrowser_[bindex]->refresh(); - editor_->field(d.path()); + editor_->field(d.path().c_str()); kit.pop_style(); } @@ -563,7 +563,7 @@ bool SymChooserImpl::filtered(const String& name, FieldEditor* e) { if (s == NULL || s->length() == 0) { return true; } - return s == NULL || s->length() == 0 || SymDirectory::match(name, *s); + return s == NULL || s->length() == 0 || SymDirectory::match(name.string(), s->string()); } void SymChooserImpl::accept_browser_index(int bindex) { @@ -573,8 +573,8 @@ void SymChooserImpl::accept_browser_index(int bindex) { } // i = filter_map_[i]; SymDirectory* dir = dir_[bindex]; - const String& path = dir->path(); - const String& name = dir->name(i); + const String& path = dir->path().c_str(); + const String& name = dir->name(i).c_str(); Symbol* sym = dir->symbol(i); int length = path.length() + name.length(); auto const tmp_len = length + 2; @@ -584,7 +584,7 @@ void SymChooserImpl::accept_browser_index(int bindex) { editor_->field(tmp); last_selected_ = tmp; last_index_ = i; - selected_ = editor_->text(); + selected_ = editor_->text()->string(); if (dir->is_directory(i)) { if (chdir(bindex, i)) { fchooser_->focus(editor_); @@ -600,7 +600,7 @@ void SymChooserImpl::accept_browser_index(int bindex) { } double* SymChooserImpl::selected_var() { - if (last_index_ != -1 && strcmp(selected_->string(), last_selected_.string()) == 0) { + if (last_index_ != -1 && selected_ == last_selected_.string()) { SymDirectory* dir = dir_[browser_index_]; return dir->variable(last_index_); } else { @@ -609,7 +609,7 @@ double* SymChooserImpl::selected_var() { } int SymChooserImpl::selected_vector_count() { - if (last_index_ != -1 && strcmp(selected_->string(), last_selected_.string()) == 0) { + if (last_index_ != -1 && selected_ == last_selected_.string()) { SymDirectory* dir = dir_[browser_index_]; return dir->whole_vector(last_index_); } else { @@ -625,15 +625,15 @@ void SymChooserImpl::accept_browser() { return; } // i = filter_map_[i]; - const String& path = dir_[bi]->path(); - const String& name = dir_[bi]->name(i); + const String& path = dir_[bi]->path().c_str(); + const String& name = dir_[bi]->name(i).c_str(); int length = path.length() + name.length(); char* tmp = new char[length + 1]; std::snprintf( tmp, length + 1, "%.*s%.*s", path.length(), path.string(), name.length(), name.string()); // printf("accept_browser %s\n", tmp); editor_->field(tmp); - selected_ = editor_->text(); + selected_ = editor_->text()->string(); if (dir_[bi]->is_directory(i)) { if (chdir(bi, i)) { fchooser_->focus(editor_); @@ -647,21 +647,19 @@ void SymChooserImpl::accept_browser() { } void SymChooserImpl::cancel_browser() { - selected_ = NULL; + selected_.clear(); fchooser_->dismiss(false); } void SymChooserImpl::editor_accept(FieldEditor* e) { - int i; - int bi = browser_index_; - if ((i = dir_[bi]->index(*e->text())) >= 0) { - if (!chdir(bi, i)) { - selected_ = &dir_[bi]->name(i); + if (int i = dir_[browser_index_]->index(e->text()->string()); i >= 0) { + if (!chdir(browser_index_, i)) { + selected_ = dir_[browser_index_]->name(i); fchooser_->dismiss(true); } return; } else { - selected_ = e->text(); + selected_ = e->text()->string(); fchooser_->dismiss(true); } } diff --git a/src/ivoc/symchoos.h b/src/ivoc/symchoos.h index 2d94449d09..dc465fe355 100644 --- a/src/ivoc/symchoos.h +++ b/src/ivoc/symchoos.h @@ -55,7 +55,7 @@ class SymChooser: public Dialog { SymChooser(SymDirectory*, WidgetKit*, Style*, SymChooserAction* = NULL, int nbrowser = 3); virtual ~SymChooser(); - virtual const String* selected() const; + virtual const std::string& selected() const; virtual double* selected_var(); virtual int selected_vector_count(); virtual void reread(); diff --git a/src/ivoc/symdir.cpp b/src/ivoc/symdir.cpp index 2a06893c21..0083f37c81 100644 --- a/src/ivoc/symdir.cpp +++ b/src/ivoc/symdir.cpp @@ -44,7 +44,7 @@ class SymDirectoryImpl: public Observer { cTemplate* t_; std::vector symbol_lists_; - CopyString path_; + std::string path_; void load(int type); void load(int type, Symlist*); @@ -62,7 +62,7 @@ class SymDirectoryImpl: public Observer { }; static int compare_entries(const SymbolItem* e1, const SymbolItem* e2) { - int i = strcmp(e1->name().string(), e2->name().string()); + int i = strcmp(e1->name().c_str(), e2->name().c_str()); if (i == 0) { return e1->array_index() > e2->array_index(); } @@ -74,7 +74,7 @@ void SymDirectoryImpl::sort() { } // SymDirectory -SymDirectory::SymDirectory(const String& parent_path, +SymDirectory::SymDirectory(const std::string& parent_path, Object* parent_obj, Symbol* sym, int array_index, @@ -94,7 +94,7 @@ SymDirectory::SymDirectory(const String& parent_path, if (sym->type == TEMPLATE) { suffix = '_'; } - impl_->make_pathname(parent_path.string(), + impl_->make_pathname(parent_path.c_str(), sym->name, hoc_araystr(sym, array_index, obd), suffix); @@ -126,7 +126,7 @@ SymDirectory::SymDirectory(const String& parent_path, } break; default: - hoc_execerror("Don't know how to make a directory out of", path().string()); + hoc_execerror("Don't know how to make a directory out of", path().c_str()); break; } impl_->sort(); @@ -157,8 +157,8 @@ SymDirectory* SymDirectory::newsymdir(int index) { section_ref(d->impl_->sec_); d->impl_->load_section(); } - d->impl_->path_ = concat(path().string(), si->name().string()); - d->impl_->path_ = concat(d->impl_->path_.string(), "."); + d->impl_->path_ = concat(path().c_str(), si->name().c_str()); + d->impl_->path_ = concat(d->impl_->path_.c_str(), "."); d->impl_->sort(); return d; } @@ -258,7 +258,7 @@ double* SymDirectory::variable(int index) { } else { char buf[256], *cp; - Sprintf(buf, "%s%s", path().string(), name(index).string()); + Sprintf(buf, "%s%s", path().c_str(), name(index).c_str()); if (whole_vector(index)) { // rangevar case for [all] // replace [all] with [0] cp = strstr(buf, "[all]"); @@ -278,20 +278,20 @@ int SymDirectory::whole_vector(int index) { return impl_->symbol_lists_.at(index)->whole_vector(); } -const String& SymDirectory::path() const { +const std::string& SymDirectory::path() const { return impl_->path_; } int SymDirectory::count() const { return impl_->symbol_lists_.size(); } -const String& SymDirectory::name(int index) const { +const std::string& SymDirectory::name(int index) const { return impl_->symbol_lists_.at(index)->name(); } int SymDirectory::array_index(int i) const { return impl_->symbol_lists_.at(i)->array_index(); } -int SymDirectory::index(const String& name) const { +int SymDirectory::index(const std::string& name) const { for (const auto&& [i, symbol]: enumerate(impl_->symbol_lists_)) { if (name == symbol->name()) { return i; @@ -299,15 +299,15 @@ int SymDirectory::index(const String& name) const { } return -1; } -void SymDirectory::whole_name(int index, CopyString& s) const { - const String& s1 = impl_->path_; - const String& s2 = name(index); - s = concat(s1.string(), s2.string()); +void SymDirectory::whole_name(int index, std::string& s) const { + auto s1 = impl_->path_; + auto s2 = name(index); + s = s1 + s2; } bool SymDirectory::is_directory(int index) const { return impl_->symbol_lists_.at(index)->is_directory(); } -bool SymDirectory::match(const String&, const String&) { +bool SymDirectory::match(const std::string&, const std::string&) { return true; } Symbol* SymDirectory::symbol(int index) const { diff --git a/src/ivoc/symdir.h b/src/ivoc/symdir.h index 20b269b4fc..f71bdb3d98 100644 --- a/src/ivoc/symdir.h +++ b/src/ivoc/symdir.h @@ -20,14 +20,14 @@ class IvocAliases { Symbol* symbol(int); Object* ob_; // not referenced - std::map symtab_; + std::map symtab_; }; /* List of Symbols considered as a directory */ class SymDirectory: public Resource { public: - SymDirectory(const String& parent_path, + SymDirectory(const std::string& parent_path, Object* parent_object, Symbol*, int array_index = 0, @@ -37,16 +37,16 @@ class SymDirectory: public Resource { SymDirectory(); virtual ~SymDirectory(); - virtual const String& path() const; + virtual const std::string& path() const; virtual int count() const; - virtual const String& name(int index) const; - virtual int index(const String&) const; - virtual void whole_name(int index, CopyString&) const; + virtual const std::string& name(int index) const; + virtual int index(const std::string&) const; + virtual void whole_name(int index, std::string&) const; virtual bool is_directory(int index) const; virtual double* variable(int index); virtual int whole_vector(int index); - static bool match(const String& name, const String& pattern); + static bool match(const std::string& name, const std::string& pattern); Symbol* symbol(int index) const; int array_index(int index) const; Object* object() const; // the parent_object diff --git a/src/ivoc/xmenu.cpp b/src/ivoc/xmenu.cpp index 082db077ec..82d50997f9 100644 --- a/src/ivoc/xmenu.cpp +++ b/src/ivoc/xmenu.cpp @@ -1456,7 +1456,6 @@ HocVarLabel::HocVarLabel(char** cpp, PolyGlyph* pg, Object* pyvar) } else { cp_ = *cpp_; } - variable_ = NULL; p_ = new Patch(LayoutKit::instance()->margin(WidgetKit::instance()->label(cp_), 3)); p_->ref(); pg->append(p_); @@ -1464,9 +1463,6 @@ HocVarLabel::HocVarLabel(char** cpp, PolyGlyph* pg, Object* pyvar) HocVarLabel::~HocVarLabel() { p_->unref(); - if (variable_) { - delete variable_; - } if (pyvar_) { hoc_obj_unref(pyvar_); if (cp_) { @@ -1476,9 +1472,9 @@ HocVarLabel::~HocVarLabel() { } void HocVarLabel::write(std::ostream& o) { - if (variable_ && cpp_) { + if (!variable_.empty() && cpp_) { char buf[256]; - Sprintf(buf, "xvarlabel(%s)", variable_->string()); + Sprintf(buf, "xvarlabel(%s)", variable_.c_str()); o << buf << std::endl; } else { o << "xlabel(\"\")" << std::endl; @@ -1879,12 +1875,11 @@ HocValEditor::HocValEditor(const char* name, canrun_ = canrun; active_ = false; domain_limits_ = NULL; - variable_ = NULL; pyvar_ = pyvar; if (pyvar) { hoc_obj_ref(pyvar); } else if (variable) { - variable_ = new CopyString(variable); + variable_ = variable; Symbol* sym = hoc_get_symbol(variable); if (sym && sym->extra) { domain_limits_ = sym->extra->parmlimits; @@ -1896,9 +1891,6 @@ HocValEditor::HocValEditor(const char* name, HocValEditor::~HocValEditor() { // printf("~HocValEditor\n"); - if (variable_) { - delete variable_; - } if (pyvar_) { hoc_obj_unref(pyvar_); } @@ -1942,8 +1934,8 @@ void HocValEditor::set_val(double x) { Oc oc; if (pval_) { *pval_ = hoc_ac_; - } else if (variable_) { - Sprintf(buf, "%s = hoc_ac_\n", variable_->string()); + } else if (!variable_.empty()) { + Sprintf(buf, "%s = hoc_ac_\n", variable_.c_str()); oc.run(buf); } } @@ -1954,9 +1946,9 @@ double HocValEditor::get_val() { return neuron::python::methods.guigetval(pyvar_); } else if (pval_) { return *pval_; - } else if (variable_) { + } else if (!variable_.empty()) { Oc oc; - Sprintf(buf, "hoc_ac_ = %s\n", variable_->string()); + Sprintf(buf, "hoc_ac_ = %s\n", variable_.c_str()); oc.run(buf); return hoc_ac_; } else { @@ -1983,8 +1975,8 @@ void HocValEditor::audit() { auto sout = std::stringstream{}; if (pyvar_) { return; - } else if (variable_) { - sout << variable_->string() << " = " << fe_->text()->string(); + } else if (!variable_.empty()) { + sout << variable_ << " = " << fe_->text()->string(); } else if (pval_) { sout << "// " << pval_ << " set to " << fe_->text()->string(); } @@ -2002,9 +1994,9 @@ void HocValEditor::updateField() { } else if (pval_) { Sprintf(buf, xvalue_format->string(), *pval_); hoc_ac_ = *pval_; - } else if (variable_) { + } else if (!variable_.empty()) { Oc oc; - Sprintf(buf, "hoc_ac_ = %s\n", variable_->string()); + Sprintf(buf, "hoc_ac_ = %s\n", variable_.c_str()); if (oc.run(buf, 0)) { strcpy(buf, "Doesn't exist"); } else { @@ -2021,10 +2013,10 @@ void HocValEditor::updateField() { void HocValEditor::write(std::ostream& o) { char buf[200]; Oc oc; - if (variable_) { - Sprintf(buf, "hoc_ac_ = %s\n", variable_->string()); + if (!variable_.empty()) { + Sprintf(buf, "hoc_ac_ = %s\n", variable_.c_str()); oc.run(buf); - Sprintf(buf, "%s = %g", variable_->string(), hoc_ac_); + Sprintf(buf, "%s = %g", variable_.c_str(), hoc_ac_); } else if (pval_) { Sprintf(buf, "/* don't know the hoc path to %g", *pval_); return; @@ -2044,7 +2036,7 @@ void HocValEditor::write(std::ostream& o) { 200, "xvalue(\"%s\",\"%s\", %d,\"%s\", %d, %d )", getStr(), - variable_->string(), + variable_.c_str(), hoc_default_val_editor(), hideQuote(action_->name()), (int) canrun_, @@ -2053,8 +2045,8 @@ void HocValEditor::write(std::ostream& o) { } const char* HocValEditor::variable() const { - if (variable_) { - return variable_->string(); + if (!variable_.empty()) { + return variable_.c_str(); } else { return NULL; } @@ -2321,28 +2313,22 @@ void HocPanel::data_path(HocDataPaths* hdp, bool append) { } void HocValEditor::data_path(HocDataPaths* hdp, bool append) { - if (!variable_) { + if (variable_.empty()) { auto* const pval_raw = static_cast(pval_); if (append) { hdp->append(pval_raw); } else { - String* s = hdp->retrieve(pval_raw); - if (s) { - variable_ = new CopyString(s->string()); - } + variable_ = hdp->retrieve(pval_raw); } } } void HocVarLabel::data_path(HocDataPaths* hdp, bool append) { - if (cpp_ && !variable_) { + if (cpp_ && variable_.empty()) { if (append) { hdp->append(cpp_); } else { - String* s = hdp->retrieve(cpp_); - if (s) { - variable_ = new CopyString(s->string()); - } + variable_ = hdp->retrieve(cpp_); } } } @@ -2638,7 +2624,6 @@ OcSlider::OcSlider(neuron::container::data_handle pd, Object* pysend) : HocUpdateItem("") { resolution_ = resolution; - variable_ = NULL; pval_ = pd; pyvar_ = pyvar; if (pyvar_) { @@ -2663,9 +2648,6 @@ OcSlider::~OcSlider() { delete send_; } delete bv_; - if (variable_) { - delete variable_; - } if (pyvar_) { hoc_obj_unref(pyvar_); } @@ -2704,8 +2686,8 @@ void OcSlider::audit() { auto sout = std::stringstream{}; char buf[200]; Sprintf(buf, "%g", *pval_); - if (variable_) { - sout << variable_->string() << " = " << buf << "\n"; + if (!variable_.empty()) { + sout << variable_.c_str() << " = " << buf << "\n"; } else if (pval_) { sout << "// " << pval_ << " set to " << buf << "\n"; } @@ -2760,25 +2742,22 @@ void OcSlider::check_pointer(void* v, int size) { } } void OcSlider::data_path(HocDataPaths* hdp, bool append) { - if (!variable_ && pval_) { + if (variable_.empty() && pval_) { auto* const pval_raw = static_cast(pval_); if (append) { hdp->append(pval_raw); } else { - String* s = hdp->retrieve(pval_raw); - if (s) { - variable_ = new CopyString(s->string()); - } + variable_ = hdp->retrieve(pval_raw); } } } void OcSlider::write(std::ostream& o) { - if (variable_) { + if (!variable_.empty()) { char buf[256]; if (send_) { Sprintf(buf, "xslider(&%s, %g, %g, \"%s\", %d, %d)", - variable_->string(), + variable_.c_str(), bv_->lower(Dimension_X), bv_->upper(Dimension_X), hideQuote(send_->name()), @@ -2787,7 +2766,7 @@ void OcSlider::write(std::ostream& o) { } else { Sprintf(buf, "xslider(&%s, %g, %g, %d, %d)", - variable_->string(), + variable_.c_str(), bv_->lower(Dimension_X), bv_->upper(Dimension_X), vert_, @@ -2837,7 +2816,6 @@ HocStateButton::HocStateButton(neuron::container::data_handle pd, if (pyvar_) { hoc_obj_ref(pyvar_); } - variable_ = NULL; name_ = new CopyString(text); action_ = action; action->hoc_item(this); @@ -2850,8 +2828,6 @@ HocStateButton::HocStateButton(neuron::container::data_handle pd, HocStateButton::~HocStateButton() { - if (variable_) - delete variable_; if (pyvar_) { hoc_obj_unref(pyvar_); } @@ -2934,32 +2910,29 @@ void HocStateButton::check_pointer(void* v, int size) { } void HocStateButton::data_path(HocDataPaths* hdp, bool append) { - if (!variable_ && pval_) { + if (variable_.empty() && pval_) { auto* const pval_raw = static_cast(pval_); if (append) { hdp->append(pval_raw); } else { - String* s = hdp->retrieve(pval_raw); - if (s) { - variable_ = new CopyString(s->string()); - } + variable_ = hdp->retrieve(pval_raw); } } } void HocStateButton::write(std::ostream& o) { - if (variable_) { + if (!variable_.empty()) { char buf[256]; if (style_ == PALETTE) { Sprintf(buf, "xstatebutton(\"%s\",&%s,\"%s\")", name_->string(), - variable_->string(), + variable_.c_str(), hideQuote(action_->name())); } else { Sprintf(buf, "xcheckbox(\"%s\",&%s,\"%s\")", name_->string(), - variable_->string(), + variable_.c_str(), hideQuote(action_->name())); } o << buf << std::endl; @@ -3000,7 +2973,6 @@ HocStateMenuItem::HocStateMenuItem(neuron::container::data_handle pd, if (pyvar_) { hoc_obj_ref(pyvar_); } - variable_ = NULL; name_ = new CopyString(text); action_ = action; action->hoc_item(this); @@ -3013,8 +2985,6 @@ HocStateMenuItem::HocStateMenuItem(neuron::container::data_handle pd, HocStateMenuItem::~HocStateMenuItem() { - if (variable_) - delete variable_; delete name_; if (pyvar_) { hoc_obj_unref(pyvar_); @@ -3098,26 +3068,23 @@ void HocStateMenuItem::check_pointer(void* v, int size) { } void HocStateMenuItem::data_path(HocDataPaths* hdp, bool append) { - if (!variable_ && pval_) { + if (variable_.empty() && pval_) { auto* const pval_raw = static_cast(pval_); if (append) { hdp->append(pval_raw); } else { - String* s = hdp->retrieve(pval_raw); - if (s) { - variable_ = new CopyString(s->string()); - } + variable_ = hdp->retrieve(pval_raw); } } } void HocStateMenuItem::write(std::ostream& o) { - if (variable_) { + if (!variable_.empty()) { char buf[256]; Sprintf(buf, "xcheckbox(\"%s\",&%s,\"%s\")", name_->string(), - variable_->string(), + variable_.c_str(), hideQuote(action_->name())); o << buf << std::endl; diff --git a/src/ivoc/xmenu.h b/src/ivoc/xmenu.h index 81eb9d1e85..929bb84511 100644 --- a/src/ivoc/xmenu.h +++ b/src/ivoc/xmenu.h @@ -207,7 +207,7 @@ class HocVarLabel: public HocUpdateItem { Patch* p_; char** cpp_; char* cp_; - CopyString* variable_; + std::string variable_{}; Object* pyvar_; }; @@ -332,7 +332,7 @@ class HocValEditor: public HocUpdateItem { bool active_; bool canrun_; HocAction* action_; - CopyString* variable_; + std::string variable_{}; neuron::container::data_handle pval_; ValEdLabel* prompt_; float* domain_limits_; @@ -445,7 +445,7 @@ class OcSlider: public HocUpdateItem, public Observer { HocCommand* send_; neuron::container::data_handle pval_; Object* pyvar_; - CopyString* variable_; + std::string variable_{}; bool scrolling_; bool vert_; bool slow_; @@ -475,7 +475,7 @@ class HocStateButton: public HocUpdateItem, public Observer { private: int style_; - CopyString* variable_; + std::string variable_{}; CopyString* name_; neuron::container::data_handle pval_; Object* pyvar_; @@ -504,7 +504,7 @@ class HocStateMenuItem: public HocUpdateItem, public Observer { virtual void print(Printer*, const Allocation&) const; private: - CopyString* variable_; + std::string variable_{}; CopyString* name_; neuron::container::data_handle pval_; Object* pyvar_; diff --git a/src/ivos/OS/_defines.h b/src/ivos/OS/_defines.h index e6098beebe..9f81f58dcb 100755 --- a/src/ivos/OS/_defines.h +++ b/src/ivos/OS/_defines.h @@ -1,5 +1,4 @@ #define u_char _lib_os(u_char) -#define CopyString _lib_os(CopyString) #define List _lib_os(List) #define NullTerminatedString _lib_os(NullTerminatedString) #define PtrList _lib_os(PtrList) diff --git a/src/ivos/OS/_undefs.h b/src/ivos/OS/_undefs.h index 195b4e9ae6..aff441fc98 100755 --- a/src/ivos/OS/_undefs.h +++ b/src/ivos/OS/_undefs.h @@ -1,5 +1,4 @@ #undef u_char -#undef CopyString #undef List #undef NullTerminatedString #undef PtrList diff --git a/src/ivos/OS/string.h b/src/ivos/OS/string.h index 97ec9a1b86..81113511c5 100644 --- a/src/ivos/OS/string.h +++ b/src/ivos/OS/string.h @@ -91,30 +91,6 @@ class String { int length_; }; -class CopyString : public String { -public: -#ifdef _DELTA_EXTENSIONS -#pragma __static_class -#endif - CopyString(); - CopyString(const char*); - CopyString(const char*, int length); - CopyString(const String&); - CopyString(const CopyString&); - virtual ~CopyString(); - - virtual String& operator =(const CopyString&); - virtual String& operator =(const String&); - virtual String& operator =(const char*); - - virtual bool null_terminated() const; -protected: - virtual void set_value(const char*); - virtual void set_value(const char*, int); -private: - void strfree(); -}; - class NullTerminatedString : public String { public: #ifdef _DELTA_EXTENSIONS diff --git a/src/ivos/string.cpp b/src/ivos/string.cpp index 7be01128b2..78341a6102 100644 --- a/src/ivos/string.cpp +++ b/src/ivos/string.cpp @@ -280,69 +280,6 @@ bool String::convert(double& value) const { return ptr != str; } -/* class CopyString */ - -CopyString::CopyString() : String() { } - -CopyString::CopyString(const char* s) : String() { - set_value(s); -} - -CopyString::CopyString(const char* s, int length) : String() { - set_value(s, length); -} - -CopyString::CopyString(const String& s) : String() { - set_value(s.string(), s.length()); -} - -CopyString::CopyString(const CopyString& s) : String() { - set_value(s.string(), s.length()); -} - -CopyString::~CopyString() { - strfree(); -} - -String& CopyString::operator =(const CopyString& s) { - strfree(); - set_value(s.string(), s.length()); - return *this; -} - -String& CopyString::operator =(const String& s) { - strfree(); - set_value(s.string(), s.length()); - return *this; -} - -String& CopyString::operator =(const char* s) { - strfree(); - set_value(s); - return *this; -} - -bool CopyString::null_terminated() const { return true; } - -void CopyString::set_value(const char* s) { - set_value(s, strlen(s)); -} - -/* - * Guarantee null-terminated string for compatibility with printf et al. - */ - -void CopyString::set_value(const char* s, int len) { - char* ns = new char[len + 1]; - ns[len] = '\0'; - String::set_value(strncpy(ns, s, len), len); -} - -void CopyString::strfree() { - char* s = (char*)(string()); - delete [] s; -} - /* * class NullTerminatedString */ diff --git a/src/nrncvode/netcvode.cpp b/src/nrncvode/netcvode.cpp index 599f9c53c1..d2dd5ffcb5 100644 --- a/src/nrncvode/netcvode.cpp +++ b/src/nrncvode/netcvode.cpp @@ -4463,8 +4463,8 @@ std::string NetCvode::statename(int is, int style) { assert(sym); return sym2name(sym); } else { - auto* s = hdp.retrieve(raw_ptr); - return s ? s->string() : "unknown"; + std::string s = hdp.retrieve(raw_ptr); + return !s.empty() ? s.c_str() : "unknown"; } }; int j{}; diff --git a/src/nrniv/kschan.cpp b/src/nrniv/kschan.cpp index 67ad2b0604..655d4b376a 100644 --- a/src/nrniv/kschan.cpp +++ b/src/nrniv/kschan.cpp @@ -399,7 +399,7 @@ static const char** ks_name(void* v) { ks->setname(gargstr(1)); } char** ps = hoc_temp_charptr(); - *ps = (char*) ks->name_.string(); + *ps = (char*) ks->name_.c_str(); return (const char**) ps; } @@ -409,7 +409,7 @@ static const char** ks_ion(void* v) { ks->setion(gargstr(1)); } char** ps = hoc_temp_charptr(); - *ps = (char*) ks->ion_.string(); + *ps = (char*) ks->ion_.c_str(); return (const char**) ps; } @@ -639,9 +639,9 @@ static double ks_pr(void* v) { Printf("%s type properties\n", hoc_object_name(ks->obj_)); Printf("name=%s is_point_=%s ion_=%s cond_model_=%d\n", - ks->name_.string(), + ks->name_.c_str(), (ks->is_point() ? "true" : "false"), - ks->ion_.string(), + ks->ion_.c_str(), ks->cond_model_); Printf(" ngate=%d nstate=%d nhhstate=%d nligand=%d ntrans=%d ivkstrans=%d iligtrans=%d\n", ks->ngate_, @@ -886,12 +886,12 @@ KSChan::KSChan(Object* obj, bool is_p) { gmax_deflt_ = 0.; erev_deflt_ = 0.; soffset_ = 4; // gmax, e, g, i before the first state in p array - const char* suffix = name_.string(); + const char* suffix = name_.c_str(); char unsuffix[100]; if (is_point()) { unsuffix[0] = '\0'; } else { - Sprintf(unsuffix, "_%s", name_.string()); + Sprintf(unsuffix, "_%s", name_.c_str()); } if (looksym(suffix)) { hoc_execerror(suffix, "already exists"); @@ -929,21 +929,21 @@ KSChan::KSChan(Object* obj, bool is_p) { } setcond(); sname_install(); - // printf("%s allowed in insert statement\n", name_.string()); + // printf("%s allowed in insert statement\n", name_.c_str()); } void KSChan::setname(const char* s) { // printf("KSChan::setname\n"); int i; - if (strcmp(s, name_.string()) == 0) { + if (strcmp(s, name_.c_str()) == 0) { return; } name_ = s; if (mechsym_) { char old_suffix[100]; i = 0; - while (strcmp(mechsym_->name, name_.string()) != 0 && looksym(name_.string())) { - Printf("KSChan::setname %s already in use\n", name_.string()); + while (strcmp(mechsym_->name, name_.c_str()) != 0 && looksym(name_.c_str())) { + Printf("KSChan::setname %s already in use\n", name_.c_str()); Sprintf(old_suffix, "%s%d", s, i); name_ = old_suffix; ++i; @@ -952,7 +952,7 @@ void KSChan::setname(const char* s) { // return; } Sprintf(old_suffix, "_%s", mechsym_->name); - const char* suffix = name_.string(); + const char* suffix = name_.c_str(); free(mechsym_->name); mechsym_->name = strdup(suffix); if (is_point()) { @@ -977,7 +977,7 @@ void KSChan::setname(const char* s) { sp->name = s1; } } - // printf("%s renamed to %s\n", old_suffix+1, name_.string()); + // printf("%s renamed to %s\n", old_suffix+1, name_.c_str()); } } @@ -1133,7 +1133,7 @@ void KSChan::update_prop() { std::string name{state(i)}; if (!is_point()) { // only called from set_single so never reached. name += "_"; - name += name_.string(); + name += name_.c_str(); } int j = i + soffset_; @@ -1151,7 +1151,7 @@ void KSChan::update_prop() { void KSChan::setion(const char* s) { // printf("KSChan::setion\n"); int i; - if (strcmp(ion_.string(), s) == 0) { + if (strcmp(ion_.c_str(), s) == 0) { return; } // before doing anything destructive, check if update_size is going to succeed below @@ -1160,7 +1160,7 @@ void KSChan::setion(const char* s) { // now we know update_size will succeed, we can start modifying member data Symbol* searchsym = (is_point() ? mechsym_ : NULL); - ion_ = new_ion.c_str(); + ion_ = new_ion; char buf[100]; int pdoff = ppoff_; int io = gmaxoffset_; @@ -1209,7 +1209,7 @@ void KSChan::setion(const char* s) { if (ion_sym_) { // there already is an ion if (strcmp(ion_sym_->name, buf) != 0) { // is it different // printf(" mechanism %s now uses %s instead of %s\n", - // name_.string(), sym->name, ion_sym_->name); + // name_.c_str(), sym->name, ion_sym_->name); ion_sym_ = sym; ion_consist(); } @@ -2294,7 +2294,7 @@ void KSChan::update_size() { void KSChan::alloc(Prop* prop) { // printf("KSChan::alloc nstate_=%d nligand_=%d\n", nstate_, nligand_); - // printf("KSChan::alloc %s param=%p\n", name_.string(), prop->param); + // printf("KSChan::alloc %s param=%p\n", name_.c_str(), prop->param); int j; assert(prop->param_size() == prop->param_num_vars()); // no array vars assert(prop->param_num_vars() == soffset_ + 2 * nstate_); diff --git a/src/nrniv/kschan.h b/src/nrniv/kschan.h index ff05871618..02d8779bd0 100644 --- a/src/nrniv/kschan.h +++ b/src/nrniv/kschan.h @@ -326,10 +326,10 @@ class KSState { KSState(); virtual ~KSState(); const char* string() { - return name_.string(); + return name_.c_str(); } double f_; // normalized conductance - CopyString name_; + std::string name_; int index_; // into state_ array KSChan* ks_; Object* obj_; @@ -440,8 +440,8 @@ class KSChan { int mechtype_; public: - CopyString name_; // name of channel - CopyString ion_; // name of ion , "" means non-specific + std::string name_; // name of channel + std::string ion_; // name of ion , "" means non-specific double gmax_deflt_; double erev_deflt_; int cond_model_; diff --git a/src/nrniv/nrnmenu.cpp b/src/nrniv/nrnmenu.cpp index 4cc3e1c22e..3124426de4 100644 --- a/src/nrniv/nrnmenu.cpp +++ b/src/nrniv/nrnmenu.cpp @@ -763,7 +763,7 @@ void MechanismStandard::panel(const char* label) { hoc_pushx(0.0); pyactval = neuron::python::methods.callable_with_args(pyact_, 3); } else { - Sprintf(buf, "hoc_ac_ = %d %s", i, action_.string()); + Sprintf(buf, "hoc_ac_ = %d %s", i, action_.c_str()); } hoc_ivvaluerun_ex(sym->name, NULL, @@ -788,7 +788,7 @@ void MechanismStandard::panel(const char* label) { hoc_pushx(double(j)); pyactval = neuron::python::methods.callable_with_args(pyact_, 3); } else { - Sprintf(buf, "hoc_ac_ = %d %s", i, action_.string()); + Sprintf(buf, "hoc_ac_ = %d %s", i, action_.c_str()); } char buf2[200]; Sprintf(buf2, "%s[%d]", sym->name, j); @@ -1139,7 +1139,7 @@ void MechanismType_reg() { int* type_; int count_; int select_; - CopyString action_; + std::string action_; Object* pyact_; Section* sec_iter_; int inode_iter_; @@ -1316,11 +1316,8 @@ void MechanismType::menu() { hoc_ivbutton(s->name, NULL, pyactval); hoc_obj_unref(pyactval); } else { - Sprintf(buf, - "xbutton(\"%s\", \"hoc_ac_=%d %s\")\n", - s->name, - i, - mti_->action_.string()); + Sprintf( + buf, "xbutton(\"%s\", \"hoc_ac_=%d %s\")\n", s->name, i, mti_->action_.c_str()); oc.run(buf); } } diff --git a/src/nrniv/nrnmenu.h b/src/nrniv/nrnmenu.h index 59bd8d3754..e63b119433 100644 --- a/src/nrniv/nrnmenu.h +++ b/src/nrniv/nrnmenu.h @@ -39,7 +39,7 @@ class MechanismStandard: public Resource { int name_cnt_; int offset_; int vartype_; - CopyString action_; + std::string action_; Object* pyact_; Symbol** glosym_; void mschk(const char*); diff --git a/src/nrniv/shape.cpp b/src/nrniv/shape.cpp index 64f36f8988..389c17b1e7 100644 --- a/src/nrniv/shape.cpp +++ b/src/nrniv/shape.cpp @@ -878,7 +878,6 @@ ShapeScene::ShapeScene(SectionList* sl) r3b_ = new Rotate3Band(NULL, new RubberCallback(ShapeScene)(this, &ShapeScene::transform3d)); r3b_->ref(); observe(sl); - var_name_ = NULL; wk.style()->find_attribute("shape_beveljoin", beveljoin_); MenuItem* mi; @@ -961,9 +960,6 @@ ShapeScene::~ShapeScene() { Resource::unref(sg_); Resource::unref(r3b_); delete shape_changed_; - if (var_name_) { - delete var_name_; - } } void ShapeScene::erase_all() { @@ -1040,24 +1036,17 @@ PolyGlyph* ShapeScene::shape_section_list() { } void ShapeScene::name(const char* s) { - if (!var_name_) { - var_name_ = new CopyString(s); - } else { - *var_name_ = s; - } + var_name_ = s; } void ShapeScene::save_phase2(std::ostream& o) { - char buf[256]; - if (var_name_) { - if ((var_name_->string())[var_name_->length() - 1] == '.') { - Sprintf(buf, "%sappend(save_window_)", var_name_->string()); + if (!var_name_.empty()) { + if (var_name_.back() == '.') { + o << var_name_ << "append(save_window_)" << std::endl; } else { - Sprintf(buf, "%s = save_window_", var_name_->string()); + o << var_name_ << " = save_window_" << std::endl; } - o << buf << std::endl; - Sprintf(buf, "save_window_.save_name(\"%s\")", var_name_->string()); - o << buf << std::endl; + o << "save_window_.save_name(\"" << var_name_ << "\")" << std::endl; } Graph::save_phase2(o); } diff --git a/src/nrniv/shape.h b/src/nrniv/shape.h index f74de89d58..fdf0ccfc67 100644 --- a/src/nrniv/shape.h +++ b/src/nrniv/shape.h @@ -80,7 +80,7 @@ class ShapeScene: public Graph { // entire neuron SectionHandler* section_handler_; PolyGlyph* sg_; Rotate3Band* r3b_; - CopyString* var_name_; + std::string var_name_; ShapeChangeObserver* shape_changed_; }; diff --git a/src/nrniv/shapeplt.cpp b/src/nrniv/shapeplt.cpp index 27df1aa624..994cdddb11 100644 --- a/src/nrniv/shapeplt.cpp +++ b/src/nrniv/shapeplt.cpp @@ -768,7 +768,7 @@ void ShapePlotImpl::select_variable() { sc->ref(); while (sc->post_for(XYView::current_pick_view()->canvas()->window())) { Symbol* s; - s = hoc_table_lookup(sc->selected()->string(), hoc_built_in_symlist); + s = hoc_table_lookup(sc->selected().c_str(), hoc_built_in_symlist); if (s) { sp_->variable(s); break; diff --git a/src/nrniv/spaceplt.cpp b/src/nrniv/spaceplt.cpp index 8308e98232..80eec32699 100644 --- a/src/nrniv/spaceplt.cpp +++ b/src/nrniv/spaceplt.cpp @@ -112,7 +112,7 @@ class RangeVarPlot: public NoIVGraphVector { Section *begin_section_, *end_section_; float x_begin_, x_end_, origin_; SecPosList* sec_list_; - CopyString expr_; + std::string expr_; int shape_changed_; int struc_changed_; double d2root_; // distance to root of closest point to root @@ -441,7 +441,7 @@ void RangeVarPlot::request(Requisition& req) const { void RangeVarPlot::save(std::ostream& o) { char buf[256]; o << "objectvar rvp_" << std::endl; - Sprintf(buf, "rvp_ = new RangeVarPlot(\"%s\")", expr_.string()); + Sprintf(buf, "rvp_ = new RangeVarPlot(\"%s\")", expr_.c_str()); o << buf << std::endl; Sprintf(buf, "%s rvp_.begin(%g)", hoc_section_pathname(begin_section_), x_begin_); o << buf << std::endl; @@ -515,12 +515,12 @@ void RangeVarPlot::fill_pointers() { if (rexp_) { rexp_->fill(); } else { - sscanf(expr_.string(), "%[^[]", buf); + sscanf(expr_.c_str(), "%[^[]", buf); sym = hoc_lookup(buf); if (!sym) { return; } - Sprintf(buf, "%s(hoc_ac_)", expr_.string()); + Sprintf(buf, "%s(hoc_ac_)", expr_.c_str()); } int noexist = 0; // don't plot single points that don't exist bool does_exist;