Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
BinaryFileInputStream.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 <cstddef>
12#include <optional>
13
14namespace ph
15{
16
18{
19public:
20 inline BinaryFileInputStream() = default;
21 explicit BinaryFileInputStream(const Path& filePath);
23
24 template<typename T, bool DO_BYTE_REVERSAL = false>
25 void readData(T* out_data);
26
27 template<typename T, bool DO_BYTE_REVERSAL = false>
28 void readData(TSpan<T> out_data);
29
30 std::optional<std::size_t> getFileSizeInBytes() const;
31
33
34private:
35 Path m_filePath;
36};
37
38// In-header Implementations:
39
40template<typename T, bool DO_BYTE_REVERSAL>
41inline void BinaryFileInputStream::readData(T* const out_data)
42{
43 readData(TSpan<T>{out_data, 1});
44}
45
46template<typename T, bool DO_BYTE_REVERSAL>
48{
49 static_assert(std::is_trivially_copyable_v<T>);
50 PH_ASSERT(out_data.data());
51
52 auto const dataAsBytes = std::as_writable_bytes(out_data);
53 read(dataAsBytes.size(), dataAsBytes.data());
54
55 if constexpr(DO_BYTE_REVERSAL)
56 {
57 for(std::size_t di = 0; di < out_data.size(); ++di)
58 {
59 reverse_bytes<sizeof(T)>(reinterpret_cast<std::byte*>(&out_data[di]));
60 }
61 }
62}
63
64}// end namespace ph
Definition BinaryFileInputStream.h:18
std::optional< std::size_t > getFileSizeInBytes() const
Definition BinaryFileInputStream.cpp:19
BinaryFileInputStream(BinaryFileInputStream &&other)=default
BinaryFileInputStream & operator=(BinaryFileInputStream &&rhs)=default
void readData(T *out_data)
Definition BinaryFileInputStream.h:41
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
Definition StdInputStream.h:15
void read(std::size_t numBytes, std::byte *out_bytes) override
Read specific number of raw bytes in one go. The method does not return before finishing the reading ...
Definition StdInputStream.cpp:37
The root for all renderer implementations.
Definition EEngineProject.h:6
std::span< T, EXTENT > TSpan
A contiguous sequence of objects of type T. Effectively the same as std::span.
Definition TSpan.h:12