Public Types | Public Member Functions | List of all members
ime::ResourceHolder< T > Class Template Reference

Class template for a resource container. More...

#include <ResourceHolder.h>

Inheritance diagram for ime::ResourceHolder< T >:
ime::utility::NonCopyable

Public Types

using Ptr = std::shared_ptr< T >
 Shared T pointer. More...
 

Public Member Functions

 ResourceHolder (const std::string &filePath)
 Construct a resource holder. More...
 
void setPath (const std::string &filepath)
 Change the path where resources are located on the disk. More...
 
const std::string & getPath () const
 Get the path to the resources being held. More...
 
bool loadFromFile (const std::string &filename)
 Load a resource from the disk and store it in a buffer. More...
 
bool unload (const std::string &filename)
 Remove a resource from the resource holder. More...
 
bool unloadAll ()
 Remove all resources from the resource holder. More...
 
ResourceHolder::Ptr get (const std::string &filename)
 Get a resource. More...
 
unsigned int getSize () const
 Get the number of resources in the resource holder. More...
 
bool hasResource (const std::string &filename) const
 Check if a resource exists or not. More...
 

Detailed Description

template<class T>
class ime::ResourceHolder< T >

Class template for a resource container.

Definition at line 41 of file ResourceHolder.h.

Member Typedef Documentation

◆ Ptr

template<class T >
using ime::ResourceHolder< T >::Ptr = std::shared_ptr<T>

Shared T pointer.

Definition at line 43 of file ResourceHolder.h.

Constructor & Destructor Documentation

◆ ResourceHolder()

template<class T >
ime::ResourceHolder< T >::ResourceHolder ( const std::string &  filePath)
explicit

Construct a resource holder.

Parameters
filePathPath to the resource to store

Member Function Documentation

◆ get()

template<class T >
ResourceHolder::Ptr ime::ResourceHolder< T >::get ( const std::string &  filename)

Get a resource.

Parameters
filenameFilename of the resource to be retrieved
Exceptions
FileNotFoundIf the the file cannot be found on the disk
Returns
Shared pointer to a resource in a buffer

If the specified resource does not exist in the resource holder, an attempt will be made to load it from the disk. If it cannot be loaded from the disk, a "FileNotFound" exception will be raised. This means that the returned pointer can never be a nullptr

◆ getPath()

template<class T >
const std::string& ime::ResourceHolder< T >::getPath ( ) const

Get the path to the resources being held.

Returns
The path to the resource on the disk

This path is where the program looks for the specified resources when loading them

◆ getSize()

template<class T >
unsigned int ime::ResourceHolder< T >::getSize ( ) const

Get the number of resources in the resource holder.

Returns
The number of resources in the resource holder

◆ hasResource()

template<class T >
bool ime::ResourceHolder< T >::hasResource ( const std::string &  filename) const

Check if a resource exists or not.

Parameters
filenameFilename of the resource to check
Returns
True if the resource exists, otherwise false

◆ loadFromFile()

template<class T >
bool ime::ResourceHolder< T >::loadFromFile ( const std::string &  filename)

Load a resource from the disk and store it in a buffer.

Parameters
filenameFilename of the resource to load
Exceptions
FileNotFoundIf the file cannot be found on the disk
Returns
True if resource was loaded successfully, otherwise false

This function will look for the resource in the file path specified during instantiation. A FileNotFound exception will be raised if the resource with the specified filename cannot be found

◆ setPath()

template<class T >
void ime::ResourceHolder< T >::setPath ( const std::string &  filepath)

Change the path where resources are located on the disk.

Parameters
filepathPath to the resources to store

This new path is where the program will search for resources when loading them

◆ unload()

template<class T >
bool ime::ResourceHolder< T >::unload ( const std::string &  filename)

Remove a resource from the resource holder.

Parameters
filenameFilename of the resource to be removed
Returns
True if the resource was successfully removed, or false if the resource with the given filename does not exist

◆ unloadAll()

template<class T >
bool ime::ResourceHolder< T >::unloadAll ( )

Remove all resources from the resource holder.

Returns
True if all the resource were removed or false if the resource holder is already empty

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