From 4cb120047c10df2d311950c99b1ad32a1fa1c1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Sun, 25 Jun 2017 18:22:46 +0200 Subject: [PATCH] replace char* by string --- libsrc/include/nginterface.h | 2 +- libsrc/visualization/visualpkg.cpp | 14 +++++++------- libsrc/visualization/vssolution.cpp | 15 ++++++++------- libsrc/visualization/vssolution.hpp | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libsrc/include/nginterface.h b/libsrc/include/nginterface.h index 918f445d..a76ebe1d 100644 --- a/libsrc/include/nginterface.h +++ b/libsrc/include/nginterface.h @@ -308,7 +308,7 @@ extern "C" { struct Ng_SolutionData { - const char * name; // name of gridfunction + string name; // name of gridfunction double * data; // solution values int components; // relevant (double) components in solution vector int dist; // # doubles per entry alignment! diff --git a/libsrc/visualization/visualpkg.cpp b/libsrc/visualization/visualpkg.cpp index 40ce1099..79ba3067 100644 --- a/libsrc/visualization/visualpkg.cpp +++ b/libsrc/visualization/visualpkg.cpp @@ -79,8 +79,8 @@ namespace netgen for (int i = 0; i < vssolution.soldata.Size(); i++) { - if ( (strlen (vssolution.soldata[i]->name) == size_t(pointpos-1)) && - (strncmp (vssolution.soldata[i]->name, scalname, pointpos-1) == 0) ) + if ( (strlen (vssolution.soldata[i]->name.c_str()) == size_t(pointpos-1)) && + (strncmp (vssolution.soldata[i]->name.c_str(), scalname, pointpos-1) == 0) ) { vssolution.scalfunction = i; vssolution.scalcomp = atoi (scalname + pointpos); @@ -96,10 +96,10 @@ namespace netgen Tcl_SetVar ( interp, "::visoptions.scalfunction", newscalname, TCL_GLOBAL_ONLY ); scalname = Tcl_GetVar (interp, "::visoptions.scalfunction", TCL_GLOBAL_ONLY); } - if (strcmp (vssolution.soldata[i]->name, vecname) == 0) + if (strcmp (vssolution.soldata[i]->name.c_str(), vecname) == 0) vssolution.vecfunction = i; - if (strcmp (vssolution.soldata[i]->name, fieldlines_vecname) == 0) + if (strcmp (vssolution.soldata[i]->name.c_str(), fieldlines_vecname) == 0) vssolution.fieldlines_vecfunction = i; } @@ -315,7 +315,7 @@ namespace netgen return TCL_ERROR; for (i = 0; i < vssolution.GetNSolData(); i++) - if (strcmp (vssolution.GetSolData(i)->name, argv[2]) == 0) + if (strcmp (vssolution.GetSolData(i)->name.c_str(), argv[2]) == 0) { cout << "found soldata " << i << endl; } @@ -328,7 +328,7 @@ namespace netgen if (strcmp (argv[1], "getfieldname") == 0) { - sprintf (buf, "%s", vssolution.GetSolData(atoi(argv[2])-1)->name); + sprintf (buf, "%s", vssolution.GetSolData(atoi(argv[2])-1)->name.c_str()); } if (strcmp (argv[1], "iscomplex") == 0) @@ -346,7 +346,7 @@ namespace netgen { for (i = 0; i < vssolution.GetNSolData(); i++) { - strcat (buf, vssolution.GetSolData(i)->name); + strcat (buf, vssolution.GetSolData(i)->name.c_str()); strcat (buf, " "); } strcat (buf, "var1 var2 var3"); diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index 06a2b2bb..c5bb4642 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -24,12 +24,12 @@ namespace netgen VisualSceneSolution :: SolData :: SolData () - : name (0), data (0), solclass(0) + : data (0), solclass(0) { ; } VisualSceneSolution :: SolData :: ~SolData () { - delete [] name; + // delete [] name; delete data; delete solclass; } @@ -86,7 +86,8 @@ namespace netgen int funcnr = -1; for (int i = 0; i < soldata.Size(); i++) { - if (strcmp (soldata[i]->name, sd->name) == 0) + // if (strcmp (soldata[i]->name, sd->name) == 0) + if (soldata[i]->name == sd->name) { delete soldata[i]; soldata[i] = sd; @@ -4778,7 +4779,7 @@ void Ng_ClearSolutionData () void Ng_InitSolutionData (Ng_SolutionData * soldata) { - soldata -> name = NULL; + // soldata -> name = NULL; soldata -> data = NULL; soldata -> components = 1; soldata -> dist = 1; @@ -4797,9 +4798,9 @@ void Ng_SetSolutionData (Ng_SolutionData * soldata) // vssolution.ClearSolutionData (); netgen::VisualSceneSolution::SolData * vss = new netgen::VisualSceneSolution::SolData; - vss->name = new char[strlen (soldata->name)+1]; - strcpy (vss->name, soldata->name); - + // vss->name = new char[strlen (soldata->name)+1]; + // strcpy (vss->name, soldata->name); + vss->name = soldata->name; vss->data = soldata->data; vss->components = soldata->components; vss->dist = soldata->dist; diff --git a/libsrc/visualization/vssolution.hpp b/libsrc/visualization/vssolution.hpp index bb2b4c7d..dbf61150 100644 --- a/libsrc/visualization/vssolution.hpp +++ b/libsrc/visualization/vssolution.hpp @@ -136,7 +136,7 @@ public: SolData (); ~SolData (); - char * name; + string name; double * data; int components; int dist;