Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/GenericToolbox.h @ 1213:86a8266b8888 broker
moving the scene from IViewport to ViewportController
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 04 Dec 2019 17:54:10 +0100 |
parents | bdc6837d5917 |
children | 0ca50d275b9a |
rev | line source |
---|---|
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
1 /** |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
2 * Stone of Orthanc |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
6 * |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
11 * |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
16 * |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
19 **/ |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
20 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
21 #pragma once |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
22 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
23 #include <string> |
1101
141593f1aa88
fix build on ubuntu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1080
diff
changeset
|
24 #include <stdint.h> |
1166
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
25 #include <math.h> |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
26 |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
27 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
28 namespace OrthancStone |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
29 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
30 namespace GenericToolbox |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
31 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
32 inline bool LegitDoubleString(const char* text) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
33 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
34 const char* p = text; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
35 if(*p == '-') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
36 p++; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
37 size_t period = 0; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
38 while(*p != 0) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
39 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
40 if (*p >= '0' && *p <= '9') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
41 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
42 else if(*p == '.') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
43 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
44 if(period > 0) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
45 return false; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
46 else |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
47 period++; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
48 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
49 } |
1166
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
50 else if (*p == 'e' || *p == 'E') |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
51 { |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
52 ++p; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
53 if (*p == '-' || *p == '+') |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
54 ++p; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
55 // "e+"/"E+" "e-"/"E-" or "e"/"E" must be followed by a number |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
56 if (!(*p >= '0' && *p <= '9')) |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
57 return false; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
58 |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
59 // these must be the last in the string |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
60 while(*p >= '0' && *p <= '9') |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
61 ++p; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
62 |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
63 return (*p == 0); |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
64 } |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
65 else |
1166
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
66 { |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
67 return false; |
1166
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
68 } |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
69 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
70 return true; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
71 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
72 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
73 inline bool LegitIntegerString(const char* text) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
74 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
75 const char* p = text; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
76 if (*p == '-') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
77 p++; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
78 while (*p != 0) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
79 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
80 if (*p >= '0' && *p <= '9') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
81 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
82 else |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
83 return false; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
84 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
85 return true; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
86 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
87 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
88 /* |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
89 String to doubles with at most 18 digits |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
90 */ |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
91 inline bool StringToDouble(double& r, const char* text) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
92 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
93 if(!LegitDoubleString(text)) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
94 return false; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
95 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
96 static const double FRAC_FACTORS[] = |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
97 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
98 1.0, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
99 0.1, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
100 0.01, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
101 0.001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
102 0.0001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
103 0.00001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
104 0.000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
105 0.0000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
106 0.00000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
107 0.000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
108 0.0000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
109 0.00000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
110 0.000000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
111 0.0000000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
112 0.00000000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
113 0.000000000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
114 0.0000000000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
115 0.00000000000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
116 0.000000000000000001, |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
117 0.0000000000000000001 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
118 }; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
119 const size_t FRAC_FACTORS_LEN = sizeof(FRAC_FACTORS)/sizeof(double); |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
120 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
121 r = 0.0; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
122 double neg = 1.0; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
123 const char* p = text; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
124 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
125 if (*p == '-') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
126 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
127 neg = -1.0; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
128 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
129 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
130 // 12345.67890 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
131 while (*p >= '0' && *p <= '9') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
132 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
133 r = (r*10.0) + (*p - '0'); // 1 12 123 123 12345 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
134 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
135 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
136 if (*p == '.') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
137 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
138 double f = 0.0; |
1192 | 139 size_t n = 1; |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
140 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
141 while (*p >= '0' && *p <= '9' && n < FRAC_FACTORS_LEN) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
142 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
143 f += (*p - '0') * FRAC_FACTORS[n]; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
144 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
145 ++n; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
146 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
147 r += f; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
148 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
149 r *= neg; |
1166
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
150 |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
151 // skip the remaining numbers until we reach not-a-digit (either the |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
152 // end of the string OR the scientific notation symbol) |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
153 while ((*p >= '0' && *p <= '9')) |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
154 ++p; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
155 |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
156 if (*p == 0 ) |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
157 { |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
158 return true; |
1166
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
159 } |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
160 else if ((*p == 'e') || (*p == 'E')) |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
161 { |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
162 // process the scientific notation |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
163 double sign; // no init is safe (read below) |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
164 ++p; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
165 if (*p == '-') |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
166 { |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
167 sign = -1.0; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
168 // point to first number |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
169 ++p; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
170 } |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
171 else if (*p == '+') |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
172 { |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
173 sign = 1.0; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
174 // point to first number |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
175 ++p; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
176 } |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
177 else if (*p >= '0' && *p <= '9') |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
178 { |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
179 sign = 1.0; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
180 } |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
181 else |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
182 { |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
183 // only a sign char or a number is allowed |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
184 return false; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
185 } |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
186 // now p points to the absolute value of the exponent |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
187 double exp = 0; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
188 while (*p >= '0' && *p <= '9') |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
189 { |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
190 exp = (exp * 10.0) + static_cast<double>(*p - '0'); // 1 12 123 123 12345 |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
191 ++p; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
192 } |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
193 // now we have our exponent. put a sign on it. |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
194 exp *= sign; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
195 double scFac = ::pow(10.0, exp); |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
196 r *= scFac; |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
197 |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
198 // only allowed symbol here is EOS |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
199 return (*p == 0); |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
200 } |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
201 else |
1166
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
202 { |
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
203 // not allowed |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
204 return false; |
1166
f68da12e852b
Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents:
1101
diff
changeset
|
205 } |
1080
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
206 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
207 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
208 inline bool StringToDouble(double& r, const std::string& text) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
209 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
210 return StringToDouble(r, text.c_str()); |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
211 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
212 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
213 template<typename T> |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
214 inline bool StringToInteger(T& r, const char* text) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
215 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
216 if (!LegitDoubleString(text)) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
217 return false; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
218 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
219 r = 0; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
220 T neg = 1; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
221 const char* p = text; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
222 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
223 if (*p == '-') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
224 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
225 neg = -1; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
226 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
227 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
228 while (*p >= '0' && *p <= '9') |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
229 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
230 r = (r * 10) + (*p - '0'); // 1 12 123 123 12345 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
231 ++p; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
232 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
233 r *= neg; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
234 if (*p == 0) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
235 return true; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
236 else |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
237 return false; |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
238 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
239 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
240 template<typename T> |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
241 inline bool StringToInteger(T& r, const std::string& text) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
242 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
243 return StringToInteger<T>(r, text.c_str()); |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
244 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
245 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
246 /** |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
247 "rgb(12,23,255)" --> red, green, blue and returns true |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
248 "everything else" --> returns false (other values left untouched) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
249 */ |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
250 bool GetRgbValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, const char* text); |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
251 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
252 /** |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
253 See other overload |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
254 */ |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
255 inline bool GetRgbValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, const std::string& text) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
256 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
257 return GetRgbValuesFromString(red, green, blue, text.c_str()); |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
258 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
259 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
260 bool GetRgbaValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, uint8_t& alpha, const char* text); |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
261 |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
262 inline bool GetRgbaValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, uint8_t& alpha, const std::string& text) |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
263 { |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
264 return GetRgbaValuesFromString(red, green, blue, alpha, text.c_str()); |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
265 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
266 } |
287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
267 } |