Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
number-opt-number.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_NUMBER_OPT_NUMBER_H
3#define SEEN_NUMBER_OPT_NUMBER_H
4
8/*
9 * Authors:
10 * Hugo Rodrigues <haa.rodrigues@gmail.com>
11 *
12 * Copyright (C) 2006 Hugo Rodrigues
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#include <glib.h>
18#include <glib/gprintf.h>
19#include <cstdlib>
20
21#include "svg/stringstream.h"
22
24{
25public:
27 {
28 _num = 0.0;
29 _set = false;
30 _optnum = 0.0;
31 _optset = false;
32 }
33
35 {
36 _num = num;
37 _set = true;
38 _optnum = 0.0;
39 _optset = false;
40 }
41
42 NumberOptNumber(float num, float optnum)
43 {
44 _num = num;
45 _set = true;
46 _optnum = optnum;
47 _optset = true;
48 }
49
50 float getNumber() const
51 {
52 return _set ? _num : -1;
53 }
54
55 float getOptNumber(bool or_num = false) const
56 {
57 return _optset ? _optnum : (or_num ? _num : -1);
58 }
59
60 void setNumber(float num)
61 {
62 _set = true;
63 _num = num;
64 }
65
66 void setOptNumber(float optnum)
67 {
68 _optset = optnum != -1;
69 _optnum = optnum;
70 }
71
72 bool numIsSet() const
73 {
74 return _set;
75 }
76
77 bool optNumIsSet() const
78 {
79 return _optset;
80 }
81
82 std::string getValueString() const
83 {
85
86 if (_set) {
87 os << _num;
88 if (_optset) {
89 os << " " << _optnum;
90 }
91 }
92
93 return os.str();
94 }
95
96 void set(char const *str)
97 {
98 if (!str) {
99 return;
100 }
101
102 _set = false;
103 _optset = false;
104
105 char **values = g_strsplit(str, " ", 2);
106
107 if (values[0]) {
108 _num = g_ascii_strtod(values[0], nullptr);
109 _set = true;
110
111 if (values[1]) {
112 _optnum = g_ascii_strtod(values[1], nullptr);
113 _optset = true;
114 }
115 }
116
117 g_strfreev(values);
118 }
119
120private:
121 float _num;
122 float _optnum;
123 bool _set : 1;
124 bool _optset : 1;
125};
126
127#endif // SEEN_NUMBER_OPT_NUMBER_H
128
129/*
130 Local Variables:
131 mode:c++
132 c-file-style:"stroustrup"
133 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
134 indent-tabs-mode:nil
135 fill-column:99
136 End:
137*/
138// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
std::string str() const
float getOptNumber(bool or_num=false) const
float getNumber() const
NumberOptNumber(float num, float optnum)
NumberOptNumber(float num)
void set(char const *str)
bool optNumIsSet() const
bool numIsSet() const
void setOptNumber(float optnum)
std::string getValueString() const
void setNumber(float num)
int num
Definition scribble.cpp:47
TODO: insert short description here.