22
22
// can be more clear.
23
23
#define HELPERFNS_NO_WARNING false
25
/* Setting warning to false disables conversion error warnings from
25
/* convert localized ascii representation to double
26
* the function can only be used to convert numbers as given by gui elements that use localized representation
27
* @param value ascii representation of the number
28
* @return the converted number
30
* Setting warning to false disables conversion error warnings from
26
31
* this function. This can be useful in places, where the input type
27
32
* is not known beforehand. For example, see sp_feColorMatrix_set in
28
33
* sp-fecolormatrix.cpp */
29
34
inline double helperfns_read_number(gchar const *value, bool warning = true) {
36
g_warning("Called helperfns_read_number with value==null_ptr, this can lead to unexpected behaviour.");
32
double ret = g_ascii_strtod(value, &end);
40
double ret = g_strtod(value, &end);
35
g_warning("Unable to convert \"%s\" to number", value);
43
g_warning("helper-fns::helperfns_read_number() Unable to convert \"%s\" to number", value);
37
45
// We could leave this out, too. If strtod can't convert
38
46
// anything, it will return zero.
54
62
return default_value;
65
/* convert localized ascii representation to double
66
* the function can only be used to convert numbers as given by gui elements that use localized representation
67
* numbers are delimeted by space
68
* @param value ascii representation of the number
69
* @param size number of elements in string
70
* @return the vector of the converted numbers
57
72
inline std::vector<gdouble> helperfns_read_vector(const gchar* value, int size){
58
73
std::vector<gdouble> v(size, (gdouble) 0);
59
74
std::istringstream is(value);
60
for(int i = 0; i < size && (is >> v[i]); i++);
75
for(int i = 0; i < size; i++){
80
double ret = g_strtod(str.c_str(), &end);
82
g_warning("helper-fns::helperfns_read_vector() Unable to convert \"%s\" to number", str.c_str());
83
// We could leave this out, too. If strtod can't convert
84
// anything, it will return zero.
92
/* convert localized ascii representation to double
93
* the function can only be used to convert numbers as given by gui elements that use localized representation
94
* numbers are delimeted by space
95
* @param value ascii representation of the number
96
* @return the vector of the converted numbers
64
98
inline std::vector<gdouble> helperfns_read_vector(const gchar* value){
65
99
std::vector<gdouble> v;
66
std::istringstream is(value);
101
gchar const* beg = value;
102
while(isspace(*beg)) beg++;
106
double ret = g_strtod(beg, &end);
108
g_warning("helper-fns::helperfns_read_vector() Unable to convert \"%s\" to number", beg);
109
// We could leave this out, too. If strtod can't convert
110
// anything, it will return zero.
116
while(isspace(*beg)) beg++;