Code

Fixed icon loading, cacheing and fallback to use stock mechanisms.
[inkscape.git] / src / helper-fns.h
index b4976bad44f044cca86ab35561f5a95f43e3ff80..39d919aa7b4c8472355516557b60ec4d80715a80 100644 (file)
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
+#include <string.h>
+#include <vector>
 #include <sstream>
 
-inline double helperfns_read_number(gchar const *value) {
+// calling helperfns_read_number(string, false), it's not obvious, what
+// that false stands for. helperfns_read_number(string, HELPERFNS_NO_WARNING)
+// can be more clear.
+#define HELPERFNS_NO_WARNING false
+
+/* Setting warning to false disables conversion error warnings from
+ * this function. This can be useful in places, where the input type
+ * is not known beforehand. For example, see sp_feColorMatrix_set in
+ * sp-fecolormatrix.cpp */
+inline double helperfns_read_number(gchar const *value, bool warning = true) {
     if (!value) return 0;
     char *end;
     double ret = g_ascii_strtod(value, &end);
     if (*end) {
-        g_warning("Unable to convert \"%s\" to number", value);
+        if (warning) {
+            g_warning("Unable to convert \"%s\" to number", value);
+        }
         // We could leave this out, too. If strtod can't convert
         // anything, it will return zero.
         ret = 0;
@@ -48,6 +61,16 @@ inline std::vector<gdouble> helperfns_read_vector(const gchar* value, int size){
         return v;
 }
 
+inline std::vector<gdouble> helperfns_read_vector(const gchar* value){
+        std::vector<gdouble> v;
+        std::istringstream is(value);
+        gdouble d;
+        while (is >> d){
+            v.push_back(d);
+        }
+        return v;
+}
+
 #endif /* !SEEN_HELPER_FNS_H */
 
 /*