1 #include "nta/IOManager.h"
2 #include "nta/Logger.h"
6 return std::ifstream(path.c_str()).good();
10 std::ifstream file(filePath.c_str(), std::ios::binary);
15 file.seekg(0, std::ios::end);
16 unsigned int fileSize = file.tellg();
17 file.seekg(0, std::ios::beg);
18 fileSize -= file.tellg();
19 buffer.resize(fileSize);
20 file.read((
char*)&buffer[0], fileSize);
27 std::ifstream file(filePath.c_str(), std::ios::binary);
32 file.seekg(0, std::ios::end);
33 unsigned int fileSize = file.tellg();
34 file.seekg(0, std::ios::beg);
35 fileSize -= file.tellg();
36 buffer.resize(fileSize);
37 file.read((
char*)&buffer[0], fileSize);
43 std::ofstream file(filePath.c_str(), std::ios::binary);
44 file.write((
char*)&buffer[0], buffer.size());
49 std::ofstream file(filePath.c_str(), std::ios::binary);
50 file.write((
char*)&buffer[0], buffer.size());
55 for (
int i = 0; i < 4; i++) {
56 bytes[i] = ((
char*)&val)[i];
62 for (
int i = 0; i < 4; i++) {
63 bytes[i] = ((
char*)&val)[i];
65 buffer.insert(buffer.end(), bytes, bytes+4);
67 float IOManager::readFloatLE(std::ifstream& file) {
71 for (
int i = 0; i < 4; i++) {
72 ((
char*)&ret)[i] = bytes[i];
76 float IOManager::readFloatLE(
const FileBuffer& buffer,
int pos) {
78 for (
int i = 0; i < 4; i++) {
79 ((
char*)&ret)[i] = buffer[i+pos];
85 for (
int i = 0; i < 4; i++) {
86 bytes[i] = (val >> (8*i)) & 0xFF;
92 for (
int i = 0; i < 4; i++) {
93 bytes[i] = (val >> (8*i)) & 0xFF;
95 buffer.insert(buffer.end(), bytes, bytes+4);
97 int IOManager::readIntLE(std::ifstream& file) {
101 for (
int i = 0; i < 4; i++) {
102 ret |= bytes[i] << (i*8);
106 int IOManager::readIntLE(
const FileBuffer& buffer,
int pos) {
108 for (
int i = 0; i < 4; i++) {
109 ret |= buffer[pos+i] << (i*8);
113 int IOManager::readIntBE(std::ifstream& file) {
117 for (
int i = 0; i < 4; i++) {
118 ret |= bytes[i] << ((3-i)*8);
124 for (
int i = 0; i < 2; i++) {
125 bytes[i] = (val >> (8*i)) & 0xFF;
127 file.write(bytes, 2);
129 short IOManager::readShortLE(std::ifstream& file) {
132 return bytes[0] | (bytes[1] << 8);