StateRecorderImpl.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 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. /// Read a string of bytes from the binary stream
  19. virtual void ReadBytes(void *outData, size_t inNumBytes) override;
  20. // See StreamIn
  21. virtual bool IsEOF() const override { return mStream.eof(); }
  22. // See StreamIn / StreamOut
  23. virtual bool IsFailed() const override { return mStream.fail(); }
  24. /// Compare this state with a reference state and ensure they are the same
  25. bool IsEqual(StateRecorderImpl &inReference);
  26. /// Convert the binary data to a string
  27. string GetData() const { return mStream.str(); }
  28. private:
  29. std::stringstream mStream;
  30. };
  31. JPH_NAMESPACE_END