Debian Codegraph @

thirdparty/jolt_physics/Jolt/Core/StreamWrapper.h

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 #include <Jolt/Core/StreamIn.h>
8 #include <Jolt/Core/StreamOut.h>
9
10 JPH_SUPPRESS_WARNINGS_STD_BEGIN
11 #include <ostream>
12 JPH_SUPPRESS_WARNINGS_STD_END
13
14 JPH_NAMESPACE_BEGIN
15
16 /// Wrapper around std::ostream
17 class StreamOutWrapper : public StreamOut
18 {
19 public:
20 /// Constructor
21 StreamOutWrapper(ostream &ioWrapped) : mWrapped(ioWrapped) { }
22
23 /// Write a string of bytes to the binary stream
24 virtual void WriteBytes(const void *inData, size_t inNumBytes) override { mWrapped.write((const char *)inData, inNumBytes); }
25
26 /// Returns true if there was an IO failure
27 virtual bool IsFailed() const override { return mWrapped.fail(); }
28
29 private:
30 ostream & mWrapped;
31 };
32
33 /// Wrapper around std::istream
34 class StreamInWrapper : public StreamIn
35 {
36 public:
37 /// Constructor
38 StreamInWrapper(istream &ioWrapped) : mWrapped(ioWrapped) { }
39
40 /// Write a string of bytes to the binary stream
41 virtual void ReadBytes(void *outData, size_t inNumBytes) override { mWrapped.read((char *)outData, inNumBytes); }
42
43 /// Returns true when an attempt has been made to read past the end of the file
44 virtual bool IsEOF() const override { return mWrapped.eof(); }
45
46 /// Returns true if there was an IO failure
47 virtual bool IsFailed() const override { return mWrapped.fail(); }
48
49 private:
50 istream & mWrapped;
51 };
52
53 JPH_NAMESPACE_END