annotate Framework/Common/IResult.cpp @ 489:e8b4bb6a33e7

introduction of ORTHANC_SDK_COMPATIBLE_VERSIONS in CMake
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 22 Mar 2024 14:27:36 +0100
parents ecd0b719cff5
children 54d518dcd74a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
298
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
459
ecd0b719cff5 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
ecd0b719cff5 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
298
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Affero General Public License for more details.
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "IResult.h"
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "Utf8StringValue.h"
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <Compatibility.h>
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <OrthancException.h>
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <cassert>
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <list>
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <vector>
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <ostream>
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace OrthancDatabases
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 static void PrintSeparators(std::ostream& stream,
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 char c,
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 size_t count)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 for (size_t i = 0; i < count; i++)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 stream << c;
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 static void PrintHeader(std::ostream& stream,
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 const std::vector<size_t>& maxWidth)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 for (size_t i = 0; i < maxWidth.size(); i++)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 stream << '+';
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 PrintSeparators(stream, '-', maxWidth[i] + 2);
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 stream << '+' << std::endl;
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 void IResult::Print(std::ostream& stream,
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 IResult& result)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 typedef std::list< std::vector<std::string> > Table;
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 Table table;
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 const size_t columns = result.GetFieldsCount();
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 std::vector<size_t> maxWidth(columns);
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 while (!result.IsDone())
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 table.push_back(std::vector<std::string>(columns));
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 for (size_t i = 0; i < columns; i++)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 std::string value;
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 try
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 std::unique_ptr<IValue> converted(
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 result.GetField(i).Convert(ValueType_Utf8String));
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 value = dynamic_cast<Utf8StringValue&>(*converted).GetContent();
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 catch (Orthanc::OrthancException&)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 value = "?";
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 if (value.size() > maxWidth[i])
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 maxWidth[i] = value.size();
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 table.back() [i] = value;
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 result.Next();
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 PrintHeader(stream, maxWidth);
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 for (Table::const_iterator it = table.begin(); it != table.end(); ++it)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 assert(it->size() == maxWidth.size());
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 for (size_t i = 0; i < it->size(); i++)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 const std::string& value = (*it) [i];
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 stream << "| " << value << ' ';
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 for (size_t j = value.size(); j < maxWidth[i]; j++)
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 stream << ' ';
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 stream << '|' << std::endl;
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 PrintHeader(stream, maxWidth);
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }
8f655f308de9 added IResult::Print()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }