annotate OrthancFramework/Sources/StringMemoryBuffer.cpp @ 5448:2d23c92c359a

Zip of studies whose PatientName and PatientID did not contain any ASCII character are now valid
author Alain Mazy <am@osimis.io>
date Mon, 27 Nov 2023 09:05:05 +0100
parents 0ea402b4d901
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Lesser General Public License for more details.
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * License along with this program. If not, see
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * <http://www.gnu.org/licenses/>.
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "PrecompiledHeaders.h"
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "StringMemoryBuffer.h"
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace Orthanc
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 void StringMemoryBuffer::MoveToString(std::string& target)
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 buffer_.swap(target);
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 buffer_.clear();
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 }
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 IMemoryBuffer* StringMemoryBuffer::CreateFromSwap(std::string& buffer)
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 std::unique_ptr<StringMemoryBuffer> result(new StringMemoryBuffer);
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 result->Swap(buffer);
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 return result.release();
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 IMemoryBuffer* StringMemoryBuffer::CreateFromCopy(const std::string& buffer)
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 std::unique_ptr<StringMemoryBuffer> result(new StringMemoryBuffer);
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 result->Copy(buffer);
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 return result.release();
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
51
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
52
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
53 IMemoryBuffer* StringMemoryBuffer::CreateFromCopy(const std::string& buffer,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
54 size_t start /* inclusive */,
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
55 size_t end /* exclusive */)
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
56 {
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
57 std::unique_ptr<StringMemoryBuffer> result(new StringMemoryBuffer);
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
58 result->Copy(buffer, start, end);
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
59 return result.release();
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4484
diff changeset
60 }
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }