annotate OrthancFramework/Sources/ChunkedBuffer.cpp @ 5345:34781fb0172a

fix unit test Versions.BoostStatic
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Jun 2023 12:40:46 +0200
parents 0ea402b4d901
children 48b8dae6dc77
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
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * the License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
12 *
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * 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
16 * Lesser General Public License for more details.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
0
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
24 #include "PrecompiledHeaders.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "ChunkedBuffer.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <cassert>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <string.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
31 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 void ChunkedBuffer::Clear()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 numBytes_ = 0;
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
36 pendingPos_ = 0;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 for (Chunks::iterator it = chunks_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
39 it != chunks_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 delete *it;
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
46 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
47 size_t chunkSize)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 if (chunkSize == 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
2040
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
53 else
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
54 {
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
55 assert(chunkData != NULL);
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
56 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
57 numBytes_ += chunkSize;
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1921
diff changeset
58 }
0
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
62 void ChunkedBuffer::FlushPendingBuffer()
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
63 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
64 assert(pendingPos_ <= pendingBuffer_.size());
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
65
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
66 if (!pendingBuffer_.empty())
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
67 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
68 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
69 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
70 else
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
71 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
72 assert(pendingPos_ == 0);
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
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
75 pendingPos_ = 0;
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
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
79 ChunkedBuffer::ChunkedBuffer() :
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
80 numBytes_(0),
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
81 pendingPos_(0)
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
82 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
83 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
84 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
85
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
86
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
87 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
88 {
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 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
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
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 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
94 {
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 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
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
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
98
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
99 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
100 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
101 FlushPendingBuffer();
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
102 pendingBuffer_.resize(size);
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
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
105
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
106 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
107 {
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 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
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
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
111
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
112 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
113 size_t chunkSize)
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
114 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
115 if (chunkSize > 0)
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
116 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
117 #if 1
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
118 assert(sizeof(char) == 1);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
119
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
120 // 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
121 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
122 {
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
123 // 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
124 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
125 pendingPos_ += chunkSize;
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
126 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
127 else
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
128 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
129 FlushPendingBuffer();
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
130
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
131 if (!pendingBuffer_.empty() &&
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
132 chunkSize < pendingBuffer_.size())
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
133 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
134 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
135 pendingPos_ = chunkSize;
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
136 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
137 else
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
138 {
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
139 AddChunkInternal(chunkData, chunkSize);
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 }
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
142 #else
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
143 // 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
144 AddChunkInternal(chunkData, chunkSize);
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
145 #endif
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
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
149
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
150 void ChunkedBuffer::AddChunk(const std::string& chunk)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
151 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
152 if (chunk.size() > 0)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
153 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
154 AddChunk(&chunk[0], chunk.size());
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
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
158
4148
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
159 void ChunkedBuffer::AddChunk(const std::string::const_iterator& begin,
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
160 const std::string::const_iterator& end)
3385
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
161 {
4148
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
162 const size_t s = end - begin;
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
163
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
164 if (s > 0)
3385
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
165 {
4148
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
166 AddChunk(&begin[0], s);
3385
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
167 }
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
168 }
4148
732ad6c618ba removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
169
3385
f5467ab24aa4 ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
170
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 void ChunkedBuffer::Flatten(std::string& result)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
4150
b56f3a37a4a1 optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4148
diff changeset
173 FlushPendingBuffer();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 result.resize(numBytes_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 size_t pos = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 for (Chunks::iterator it = chunks_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
178 it != chunks_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 assert(*it != NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 size_t s = (*it)->size();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 if (s != 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 memcpy(&result[pos], (*it)->c_str(), s);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 pos += s;
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 delete *it;
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 chunks_.clear();
1921
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
193 numBytes_ = 0;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }