Code

51966a101b937b38d45864d6ec8cc84880c1b905
[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 #include <glib.h>
17 #include <glib/gprintf.h>
18 //todo: use glib instead of stdlib
19 #include <stdlib.h>
20 #include "svg/stringstream.h"
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 class NumberOptNumber {
28 public:
30     gfloat number; 
32     gfloat optNumber;
34     guint _set : 1;
36     guint optNumber_set : 1;
38     NumberOptNumber()
39     {
40         number = 0.0;
41         optNumber = 0.0;
43         _set = FALSE;
44         optNumber_set = FALSE;
45     }
47     gfloat getNumber()
48     {
49         if(_set)
50             return number;
51         return -1;
52     }
54     gfloat getOptNumber()
55     {
56         if(optNumber_set)
57             return optNumber;
58         return -1;
59     }
61     void setOptNumber(gfloat num)
62     {
63         optNumber_set = true;
64         optNumber = num;
65     }
67     void setNumber(gfloat num)
68     {
69         _set = true;
70         number = num;
71     }
73     gchar *getValueString()
74     {
75         Inkscape::SVGOStringStream os;
77         if( _set )
78         {
80             if( optNumber_set )
81             {
82                 os << number << " " << optNumber;
83             }
84             else {
85                 os << number;
86             }
87         }
88         return g_strdup(os.str().c_str());
89     }
91     void set(gchar const *str)
92     {
93         if(!str)
94             return;
96         gchar **values = g_strsplit(str, " ", 2);
98         if( values[0] != NULL )
99         {
100             number = g_ascii_strtod(values[0], NULL);
101             _set = TRUE;
103             if( values[1] != NULL )
104             {
105                 optNumber = g_ascii_strtod(values[1], NULL);
106                 optNumber_set = TRUE;
107             }
108             else
109                 optNumber_set = FALSE;
110         }
111         else {
112                 _set = FALSE;
113                 optNumber_set = FALSE;
114         }
115     }
117 };
119 #endif /* !SEEN_NUMBER_OPT_NUMBER_H */
121 /*
122   Local Variables:
123   mode:c++
124   c-file-style:"stroustrup"
125   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
126   indent-tabs-mode:nil
127   fill-column:99
128   End:
129 */
130 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :