Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
BinaryFileReader.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7#include <fstream>
8#include <vector>
9
10namespace ph
11{
12
14{
15public:
16 explicit BinaryFileReader(const Path& filePath);
17 virtual ~BinaryFileReader();
18
19 bool open();
20 void close();
21
22 // TODO: able to specify byte order
23 template<typename T>
24 void read(T* out_buffer, std::size_t numElements = 1);
25
26private:
27 Path m_filePath;
28 std::ifstream m_inputStream;
29};
30
31// In-header Implementations:
32
34 m_filePath(filePath), m_inputStream()
35{}
36
41
43{
44 m_inputStream.close();
45}
46
47template<typename T>
48inline void BinaryFileReader::read(T* const out_buffer, const std::size_t numElements)
49{
50 // FIXME: this is only safe for trivially copyable types
51
52 PH_ASSERT(out_buffer && numElements > 0 && m_inputStream.good());
53
54 m_inputStream.read(reinterpret_cast<char*>(out_buffer), sizeof(T) * numElements);
55}
56
57}// end namespace ph
Definition BinaryFileReader.h:14
virtual ~BinaryFileReader()
Definition BinaryFileReader.h:37
void read(T *out_buffer, std::size_t numElements=1)
Definition BinaryFileReader.h:48
BinaryFileReader(const Path &filePath)
Definition BinaryFileReader.h:33
bool open()
Definition BinaryFileReader.cpp:10
void close()
Definition BinaryFileReader.h:42
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
The root for all renderer implementations.
Definition EEngineProject.h:6