 |
Gorgon Game Engine
|
Go to the documentation of this file.
9 #include "../Utils/Assert.h"
10 #include "../Filesystem.h"
11 #include "../IO/Stream.h"
13 namespace Gorgon {
namespace Resource {
80 reader(&reader), target(target) {}
86 explicit operator bool()
const {
87 auto pos=reader->
Tell();
88 if(pos<target)
return false;
90 ASSERT(pos==target,
"Reading operation passed the target.");
96 unsigned long Tell()
const {
102 unsigned long target;
119 if(--keepopenrequests) {
172 return (
unsigned long)
stream->tellg();
180 stream->seekg((std::streampos)pos, std::ios::beg);
188 stream->seekg((std::streampos)pos.
Tell(), std::ios::beg);
212 return IO::ReadEnum32<E_>(*
stream);
337 IO::ReadArray<T_>(*
stream, data, size);
393 stream->seekg(size, std::ios::cur);
402 stream->seekg(size, std::ios::cur);
415 virtual bool open(
bool thrw) = 0;
422 int keepopenrequests = 0;
429 FileReader(
const std::string &filename) : filename(filename) {
442 virtual bool open(
bool thrw)
override {
443 file.open(filename, std::ios::binary);
445 if(!file.is_open()) {
460 std::string filename;
virtual void close() override
This function should close the stream.
Definition: Reader.h:438
char ReadInt8()
Reads an 8-bit integer from the stream.
Definition: Reader.h:253
This class represents a color information.
Definition: Color.h:91
bool IsFailed() const
Checks if the stream is open and it can be read from.
Definition: Reader.h:145
This is a file reader. Allows a Gorgon Resource to be loaded from a file.
Definition: Reader.h:426
E_ ReadEnum32()
Reads an enumeration as 32-bit integer from the stream.
Definition: Reader.h:208
void KeepOpen()
Request reader to keep reading stream open.
Definition: Reader.h:111
Graphics::RGBA ReadRGBA(std::istream &stream)
Reads a RGBA color, R will be read first.
Definition: Stream.h:110
char ReadInt8(std::istream &stream)
Reads an 8-bit integer from the stream.
Definition: Stream.h:62
@ VersionMismatch
Version in the file is not recognized.
Definition: Reader.h:31
std::string ReadString()
Reads a string from a given stream.
Definition: Reader.h:313
@ NoFileObject
There is no file object associated with the resource. Generally thrown during late loading.
Definition: Reader.h:43
@ UnknownNode
There is an unknown node in the file. This is never thrown in release mode.
Definition: Reader.h:37
Mark(const Mark &)=default
Copy constructor.
@ FileCannotBeOpened
Cannot open the given file.
Definition: Reader.h:40
Graphics::RGBAf ReadRGBAf()
Reads a RGBAf color, R will be read first.
Definition: Reader.h:304
void ReadArray(T_ *data, unsigned long size)
Reads an array from the file.
Definition: Reader.h:333
@ Containment
There is no containing root folder.
Definition: Reader.h:34
Represents a four channel 32 bit float per channel color information.
Definition: Color.h:373
Byte ReadUInt8()
Reads an 8-bit unsigned integer from the stream.
Definition: Reader.h:262
void Seek(const Mark &pos)
Seeks to the given position.
Definition: Reader.h:184
std::istream * stream
This is the stream that will be used to read data from.
Definition: Reader.h:419
@ UnsupportedCompression
If the compression type in the file is not supported.
Definition: Reader.h:46
Graphics::RGBAf ReadRGBAf(std::istream &stream)
Reads a RGBAf color, R will be read first.
Definition: Stream.h:122
@ Signature
File does not contain correct signature and is probably not a Gorgon resource.
Definition: Reader.h:28
float ReadFloat(std::istream &stream)
Reads a 32 bit IEEE floating point number from the stream.
Definition: Stream.h:80
float ReadFloat()
Reads a 32 bit IEEE floating point number from the file.
Definition: Reader.h:271
long ReadInt32()
Reads a 32-bit integer from the stream.
Definition: Reader.h:217
long ReadInt32(std::istream &stream)
Reads a 32-bit integer from the stream.
Definition: Stream.h:26
unsigned long Tell() const
Tells the current position.
Definition: Reader.h:168
std::string ReadString(unsigned long size)
Reads a string with the given size.
Definition: Reader.h:321
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
SGuid ReadGuid()
Reads a GUID from the given stream.
Definition: Reader.h:349
FileReader(const std::string &filename)
Constructor requires a file to be opened later.
Definition: Reader.h:429
double ReadDouble()
Reads a 64 bit IEEE double precision floating point number from the file.
Definition: Reader.h:280
bool ReadBool(std::istream &stream)
Reads a boolean value. In resource 1.0, booleans are stored as 32bit integers.
Definition: Stream.h:105
unsigned long ReadUInt32()
Reads a 32-bit unsigned integer from the stream.
Definition: Reader.h:226
This class allows resource objects to read data from a stream.
Definition: Reader.h:70
int ReadInt16(std::istream &stream)
Reads a 16-bit integer from the stream.
Definition: Stream.h:44
unsigned long ReadUInt32(std::istream &stream)
Reads a 32-bit unsigned integer from the stream.
Definition: Stream.h:35
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
unsigned long ReadChunkSize()
Reads chunk size from a stream.
Definition: Reader.h:381
LoadError(ErrorType number, const std::string &text)
A constructor to allow custom text for the error.
Definition: Reader.h:55
unsigned ReadUInt16(std::istream &stream)
Reads a 16-bit unsigned integer from the stream.
Definition: Stream.h:53
ErrorType
Error types.
Definition: Reader.h:20
This class is the base for all Gorgon Resources.
Definition: Base.h:20
@ FileNotFound
Cannot find the given file.
Definition: Reader.h:25
Mark(Reader &reader, unsigned long target)
Constructs a target using a reader and absolute file position.
Definition: Reader.h:79
bool TryOpen()
Tries to open the stream, if it fails, this function returns false.
Definition: Reader.h:151
Mark Target(unsigned long delta)
Creates mark to the the target that is delta distance from current point in file.
Definition: Reader.h:193
void EatChunk(long size)
Removes a chunk of data with the given size from the stream.
Definition: Reader.h:389
virtual bool open(bool thrw) override
This function should open the stream and set stream member.
Definition: Reader.h:442
This class represents a 2D point.
Definition: Point.h:32
LoadError(ErrorType number=Unknown)
Regular constructor, creates error text from error number.
Definition: Reader.h:50
virtual ~Reader()
Definition: Reader.h:107
int ReadInt16()
Reads a 16-bit integer from the stream.
Definition: Reader.h:235
GID::Type ReadGID()
Reads a GID from the given stream.
Definition: Reader.h:341
This class represents a loading error.
Definition: Reader.h:16
bool IsOpen() const
Checks if the stream is open.
Definition: Reader.h:135
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
ErrorType number
The type of loading error occurred.
Definition: Reader.h:60
Geometry::Point ReadPoint()
Reads a Point from the given stream.
Definition: Reader.h:357
unsigned ReadUInt16()
Reads a 16-bit unsigned integer from the stream.
Definition: Reader.h:244
std::istream & GetStream()
This should be last resort, use if the actual stream is needed.
Definition: Reader.h:161
bool ReadBool()
Reads a boolean value. In resource 1.0, booleans are stored as 32bit integers.
Definition: Reader.h:288
void EatChunk()
Removes a chunk of data from the stream, the size will be read from the stream.
Definition: Reader.h:397
void NoLongerNeeded()
Marks that this reader is no longer needed.
Definition: Reader.h:118
Type
Definition: Shader.h:14
Geometry::Pointf ReadPointf(std::istream &stream)
Definition: Stream.h:174
static const std::string ErrorStrings[8]
Strings for error codes.
Definition: Reader.h:63
Reader()
Definition: Reader.h:105
Type to store GID information.
Definition: GID.h:23
This class represents a short globally unique identifier.
Definition: SGuid.h:22
Geometry::Point ReadPointf()
Reads a Pointf from the given stream.
Definition: Reader.h:365
Geometry::Size ReadSize(std::istream &stream)
Definition: Stream.h:181
std::string Canonical(const std::string &path)
Canonicalizes a given relative path.
Definition: Linux.cpp:94
void Open()
Opens the reader. If this operation fails, it will throw LoadError.
Definition: Reader.h:126
Geometry::Size ReadSize()
Reads a Size from the given stream.
Definition: Reader.h:373
Marks a target position in file.
Definition: Reader.h:75
SGuid ReadGuid(std::istream &stream)
Reads a GUID from the given stream.
Definition: Stream.h:163
double ReadDouble(std::istream &stream)
Reads a 64 bit IEEE double precision floating point number from the stream.
Definition: Stream.h:93
bool ReadCommonChunk(Base &self, GID::Type gid, unsigned long size)
Definition: File.cpp:41
Geometry::Point ReadPoint(std::istream &stream)
Definition: Stream.h:167
Graphics::RGBA ReadRGBA()
Reads a RGBA color, R will be read first.
Definition: Reader.h:296
bool IsGood() const
Checks if the stream is open and it can be read from.
Definition: Reader.h:140
void Seek(unsigned long pos)
Seeks to the given position.
Definition: Reader.h:176
virtual bool open(bool thrw)=0
This function should open the stream and set stream member.
Byte ReadUInt8(std::istream &stream)
Reads an 8-bit unsigned integer from the stream.
Definition: Stream.h:71
std::string ReadString(std::istream &stream)
Reads a string from a given stream.
Definition: Stream.h:135
unsigned long Tell() const
Tells the position of this mark.
Definition: Reader.h:96
@ Unknown
An unknown error occurred.
Definition: Reader.h:22
virtual void close()=0
This function should close the stream.