Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/GenericToolbox.cpp @ 1080:287ec78f63b4
GenericToolbox (fast c-string --> double or integer) + refactoring to be able
to set structures lut into configurator + fixed missing revision bump in
configurator + UT
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 21 Oct 2019 16:01:29 +0200 |
parents | |
children | fe723ea10d98 |
comparison
equal
deleted
inserted
replaced
1072:391fb6d6905d | 1080:287ec78f63b4 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "GenericToolbox.h" | |
23 | |
24 #include <boost/regex.hpp> | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 namespace GenericToolbox | |
29 { | |
30 bool GetRgbaValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, uint8_t& alpha, const char* text) | |
31 { | |
32 boost::regex pattern(R"bgo(\s*rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)\s*)bgo"); | |
33 | |
34 boost::cmatch what; | |
35 | |
36 if (boost::regex_match(text, what, pattern)) | |
37 { | |
38 { | |
39 std::string redStr = what[1]; | |
40 bool ok = StringToInteger<uint8_t>(red, redStr); | |
41 if (!ok) | |
42 return false; | |
43 } | |
44 { | |
45 std::string greenStr = what[2]; | |
46 bool ok = StringToInteger<uint8_t>(green, greenStr); | |
47 if (!ok) | |
48 return false; | |
49 } | |
50 { | |
51 std::string blueStr = what[3]; | |
52 bool ok = StringToInteger<uint8_t>(blue, blueStr); | |
53 if (!ok) | |
54 return false; | |
55 } | |
56 { | |
57 std::string alphaStr = what[4]; | |
58 bool ok = StringToInteger<uint8_t>(alpha, alphaStr); | |
59 if (!ok) | |
60 return false; | |
61 } | |
62 return true; | |
63 } | |
64 else | |
65 { | |
66 return false; | |
67 } | |
68 } | |
69 bool GetRgbValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, const char* text) | |
70 { | |
71 boost::regex pattern(R"bgo(\s*rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)\s*)bgo"); | |
72 | |
73 boost::cmatch what; | |
74 | |
75 if (boost::regex_match(text, what, pattern)) | |
76 { | |
77 { | |
78 std::string redStr = what[1]; | |
79 bool ok = StringToInteger<uint8_t>(red, redStr); | |
80 if (!ok) | |
81 return false; | |
82 } | |
83 { | |
84 std::string greenStr = what[2]; | |
85 bool ok = StringToInteger<uint8_t>(green, greenStr); | |
86 if (!ok) | |
87 return false; | |
88 } | |
89 { | |
90 std::string blueStr = what[3]; | |
91 bool ok = StringToInteger<uint8_t>(blue, blueStr); | |
92 if (!ok) | |
93 return false; | |
94 } | |
95 return true; | |
96 } | |
97 else | |
98 { | |
99 return false; | |
100 } | |
101 } | |
102 | |
103 } | |
104 } |