 |
Crossfire Server, Trunk
1.75.0
|
Go to the documentation of this file.
13 #ifndef ASSETSCOLLECTION_H
14 #define ASSETSCOLLECTION_H
17 #include <unordered_map>
35 template <
class T,
class Key>
54 template<
class T,
class Key = std::
string>
95 T *add = asset_create<T>(
name);
110 return asset !=
m_assets.end() ? asset->second :
nullptr;
124 replace(existing->second, asset);
125 return existing->second;
143 if (current ==
nullptr) {
147 auto c = std::find_if(
m_assets.begin(),
m_assets.end(), [¤t](
auto& item) { return item.second == current; });
158 void each(std::function<
void(T *)> op) {
159 std::for_each(
m_assets.begin(),
m_assets.end(), [&op] (
auto item) { op(item.second); });
167 T *
first(std::function<
bool(
const T *)> op) {
168 auto found = std::find_if(
m_assets.begin(),
m_assets.end(), [&op] (
auto item) { return op(item.second); });
183 std::vector<Key>
keys()
const {
185 std::for_each(
m_assets.cbegin(),
m_assets.cend(), [&k] (
const auto &asset) { k.push_back(asset.first); });
198 virtual void replace(T *existing, T *update) = 0;
size_t count() const
Get the number of assets.
const std::set< Key > & undefined() const
Return the list of undefined assets, that is assets requested through get() but not defined through d...
T * first(std::function< bool(const T *)> op)
Find the first asset matching some condition.
static event_registration c
virtual void added(T *)
An asset was either referenced (but undefined) or defined.
std::vector< Key > keys() const
Get the names of all defined assets.
T * find(const Key &name)
Get a named asset if it exists.
Plugin animator file specs[Config] name
virtual void replace(T *existing, T *update)=0
Replace an asset by an updated version.
Collection of assets identified by a unique name.
T * define(const Key &name, T *asset)
Define an asset, erasing an existing one.
std::set< Key > m_undefined
List of undefined assets.
T * get(const Key &name)
Get a named asset.
void each(std::function< void(T *)> op)
Apply a function to each asset.
T * next(T *current)
Allow browsing assets in a list-like manner.
virtual ~AssetsCollection()
Destroy this instance and all assets it owns.
void asset_destroy(T *asset)
Destroy an asset.
std::unordered_map< Key, T * > m_assets
Known assets.
void clear()
Clear all assets.
T * asset_create(const Key &key)
Create an asset with the specified key.