![]() |
Crossfire Server, Trunk
1.75.0
|
Collection of assets identified by a unique name. More...
#include <AssetsCollection.h>
Public Member Functions | |
void | clear () |
Clear all assets. More... | |
size_t | count () const |
Get the number of assets. More... | |
T * | define (const Key &name, T *asset) |
Define an asset, erasing an existing one. More... | |
void | each (std::function< void(T *)> op) |
Apply a function to each asset. More... | |
T * | find (const Key &name) |
Get a named asset if it exists. More... | |
T * | first (std::function< bool(const T *)> op) |
Find the first asset matching some condition. More... | |
T * | get (const Key &name) |
Get a named asset. More... | |
std::vector< Key > | keys () const |
Get the names of all defined assets. More... | |
T * | next (T *current) |
Allow browsing assets in a list-like manner. More... | |
const std::set< Key > & | undefined () const |
Return the list of undefined assets, that is assets requested through get() but not defined through define(). More... | |
virtual | ~AssetsCollection () |
Destroy this instance and all assets it owns. More... | |
Protected Member Functions | |
virtual void | added (T *) |
An asset was either referenced (but undefined) or defined. More... | |
virtual void | replace (T *existing, T *update)=0 |
Replace an asset by an updated version. More... | |
Protected Attributes | |
std::unordered_map< Key, T * > | m_assets |
Known assets. More... | |
std::set< Key > | m_undefined |
List of undefined assets. More... | |
Collection of assets identified by a unique name.
An asset is whetever is wanted, no assumption are done on the class.
A pointer to an asset returned by this class is deleted only when the AssetsCollection instance is destroyed. The contents of the asset itself may change though.
If an asset is searched for and created on the fly, it is marked as "undefined" until actually defined through a call to define().
Assets are owned by this instance, and deleted when the instance is destroyed or clear() is called. The asset_destroy() and asset_create() functions must be implemented for the type T and key Key.
Actual implementations must provide some pure virtual functions.
Definition at line 55 of file AssetsCollection.h.
|
inlinevirtual |
Destroy this instance and all assets it owns.
Definition at line 62 of file AssetsCollection.h.
|
inlineprotectedvirtual |
An asset was either referenced (but undefined) or defined.
Reimplemented in Quests, Messages, Facesets, Faces, and AllAnimations.
Definition at line 203 of file AssetsCollection.h.
Referenced by AssetsCollection< Animations >::define(), and AssetsCollection< Animations >::get().
|
inline |
Clear all assets.
Definition at line 69 of file AssetsCollection.h.
Referenced by AssetsCollection< Animations >::~AssetsCollection().
|
inline |
Get the number of assets.
Definition at line 80 of file AssetsCollection.h.
Referenced by assets_number_of_treasurelists(), get_faces_count(), malloc_info(), and quests_count().
|
inline |
Define an asset, erasing an existing one.
name | unique asset name. |
asset | new version of the asset. This pointer may become invalid and must not be used after the call. |
Definition at line 120 of file AssetsCollection.h.
Referenced by FacesetLoader::load(), ArchetypeLoader::load(), MessageLoader::load(), FaceLoader::load(), QuestLoader::load(), TreasureLoader::load(), and FaceLoader::loadAnimationBlock().
|
inline |
Apply a function to each asset.
op | function to apply. |
Definition at line 158 of file AssetsCollection.h.
Referenced by archetypes_for_each(), assets_end_load(), assets_finish_archetypes_for_play(), build_class_list_reply(), build_race_list_reply(), cfapi_system_get_archetype_vector(), check_generators(), check_spells(), check_summoned(), do_pack(), dump_abilities(), dump_all_archetypes(), dump_animations(), dump_faces(), dump_monster_treasure(), dump_spells(), faces_for_each(), get_player_archetype(), get_spell_by_name(), pack_images(), polymorph_item(), polymorph_living(), print_monsters(), quest_for_each(), recipe_find_ingredient_cost(), send_image_info(), and send_map_info().
|
inline |
Get a named asset if it exists.
name | asset name. |
Definition at line 108 of file AssetsCollection.h.
Referenced by finish_races(), get_message_from_identifier(), quest_get_by_code(), try_find_animation(), try_find_archetype(), and try_find_face().
|
inline |
Find the first asset matching some condition.
op | function which must return true if the asset matches, false else. |
Definition at line 167 of file AssetsCollection.h.
|
inline |
Get a named asset.
name | asset name. |
Definition at line 89 of file AssetsCollection.h.
Referenced by AssetsManager::AssetsManager(), find_animation(), find_archetype(), find_face(), find_treasurelist(), FacesetLoader::load(), PngLoader::load(), FaceLoader::load(), QuestLoader::load(), and TreasureLoader::loadTreasure().
|
inline |
Get the names of all defined assets.
Definition at line 183 of file AssetsCollection.h.
|
inline |
Allow browsing assets in a list-like manner.
current | asset to get the next of, nullptr to get the first asset. |
Definition at line 139 of file AssetsCollection.h.
Referenced by get_next_archetype().
|
protectedpure virtual |
Replace an asset by an updated version.
existing | asset to be updated. |
update | new version of the asset, which must be destroyed. |
Implemented in Treasures, Quests, Messages, Facesets, Faces, Archetypes, and AllAnimations.
Referenced by AssetsCollection< Animations >::define().
|
inline |
Return the list of undefined assets, that is assets requested through get() but not defined through define().
Definition at line 177 of file AssetsCollection.h.
Referenced by AssetsManager::dumpUndefined().
|
protected |
Known assets.
Definition at line 190 of file AssetsCollection.h.
Referenced by AssetsCollection< Animations >::clear(), AssetsCollection< Animations >::count(), AssetsCollection< Animations >::define(), AssetsCollection< Animations >::each(), AssetsCollection< Animations >::find(), AssetsCollection< Animations >::first(), AssetsCollection< Animations >::get(), AssetsCollection< Animations >::keys(), and AssetsCollection< Animations >::next().
|
protected |
List of undefined assets.
Definition at line 191 of file AssetsCollection.h.
Referenced by AssetsCollection< Animations >::define(), AssetsCollection< Animations >::get(), and AssetsCollection< Animations >::undefined().