annotate OrthancFramework/Sources/ChunkedBuffer.cpp @ 4731:283d246fafdb

fix broken "Do lookup" button in Orthanc Explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 27 Jun 2021 12:48:26 +0200
parents d9473bd5ed43
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * the License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
11 *
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * Lesser General Public License for more details.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
23 #include "PrecompiledHeaders.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "ChunkedBuffer.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <cassert>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <string.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
30 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 void ChunkedBuffer::Clear()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 numBytes_ = 0;
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
35 pendingPos_ = 0;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 for (Chunks::iterator it = chunks_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
38 it != chunks_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 delete *it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
45 void ChunkedBuffer::AddChunkInternal(const void* chunkData,
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
46 size_t chunkSize)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 if (chunkSize == 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
2040
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
52 else
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
53 {
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
54 assert(chunkData != NULL);
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
55 chunks_.push_back(new std::string(reinterpret_cast<const char*>(chunkData), chunkSize));
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
56 numBytes_ += chunkSize;
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
57 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
61 void ChunkedBuffer::FlushPendingBuffer()
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
62 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
63 assert(pendingPos_ <= pendingBuffer_.size());
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
64
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
65 if (!pendingBuffer_.empty())
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
66 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
67 AddChunkInternal(pendingBuffer_.c_str(), pendingPos_);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
68 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
69 else
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
70 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
71 assert(pendingPos_ == 0);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
72 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
73
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
74 pendingPos_ = 0;
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
75 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
76
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
77
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
78 ChunkedBuffer::ChunkedBuffer() :
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
79 numBytes_(0),
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
80 pendingPos_(0)
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
81 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
82 pendingBuffer_.resize(16 * 1024); // Default size of the pending buffer: 16KB
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
83 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
84
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
85
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
86 ChunkedBuffer::~ChunkedBuffer()
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
87 {
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
88 Clear();
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
89 }
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
90
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
91
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
92 size_t ChunkedBuffer::GetNumBytes() const
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
93 {
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
94 return numBytes_ + pendingPos_;
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
95 }
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
96
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
97
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
98 void ChunkedBuffer::SetPendingBufferSize(size_t size)
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
99 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
100 FlushPendingBuffer();
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
101 pendingBuffer_.resize(size);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
102 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
103
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
104
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
105 size_t ChunkedBuffer::GetPendingBufferSize() const
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
106 {
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
107 return pendingBuffer_.size();
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
108 }
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
109
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4151
diff changeset
110
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
111 void ChunkedBuffer::AddChunk(const void* chunkData,
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
112 size_t chunkSize)
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
113 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
114 if (chunkSize > 0)
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
115 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
116 #if 1
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
117 assert(sizeof(char) == 1);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
118
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
119 // Optimization if Orthanc >= 1.7.3, to speed up in the presence of many small chunks
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
120 if (pendingPos_ + chunkSize <= pendingBuffer_.size())
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
121 {
4151
8c559dd5034b Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4150
diff changeset
122 // There remains enough place in the pending buffer
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
123 memcpy(&pendingBuffer_[pendingPos_], chunkData, chunkSize);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
124 pendingPos_ += chunkSize;
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
125 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
126 else
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
127 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
128 FlushPendingBuffer();
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
129
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
130 if (!pendingBuffer_.empty() &&
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
131 chunkSize < pendingBuffer_.size())
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
132 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
133 memcpy(&pendingBuffer_[0], chunkData, chunkSize);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
134 pendingPos_ = chunkSize;
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
135 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
136 else
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
137 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
138 AddChunkInternal(chunkData, chunkSize);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
139 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
140 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
141 #else
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
142 // Non-optimized implementation in Orthanc <= 1.7.2
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
143 AddChunkInternal(chunkData, chunkSize);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
144 #endif
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
145 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
146 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
147
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
148
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
149 void ChunkedBuffer::AddChunk(const std::string& chunk)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
150 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
151 if (chunk.size() > 0)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
152 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
153 AddChunk(&chunk[0], chunk.size());
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
154 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
155 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
156
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
157
4148
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
158 void ChunkedBuffer::AddChunk(const std::string::const_iterator& begin,
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
159 const std::string::const_iterator& end)
3385
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
160 {
4148
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
161 const size_t s = end - begin;
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
162
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
163 if (s > 0)
3385
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
164 {
4148
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
165 AddChunk(&begin[0], s);
3385
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
166 }
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
167 }
4148
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
168
3385
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
169
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 void ChunkedBuffer::Flatten(std::string& result)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
172 FlushPendingBuffer();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 result.resize(numBytes_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 size_t pos = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 for (Chunks::iterator it = chunks_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
177 it != chunks_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 assert(*it != NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 size_t s = (*it)->size();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 if (s != 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 memcpy(&result[pos], (*it)->c_str(), s);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 pos += s;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 delete *it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 chunks_.clear();
1921
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
192 numBytes_ = 0;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }