SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
vsistream.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#pragma once
5#include <fstream>
6
7#include "slideio/base/exceptions.hpp"
8#include "slideio/drivers/vsi/vsi_api_def.hpp"
9#include <memory>
10
11#if defined(_MSC_VER)
12#pragma warning( push )
13#pragma warning(disable: 4251)
14#endif
15
16namespace slideio {
17 namespace vsi
18 {
19 class SLIDEIO_VSI_EXPORTS VSIStream
20 {
21 public:
22 VSIStream(std::string& filePath);
23
24 template <typename T>
25 void read(T& value) {
26 m_stream->read((char*)&value, sizeof(T));
27 if (m_stream->bad()) {
28 RAISE_RUNTIME_ERROR << "VSI driver: error by reading stream";
29 }
30 }
31 template <typename T>
32 T readValue() {
33 T value;
34 m_stream->read((char*)&value, sizeof(T));
35 if (m_stream->bad()) {
36 RAISE_RUNTIME_ERROR << "VSI driver: error by reading stream";
37 }
38 return value;
39 }
40 std::string readString(size_t dataSize);
41 int64_t getPos() const;
42 void setPos(int64_t pos);
43 int64_t getSize();
44 void skipBytes(uint32_t bytes);
45 void readBytes(uint8_t* bytes, uint32_t size);
46 private:
47 std::unique_ptr<std::ifstream> m_stream;
48 int64_t m_size;
49
50 };
51 };
52}
53
54#if defined(_MSC_VER)
55#pragma warning( pop )
56#endif
Definition: exceptions.hpp:12