Commit 9176ba5c authored by George Zagaris's avatar George Zagaris

ENH: Replace snprintf with C++ string streams

Replaced code that was converting primitives(ints, doubles,etc.) to
strings using snprintf with C++ output string streams. This yields
a more robust conversion, without any implicit assumptions, and a
portable solution that transparently will work on Windows.

Change-Id: I185370e8bb69b9d21b804439658a722df8c43d9b
parent fdaa8b48
......@@ -29,6 +29,7 @@
#include <vtksys/SystemTools.hxx>
#include <algorithm>
#include <sstream>
#include <map>
#include <string>
......@@ -231,25 +232,25 @@ void vtkPythonProgrammableFilter::SetParameterInternal(const char *raw_name,
void vtkPythonProgrammableFilter::SetParameter(const char *raw_name,
const int value)
{
char buf[20];
snprintf(buf, 20, "%d", value);
this->SetParameterInternal(raw_name, buf);
std::ostringstream buf;
buf << value;
this->SetParameterInternal(raw_name, buf.str().c_str() );
}
void vtkPythonProgrammableFilter::SetParameter(const char *raw_name,
const double value)
{
char buf[20];
snprintf(buf, 20, "%f", value);
this->SetParameterInternal(raw_name, buf);
std::ostringstream buf;
buf << value;
this->SetParameterInternal(raw_name, buf.str().c_str() );
}
void vtkPythonProgrammableFilter::SetParameter(const char *raw_name,
const char *value)
{
char buf[100];
snprintf(buf, 100, "'%s'", value);
this->SetParameterInternal(raw_name, buf);
std::ostringstream buf;
buf << value;
this->SetParameterInternal(raw_name, buf.str().c_str() );
}
void vtkPythonProgrammableFilter::SetParameter(
......@@ -258,9 +259,9 @@ void vtkPythonProgrammableFilter::SetParameter(
const double value2,
const double value3)
{
char buf[100];
snprintf(buf, 100, "[%f, %f, %f]", value1, value2, value3);
this->SetParameterInternal(raw_name, buf);
std::ostringstream buf;
buf << value1 << value2 << value3;
this->SetParameterInternal(raw_name, buf.str().c_str() );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment