Code

added forward decl to fixed_g_ascii_strtod to fix compiler issue on WinXP
[inkscape.git] / src / number-opt-number.h
1 #ifndef SEEN_NUMBER_OPT_NUMBER_H
2 #define SEEN_NUMBER_OPT_NUMBER_H
4 /** \file
5  * <number-opt-number> implementation.
6  */
7 /*
8  * Authors:
9  *   Hugo Rodrigues <haa.rodrigues@gmail.com>
10  *
11  * Copyright (C) 2006 Hugo Rodrigues
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
20 #include <glib.h>
21 #include <glib/gprintf.h>
22 //todo: use glib instead of stdlib
23 #include <stdlib.h>
24 #include "svg/stringstream.h"
27 gdouble fixed_g_ascii_strtod (const gchar *nptr, gchar **endptr);
29 class NumberOptNumber {
31 public:
33     gfloat number; 
35     gfloat optNumber;
37     guint _set : 1;
39     guint optNumber_set : 1;
41     NumberOptNumber()
42     {
43         number = 0.0;
44         optNumber = 0.0;
46         _set = FALSE;
47         optNumber_set = FALSE;
48     }
50     gfloat getNumber()
51     {
52         if(_set)
53             return number;
54         return -1;
55     }
57     gfloat getOptNumber()
58     {
59         if(optNumber_set)
60             return optNumber;
61         return -1;
62     }
64     void setOptNumber(gfloat num)
65     {
66         optNumber_set = true;
67         optNumber = num;
68     }
70     void setNumber(gfloat num)
71     {
72         _set = true;
73         number = num;
74     }
76     gchar *getValueString()
77     {
78         Inkscape::SVGOStringStream os;
80         if( _set )
81         {
83             if( optNumber_set )
84             {
85                 os << number << " " << optNumber;
86             }
87             else {
88                 os << number;
89             }
90         }
91         return g_strdup(os.str().c_str());
92     }
94     void set(gchar const *str)
95     {
96         if(!str)
97             return;
99         gchar **values = g_strsplit(str, " ", 2);
101         if( values[0] != NULL )
102         {
103             number = g_ascii_strtod(values[0], NULL);
104             _set = TRUE;
106             if( values[1] != NULL )
107             {
108                 optNumber = g_ascii_strtod(values[1], NULL);
109                 optNumber_set = TRUE;
110             }
111             else
112                 optNumber_set = FALSE;
113         }
114         else {
115                 _set = FALSE;
116                 optNumber_set = FALSE;
117         }
118     }
120 };
122 #endif /* !SEEN_NUMBER_OPT_NUMBER_H */
124 /*
125   Local Variables:
126   mode:c++
127   c-file-style:"stroustrup"
128   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
129   indent-tabs-mode:nil
130   fill-column:99
131   End:
132 */
133 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :