annotate Framework/Toolbox/GenericToolbox.h @ 1310:9bea7e15b519 broker

- first pass at changes to cope with the refactoring of the loading system - global loader-related data accessible through ILoadersContext::ILock - many changes in legacy loaders (CT, RTSTRUCT, DOSE) + loader cache - NOT FINISHED! there are shared_from_this calls in ctors! this will crash!
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 09 Mar 2020 14:53:22 +0100
parents fef1ec42a7db
children fd616c4a5904
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1192
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1080
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 {
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
32 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
33 Fast floating point string validation.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
34 No trimming applied, so the input must match regex
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
35 /^[-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
36 The following are allowed as edge cases: "" and "-"
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
37 */
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38 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
39 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40 const char* p = text;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 if(*p == '-')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42 p++;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43 size_t period = 0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 while(*p != 0)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46 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
47 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
48 else if(*p == '.')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50 if(period > 0)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 else
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53 period++;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 }
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
56 else if (*p == 'e' || *p == 'E')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
57 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
58 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
59 if (*p == '-' || *p == '+')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
60 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
61 // "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
62 if (!(*p >= '0' && *p <= '9'))
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
63 return false;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
64
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
65 // these must be the last in the string
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
66 while(*p >= '0' && *p <= '9')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
67 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
68
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
69 return (*p == 0);
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
70 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 else
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
72 {
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73 return false;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
74 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
75 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76 return true;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
79 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
80 Fast integer string validation.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
81 No trimming applied, so the input must match regex /^-?[0-9]*$/
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
82 The following are allowed as edge cases: "" and "-"
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
83 */
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84 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
85 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
86 const char* p = text;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
87 if (*p == '-')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
88 p++;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
89 while (*p != 0)
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 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
92 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
93 else
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 return true;
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
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
99 /*
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
100 Fast string --> double conversion.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
101 Must pass the LegitDoubleString test
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
102
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
103 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
104 */
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
105 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
106 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107 if(!LegitDoubleString(text))
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
109
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
110 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
111 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
112 1.0,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
113 0.1,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 0.01,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
115 0.001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
116 0.0001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
117 0.00001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118 0.000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
119 0.0000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
120 0.00000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
121 0.000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122 0.0000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123 0.00000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
124 0.000000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 0.0000000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 0.00000000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 0.000000000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 0.0000000000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 0.00000000000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 0.000000000000000001,
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
131 0.0000000000000000001
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 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
134
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135 r = 0.0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 double neg = 1.0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137 const char* p = text;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
138
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
139 if (*p == '-')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
141 neg = -1.0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144 // 12345.67890
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
145 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
146 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
147 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
148 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
150 if (*p == '.')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
151 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
152 double f = 0.0;
1192
91d86144fb79 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1166
diff changeset
153 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
154 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
155 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
156 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
157 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
158 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159 ++n;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
160 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
161 r += f;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163 r *= neg;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
164
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
165 // 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
166 // 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
167 while ((*p >= '0' && *p <= '9'))
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
168 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
169
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
170 if (*p == 0 )
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
171 {
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
172 return true;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
173 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
174 else if ((*p == 'e') || (*p == 'E'))
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
175 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
176 // process the scientific notation
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
177 double sign; // no init is safe (read below)
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
178 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
179 if (*p == '-')
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 sign = -1.0;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
182 // point to first number
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
183 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
184 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
185 else if (*p == '+')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
186 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
187 sign = 1.0;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
188 // point to first number
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
189 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
190 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
191 else if (*p >= '0' && *p <= '9')
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 sign = 1.0;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
194 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
195 else
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
196 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
197 // 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
198 return false;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
199 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
200 // 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
201 double exp = 0;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
202 while (*p >= '0' && *p <= '9')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
203 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
204 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
205 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
206 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
207 // 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
208 exp *= sign;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
209 double scFac = ::pow(10.0, exp);
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
210 r *= scFac;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
211
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
212 // only allowed symbol here is EOS
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
213 return (*p == 0);
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
214 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215 else
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
216 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
217 // not allowed
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
218 return false;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
219 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222 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
223 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
224 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
225 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
226
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
227 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
228 Fast string to integer conversion. Leading zeroes and minus are accepted,
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
229 but a leading + sign is NOT.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
230 Must pass the LegitIntegerString function test.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
231 In addition, an empty string (or lone minus sign) yields 0.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
232 */
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
233
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234 template<typename T>
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235 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
236 {
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
237 if (!LegitIntegerString(text))
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
238 return false;
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 r = 0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 T neg = 1;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242 const char* p = text;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 if (*p == '-')
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 neg = -1;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
247 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
248 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
249 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
250 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
251 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
252 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
254 r *= neg;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
255 if (*p == 0)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
256 return true;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 else
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 return false;
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
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
261 template<typename T>
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
262 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
263 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
264 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
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 /**
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
268 if input is "rgb(12,23,255)" --> function fills `red`, `green` and `blue` and returns true
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
269 else ("everything else") --> function returns false and leaves all values untouched
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
270 */
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
271 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
272
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
273 /**
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
274 See main overload
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
275 */
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
276 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
277 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
278 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
279 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
280
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
281 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
282 Same as GetRgbValuesFromString
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
283 */
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
284 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
285
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
286 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
287 Same as GetRgbValuesFromString
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
288 */
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
289 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
290 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
291 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
292 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
293 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
294 }