Code

Refactoring SPColor to C++ and removing legacy CMYK implementation
[inkscape.git] / src / helper-fns.h
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 inline double helperfns_read_number(gchar const *value) {
19     if (!value) return 0;
20     char *end;
21     double ret = g_ascii_strtod(value, &end);
22     if (*end) {
23         g_warning("Unable to convert \"%s\" to number", value);
24         // We could leave this out, too. If strtod can't convert
25         // anything, it will return zero.
26         ret = 0;
27     }
28     return ret;
29 }
31 inline bool helperfns_read_bool(gchar const *value, bool default_value){
32     if (!value) return default_value;
33     switch(value[0]){
34         case 't':
35             if (strncmp(value, "true", 4) == 0) return true;
36             break;
37         case 'f':
38             if (strncmp(value, "false", 5) == 0) return false;
39             break;
40     }
41     return default_value;
42 }
44 inline std::vector<gdouble> helperfns_read_vector(const gchar* value, int size){
45         std::vector<gdouble> v(size, (gdouble) 0);
46         std::istringstream is(value);
47         for(int i = 0; i < size && (is >> v[i]); i++);
48         return v;
49 }
51 #endif /* !SEEN_HELPER_FNS_H */
53 /*
54   Local Variables:
55   mode:c++
56   c-file-style:"stroustrup"
57   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
58   indent-tabs-mode:nil
59   fill-column:99
60   End:
61 */
62 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :