-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHandler.tpp
More file actions
20 lines (19 loc) · 779 Bytes
/
FileHandler.tpp
File metadata and controls
20 lines (19 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
template <typename T>
void FileHandler::writeBytes(T data, size_t numberOfBytes) {
char* buffer = new char[numberOfBytes];
for (int idx = 0; idx < numberOfBytes; idx++) {
unsigned int bitMaskForLowestByte = 0xFF;
unsigned int shiftByBits = 8;
buffer[idx] = data & bitMaskForLowestByte;
data = data >> shiftByBits;
}
this->fileOutStream.write(buffer, numberOfBytes);
delete [] buffer;
}
template <typename T>
void FileHandler::modifyBytes(T data, unsigned int bytePosition, size_t numberOfBytes) {
unsigned int currentFilePosition = this->fileOutStream.tellp();
this->fileOutStream.seekp(bytePosition, ios::beg);
this->writeBytes(data, numberOfBytes);
this->fileOutStream.seekp(currentFilePosition, ios::beg);
}