Skip to content
0.2.0-dev Download ZIP
50 lines ·1.5 KB Raw
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/Physics/StateRecorder.h>
8
9JPH_NAMESPACE_BEGIN
10
11/// Implementation of the StateRecorder class that uses a stringstream as underlying store and that implements checking if the state doesn't change upon reading
12class JPH_EXPORT StateRecorderImpl final : public StateRecorder
13{
14public:
15 /// Constructor
16 StateRecorderImpl() = default;
17 StateRecorderImpl(StateRecorderImpl &&inRHS) : StateRecorder(inRHS), mStream(std::move(inRHS.mStream)) { }
18
19 /// Write a string of bytes to the binary stream
20 virtual void WriteBytes(const void *inData, size_t inNumBytes) override;
21
22 /// Rewind the stream for reading
23 void Rewind();
24
25 /// Clear the stream for reuse
26 void Clear();
27
28 /// Read a string of bytes from the binary stream
29 virtual void ReadBytes(void *outData, size_t inNumBytes) override;
30
31 // See StreamIn
32 virtual bool IsEOF() const override { return mStream.eof(); }
33
34 // See StreamIn / StreamOut
35 virtual bool IsFailed() const override { return mStream.fail(); }
36
37 /// Compare this state with a reference state and ensure they are the same
38 bool IsEqual(StateRecorderImpl &inReference);
39
40 /// Convert the binary data to a string
41 std::string GetData() const { return mStream.str(); }
42
43 /// Get size of the binary data in bytes
44 size_t GetDataSize() { return size_t(mStream.tellp()); }
45
46private:
47 std::stringstream mStream;
48};
49
50JPH_NAMESPACE_END