This is a skeleton cache class. This can only be used by the ResourceManager or other classes who actually maintain proper pointer ownership.
More...
#include <Cache.hpp>
|
| | Cache () |
| |
| T * | findItem (S &key) |
| | Finds an item based on a key. More...
|
| |
| T * | operator[] (S &key) |
| | An operator overload that returns the object stored at key. Analagous to findItem();. More...
|
| |
| bool | addItem (S &key, T *item) |
| | Simply adds an item. More...
|
| |
| bool | setItem (S &key, T *item) |
| | Adds or overwrites an item. More...
|
| |
| T * | createItem (S &key, std::function< T *()> creationFunc=[]() -> T *{ return new T();}) |
| | Creates an item with a given key and uses the constructor to fill out the rest. If it already exists, overwrite it and return that pointer. More...
|
| |
| void | clear () |
| | Clears the cache. Destroys all data, calling their respective destructors, then delete. More...
|
| |
| unsigned int | getCount () |
| | Returns the number of items in the cache. More...
|
| |
| std::unordered_map< S, T * >::iterator | begin () |
| |
| std::unordered_map< S, T * >::iterator | end () |
| |
| bool | operator!= (Cache &other) |
| |
|
| std::unordered_map< S, T * > | m_data |
| |
template<typename S, typename T>
class BARE2D::Cache< S, T >
This is a skeleton cache class. This can only be used by the ResourceManager or other classes who actually maintain proper pointer ownership.
Definition at line 15 of file Cache.hpp.
◆ Cache()
template<typename S , typename T >
◆ addItem()
template<typename S , typename T >
Simply adds an item.
- Parameters
-
| key | The key for the item - how it is stored |
| item | The item itself |
- Returns
- True if successful, false otherwise.
Referenced by BARE2D::XMLDataManager::addData().
◆ begin()
template<typename S , typename T >
| std::unordered_map<S, T*>::iterator BARE2D::Cache< S, T >::begin |
( |
| ) |
|
◆ clear()
template<typename S , typename T >
Clears the cache. Destroys all data, calling their respective destructors, then delete.
◆ createItem()
template<typename S , typename T >
| T* BARE2D::Cache< S, T >::createItem |
( |
S & |
key, |
|
|
std::function< T *()> |
creationFunc = []() -> T *{ return new T();} |
|
) |
| |
Creates an item with a given key and uses the constructor to fill out the rest. If it already exists, overwrite it and return that pointer.
- Parameters
-
| key | The key to give the item. |
| creationFunc | A function that allocates and returns a new object. Defaults, but it can slice data if you're using inheritance. |
- Returns
- A pointer to that item.
◆ end()
template<typename S , typename T >
| std::unordered_map<S, T*>::iterator BARE2D::Cache< S, T >::end |
( |
| ) |
|
◆ findItem()
template<typename S , typename T >
Finds an item based on a key.
- Parameters
-
| key | The key to find the item by. |
- Returns
- A pointer to the data, or nullptr if no such data exists
Referenced by BARE2D::XMLDataManager::addData().
◆ getCount()
template<typename S , typename T >
Returns the number of items in the cache.
◆ operator!=()
template<typename S , typename T >
◆ operator[]()
template<typename S , typename T >
An operator overload that returns the object stored at key. Analagous to findItem();.
- Parameters
-
◆ setItem()
template<typename S , typename T >
Adds or overwrites an item.
- Parameters
-
| key | The key for the item - how it is stored |
| item | The item itself |
- Returns
- True if successful, false otherwise.
Referenced by BARE2D::XMLDataManager::setData().
◆ m_data
template<typename S , typename T >
The documentation for this class was generated from the following file: