Anim import
This commit is contained in:
@ -2,6 +2,63 @@
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
std::string Stream::Reader::ReadString()
|
||||
{
|
||||
std::string str;
|
||||
|
||||
while (char byte = Stream::Reader::ReadByte())
|
||||
{
|
||||
str.append(&byte, 1);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
const char* Stream::Reader::ReadCString()
|
||||
{
|
||||
return Stream::Reader::Allocator->DuplicateString(Stream::Reader::ReadString());
|
||||
}
|
||||
|
||||
char Stream::Reader::ReadByte()
|
||||
{
|
||||
if ((Stream::Reader::Position + 1) <= Stream::Reader::Buffer.size())
|
||||
{
|
||||
return Stream::Reader::Buffer[Stream::Reader::Position++];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* Stream::Reader::Read(size_t size, size_t count)
|
||||
{
|
||||
size_t bytes = size * count;
|
||||
|
||||
if ((Stream::Reader::Position + bytes) <= Stream::Reader::Buffer.size())
|
||||
{
|
||||
void* buffer = Stream::Reader::Allocator->Allocate(bytes);
|
||||
|
||||
std::memcpy(buffer, Stream::Reader::Buffer.data() + Stream::Reader::Position, bytes);
|
||||
Stream::Reader::Position += bytes;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Stream::Reader::End()
|
||||
{
|
||||
return (Stream::Reader::Buffer.size() == Stream::Reader::Position);
|
||||
}
|
||||
|
||||
void Stream::Reader::Seek(unsigned int position)
|
||||
{
|
||||
if (Stream::Reader::Buffer.size() >= position)
|
||||
{
|
||||
Stream::Reader::Position = position;
|
||||
}
|
||||
}
|
||||
|
||||
Stream::Stream() : CriticalSectionState(0)
|
||||
{
|
||||
memset(Stream::BlockSize, 0, sizeof(Stream::BlockSize));
|
||||
|
@ -9,6 +9,31 @@ namespace Utils
|
||||
std::string Buffer;
|
||||
|
||||
public:
|
||||
class Reader
|
||||
{
|
||||
public:
|
||||
Reader(Utils::Memory::Allocator* allocator, std::string& buffer) : Buffer(buffer), Allocator(allocator), Position(0) {}
|
||||
|
||||
std::string ReadString();
|
||||
const char* ReadCString();
|
||||
|
||||
char ReadByte();
|
||||
|
||||
void* Read(size_t size, size_t count = 1);
|
||||
template <typename T> T* ReadArray(size_t count = 1)
|
||||
{
|
||||
return reinterpret_cast<T*>(Read(sizeof(T), count));
|
||||
}
|
||||
|
||||
bool End();
|
||||
void Seek(unsigned int position);
|
||||
|
||||
private:
|
||||
unsigned int Position;
|
||||
std::string Buffer;
|
||||
Utils::Memory::Allocator* Allocator;
|
||||
};
|
||||
|
||||
enum Alignment
|
||||
{
|
||||
ALIGN_2,
|
||||
|
Reference in New Issue
Block a user