MUSX Document Model
Loading...
Searching...
No Matches
musx::dom::ObjectPool< ObjectBaseType, TopKeyElementType > Class Template Reference

A pool that manages collections of OthersBase objects, organized by XML node names and Cmper values. More...

#include <ObjectPool.h>

Classes

struct  ObjectKey
 key type for storing in pool More...
 

Public Types

using ObjectPtr = std::shared_ptr< ObjectBaseType >
 shared pointer to ObjectBaseType
 

Public Member Functions

virtual ~ObjectPool ()=default
 virtual destructor
 
void add (const ObjectKey &key, ObjectPtr object)
 Adds an OthersBase object to the pool.
 
template<typename T >
std::vector< std::shared_ptr< T > > getArray (const ObjectKey &key) const
 Retrieves a vector of objects of a specific type from the pool.
 
template<typename T >
std::vector< std::shared_ptr< T > > getArrayForPart (const ObjectKey &key) const
 Retrieves a vector of objects of a specific type from the pool.
 
template<typename T >
std::shared_ptr< T > get (const ObjectKey &key) const
 Retrieves the first (and usually only) object of a specific type from the pool.
 
template<typename T >
std::shared_ptr< T > getEffectiveForPart (const ObjectKey &key) const
 Retrieves the first (and usually only) object of a specific type from the pool for a part.
 

Detailed Description

template<typename ObjectBaseType, typename TopKeyElementType = std::string>
class musx::dom::ObjectPool< ObjectBaseType, TopKeyElementType >

A pool that manages collections of OthersBase objects, organized by XML node names and Cmper values.

This class provides functionality to store and retrieve objects derived from a Base object type, It supports dynamic retrieval of objects cast to their specific derived types.

Template Parameters
ObjectBaseTypethe base type for the objects in the pool

Member Function Documentation

◆ add()

template<typename ObjectBaseType , typename TopKeyElementType = std::string>
void musx::dom::ObjectPool< ObjectBaseType, TopKeyElementType >::add ( const ObjectKey key,
ObjectPtr  object 
)
inline

Adds an OthersBase object to the pool.

Parameters
keyThe key with which to store the object
objectA shared pointer to the ObjectBaseType object to add.

◆ get()

template<typename ObjectBaseType , typename TopKeyElementType = std::string>
template<typename T >
std::shared_ptr< T > musx::dom::ObjectPool< ObjectBaseType, TopKeyElementType >::get ( const ObjectKey key) const
inline

Retrieves the first (and usually only) object of a specific type from the pool.

Many types are scalar values with only one instance per key. Use this function to retrieve them.

Template Parameters
TThe derived type of OthersBase to retrieve. Must have a constexpr static std::string_view XmlNodeName member.
Parameters
keyThe key value used to filter the objects.
Returns
A shared_ptr to the type or nullptr if none exists

◆ getArray()

template<typename ObjectBaseType , typename TopKeyElementType = std::string>
template<typename T >
std::vector< std::shared_ptr< T > > musx::dom::ObjectPool< ObjectBaseType, TopKeyElementType >::getArray ( const ObjectKey key) const
inline

Retrieves a vector of objects of a specific type from the pool.

This function may be used to

  • retrieve a multi-inci array
  • get all the objects of a specific type, regardless of Cmper value(s), such as getting a vector of all the others::TextExpressionDef instances.
Template Parameters
TThe derived type of OthersBase to retrieve.
Parameters
keyThe key value used to filter the objects.
Returns
A vector of shared pointers to objects of type T.

◆ getArrayForPart()

template<typename ObjectBaseType , typename TopKeyElementType = std::string>
template<typename T >
std::vector< std::shared_ptr< T > > musx::dom::ObjectPool< ObjectBaseType, TopKeyElementType >::getArrayForPart ( const ObjectKey key) const
inline

Retrieves a vector of objects of a specific type from the pool.

This function may be used to

  • retrieve a multi-inci array
  • get all the objects of a specific type, regardless of Cmper value(s), such as getting a vector of all the others::TextExpressionDef instances.
Template Parameters
TThe derived type of OthersBase to retrieve.
Parameters
keyThe key value used to filter the objects.
Returns
A vector of shared pointers to objects of type T.

◆ getEffectiveForPart()

template<typename ObjectBaseType , typename TopKeyElementType = std::string>
template<typename T >
std::shared_ptr< T > musx::dom::ObjectPool< ObjectBaseType, TopKeyElementType >::getEffectiveForPart ( const ObjectKey key) const
inline

Retrieves the first (and usually only) object of a specific type from the pool for a part.

If no part item exists, returns the score item.

Template Parameters
TThe derived type of OthersBase to retrieve. Must have a constexpr static std::string_view XmlNodeName member.
Parameters
keyThe key value used to filter the objects.
Returns
A shared_ptr to the type or nullptr if none exists