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)
 
T * next (T *current)
 
const std::set< Key > & undefined () const
 

Protected Member Functions

virtual void added (T *)
 
virtual T * create (const Key &name)=0
 
virtual void destroy (T *item)=0
 
virtual void replace (T *existing, T *update)=0
 

Protected Attributes

std::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 NamedAssets 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 clear() is called. Because of how C++ destructors work, clear() unfortunately can't be called automatically (virtual function).

Actual implementations must provide some pure virtual functions.

Definition at line 39 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 181 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

Destroy all assets.

Definition at line 46 of file AssetsCollection.h.

Referenced by START_TEST(), and AssetsManager::~AssetsManager().

+ 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 57 of file AssetsCollection.h.

Referenced by assets_number_of_animations(), assets_number_of_archetypes(), assets_number_of_treasurelists(), get_faces_count(), quests_count(), and CREFacesetsPanel::setItem().

+ Here is the caller graph for this function:

◆ create()

template<class T , class Key = std::string>
virtual T* AssetsCollection< T, Key >::create ( const Key &  name)
protectedpure virtual

Create a new asset.

Parameters
nameasset unique name.
Returns
asset.

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

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

+ 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 97 of file AssetsCollection.h.

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

+ Here is the caller graph for this function:

◆ destroy()

template<class T , class Key = std::string>
virtual void AssetsCollection< T, Key >::destroy ( T *  item)
protectedpure virtual

Destroy an asset.

Parameters
itemasset to destroy.

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

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

+ 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 135 of file AssetsCollection.h.

Referenced by addArchetypes(), animations_for_each(), archetypes_for_each(), ArchetypesModel::ArchetypesModel(), ResourcesManager::archetypeUse(), assets_end_load(), assets_finish_archetypes_for_play(), CREMapInformationManager::browseMaps(), check_generators(), check_spells(), check_summoned(), CRECombatSimulator::CRECombatSimulator(), CREFormulaePanel::CREFormulaePanel(), CREQuestPanel::CREQuestPanel(), CRESubItemQuest::CRESubItemQuest(), do_pack(), FaceComboBox::FaceComboBox(), faces_for_each(), facesets_for_each(), CREResourcesWindow::fillAnimations(), CREResourcesWindow::fillArchetypes(), fillEvents(), CREResourcesWindow::fillFaces(), CREMainWindow::fillFacesets(), CREResourcesWindow::fillFacesets(), CREResourcesWindow::fillGeneralMessages(), CREResourcesWindow::fillQuests(), CREResourcesWindow::fillTreasures(), isValidArchFlesh(), CREMainWindow::onReportAlchemy(), CREMainWindow::onReportArchetypes(), CREMainWindow::onReportDuplicate(), CREMainWindow::onReportLicenses(), CREMainWindow::onReportPlayer(), CREMainWindow::onReportQuests(), CREMainWindow::onReportSpellDamage(), CREMainWindow::onReportSpells(), CREMainWindow::onReportSummon(), pack_images(), quest_for_each(), recipe_find_ingredient_cost(), CRETreasurePanel::setItem(), CREFacePanel::setItem(), CREFacesetsPanel::setItem(), CREAnimationPanel::setItem(), and spellsTable().

+ Here is the caller graph for this function:

◆ 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 85 of file AssetsCollection.h.

Referenced by finish_races(), get_message_from_identifier(), CREMainWindow::onReportAlchemyGraph(), CREMainWindow::onReportQuests(), quest_get_by_code(), CRESubItemQuest::selectedQuestChanged(), CREFacePanel::setItem(), START_TEST(), treasureContains(), try_find_animation(), try_find_archetype(), and try_find_face().

+ 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 144 of file AssetsCollection.h.

◆ get()

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

◆ 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 116 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 154 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: