diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 118: Move the string split() function to a separate Util module.

Message ID 20110810135820.1453.95436.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org Aug. 10, 2011, 1:58 p.m. UTC
------------------------------------------------------------
revno: 118
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Tue 2011-08-09 13:34:49 +0300
message:
  Move the string split() function to a separate Util module.
added:
  src/util.cpp
  src/util.h
modified:
  src/benchmark.cpp
  src/scene-effect-2d.cpp


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/benchmark.cpp'
--- src/benchmark.cpp	2011-06-09 14:07:23 +0000
+++ src/benchmark.cpp	2011-08-09 10:34:49 +0000
@@ -22,7 +22,7 @@ 
 
 #include "benchmark.h"
 #include "log.h"
-#include <sstream>
+#include "util.h"
 
 using std::string;
 using std::vector;
@@ -30,22 +30,12 @@ 
 
 std::map<string, Scene *> Benchmark::mSceneMap;
 
-static void
-split(const string &s, char delim, vector<string> &elems)
-{
-    std::stringstream ss(s);
-
-    string item;
-    while(std::getline(ss, item, delim))
-        elems.push_back(item);
-}
-
 static Scene &
 get_scene_from_description(const string &s)
 {
     vector<string> elems;
 
-    split(s, ':', elems);
+    Util::split(s, ':', elems);
 
     const string &name = !elems.empty() ? elems[0] : ""; 
 
@@ -58,7 +48,7 @@ 
     vector<Benchmark::OptionPair> options;
     vector<string> elems;
 
-    split(s, ':', elems);
+    Util::split(s, ':', elems);
 
     for (vector<string>::const_iterator iter = ++elems.begin();
          iter != elems.end();
@@ -66,7 +56,7 @@ 
     {
         vector<string> opt;
 
-        split(*iter, '=', opt);
+        Util::split(*iter, '=', opt);
         if (opt.size() == 2)
             options.push_back(Benchmark::OptionPair(opt[0], opt[1]));
         else

=== modified file 'src/scene-effect-2d.cpp'
--- src/scene-effect-2d.cpp	2011-08-02 16:01:29 +0000
+++ src/scene-effect-2d.cpp	2011-08-09 10:34:49 +0000
@@ -30,6 +30,7 @@ 
 #include "log.h"
 #include "program.h"
 #include "shader-source.h"
+#include "util.h"
 
 
 SceneEffect2D::SceneEffect2D(Canvas &pCanvas) :
@@ -169,23 +170,6 @@ 
 }
 
 /** 
- * Splits a string using a delimiter
- * 
- * @param s the string to split
- * @param delim the delimitir to use
- * @param elems the string vector to populate
- */
-static void
-split(const std::string &s, char delim, std::vector<std::string> &elems)
-{
-    std::stringstream ss(s);
-
-    std::string item;
-    while(std::getline(ss, item, delim))
-        elems.push_back(item);
-}
-
-/** 
  * Parses a string representation of a matrix and returns it
  * in row-major format.
  *
@@ -207,7 +191,7 @@ 
     std::vector<std::string> rows;
     unsigned int w = UINT_MAX;
 
-    split(str, ';', rows);
+    Util::split(str, ';', rows);
 
     Log::debug("Parsing kernel matrix:\n");
 
@@ -216,7 +200,7 @@ 
          iter++)
     {
         std::vector<std::string> elems;
-        split(*iter, ',', elems);
+        Util::split(*iter, ',', elems);
 
         if (w != UINT_MAX && elems.size() != w) {
             Log::error("Matrix row %u contains %u elements, whereas previous"

=== added file 'src/util.cpp'
--- src/util.cpp	1970-01-01 00:00:00 +0000
+++ src/util.cpp	2011-08-09 10:34:49 +0000
@@ -0,0 +1,44 @@ 
+/*
+ * Copyright © 2011 Linaro Limited
+ *
+ * This file is part of glcompbench.
+ *
+ * glcompbench is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * glcompbench is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with glcompbench.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis <alexandros.frantzis@linaro.org>
+ *  Jesse Barker <jesse.barker@linaro.org>
+ */
+
+#include <sstream>
+
+#include "util.h"
+
+/** 
+ * Splits a string using a delimiter
+ * 
+ * @param s the string to split
+ * @param delim the delimitir to use
+ * @param elems the string vector to populate
+ */
+void
+Util::split(const std::string &s, char delim, std::vector<std::string> &elems)
+{
+    std::stringstream ss(s);
+
+    std::string item;
+    while(std::getline(ss, item, delim))
+        elems.push_back(item);
+}
+

=== added file 'src/util.h'
--- src/util.h	1970-01-01 00:00:00 +0000
+++ src/util.h	2011-08-09 10:34:49 +0000
@@ -0,0 +1,34 @@ 
+/*
+ * Copyright © 2011 Linaro Limited
+ *
+ * This file is part of glcompbench.
+ *
+ * glcompbench is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * glcompbench is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with glcompbench.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis <alexandros.frantzis@linaro.org>
+ *  Jesse Barker <jesse.barker@linaro.org>
+ */
+
+#ifndef UTIL_H_
+#define UTIL_H_
+
+#include <string>
+#include <vector>
+
+struct Util {
+    static void split(const std::string &s, char delim, std::vector<std::string> &elems);
+};
+
+#endif /* UTIL_H */