Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
StreamOut.h
Go to the documentation of this file.
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
8
11{
12public:
14 virtual ~StreamOut() = default;
15
17 virtual void WriteBytes(const void *inData, size_t inNumBytes) = 0;
18
20 virtual bool IsFailed() const = 0;
21
23 template <class T>
24 void Write(const T &inT)
25 {
26 WriteBytes(&inT, sizeof(inT));
27 }
28
30 template <class T, class A>
31 void Write(const std::vector<T, A> &inT)
32 {
33 typename Array<T>::size_type len = inT.size();
34 Write(len);
35 if (!IsFailed())
36 for (typename Array<T>::size_type i = 0; i < len; ++i)
37 Write(inT[i]);
38 }
39
41 template <class Type, class Traits, class Allocator>
42 void Write(const std::basic_string<Type, Traits, Allocator> &inString)
43 {
44 typename std::basic_string<Type, Traits, Allocator>::size_type len = inString.size();
45 Write(len);
46 if (!IsFailed())
47 WriteBytes(inString.data(), len * sizeof(Type));
48 }
49
51 void Write(const Vec3 &inVec)
52 {
53 WriteBytes(&inVec, 3 * sizeof(float));
54 }
55
57 void Write(const DVec3 &inVec)
58 {
59 WriteBytes(&inVec, 3 * sizeof(double));
60 }
61
63 void Write(const DMat44 &inVec)
64 {
65 Write(inVec.GetColumn4(0));
66 Write(inVec.GetColumn4(1));
67 Write(inVec.GetColumn4(2));
68
69 Write(inVec.GetTranslation());
70 }
71};
72
#define JPH_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
Holds a 4x4 matrix of floats with the last column consisting of doubles.
Definition: DMat44.h:13
JPH_INLINE Vec4 GetColumn4(uint inCol) const
Definition: DMat44.h:114
JPH_INLINE DVec3 GetTranslation() const
Definition: DMat44.h:110
Definition: DVec3.h:14
Simple binary output stream.
Definition: StreamOut.h:11
void Write(const Vec3 &inVec)
Write a Vec3 (don't write W)
Definition: StreamOut.h:51
void Write(const DMat44 &inVec)
Write a DMat44 (don't write W component of translation)
Definition: StreamOut.h:63
void Write(const std::vector< T, A > &inT)
Write a vector of primitives from the binary stream.
Definition: StreamOut.h:31
virtual bool IsFailed() const =0
Returns true if there was an IO failure.
void Write(const DVec3 &inVec)
Write a DVec3 (don't write W)
Definition: StreamOut.h:57
virtual void WriteBytes(const void *inData, size_t inNumBytes)=0
Write a string of bytes to the binary stream.
void Write(const T &inT)
Write a primitive (e.g. float, int, etc.) to the binary stream.
Definition: StreamOut.h:24
void Write(const std::basic_string< Type, Traits, Allocator > &inString)
Write a string to the binary stream (writes the number of characters and then the characters)
Definition: StreamOut.h:42
virtual ~StreamOut()=default
Virtual destructor.
Definition: Vec3.h:16