Gorgon Game Engine
File Class Reference

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...
 
BaseLoadChunk (Base &self, GID::Type gid, unsigned long size, bool skipobjects=false)
 Loads a resource object from the given file, GID and size. More...
 
BaseLoadChunk (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< FolderRelease ()
 Detaches the root of the File from the File object. More...
 
FolderRoot ()
 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< FileSelf () const
 Returns a weak reference to this file. More...
 

Public Attributes

std::map< GID::Type, LoaderLoaders
 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< Readerreader
 The reader that would be used to read the file. More...
 
Folderroot
 The root folder, root changes while loading a file. More...
 
std::shared_ptr< Writerwriter
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ File()

File ( )

Default constructor.

◆ ~File()

virtual ~File ( )
virtual

Destroys file object. If the root is not detached, it will destroy resource tree as well.

References File::root.

Member Function Documentation

◆ Destroy()

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.

◆ Discard()

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.

◆ load()

◆ LoadChunk() [1/2]

Base * LoadChunk ( Base self,
GID::Type  gid,
unsigned long  size,
bool  skipobjects = false 
)

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

Warning
This function is intended to be used while loading a resource. It can be used for any purpose, however, would not be very useful outside its prime use

References ASSERT, Gorgon::String::From(), File::Loaders, Gorgon::Resource::GID::Null, and File::reader.

◆ LoadChunk() [2/2]

Base * LoadChunk ( GID::Type  gid,
unsigned long  size 
)

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.

Warning
This function is intended to be used while loading a resource. It can be used for any purpose, however, would not be very useful outside its prime use

References ASSERT, Gorgon::String::From(), File::Loaders, Gorgon::Resource::GID::Null, and File::reader.

◆ LoadFile()

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.

Exceptions
LoadError
std::runtime_error

References File::load().

◆ LoadFirst()

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.

Exceptions
LoadError
std::runtime_error

References File::load().

◆ LoadShallow()

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.

Exceptions
LoadError
runtime_error

References File::load().

◆ Prepare()

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.

◆ Release()

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.

◆ Root()

Folder& Root ( )

Returns the root folder of the file.

References File::root.

◆ save()

void save ( ) const
protected

This function performs the save operation.

References Type::AsInteger(), File::filetype, File::root, Folder::save(), and File::writer.

◆ Save()

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.

◆ Self()

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.

Member Data Documentation

◆ filetype

GID::Type filetype
protected

Type of the loaded file.

◆ fileversion

unsigned long fileversion
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.

◆ keepopen

bool keepopen
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.

◆ Loaders

std::map<GID::Type, Loader> Loaders

Resource Loaders.

You may add or remove any loaders that is necessary. Initially a file loads all internal resources.

◆ mapping

std::map<SGuid, Base*> mapping
mutable

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.

Warning
Stale information.

◆ reader

std::shared_ptr<Reader> reader
protected

The reader that would be used to read the file.

◆ root

Folder* root
protected

The root folder, root changes while loading a file.

◆ writer

std::shared_ptr<Writer> writer
protected

The documentation for this class was generated from the following files: