Crossfire Server, Trunk
AssetsCollection< T, Key > Class Template Referenceabstract

#include <AssetsCollection.h>

+ Inheritance diagram for AssetsCollection< T, Key >:
+ Collaboration diagram for AssetsCollection< T, Key >:

Public Member Functions

void clear ()
 
size_t count () const
 
T * define (const Key &name, T *asset)
 
void each (std::function< void(T *)> op)
 
T * find (const Key &name)
 
T * first (std::function< bool(const T *)> op)
 
T * get (const Key &name)
 
std::vector< Key > keys () const
 
T * next (T *current)
 
const std::set< Key > & undefined () const
 
virtual ~AssetsCollection ()
 

Protected Member Functions

virtual void added (T *)
 
virtual void replace (T *existing, T *update)=0
 

Protected Attributes

std::unordered_map< Key, T * > m_assets
 
std::set< Key > m_undefined
 

Detailed Description

template<class T, class Key = std::string>
class AssetsCollection< T, Key >

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.

Constructor & Destructor Documentation

◆ ~AssetsCollection()

template<class T , class Key = std::string>
virtual AssetsCollection< T, Key >::~AssetsCollection ( )
inlinevirtual

Destroy this instance and all assets it owns.

Definition at line 62 of file AssetsCollection.h.

Member Function Documentation

◆ added()

template<class T , class Key = std::string>
virtual void AssetsCollection< T, Key >::added ( T *  )
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().

+ Here is the caller graph for this function:

◆ clear()

template<class T , class Key = std::string>
void AssetsCollection< T, Key >::clear ( )
inline

Clear all assets.

Definition at line 69 of file AssetsCollection.h.

Referenced by START_TEST(), and AssetsCollection< Animations >::~AssetsCollection().

+ Here is the caller graph for this function:

◆ count()

template<class T , class Key = std::string>
size_t AssetsCollection< T, Key >::count ( ) const
inline

Get the number of assets.

Returns
number.

Definition at line 80 of file AssetsCollection.h.

Referenced by assets_number_of_treasurelists(), get_faces_count(), malloc_info(), quests_count(), and FacesetsPanel::updateItem().

+ Here is the caller graph for this function:

◆ define()

template<class T , class Key = std::string>
T* AssetsCollection< T, Key >::define ( const Key &  name,
T *  asset 
)
inline

Define an asset, erasing an existing one.

Parameters
nameunique asset name.
assetnew version of the asset. This pointer may become invalid and must not be used after the call.
Returns
asset with this name, either asset or the previous existing asset.

Definition at line 120 of file AssetsCollection.h.

Referenced by ArchetypesWrapper::addArchetype(), QuestsWrapper::addQuest(), CREResourcesWindow::addQuest(), FacesetLoader::load(), ArchetypeLoader::load(), MessageLoader::load(), FaceLoader::load(), TreasureLoader::load(), QuestLoader::load(), FaceLoader::loadAnimationBlock(), and START_TEST().

+ Here is the caller graph for this function:

◆ each()

template<class T , class Key = std::string>
void AssetsCollection< T, Key >::each ( std::function< void(T *)>  op)
inline

Apply a function to each asset.

Parameters
opfunction to apply.

Definition at line 158 of file AssetsCollection.h.

Referenced by addArchetypes(), ArchetypeComboBox::ArchetypeComboBox(), archetypes_for_each(), ArchetypesModel::ArchetypesModel(), ResourcesManager::archetypeUse(), assets_end_load(), assets_finish_archetypes_for_play(), AssetsCollectionWrapper< Animations >::AssetsCollectionWrapper(), CREMapInformationManager::browseMaps(), build_class_list_reply(), build_race_list_reply(), MonsterResistances::buildGraph(), cfapi_system_get_archetype_vector(), check_generators(), check_spells(), check_summoned(), CRESubItemQuest::CRESubItemQuest(), do_pack(), dump_abilities(), dump_all_archetypes(), dump_animations(), dump_faces(), dump_monster_treasure(), dump_spells(), FaceComboBox::FaceComboBox(), faces_for_each(), fillEvents(), CREMainWindow::fillFacesets(), get_player_archetype(), get_spell_by_name(), isValidArchFlesh(), CREMainWindow::onReportAlchemy(), CREMainWindow::onReportArchetypes(), CREMainWindow::onReportDuplicate(), CREMainWindow::onReportLicenses(), CREMainWindow::onReportPlayer(), CREMainWindow::onReportQuests(), CREMainWindow::onReportSpellDamage(), CREMainWindow::onReportSpells(), CREMainWindow::onReportSummon(), pack_images(), polymorph_item(), polymorph_living(), print_monsters(), quest_for_each(), QuestComboBox::QuestComboBox(), recipe_find_ingredient_cost(), send_image_info(), send_map_info(), spellsTable(), START_TEST(), TreasureListComboBox::TreasureListComboBox(), and FacesetsPanel::updateItem().

