StateRecorderImpl.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Physics/StateRecorder.h>
  6. JPH_NAMESPACE_BEGIN
  7. /// Implementation of the StateRecorder class that uses a stringstream as underlying store and that implements checking if the state doesn't change upon reading
  8. class JPH_EXPORT StateRecorderImpl final : public StateRecorder
  9. {
  10. public:
  11. /// Constructor
  12. StateRecorderImpl() = default;
  13. StateRecorderImpl(StateRecorderImpl &&inRHS) : StateRecorder(inRHS), mStream(std::move(inRHS.mStream)) { }
  14. /// Write a string of bytes to the binary stream
  15. virtual void WriteBytes(const void *inData, size_t inNumBytes) override;
  16. /// Rewind the stream for reading
  17. void Rewind();
  18. /// Clear the stream for reuse
  19. void Clear();
  20. /// Read a string of bytes from the binary stream
  21. virtual void ReadBytes(void *outData, size_t inNumBytes) override;
  22. // See StreamIn
  23. virtual bool IsEOF() const override { return mStream.eof(); }
  24. // See StreamIn / StreamOut
  25. virtual bool IsFailed() const override { return mStream.fail(); }
  26. /// Compare this state with a reference state and ensure they are the same
  27. bool IsEqual(StateRecorderImpl &inReference);
  28. /// Convert the binary data to a string
  29. string GetData() const { return mStream.str(); }
  30. private:
  31. std::stringstream mStream;
  32. };
  33. JPH_NAMESPACE_END