MUSX Document Model
Loading...
Searching...
No Matches
musx::dom::ObjectPool< ObjectBaseType > 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 (ObjectKey key, ObjectPtr object)
 Adds an ObjectBaseType object to the pool.
 
template<typename T >
MusxInstanceList< T > getArray (const ObjectKey &key, Cmper requestedPartId) const
 Retrieves a vector of objects of a specific type from the pool.
 
template<typename T >
MusxInstanceList< T > getArrayForPart (const ObjectKey &key) const
 Retrieves a vector of objects of a specific type from the pool.
 
template<typename T >
MusxInstance< T > getSource (const ObjectKey &key) const
 Retrieves the first (and usually only) object of a specific type from the pool.
 
template<typename T >
MusxInstance< T > getEffectiveSourceForPart (const ObjectKey &key) const
 Retrieves the first (and usually only) object of a specific type from the pool for a part.
 
template<typename T >
MusxInstance< T > getEffectiveForPart (const ObjectKey &key) const
 Retrieves the first (and usually only) object of a specific type from the pool for a part.
 
 ObjectPool (const DocumentWeakPtr &document, const std::unordered_map< std::string_view, dom::Base::ShareMode > &knownShareModes={})
 Constructs the object pool.
 

Detailed Description

template<typename ObjectBaseType>
class musx::dom::ObjectPool< ObjectBaseType >

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

Constructor & Destructor Documentation

◆ ObjectPool()

template<typename ObjectBaseType >
musx::dom::ObjectPool< ObjectBaseType >::ObjectPool ( const DocumentWeakPtr document,
const std::unordered_map< std::string_view, dom::Base::ShareMode > &  knownShareModes = {} 
)
inline

Constructs the object pool.

Parameters
documentTHe document for this pool.
knownShareModesOptional parameter that specifies known share modes for certain elements. These can be particurly important for Base::ShareMode::None because there may be no parts containing them.

Member Function Documentation

◆ add()

template<typename ObjectBaseType >
void musx::dom::ObjectPool< ObjectBaseType >::add ( ObjectKey  key,
ObjectPtr  object 
)
inline

Adds an ObjectBaseType object to the pool.

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

◆ getArray()

template<typename ObjectBaseType >
template<typename T >
MusxInstanceList< T > musx::dom::ObjectPool< ObjectBaseType >::getArray ( const ObjectKey key,
Cmper  requestedPartId 
) 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 ObjectBaseType to retrieve.
Parameters
keyThe key value used to filter the objects.
requestedPartIdThe part for which this array was requested.
Returns
An MusxInstanceList of shared pointers to objects of type T.

◆ getArrayForPart()

template<typename ObjectBaseType >
template<typename T >
MusxInstanceList< T > musx::dom::ObjectPool< ObjectBaseType >::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 ObjectBaseType to retrieve.
Parameters
keyThe key value used to filter the objects.
Returns
An MusxInstanceList of shared pointers to objects of type T.

◆ getEffectiveForPart()

template<typename ObjectBaseType >
template<typename T >
MusxInstance< T > musx::dom::ObjectPool< ObjectBaseType >::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.

If the requestedPartId differs from the sourcePartId, a copy of the source is returned with the requestedPartId set correctly.

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

◆ getEffectiveSourceForPart()

template<typename ObjectBaseType >
template<typename T >
MusxInstance< T > musx::dom::ObjectPool< ObjectBaseType >::getEffectiveSourceForPart ( const ObjectKey key) const
inline

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

Warning
The returned value is the source item from the pool and is guaranteed not to be a copy. Because of this, it does not reflect the requested part id. External callers should not directly call this function.

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

◆ getSource()

template<typename ObjectBaseType >
template<typename T >
MusxInstance< T > musx::dom::ObjectPool< ObjectBaseType >::getSource ( const ObjectKey key) const
inline

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

Warning
The returned value is the source item from the pool and is guaranteed not to be a copy. Because of this, it does not reflect the requested part id. External callers should not directly call this function.
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