◆ find()

template<class T , class Key = std::string>
T* AssetsCollection< T, Key >::find ( const Key &  name)
inline

Get a named asset if it exists.

Parameters
nameasset name.
Returns
asset pointer guaranteed to live as long as this instance if the asset exists, nullptr else.

Definition at line 108 of file AssetsCollection.h.

Referenced by ArtifactPanel::artifactChanged(), TreasureWrapper::displayIcon(), MimeUtils::extract(), finish_races(), get_message_from_identifier(), CREMainWindow::onReportAlchemyGraph(), CREMainWindow::onReportQuests(), quest_get_by_code(), CRESubItemQuest::selectedQuestChanged(), START_TEST(), treasureContains(), try_find_animation(), try_find_archetype(), try_find_face(), RecipePanel::updateItem(), and ArchetypeWrapper::uses().

+ Here is the caller graph for this function:

◆ first()

template<class T , class Key = std::string>
T* AssetsCollection< T, Key >::first ( std::function< bool(const T *)>  op)
inline

Find the first asset matching some condition.

Parameters
opfunction which must return true if the asset matches, false else.
Returns
nullptr if no asset matches, else the first matching asset.

Definition at line 167 of file AssetsCollection.h.

Referenced by ArchetypeWrapper::appearsOnTreasureList(), and SoundsDialog::soundType().

+ Here is the caller graph for this function:

◆ get()

template<class T , class Key = std::string>
T* AssetsCollection< T, Key >::get ( const Key &  name)
inline

Get a named asset.

Parameters
nameasset name.
Returns
asset pointer guaranteed to live as long as this instance, never nullptr.

Definition at line 89 of file AssetsCollection.h.

Referenced by CREResourcesWindow::addQuest(), AssetsManager::AssetsManager(), find_animation(), find_archetype(), find_face(), find_treasurelist(), generate_random_treasure(), CREPixmap::init(), FacesetLoader::load(), PngLoader::load(), FaceLoader::load(), QuestLoader::load(), TreasureLoader::loadTreasure(), FaceMakerDialog::makeFaces(), CREMainWindow::onReportQuests(), and CREPixmap::setFaceset().

+ Here is the caller graph for this function:

◆ keys()

template<class T , class Key = std::string>
std::vector<Key> AssetsCollection< T, Key >::keys ( ) const
inline

Get the names of all defined assets.

Returns
list of all names.

Definition at line 183 of file AssetsCollection.h.

Referenced by ArchetypesWrapper::addArchetype(), and QuestsWrapper::addQuest().

+ Here is the caller graph for this function:

◆ next()

template<class T , class Key = std::string>
T* AssetsCollection< T, Key >::next ( T *  current)
inline

Allow browsing assets in a list-like manner.

Note
this function is not efficient, and should not be used in C++ code.
Parameters
currentasset to get the next of, nullptr to get the first asset.
Returns
next asset, nullptr if no assets is defined or 'current' was the last one.

Definition at line 139 of file AssetsCollection.h.

Referenced by get_next_archetype().

+ Here is the caller graph for this function:

◆ replace()

template<class T , class Key = std::string>
virtual void AssetsCollection< T, Key >::replace ( T *  existing,
T *  update 
)
protectedpure virtual

Replace an asset by an updated version.

Parameters
existingasset to be updated.
updatenew version of the asset, which must be destroyed.

Implemented in Treasures, Quests, Messages, Facesets, Faces, Archetypes, and AllAnimations.

Referenced by AssetsCollection< Animations >::define().

+ Here is the caller graph for this function:

◆ undefined()

template<class T , class Key = std::string>
const std::set<Key>& AssetsCollection< T, Key >::undefined ( ) const
inline

Return the list of undefined assets, that is assets requested through get() but not defined through define().

Returns
list of undefined names.

Definition at line 177 of file AssetsCollection.h.

Referenced by AssetsManager::dumpUndefined().

+ Here is the caller graph for this function:

Field Documentation

◆ m_assets

◆ m_undefined

template<class T , class Key = std::string>
std::set<Key> AssetsCollection< T, Key >::m_undefined
protected

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