comparison OrthancFramework/Sources/DicomFormat/StreamBlockReader.h @ 4220:92a21efa5c96

reorganization of DicomStreamReader
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Sep 2020 15:33:47 +0200
parents
children 3d6f14a05db1
comparison
equal deleted inserted replaced
4219:b8ed2852a35d 4220:92a21efa5c96
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
20 **/
21
22
23 #pragma once
24
25 #include <boost/noncopyable.hpp>
26 #include <istream>
27 #include <string>
28
29
30 namespace Orthanc
31 {
32 /**
33 * This class is used to extract blocks of given size from a
34 * stream. Bytes from the stream are buffered until the requested
35 * size is available, and the full block can be returned.
36 **/
37 class StreamBlockReader : public boost::noncopyable
38 {
39 private:
40 std::istream& stream_;
41 std::string block_;
42 size_t blockPos_;
43 uint64_t processedBytes_;
44
45 public:
46 StreamBlockReader(std::istream& stream);
47
48 /**
49 * Schedule the size of the next block to be extracted from the
50 * stream.
51 **/
52 void Schedule(size_t blockSize);
53
54 /**
55 * Extract the block whose size was configured by the previous
56 * call to "Schedule()". Returns "false" iff not enough bytes are
57 * available from the stream yet: In this case, try again later.
58 **/
59 bool Read(std::string& block);
60
61 uint64_t GetProcessedBytes() const
62 {
63 return processedBytes_;
64 }
65 };
66 }