annotate OrthancStone/Sources/Toolbox/GenericToolbox.cpp @ 1870:3889ae96d2e9

added copyright UCLouvain
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Jan 2022 11:04:09 +0100
parents 9ac2a65d4172
children 7053b8a0aaec
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
1739
9ac2a65d4172 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1870
3889ae96d2e9 added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 *
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
10 * 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
11 * 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
12 *
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
13 * 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
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
16 * Lesser General Public License for more details.
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
19 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
20 * <http://www.gnu.org/licenses/>.
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21 **/
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
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
24 #include "GenericToolbox.h"
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
26 #include <Toolbox.h>
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
27
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
28 #include <boost/regex.hpp>
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 OrthancStone
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 namespace GenericToolbox
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 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
35 {
1088
fe723ea10d98 fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1080
diff changeset
36 boost::regex pattern("\\s*rgb\\s*\\(\\s*([0-9]+)\\s*,\\s*([0-9]+)\\s*,\\s*([0-9]+)\\s*,\\s*([0-9]+)\\s*\\)\\s*");
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38 boost::cmatch what;
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 (boost::regex_match(text, what, pattern))
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43 std::string redStr = what[1];
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 bool ok = StringToInteger<uint8_t>(red, redStr);
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45 if (!ok)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
47 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
48 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49 std::string greenStr = what[2];
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50 bool ok = StringToInteger<uint8_t>(green, greenStr);
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 if (!ok)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 std::string blueStr = what[3];
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56 bool ok = StringToInteger<uint8_t>(blue, blueStr);
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57 if (!ok)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 std::string alphaStr = what[4];
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 bool ok = StringToInteger<uint8_t>(alpha, alphaStr);
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 if (!ok)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66 return true;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68 else
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 false;
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 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
74 {
1088
fe723ea10d98 fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1080
diff changeset
75 boost::regex pattern("\\s*rgb\\s*\\(\\s*([0-9]+)\\s*,\\s*([0-9]+)\\s*,\\s*([0-9]+)\\s*\\)\\s*");
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 boost::cmatch what;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 if (boost::regex_match(text, what, pattern))
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
81 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82 std::string redStr = what[1];
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
83 bool ok = StringToInteger<uint8_t>(red, redStr);
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84 if (!ok)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
85 return false;
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 std::string greenStr = what[2];
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
89 bool ok = StringToInteger<uint8_t>(green, greenStr);
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90 if (!ok)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
91 return false;
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 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94 std::string blueStr = what[3];
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
95 bool ok = StringToInteger<uint8_t>(blue, blueStr);
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
96 if (!ok)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
97 return false;
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 return true;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
100 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
101 else
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
102 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
103 return false;
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 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
107
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
108 void NormalizeUuid(std::string& uuid)
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
109 {
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
110 std::string temp = Orthanc::Toolbox::StripSpaces(uuid);
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
111 Orthanc::Toolbox::ToLowerCase(temp);
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
112 uuid.swap(temp);
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
113 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
115 }