Start font reading support.
This commit is contained in:
parent
92e7a78710
commit
ed925afabf
22 changed files with 599 additions and 220 deletions
97
src/core/streams/BinaryStream.cpp
Normal file
97
src/core/streams/BinaryStream.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include "BinaryStream.h"
|
||||
|
||||
std::optional<int> BinaryStream::getNextByteAsInt(std::basic_istream<char>* stream)
|
||||
{
|
||||
return stream->get();
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextNBytes(std::basic_istream<char>* stream, char* buffer, unsigned number)
|
||||
{
|
||||
char c;
|
||||
for(unsigned idx=0; idx<number; idx++)
|
||||
{
|
||||
if(stream->get(c))
|
||||
{
|
||||
buffer[idx] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextWord(std::basic_istream<char>* stream, char* buffer)
|
||||
{
|
||||
return getNextNBytes(stream, buffer, sizeof(ByteUtils::Word));
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextDWord(std::basic_istream<char>* stream, char* buffer)
|
||||
{
|
||||
return getNextNBytes(stream, buffer, sizeof(ByteUtils::DWord));
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextQWord(std::basic_istream<char>* stream, char* buffer)
|
||||
{
|
||||
return getNextNBytes(stream, buffer, sizeof(ByteUtils::QWord));
|
||||
}
|
||||
|
||||
std::optional<ByteUtils::Word> BinaryStream::getNextWord(std::basic_istream<char>* stream, bool reverse)
|
||||
{
|
||||
char buffer[sizeof(ByteUtils::Word)];
|
||||
if(!BinaryStream::getNextWord(stream, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ByteUtils::ToWord(buffer, reverse);
|
||||
}
|
||||
|
||||
std::optional<ByteUtils::DWord> BinaryStream::getNextDWord(std::basic_istream<char>* stream)
|
||||
{
|
||||
char buffer[sizeof(ByteUtils::DWord)];
|
||||
if(!BinaryStream::getNextDWord(stream, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ByteUtils::ToDWord(buffer);;
|
||||
}
|
||||
|
||||
std::optional<ByteUtils::QWord> BinaryStream::getNextQWord(std::basic_istream<char>* stream)
|
||||
{
|
||||
char buffer[sizeof(ByteUtils::QWord)];
|
||||
if(!BinaryStream::getNextQWord(stream, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ByteUtils::ToQWord(buffer);;
|
||||
}
|
||||
|
||||
bool BinaryStream::checkNextDWord(std::basic_istream<char>* stream, const char* target)
|
||||
{
|
||||
char buffer[sizeof(ByteUtils::DWord)];
|
||||
if(!BinaryStream::getNextDWord(stream, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ByteUtils::CompareDWords(buffer, target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryStream::getNextString(std::basic_istream<char>* stream, std::string& target, unsigned numBytes)
|
||||
{
|
||||
char c;
|
||||
for(unsigned idx=0; idx<numBytes; idx++)
|
||||
{
|
||||
if(!stream->get(c))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
target += c;
|
||||
}
|
||||
return true;
|
||||
}
|
40
src/core/streams/BinaryStream.h
Normal file
40
src/core/streams/BinaryStream.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
#include "ByteUtils.h"
|
||||
|
||||
class BinaryStream
|
||||
{
|
||||
public:
|
||||
|
||||
template<typename T>
|
||||
static bool write(std::basic_ostream<char>* stream, T data)
|
||||
{
|
||||
stream->write(reinterpret_cast<char*>(&data), sizeof(data));
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::optional<int> getNextByteAsInt(std::basic_istream<char>* stream);
|
||||
|
||||
static bool getNextNBytes(std::basic_istream<char>* stream, char* buffer, unsigned numBytes);
|
||||
|
||||
static bool getNextWord(std::basic_istream<char>* stream, char* buffer);
|
||||
|
||||
static bool getNextDWord(std::basic_istream<char>* stream, char* buffer);
|
||||
|
||||
static bool getNextQWord(std::basic_istream<char>* stream, char* buffer);
|
||||
|
||||
static std::optional<ByteUtils::Word> getNextWord(std::basic_istream<char>* stream, bool reverse = true);
|
||||
|
||||
static std::optional<ByteUtils::DWord> getNextDWord(std::basic_istream<char>* stream);
|
||||
|
||||
static std::optional<ByteUtils::QWord> getNextQWord(std::basic_istream<char>* stream);
|
||||
|
||||
static bool checkNextDWord(std::basic_istream<char>* stream, const char* target);
|
||||
|
||||
static bool getNextString(std::basic_istream<char>* stream, std::string& target, unsigned numBytes);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue