Start font reading support.
This commit is contained in:
parent
92e7a78710
commit
ed925afabf
22 changed files with 599 additions and 220 deletions
|
@ -1,88 +0,0 @@
|
|||
#include "BinaryFile.h"
|
||||
#include "ByteUtils.h"
|
||||
|
||||
bool BinaryFile::GetNextByteAsInt(std::ifstream* file, int& target)
|
||||
{
|
||||
char c;
|
||||
file->get(c);
|
||||
target = int(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextNBytes(std::ifstream* file, char* buffer, unsigned number)
|
||||
{
|
||||
char c;
|
||||
for(unsigned idx=0; idx<number; idx++)
|
||||
{
|
||||
if(file->get(c))
|
||||
{
|
||||
buffer[idx] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextWord(std::ifstream* file, char* buffer)
|
||||
{
|
||||
return GetNextNBytes(file, buffer, ByteUtils::BYTES_PER_WORD);
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextDWord(std::ifstream* file, char* buffer)
|
||||
{
|
||||
return GetNextNBytes(file, buffer, ByteUtils::BYTES_PER_DWORD);
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextWord(std::ifstream* file, int& target, bool reverse)
|
||||
{
|
||||
char buffer[ByteUtils::BYTES_PER_WORD];
|
||||
if(!BinaryFile::GetNextWord(file, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
target = ByteUtils::ToWord(buffer, reverse);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextDWord(std::ifstream* file, int& target)
|
||||
{
|
||||
char buffer[ByteUtils::BYTES_PER_DWORD];
|
||||
if(!BinaryFile::GetNextDWord(file, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
target = ByteUtils::ToDWord(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::CheckNextDWord(std::ifstream* file, const char* target)
|
||||
{
|
||||
char buffer[ByteUtils::BYTES_PER_DWORD];
|
||||
if(!BinaryFile::GetNextDWord(file, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ByteUtils::CompareDWords(buffer, target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextString(std::ifstream* file, std::string& target, unsigned numBytes)
|
||||
{
|
||||
char c;
|
||||
for(unsigned idx=0; idx<numBytes; idx++)
|
||||
{
|
||||
if(!file->get(c))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
target += c;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
class BinaryFile
|
||||
{
|
||||
public:
|
||||
|
||||
template<typename T>
|
||||
static bool Write(std::ofstream* file, T data)
|
||||
{
|
||||
file->write(reinterpret_cast<char*>(&data), sizeof(data));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool GetNextByteAsInt(std::ifstream* file, int& target);
|
||||
|
||||
static bool GetNextNBytes(std::ifstream* file, char* buffer, unsigned numBytes);
|
||||
|
||||
static bool GetNextWord(std::ifstream* file, char* buffer);
|
||||
|
||||
static bool GetNextDWord(std::ifstream* file, char* buffer);
|
||||
|
||||
static bool GetNextWord(std::ifstream* file, int& target, bool reverse = true);
|
||||
|
||||
static bool GetNextDWord(std::ifstream* file, int& target);
|
||||
|
||||
static bool CheckNextDWord(std::ifstream* file, const char* target);
|
||||
|
||||
static bool GetNextString(std::ifstream* file, std::string& target, unsigned numBytes);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue