Skip to content
Snippets Groups Projects
Commit b4b0029e authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

use ostringstream instead of sprintf

parent bc889bd8
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// See the LICENSE.txt file for license information. Please report all // See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>. // bugs and problems to <gmsh@geuz.org>.
#include <sstream>
#include <algorithm> #include <algorithm>
#include "GModel.h" #include "GModel.h"
#include "GEdge.h" #include "GEdge.h"
...@@ -110,10 +111,9 @@ void GEdge::setVisibility(char val, bool recursive) ...@@ -110,10 +111,9 @@ void GEdge::setVisibility(char val, bool recursive)
std::string GEdge::getAdditionalInfoString() std::string GEdge::getAdditionalInfoString()
{ {
if(!v0 || !v1) return std::string(""); std::ostringstream sstream;
char tmp[256]; if(v0 && v1) sstream << "{" << v0->tag() << "," << v1->tag() << "}";
sprintf(tmp, "{%d,%d}", v0->tag(), v1->tag()); return sstream.str();
return std::string(tmp);
} }
GPoint GEdge::closestPoint(const SPoint3 & queryPoint) const GPoint GEdge::closestPoint(const SPoint3 & queryPoint) const
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// See the LICENSE.txt file for license information. Please report all // See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>. // bugs and problems to <gmsh@geuz.org>.
#include <stdio.h> #include <sstream>
#include "GModel.h" #include "GModel.h"
#include "GEntity.h" #include "GEntity.h"
#include "MElement.h" #include "MElement.h"
...@@ -56,24 +56,18 @@ bool GEntity::useColor() ...@@ -56,24 +56,18 @@ bool GEntity::useColor()
std::string GEntity::getInfoString() std::string GEntity::getInfoString()
{ {
char tmp[256]; std::ostringstream sstream;
sprintf(tmp, " %d", tag()); sstream << getTypeString() << " " << tag();
std::string out = getTypeString() + tmp;
std::string info = getAdditionalInfoString(); std::string info = getAdditionalInfoString();
if(info.size()) if(info.size()) sstream << " " << info;
out += " " + info;
if(physicals.size()){ if(physicals.size()){
out += " (Physical: "; sstream << " (Physical:";
for(unsigned int i = 0; i < physicals.size(); i++){ for(unsigned int i = 0; i < physicals.size(); i++)
if(i) out += " "; sstream << " " << physicals[i];
sprintf(tmp, "%d", physicals[i]); sstream << ")";
out += tmp;
}
out += ")";
} }
return out; return sstream.str();
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// See the LICENSE.txt file for license information. Please report all // See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>. // bugs and problems to <gmsh@geuz.org>.
#include <sstream>
#include "GModel.h" #include "GModel.h"
#include "GFace.h" #include "GFace.h"
#include "GEdge.h" #include "GEdge.h"
...@@ -153,25 +154,19 @@ void GFace::setVisibility(char val, bool recursive) ...@@ -153,25 +154,19 @@ void GFace::setVisibility(char val, bool recursive)
std::string GFace::getAdditionalInfoString() std::string GFace::getAdditionalInfoString()
{ {
if(l_edges.empty()) return std::string(""); std::ostringstream sstream;
if(l_edges.size() > 20){
std::string str("{"); sstream << "{" << l_edges.front()->tag() << ",...," << l_edges.back()->tag() << "}";
if(l_edges.size() > 10){
char tmp[256];
sprintf(tmp, "%d, ..., %d", l_edges.front()->tag(), l_edges.back()->tag());
str += tmp;
} }
else{ else if(l_edges.size()){
std::list<GEdge*>::const_iterator it = l_edges.begin(); sstream << "{";
for(; it != l_edges.end(); it++){ for(std::list<GEdge*>::iterator it = l_edges.begin(); it != l_edges.end(); ++it){
if(it != l_edges.begin()) str += ","; if(it != l_edges.begin()) sstream << ",";
char tmp[256]; sstream << (*it)->tag();
sprintf(tmp, "%d", (*it)->tag());
str += tmp;
} }
sstream << "}";
} }
str += "}"; return sstream.str();
return str;
} }
void GFace::computeMeanPlane() void GFace::computeMeanPlane()
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// See the LICENSE.txt file for license information. Please report all // See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>. // bugs and problems to <gmsh@geuz.org>.
#include <sstream>
#include "GModel.h" #include "GModel.h"
#include "GRegion.h" #include "GRegion.h"
#include "GFace.h" #include "GFace.h"
...@@ -119,25 +120,19 @@ void GRegion::setVisibility(char val, bool recursive) ...@@ -119,25 +120,19 @@ void GRegion::setVisibility(char val, bool recursive)
std::string GRegion::getAdditionalInfoString() std::string GRegion::getAdditionalInfoString()
{ {
if(l_faces.empty()) return std::string(""); std::ostringstream sstream;
if(l_faces.size() > 20){
std::string str("{"); sstream << "{" << l_faces.front()->tag() << ",...," << l_faces.back()->tag() << "}";
if(l_faces.size() > 10){
char tmp[256];
sprintf(tmp, "%d, ..., %d", l_faces.front()->tag(), l_faces.back()->tag());
str += tmp;
} }
else{ else if(l_faces.size()){
std::list<GFace*>::const_iterator it = l_faces.begin(); sstream << "{";
for(; it != l_faces.end(); it++){ for(std::list<GFace*>::iterator it = l_faces.begin(); it != l_faces.end(); ++it){
if(it != l_faces.begin()) str += ","; if(it != l_faces.begin()) sstream << ",";
char tmp[256]; sstream << (*it)->tag();
sprintf(tmp, "%d", (*it)->tag());
str += tmp;
} }
sstream << "}";
} }
str += "}"; return sstream.str();
return str;
} }
std::list<GEdge*> GRegion::edges() const std::list<GEdge*> GRegion::edges() const
...@@ -149,7 +144,7 @@ std::list<GEdge*> GRegion::edges() const ...@@ -149,7 +144,7 @@ std::list<GEdge*> GRegion::edges() const
e2 = (*it)->edges(); e2 = (*it)->edges();
std::list<GEdge*>::const_iterator it2 = e2.begin(); std::list<GEdge*>::const_iterator it2 = e2.begin();
while (it2 != e2.end()){ while (it2 != e2.end()){
if (std::find(e.begin(), e.end(), *it2) == e.end()) if(std::find(e.begin(), e.end(), *it2) == e.end())
e.push_back(*it2); e.push_back(*it2);
++it2; ++it2;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// See the LICENSE.txt file for license information. Please report all // See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>. // bugs and problems to <gmsh@geuz.org>.
#include <string.h> #include <sstream>
#include <algorithm> #include <algorithm>
#include "GVertex.h" #include "GVertex.h"
#include "GFace.h" #include "GFace.h"
...@@ -50,15 +50,11 @@ SPoint2 GVertex::reparamOnFace(GFace *gf, int) const ...@@ -50,15 +50,11 @@ SPoint2 GVertex::reparamOnFace(GFace *gf, int) const
std::string GVertex::getAdditionalInfoString() std::string GVertex::getAdditionalInfoString()
{ {
char str[256]; std::ostringstream sstream;
sprintf(str, "{%g,%g,%g}", x(), y(), z()); sstream << "{" << x() << "," << y() << "," << z() << "}";
double lc = prescribedMeshSizeAtVertex(); double lc = prescribedMeshSizeAtVertex();
if(lc < 1.e22){ if(lc < 1.e22) sstream << " (cl: " << lc << ")";
char str2[256]; return sstream.str();
sprintf(str2, " (cl: %g)", lc);
strcat(str, str2);
}
return std::string(str);
} }
unsigned int GVertex::getNumMeshElements() unsigned int GVertex::getNumMeshElements()
......
Point (1) = {0, 0, 0, 50};
Point (2) = {0, 339.5, 0, 50};
Point (3) = {0, 393, 0, 50};
Point (4) = {0, 393, 434, 50};
Point (5) = {0, 385, 434, 50};
Point (6) = {0, 354.5, 434, 50};
Point (7) = {0, 0, 434, 50};
Point (8) = {0, 100, 1009, 50};
Point (9) = {0, 0, 1009, 50};
Point (10) = {0, 0, 1309, 50};
Point (11) = {0, 50, 1309, 50};
Point (12) = {0, 50, 1409, 50};
Point (13) = {0, 0, 1409, 50};
Point (14) = {0, 40, 1409, 50};
Point (16) = {0, 40, 721.5, 50};
Point (17) = {0, 0, 721.5, 50};
Line (1) = {3, 4};
Line (2) = {5, 4};
Line (3) = {2, 6};
Line (4) = {5, 8};
Line (5) = {8, 11};
Line (6) = {11, 12};
Line (7) = {6, 16};
Line (8) = {16, 14};
Line (9) = {3, 2};
Line (10) = {12, 14};
//surface to be rotated
Line Loop(11) = {9,3,7,8,-10,-6,-5,-4,2,-1};
Plane Surface(12) = {11};
//rotate surface
Extrude { { 0, 0, 1 }, { 0, 0, 0 }, 2*Pi/3 } { Surface { 12 }; Layers { 6 }; }
Extrude { { 0, 0, 1 }, { 0, 0, 0 }, 2*Pi/3 } { Surface { 64 }; Layers { 6 }; }
Extrude { { 0, 0, 1 }, { 0, 0, 0 }, 2*Pi/3 } { Surface { 116 }; Layers { 6 }; }
// REMOVED THIS
//Surface Loop(168) = {167,131,135,139,143,147,151,155,159,163,63,27,31,35,39,43,47,51,55,59,83,87,91,95,99,103,107,111,115,79};
//Volume(169) = {168};
//inlet
Physical Surface(170) = {131,27,79};
//outlet
Physical Surface(171) = {43,147,95};
//walls
Physical Surface(172) = {143,39,155,103,51,47,151,91,99,159,107,55,139,35,87,59,163,111,167,135,83,115,31,63};
Physical Volume(172) = {169};
$MeshFormat
2.0 0 8
$EndMeshFormat
$Nodes
6
1 0 0 0
2 1 0 0
3 1 1 0
4 0 1 0
5 2 0 0
6 2 1 0
$EndNodes
$Elements
2
1 3 0 1 2 3 4
2 3 0 2 5 6 3
$EndElements
$NodeData
1
"A scalar view"
1
0.0
3
0
1
6
1 0.0
2 0.1
3 0.2
4 0.0
5 0.2
6 0.4
$EndNodeData
$NodeData
1
"A multi-step vector view on element 1"
1
0.0001
3
0
3
4
1 0.4 0.0 0.0
2 0.5 0.2 0.0
3 0.7 0.5 0.0
4 0.8 0.8 0.0
$EndNodeData
$NodeData
1
"A multi-step vector view on element 1"
1
0.0002
3
1
3
4
1 -0.4 0.0 0.0
2 -0.5 0.2 0.0
3 -0.7 0.5 0.0
4 -0.8 0.8 0.0
$EndNodeData
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment