4e51c9a161b2d07c2ec1177cbaee7680bb34c6c6
1 #ifndef SEEN_HELPER_FNS_H
2 #define SEEN_HELPER_FNS_H
3 /** \file
4 *
5 * Some helper functions
6 *
7 * Authors:
8 * Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
9 *
10 *
11 * Copyright (C) 2006 Hugo Rodrigues
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #include <sstream>
18 static double
19 helperfns_read_number(gchar const *value) {
20 if (!value) return 0;
21 char *end;
22 double ret = g_ascii_strtod(value, &end);
23 if (*end) {
24 g_warning("Unable to convert \"%s\" to number", value);
25 // We could leave this out, too. If strtod can't convert
26 // anything, it will return zero.
27 ret = 0;
28 }
29 return ret;
30 }
32 static bool helperfns_read_bool(gchar const *value, bool default_value){
33 if (!value) return default_value;
34 switch(value[0]){
35 case 't':
36 if (strncmp(value, "true", 4) == 0) return true;
37 break;
38 case 'f':
39 if (strncmp(value, "false", 5) == 0) return false;
40 break;
41 }
42 return default_value;
43 }
45 static std::vector<gdouble> helperfns_read_vector(const gchar* value, int size){
46 std::vector<gdouble> v(size, (gdouble) 0);
47 std::istringstream is(value);
48 for(int i = 0; i < size && (is >> v[i]); i++);
49 return v;
50 }
52 #endif /* !SEEN_HELPER_FNS_H */
54 /*
55 Local Variables:
56 mode:c++
57 c-file-style:"stroustrup"
58 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
59 indent-tabs-mode:nil
60 fill-column:99
61 End:
62 */
63 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :