*: Use Util::fromString() and Util::toString() when possible.
diff --git a/src/canvas-x11.cpp b/src/canvas-x11.cpp
index ea61a9f..1b23874 100644
--- a/src/canvas-x11.cpp
+++ b/src/canvas-x11.cpp
@@ -198,9 +198,9 @@
else
start_pos++;
- std::stringstream ss;
- ss << gl_version_str.substr(start_pos, point_pos - start_pos + 1);
- ss >> gl_major;
+ gl_major = Util::fromString<int>(
+ gl_version_str.substr(start_pos, point_pos - start_pos + 1)
+ );
}
return gl_major >= 2;
diff --git a/src/options.cpp b/src/options.cpp
index d26f093..78f0226 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -66,18 +66,14 @@
std::vector<std::string> d;
Util::split(str, 'x', d);
- std::stringstream ss(d[0]);
- ss >> size.first;
+ size.first = Util::fromString<int>(d[0]);
/*
* Parse the second element (height). If there is none, use the value
* of the first element for the second (width = height)
*/
- if (d.size() > 1) {
- ss.clear();
- ss.str(d[1]);
- ss >> size.second;
- }
+ if (d.size() > 1)
+ size.second = Util::fromString<int>(d[1]);
else
size.second = size.first;
}
diff --git a/src/scene-buffer.cpp b/src/scene-buffer.cpp
index 92280ac..4dc67e3 100644
--- a/src/scene-buffer.cpp
+++ b/src/scene-buffer.cpp
@@ -364,18 +364,10 @@
else
usage = Mesh::VBOUsageDynamic;
- std::stringstream ss;
- ss << options_["update-fraction"].value;
- ss >> update_fraction;
- ss.clear();
- ss << options_["update-dispersion"].value;
- ss >> update_dispersion;
- ss.clear();
- ss << options_["columns"].value;
- ss >> nlength;
- ss.clear();
- ss << options_["rows"].value;
- ss >> nwidth;
+ update_fraction = Util::fromString<double>(options_["update-fraction"].value);
+ update_dispersion = Util::fromString<double>(options_["update-dispersion"].value);
+ nlength = Util::fromString<size_t>(options_["columns"].value);
+ nwidth = Util::fromString<size_t>(options_["rows"].value);
if (update_method == Mesh::VBOUpdateMethodMap &&
(GLExtensions::MapBuffer == 0 || GLExtensions::UnmapBuffer == 0))
diff --git a/src/scene-conditionals.cpp b/src/scene-conditionals.cpp
index 699340b..95ec272 100644
--- a/src/scene-conditionals.cpp
+++ b/src/scene-conditionals.cpp
@@ -25,9 +25,9 @@
#include "vec.h"
#include "log.h"
#include "shader-source.h"
+#include "util.h"
#include <cmath>
-#include <sstream>
static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/conditionals");
@@ -97,17 +97,8 @@
/* Parse options */
bool vtx_conditionals = options_["vertex-conditionals"].value == "true";
bool frg_conditionals = options_["fragment-conditionals"].value == "true";
- int vtx_steps = 0;
- int frg_steps = 0;
-
- std::stringstream ss;
-
- ss << options_["vertex-steps"].value;
- ss >> vtx_steps;
- ss.clear();
- ss << options_["fragment-steps"].value;
- ss >> frg_steps;
-
+ int vtx_steps(Util::fromString<int>(options_["vertex-steps"].value));
+ int frg_steps(Util::fromString<int>(options_["fragment-steps"].value));
/* Load shaders */
std::string vtx_shader(get_vertex_shader_source(vtx_steps, vtx_conditionals));
std::string frg_shader(get_fragment_shader_source(frg_steps, frg_conditionals));
diff --git a/src/scene-desktop.cpp b/src/scene-desktop.cpp
index a235808..61f2805 100644
--- a/src/scene-desktop.cpp
+++ b/src/scene-desktop.cpp
@@ -774,7 +774,7 @@
{
Scene::setup();
- std::stringstream ss;
+ /* Parse the options */
unsigned int windows(0);
unsigned int passes(0);
unsigned int blur_radius(0);
@@ -782,20 +782,11 @@
unsigned int shadow_size(0);
bool separable(options_["separable"].value == "true");
- ss << options_["windows"].value;
- ss >> windows;
- ss.clear();
- ss << options_["window-size"].value;
- ss >> window_size_factor;
- ss.clear();
- ss << options_["passes"].value;
- ss >> passes;
- ss.clear();
- ss << options_["blur-radius"].value;
- ss >> blur_radius;
- ss.clear();
- ss << options_["shadow-size"].value;
- ss >> shadow_size;
+ windows = Util::fromString<unsigned int>(options_["windows"].value);
+ window_size_factor = Util::fromString<float>(options_["window-size"].value);
+ passes = Util::fromString<unsigned int>(options_["passes"].value);
+ blur_radius = Util::fromString<unsigned int>(options_["blur-radius"].value);
+ shadow_size = Util::fromString<unsigned int>(options_["shadow-size"].value);
/* Ensure we get a transparent clear color for all following operations */
glClearColor(0.0, 0.0, 0.0, 0.0);
diff --git a/src/scene-effect-2d.cpp b/src/scene-effect-2d.cpp
index a3f4f1a..4eb7014 100644
--- a/src/scene-effect-2d.cpp
+++ b/src/scene-effect-2d.cpp
@@ -216,10 +216,7 @@
iter_el != elems.end();
iter_el++)
{
- std::stringstream ss(*iter_el);
- float f;
-
- ss >> f;
+ float f(Util::fromString<float>(*iter_el));
matrix.push_back(f);
Log::debug("%f ", f);
}
diff --git a/src/scene-function.cpp b/src/scene-function.cpp
index b43c47c..3941928 100644
--- a/src/scene-function.cpp
+++ b/src/scene-function.cpp
@@ -25,8 +25,7 @@
#include "vec.h"
#include "log.h"
#include "shader-source.h"
-
-#include <sstream>
+#include "util.h"
static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/function");
@@ -125,16 +124,8 @@
bool frg_function = options_["fragment-function"].value == "true";
std::string vtx_complexity = options_["vertex-complexity"].value;
std::string frg_complexity = options_["fragment-complexity"].value;
- int vtx_steps = 0;
- int frg_steps = 0;
-
- std::stringstream ss;
-
- ss << options_["vertex-steps"].value;
- ss >> vtx_steps;
- ss.clear();
- ss << options_["fragment-steps"].value;
- ss >> frg_steps;
+ int vtx_steps = Util::fromString<int>(options_["vertex-steps"].value);
+ int frg_steps = Util::fromString<int>(options_["fragment-steps"].value);
/* Load shaders */
std::string vtx_shader(get_vertex_shader_source(vtx_steps, vtx_function,
diff --git a/src/scene-grid.cpp b/src/scene-grid.cpp
index 3e1a82a..8c874f8 100644
--- a/src/scene-grid.cpp
+++ b/src/scene-grid.cpp
@@ -24,8 +24,7 @@
#include "stack.h"
#include "vec.h"
#include "log.h"
-
-#include <sstream>
+#include "util.h"
SceneGrid::SceneGrid(Canvas &pCanvas, const std::string &name) :
Scene(pCanvas, name)
@@ -59,16 +58,8 @@
{
Scene::setup();
- int grid_size = 0;
- double grid_length = 0;
-
- std::stringstream ss;
-
- ss << options_["grid-size"].value;
- ss >> grid_size;
- ss.clear();
- ss << options_["grid-length"].value;
- ss >> grid_length;
+ int grid_size(Util::fromString<int>(options_["grid-size"].value));
+ double grid_length(Util::fromString<double>(options_["grid-length"].value));
/* Create and configure the grid mesh */
std::vector<int> vertex_format;
diff --git a/src/scene-loop.cpp b/src/scene-loop.cpp
index 5e93b73..61687f9 100644
--- a/src/scene-loop.cpp
+++ b/src/scene-loop.cpp
@@ -25,8 +25,7 @@
#include "vec.h"
#include "log.h"
#include "shader-source.h"
-
-#include <sstream>
+#include "util.h"
static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/loop");
@@ -68,9 +67,7 @@
source_main.replace("$NLOOPS$", "FragmentLoops");
}
else {
- std::stringstream ss_steps;
- ss_steps << steps;
- source_main.replace("$NLOOPS$", ss_steps.str());
+ source_main.replace("$NLOOPS$", Util::toString(steps));
}
}
else {
@@ -95,9 +92,7 @@
source_main.replace("$NLOOPS$", "VertexLoops");
}
else {
- std::stringstream ss_steps;
- ss_steps << steps;
- source_main.replace("$NLOOPS$", ss_steps.str());
+ source_main.replace("$NLOOPS$", Util::toString(steps));
}
}
else {
@@ -121,16 +116,8 @@
bool frg_loop = options_["fragment-loop"].value == "true";
bool vtx_uniform = options_["vertex-uniform"].value == "true";
bool frg_uniform = options_["fragment-uniform"].value == "true";
- int vtx_steps = 0;
- int frg_steps = 0;
-
- std::stringstream ss;
-
- ss << options_["vertex-steps"].value;
- ss >> vtx_steps;
- ss.clear();
- ss << options_["fragment-steps"].value;
- ss >> frg_steps;
+ int vtx_steps = Util::fromString<int>(options_["vertex-steps"].value);
+ int frg_steps = Util::fromString<int>(options_["fragment-steps"].value);
/* Load shaders */
std::string vtx_shader(get_vertex_shader_source(vtx_steps, vtx_loop,
diff --git a/src/scene-pulsar.cpp b/src/scene-pulsar.cpp
index 1acd59c..55921c7 100644
--- a/src/scene-pulsar.cpp
+++ b/src/scene-pulsar.cpp
@@ -30,6 +30,7 @@
#include "log.h"
#include "program.h"
#include "shader-source.h"
+#include "util.h"
#include <cmath>
@@ -81,9 +82,7 @@
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Create a rotation for each quad.
- std::stringstream ss;
- ss << options_["quads"].value;
- ss >> numQuads_;
+ numQuads_ = Util::fromString<int>(options_["quads"].value);
srand((unsigned)time(0));
for (int i = 0; i < numQuads_; i++) {
diff --git a/src/scene.cpp b/src/scene.cpp
index 7bb5bce..96928cd 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -25,6 +25,7 @@
#include "log.h"
#include "shader-source.h"
#include "options.h"
+#include "util.h"
#include <sstream>
#include <cmath>
#include <sys/time.h>
@@ -66,8 +67,7 @@
void
Scene::setup()
{
- stringstream ss(options_["duration"].value);
- ss >> duration_;
+ duration_ = Util::fromString<double>(options_["duration"].value);
ShaderSource::default_precision(
ShaderSource::Precision(options_["vertex-precision"].value),