StateRecorderImpl.h 1.3 KB

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