Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
stream.h
Go to the documentation of this file.
1#ifndef BVH_V2_STREAM_H
2#define BVH_V2_STREAM_H
3
4#include <istream>
5#include <ostream>
6
7namespace bvh::v2 {
8
9/// Stream of data that can be used to deserialize data structures.
11public:
12 template <typename T>
13 T read(T&& default_val = {}) {
14 T data;
15 if (read_raw(&data, sizeof(T)) != sizeof(T))
16 data = std::move(default_val);
17 return data;
18 }
19
20protected:
21 virtual size_t read_raw(void*, size_t) = 0;
22};
23
24/// Stream of data that can be used to serialize data structures.
26public:
27 template <typename T>
28 bool write(const T& data) { return write_raw(&data, sizeof(T)); }
29
30protected:
31 virtual bool write_raw(const void*, size_t) = 0;
32};
33
34/// Stream adapter for standard library input streams.
36public:
37 StdInputStream(std::istream& stream)
38 : stream_(stream)
39 {}
40
42
43protected:
44 std::istream& stream_;
45
46 size_t read_raw(void* data, size_t size) override {
47 stream_.read(reinterpret_cast<char*>(data), static_cast<std::streamsize>(size));
48 return static_cast<size_t>(stream_.gcount());
49 }
50};
51
52/// Stream adapter for standard library output streams.
54public:
55 StdOutputStream(std::ostream& stream)
56 : stream_(stream)
57 {}
58
60
61protected:
62 std::ostream& stream_;
63
64 bool write_raw(const void* data, size_t size) override {
65 stream_.write(reinterpret_cast<const char*>(data), static_cast<std::streamsize>(size));
66 return stream_.good();
67 }
68};
69
70} // namespace bvh::v2
71
72#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Stream of data that can be used to deserialize data structures.
Definition stream.h:10
T read(T &&default_val={})
Definition stream.h:13
virtual size_t read_raw(void *, size_t)=0
Stream of data that can be used to serialize data structures.
Definition stream.h:25
bool write(const T &data)
Definition stream.h:28
virtual bool write_raw(const void *, size_t)=0
Stream adapter for standard library input streams.
Definition stream.h:35
size_t read_raw(void *data, size_t size) override
Definition stream.h:46
StdInputStream(std::istream &stream)
Definition stream.h:37
std::istream & stream_
Definition stream.h:44
Stream adapter for standard library output streams.
Definition stream.h:53
std::ostream & stream_
Definition stream.h:62
StdOutputStream(std::ostream &stream)
Definition stream.h:55
bool write_raw(const void *data, size_t size) override
Definition stream.h:64
Definition bbox.h:9