 |
Gorgon Game Engine
|
Go to the documentation of this file.
10 #include "../Utils/Assert.h"
13 #include "../Filesystem.h"
14 #include "../IO/Stream.h"
19 namespace Gorgon {
namespace Resource {
33 typedef std::function<
Base* (std::weak_ptr<File>, std::shared_ptr<Reader>,
unsigned long)>
LoaderFunction;
70 std::unique_ptr<Folder> r(
root);
109 createfilereader(filename);
120 createfilereader(filename);
135 createfilereader(filename);
142 void Save(
const std::string &filename) {
167 std::weak_ptr<File>
Self()
const {
186 void load(
bool first,
bool shallow);
211 void createfilereader(std::string filename);
212 std::shared_ptr<File>
self;
virtual void Resolve(File &file)
This function shall resolve links or similar constructs.
Definition: Base.cpp:6
bool keepopen
Keeps the file open even after loading is completed.
Definition: File.h:199
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
constexpr Type Data
Data resource.
Definition: GID.h:164
std::map< SGuid, Base * > mapping
INTERNAL, allows guid to object mapping.
Definition: File.h:181
static Blob * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a blob resource from the given file.
Definition: Blob.cpp:7
constexpr Type Pointer
Definition: GID.h:196
constexpr uint32_t AsInteger() const
Returns the value of the GID as an integer.
Definition: GID.h:32
std::weak_ptr< File > Self() const
Returns a weak reference to this file.
Definition: File.h:167
virtual GID::Type GetGID() const =0
This function shall return Gorgon ID of this resource.
constexpr Type Null
Null resource.
Definition: GID.h:105
std::unique_ptr< Folder > Release()
Detaches the root of the File from the File object.
Definition: File.h:69
std::ostream * stream
This is the stream that will be used to write data to.
Definition: Writer.h:403
File()
Default constructor.
Definition: File.cpp:23
void WriteStringWithSize(const std::string &value)
Writes a string from a given stream.
Definition: Writer.h:268
constexpr Type StackedObject
Definition: GID.h:250
@ VersionMismatch
Version in the file is not recognized.
Definition: Reader.h:31
void Destroy()
Destroys the Gorgon resource tree that this file holds.
Definition: File.h:94
Folder * root
The root folder, root changes while loading a file.
Definition: File.h:192
static ScalableObject * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a tinted object resource from the file.
Definition: ScalableObject.cpp:34
bool load(std::shared_ptr< Reader > data, unsigned long size, bool first, bool shallow, bool load)
This is the actual load function.
Definition: Folder.cpp:72
constexpr Type Font
Definition: GID.h:199
constexpr Type MaskedObject
Definition: GID.h:242
@ FileCannotBeOpened
Cannot open the given file.
Definition: Reader.h:40
Allows data to be written to a file.
Definition: Writer.h:409
Folder & Root()
Returns the root folder of the file.
Definition: File.h:65
Resource::GID::Type GID
Gorgon ID of the resource that this loaded can load.
Definition: File.h:42
@ Containment
There is no containing root folder.
Definition: Reader.h:34
constexpr Type Line
Definition: GID.h:234
static Data * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Loads a data resource.
Definition: Data.cpp:18
constexpr Type Image
Image resource.
Definition: GID.h:149
Marker WriteObjectStart(const Base &base)
Writes the start of an object. Should have a matching WriteEnd with the returned marker.
Definition: File.cpp:211
constexpr Type Folder
Folder resource Gorgon::Resource::Folder.
Definition: GID.h:91
void WriteChunkSize(unsigned long value)
Writes chunk size to the stream.
Definition: Writer.h:319
void save(Writer &writer) const override
Definition: Folder.cpp:137
const Containers::Collection< Base >::ConstIterator begin() const
Allows easy iteration through range based fors.
Definition: Base.h:100
This class defines a resource loader.
Definition: File.h:23
constexpr Type TintedObject
Definition: GID.h:244
static Resource::Pointer * LoadResource(std::weak_ptr< Gorgon::Resource::File > file, std::shared_ptr< Gorgon::Resource::Reader > reader, long unsigned int size)
This function loads a bitmap font resource from the given file.
Definition: Pointer.cpp:6
void WriteGuid(const SGuid &value)
Writes a GUID to the given stream.
Definition: Writer.h:311
@ Signature
File does not contain correct signature and is probably not a Gorgon resource.
Definition: Reader.h:28
unsigned long fileversion
Version of the loaded file.
Definition: File.h:203
bool IsGood() const
Checks if the stream is open and it can be written to.
Definition: Writer.h:104
std::shared_ptr< Writer > writer
Definition: File.h:208
static Rectangle * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a rectangle resource from the file.
Definition: Rectangle.cpp:83
void Save(const std::string &filename)
Saves this file to the disk using the given filename.
Definition: File.h:142
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
static const std::string ErrorStrings[3]
Strings for error codes.
Definition: Writer.h:51
LoaderFunction Handler
Load handler function.
Definition: File.h:45
Base * LoadChunk(Base &self, GID::Type gid, unsigned long size, bool skipobjects=false)
Loads a resource object from the given file, GID and size.
Definition: File.cpp:54
constexpr Type SGuid
Identifies resources.
Definition: GID.h:115
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
Loader(GID::Type gid, LoaderFunction handler)
Filling constructor.
Definition: File.h:36
This class represents a logical resource file.
Definition: File.h:53
constexpr Type Name
Name of a resource, names are not required to be unique.
Definition: GID.h:117
LZMA Lzma
A default constructed LZMA object.
Definition: LZMA.cpp:196
constexpr Type None
Empty, different from Null resource.
Definition: GID.h:81
std::function< Base *(std::weak_ptr< File >, std::shared_ptr< Reader >, unsigned long)> LoaderFunction
This is Resource loader function prototype.
Definition: File.h:33
constexpr Type Blob
Definition: GID.h:227
std::map< GID::Type, Loader > Loaders
Resource Loaders.
Definition: File.h:174
static Font * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a bitmap font resource from the given file.
Definition: Font.cpp:116
constexpr Type Animation
Definition: GID.h:187
This class is the base for all Gorgon Resources.
Definition: Base.h:20
static Sound * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a sound resource from the given file.
Definition: Sound.cpp:7
constexpr Type Animation_Image
Definition: GID.h:188
virtual void Discard()
This function shall discard any transitional data which is not vital after Prepare function is issued...
Definition: Base.cpp:22
static Line * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a line resource from the file.
Definition: Line.cpp:44
static MaskedObject * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a masked object resource from the file.
Definition: MaskedObject.cpp:37
void save() const
This function performs the save operation.
Definition: File.cpp:197
bool Delete(const std::string &path)
Deletes the given file or directory.
Definition: Linux.cpp:106
This class represents a loading error.
Definition: Reader.h:16
virtual SGuid GetGuid() const
Returns the guid of the object.
Definition: Base.h:53
void Discard()
Discards any data that is not required after preparation.
Definition: File.h:85
constexpr Type Rectangle
Definition: GID.h:238
void Prepare()
Prepares all resources in this file to be used.
Definition: File.h:78
static Folder * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > data, unsigned long size)
Definition: Folder.cpp:150
constexpr Type GameFile
Denotes this file is a game file.
Definition: GID.h:87
static const std::string ErrorStrings[8]
Strings for error codes.
Definition: Reader.h:63
bool IsFile(const std::string &path)
Checks whether the given path is a file.
Definition: Linux.cpp:46
GID::Type filetype
Type of the loaded file.
Definition: File.h:195
Type to store GID information.
Definition: GID.h:23
void LoadFile(const std::string &filename)
Loads the given file.
Definition: File.h:108
virtual void Prepare() override
Prepares children to be used.
Definition: Folder.cpp:12
void load(bool first, bool shallow)
This is the actual load function.
Definition: File.cpp:110
static Image * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a image resource from the given file.
Definition: Image.cpp:9
void LoadFirst(const std::string &filename)
Loads only the first object of the given file.
Definition: File.h:119
void LoadShallow(const std::string &filename)
Loads only the first tier of objects.
Definition: File.h:134
static Animation * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads an animation resource from the given file.
Definition: Animation.h:51
void WriteGID(GID::Type value)
Writes a GID to the given stream.
Definition: Writer.h:303
std::shared_ptr< Reader > reader
The reader that would be used to read the file.
Definition: File.h:206
SGuid ReadGuid(std::istream &stream)
Reads a GUID from the given stream.
Definition: Stream.h:163
bool ReadCommonChunk(Base &self, GID::Type gid, unsigned long size)
Definition: File.cpp:41
static StackedObject * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a stacked object resource from the file.
Definition: StackedObject.cpp:36
This is basic folder resource, it contains other resources.
Definition: Folder.h:14
const std::string & GetName() const
Returns the name of this object.
Definition: Base.h:61
constexpr Type Sound
Definition: GID.h:219
virtual ~File()
Destroys file object. If the root is not detached, it will destroy resource tree as well.
Definition: File.h:60
unsigned long Tell() const
Tells the current position.
Definition: Writer.h:114
void Decode(I_ &input, O_ &output, Byte *compressionproperties=nullptr, unsigned long long fsize=(unsigned long long)(long long) -1)
Decodes LZMA compressed data.
Definition: LZMA.h:317
Loader()
Empty constructor.
Definition: File.h:39
std::string ReadString(std::istream &stream)
Reads a string from a given stream.
Definition: Stream.h:135
constexpr Type ScalableObject
Definition: GID.h:247
static TintedObject * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a tinted object resource from the file.
Definition: TintedObject.cpp:35