![]() |
Gorgon Game Engine
|
This class represents a logical resource file. More...
Public Member Functions | |
File () | |
Default constructor. More... | |
virtual | ~File () |
Destroys file object. If the root is not detached, it will destroy resource tree as well. More... | |
void | Destroy () |
Destroys the Gorgon resource tree that this file holds. More... | |
void | Discard () |
Discards any data that is not required after preparation. More... | |
Base * | LoadChunk (Base &self, GID::Type gid, unsigned long size, bool skipobjects=false) |
Loads a resource object from the given file, GID and size. More... | |
Base * | LoadChunk (GID::Type gid, unsigned long size) |
Loads a resource object from the given file, GID and size. More... | |
void | LoadFile (const std::string &filename) |
Loads the given file. More... | |
void | LoadFirst (const std::string &filename) |
Loads only the first object of the given file. More... | |
void | LoadShallow (const std::string &filename) |
Loads only the first tier of objects. More... | |
void | Prepare () |
Prepares all resources in this file to be used. More... | |
std::unique_ptr< Folder > | Release () |
Detaches the root of the File from the File object. More... | |
Folder & | Root () |
Returns the root folder of the file. More... | |
void | Save (const std::string &filename) |
Saves this file to the disk using the given filename. More... | |
std::weak_ptr< File > | Self () const |
Returns a weak reference to this file. More... | |
Public Attributes | |
std::map< GID::Type, Loader > | Loaders |
Resource Loaders. More... | |
std::map< SGuid, Base * > | mapping |
INTERNAL, allows guid to object mapping. More... | |
Protected Member Functions | |
void | load (bool first, bool shallow) |
This is the actual load function. More... | |
void | save () const |
This function performs the save operation. More... | |
Protected Attributes | |
GID::Type | filetype |
Type of the loaded file. More... | |
unsigned long | fileversion |
Version of the loaded file. More... | |
bool | keepopen |
Keeps the file open even after loading is completed. More... | |
std::shared_ptr< Reader > | reader |
The reader that would be used to read the file. More... | |
Folder * | root |
The root folder, root changes while loading a file. More... | |
std::shared_ptr< Writer > | writer |
This class represents a logical resource file.
A file class is necessary for loading a resource file from the disk. However, it is not required to create a resource tree in memory. Notice that Gorgon::Resource does not support saving, Gorgon::Resource::Editing has the support for saving resource files.
File | ( | ) |
Default constructor.
|
virtual |
Destroys file object. If the root is not detached, it will destroy resource tree as well.
References File::root.
void Destroy | ( | ) |
Destroys the Gorgon resource tree that this file holds.
This file object can still be used after destroy is issued
References File::filetype, File::fileversion, Gorgon::Resource::GID::Folder, Gorgon::Resource::GID::None, and File::root.
void Discard | ( | ) |
Discards any data that is not required after preparation.
The stored data might have significance in some applications, other than those, there is no reason to keep prepared data. Also discards guid mapping
References Base::Discard(), File::mapping, and File::root.
|
protected |
This is the actual load function.
References Base::begin(), LoadError::Containment, LoadError::FileCannotBeOpened, File::filetype, File::fileversion, Gorgon::Resource::GID::Folder, Base::GetGuid(), Folder::load(), File::mapping, File::reader, Base::Resolve(), File::root, LoadError::Signature, and LoadError::VersionMismatch.
Loads a resource object from the given file, GID and size.
This function may return nullptr in cases that the object cannot be loaded or no loader exists for the given gid. Both cases will throw in debug mode. Also handles SGuid and name
References ASSERT, Gorgon::String::From(), File::Loaders, Gorgon::Resource::GID::Null, and File::reader.
Loads a resource object from the given file, GID and size.
This function may return nullptr in cases that the object cannot be loaded or no loader exists for the given gid. Both cases will throw in debug mode.
References ASSERT, Gorgon::String::From(), File::Loaders, Gorgon::Resource::GID::Null, and File::reader.
void LoadFile | ( | const std::string & | filename | ) |
Loads the given file.
A prepare function call is necessary to be able to use some resources. The file could be left open if there are objects marked to be loaded when requested. If the filename not found and there is a filename.lzma file, this function extracts the compressed file and tries to load uncompressed version.
LoadError | |
std::runtime_error |
References File::load().
void LoadFirst | ( | const std::string & | filename | ) |
Loads only the first object of the given file.
Useful to retrieve header information. If the filename not found and there is a filename.lzma file, this function extracts the compressed file and tries to load uncompressed version.
LoadError | |
std::runtime_error |
References File::load().
void LoadShallow | ( | const std::string & | filename | ) |
Loads only the first tier of objects.
Only folders refrain from loading its children. Therefore, any other object will be loaded fully. This function should be use carefully in presence of links Any links that are reaching out to unloaded parts of the file will not be resolved. This may cause cast errors. Useful to selectively load a large file. Use Folder::Load function to load the contents of a specific folder. This function leaves the file open for further load attempts. If the filename not found and there is a filename.lzma file, this function extracts the compressed file and tries to load uncompressed version.
LoadError | |
runtime_error |
References File::load().
void Prepare | ( | ) |
Prepares all resources in this file to be used.
This function can be issued for individual objects and their children rather than whole file.
References Folder::Prepare(), and File::root.
std::unique_ptr<Folder> Release | ( | ) |
Detaches the root of the File from the File object.
The ownership of the root will be transferred to the caller.
References Gorgon::Resource::GID::Folder, and File::root.
Folder& Root | ( | ) |
Returns the root folder of the file.
References File::root.
|
protected |
This function performs the save operation.
References Type::AsInteger(), File::filetype, File::root, Folder::save(), and File::writer.
void Save | ( | const std::string & | filename | ) |
Saves this file to the disk using the given filename.
This operation will over write if the file exists. May throw WriteError
References File::save(), and File::writer.
std::weak_ptr<File> Self | ( | ) | const |
Returns a weak reference to this file.
This returned reference can then be used to test if this object is still in memory.
|
protected |
Type of the loaded file.
|
protected |
Version of the loaded file.
Currently there is only a single version. This version does not relate to the versions of the resources in the resource file.
|
protected |
Keeps the file open even after loading is completed.
This guarantees that the file is readable at a later point to read more data.
Resource Loaders.
You may add or remove any loaders that is necessary. Initially a file loads all internal resources.
INTERNAL, allows guid to object mapping.
This information is not kept fresh about changes in the tree. This information is used for link and object tracking and is consumed right after file is loaded. This information is kept until a discard is issued.
|
protected |
The reader that would be used to read the file.
|
protected |
The root folder, root changes while loading a file.
|
protected |