]> git.sesse.net Git - pistorm/blob - i2c_updater/pi-i2c/src/file.hpp
Initial work on FPGA I2C programmer
[pistorm] / i2c_updater / pi-i2c / src / file.hpp
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #ifndef _FILE_HPP_
6 #define _FILE_HPP_
7
8 #include <fstream>
9 #include "endian.hpp"
10
11 namespace nFile {
12
13 template<typename t_tStream, typename t_tData>
14 t_tStream readLittleEndian(t_tStream &File, t_tData &Data)
15 {
16         File.read(reinterpret_cast<char*>(&Data), sizeof(Data));
17         Data = nEndian::littleToNative(Data);
18 }
19
20 template<typename t_tStream, typename t_tData>
21 void readBigEndian(t_tStream &File, t_tData &Data)
22 {
23         File.read(reinterpret_cast<char*>(&Data), sizeof(Data));
24         Data = nEndian::bigToNative(Data);
25 }
26
27 template<typename t_tStream, typename t_tData>
28 void readData(t_tStream &File, t_tData *pData, size_t ElementCount)
29 {
30         File.read(reinterpret_cast<char*>(pData), ElementCount * sizeof(*pData));
31 }
32
33 } // namespace nFile
34
35 #endif // _FILE_HPP_