Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::ResourceSaver< Type, Parameters > Class Template Reference

Core class that represents a list of saver functions for a specific resource type. More...

Public Types

using ExtensionGetter = bool(*)(const String &extension)
 
using FormatQuerier = bool(*)(const String &format)
 
using FileSaver = bool(*)(const Type &resource, const String &filePath, const Parameters &parameters)
 
using StreamSaver = bool(*)(const Type &resource, const String &format, Stream &stream, const Parameters &parameters)
 

Static Public Member Functions

static bool IsFormatSupported (const String &extension)
 Checks whether the extension of the file is supported. More...
 
static bool SaveToFile (const Type &resource, const String &filePath, const Parameters &parameters=Parameters())
 Saves a resource to a file. More...
 
static bool SaveToStream (const Type &resource, Stream &stream, const String &format, const Parameters &parameters=Parameters())
 Saves a resource to a stream. More...
 
static void RegisterSaver (FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver=nullptr)
 Registers a saver. More...
 
static void UnregisterSaver (FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver=nullptr)
 Unregisters a saver. More...
 

Detailed Description

template<typename Type, typename Parameters>
class Nz::ResourceSaver< Type, Parameters >

Core class that represents a list of saver functions for a specific resource type.

Member Function Documentation

◆ IsFormatSupported()

template<typename Type , typename Parameters >
bool Nz::ResourceSaver< Type, Parameters >::IsFormatSupported ( const String extension)
static

Checks whether the extension of the file is supported.

Returns
true if supported
Parameters
extensionExtension of the file

◆ RegisterSaver()

template<typename Type , typename Parameters >
void Nz::ResourceSaver< Type, Parameters >::RegisterSaver ( FormatQuerier  formatQuerier,
StreamSaver  streamSaver,
FileSaver  fileSaver = nullptr 
)
static

Registers a saver.

Parameters
formatQuerierA function to test whether the format (as a string) is supported by this saver
streamSaverA function which saves the resource to a stream
fileSaverOptional function which saves the resource directly to a file given a file path
Remarks
The fileSaver argument is only present for compatibility with external savers which cannot be interfaced with streams
At least one saver is required

◆ SaveToFile()

template<typename Type , typename Parameters >
bool Nz::ResourceSaver< Type, Parameters >::SaveToFile ( const Type &  resource,
const String filePath,
const Parameters &  parameters = Parameters() 
)
static

Saves a resource to a file.

Returns
true if successfully saved
Parameters
resourceResource to save
filePathPath to the file where the resource will be written
parametersParameters for the save
Remarks
The previous file content will be discarded, to prevent this behavior you should use SaveToStream
The file extension will be used as format for the saver ("image.png" => "png", to write a specified format to a user-specified extension you should use SaveToStream
See also
SaveToStream

◆ SaveToStream()

template<typename Type , typename Parameters >
bool Nz::ResourceSaver< Type, Parameters >::SaveToStream ( const Type &  resource,
Stream stream,
const String format,
const Parameters &  parameters = Parameters() 
)
static

Saves a resource to a stream.

Returns
true if successfully saved
Parameters
resourceResource to load
streamStream with write access where the resource data will be written
formatData format to save the resource to
parametersParameters for the saving
See also
SaveToFile

◆ UnregisterSaver()

template<typename Type , typename Parameters >
void Nz::ResourceSaver< Type, Parameters >::UnregisterSaver ( FormatQuerier  formatQuerier,
StreamSaver  streamSaver,
FileSaver  fileSaver = nullptr 
)
static

Unregisters a saver.

Parameters
formatQuerierA function to test whether the format (as a string) is supported by this saver
streamSaverA function which saves the resource to a stream
fileSaverA function function which saves the resource directly to a file given a file path
Remarks
The saver will only be unregistered if the function pointers are exactly the same

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