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 bool optNumIsSet(){
77 return optNumber_set;
78 }
80 bool numIsSet(){
81 return _set;
82 }
84 gchar *getValueString()
85 {
86 Inkscape::SVGOStringStream os;
88 if( _set )
89 {
91 if( optNumber_set )
92 {
93 os << number << " " << optNumber;
94 }
95 else {
96 os << number;
97 }
98 }
99 return g_strdup(os.str().c_str());
100 }
102 void set(gchar const *str)
103 {
104 if(!str)
105 return;
107 gchar **values = g_strsplit(str, " ", 2);
109 if( values[0] != NULL )
110 {
111 number = g_ascii_strtod(values[0], NULL);
112 _set = TRUE;
114 if( values[1] != NULL )
115 {
116 optNumber = g_ascii_strtod(values[1], NULL);
117 optNumber_set = TRUE;
118 }
119 else
120 optNumber_set = FALSE;
121 }
122 else {
123 _set = FALSE;
124 optNumber_set = FALSE;
125 }
126 }
128 };
130 #endif /* !SEEN_NUMBER_OPT_NUMBER_H */
132 /*
133 Local Variables:
134 mode:c++
135 c-file-style:"stroustrup"
136 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
137 indent-tabs-mode:nil
138 fill-column:99
139 End:
140 */
141 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :