Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
BinaryFileOutputStream.h
Go to the documentation of this file.
1#pragma once
2
5#include "Utility/TSpan.h"
6
7#include <Common/assertion.h>
8#include <Common/memory.h>
9
10#include <type_traits>
11#include <array>
12#include <algorithm>
13#include <cstddef>
14
15namespace ph
16{
17
19{
20public:
21 inline BinaryFileOutputStream() = default;
22 explicit BinaryFileOutputStream(const Path& filePath);
24
25 template<typename T, bool DO_BYTE_REVERSAL = false>
26 void writeData(const T* data);
27
28 template<typename T, bool DO_BYTE_REVERSAL = false>
29 void writeData(TSpanView<T> data);
30
32};
33
34// In-header Implementations:
35
36template<typename T, bool DO_BYTE_REVERSAL>
37inline void BinaryFileOutputStream::writeData(const T* const data)
38{
40}
41
42template<typename T, bool DO_BYTE_REVERSAL>
44{
45 static_assert(std::is_trivially_copyable_v<T>);
46 PH_ASSERT(data.data());
47
48 auto const dataAsBytes = std::as_bytes(data);
49 if constexpr(DO_BYTE_REVERSAL)
50 {
51 for(std::size_t di = 0; di < data.size(); ++di)
52 {
53 std::array<std::byte, sizeof(T)> reversedBytes;
54 std::copy_n(
55 reinterpret_cast<const std::byte*>(&data[di]), sizeof(T), reversedBytes.data());
56 reverse_bytes<sizeof(T)>(reversedBytes.data());
57
58 // OPT: this is calling write() a lot as we do not have large buffer for storing the
59 // reversed bytes; should find a way to implement a more efficient way for arrays
60
61 write(sizeof(T), reversedBytes.data());
62 }
63 }
64 else
65 {
66 write(dataAsBytes.size(), dataAsBytes.data());
67 }
68}
69
70}// end namespace ph
Definition BinaryFileOutputStream.h:19
BinaryFileOutputStream(BinaryFileOutputStream &&other)=default
void writeData(const T *data)
Definition BinaryFileOutputStream.h:37
BinaryFileOutputStream & operator=(BinaryFileOutputStream &&rhs)=default
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
Definition StdOutputStream.h:15
void write(std::size_t numBytes, const std::byte *bytes) override
Write data in the form of raw bytes in one go. The method does not return before finishing the writin...
Definition StdOutputStream.cpp:26
The root for all renderer implementations.
Definition EEngineProject.h:6
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19