SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Public Types | Public Member Functions | List of all members
smtk::common::Instances< BaseType, InputTypes > Class Template Reference

The Instances class is used to manage instances of objects which share an inherited base type (the BaseType template parameter). More...

#include <Instances.h>

Inheritance diagram for smtk::common::Instances< BaseType, InputTypes >:
[legend]
Collaboration diagram for smtk::common::Instances< BaseType, InputTypes >:
[legend]

Public Types

using Superclass = smtk::common::Factory< BaseType, InputTypes... >
 An alias for the inherited parent class.
 
using Observer = std::function< void(InstanceEvent, const std::shared_ptr< BaseType > &)>
 The signature of observers watching managed instance lifecycle events.
 
using Observers = smtk::common::Observers< Observer >
 Access to the set of observers of instances.
 
using Visitor = std::function< smtk::common::Visit(const std::shared_ptr< BaseType > &)>
 The signature used to visit managed instances of objects.
 

Public Member Functions

 Instances ()
 Construct a manager of object instances.
 
 Instances (const Instances &)=delete
 Delete copy constructor and assignment operator.
 
void operator= (const Instances &)=delete
 
template<typename Type , typename... Args>
std::shared_ptr< Type > create (Args &&... args)
 Create an instance of the given Type and manage it.
 
template<typename... Args>
std::shared_ptr< BaseType > createFromName (const std::string &typeName, Args &&... args)
 Create and manage an instance of Type using its type-name.
 
template<typename... Args>
std::shared_ptr< BaseType > createFromIndex (const std::size_t &typeIndex, Args &&... args)
 Create and manage an instance of a Type using its type-index.
 
bool manage (const std::shared_ptr< BaseType > &instance)
 Manage an already-created instance of a class. More...
 
bool unmanage (const std::shared_ptr< BaseType > &instance)
 Unmanage (drop the reference to) an instance. More...
 
bool contains (const std::shared_ptr< BaseType > &instance)
 Determine whether instance is managed or not.
 
void clear ()
 Unmanage all instances.
 
Observersobservers ()
 Return the set of observers of instances (so that you can insert an observer).
 
smtk::common::Visit visit (Visitor visitor) const
 Iterate over the collection of instances, invoking a visitor on each. More...
 
std::size_t size () const
 Return the number of instances being managed.
 
- Public Member Functions inherited from smtk::common::Factory< BaseType, InputTypes... >
bool registerType ()
 Register a Type to the factory.
 
bool registerType (Metadata &&metadata)
 Register a Typeusing the Type's Metadata.
 
bool registerTypes ()
 Register a tuple of Types.
 
bool unregisterType ()
 Unregister a Type.
 
bool unregisterType (const std::string &typeName)
 Unregister a Type using its type name.
 
bool unregisterType (const std::size_t &typeIndex)
 Unregister a Type using its type index.
 
bool unregisterTypes ()
 Unregister a tuple of Types.
 
bool contains () const
 Determine whether or not a Type is available.
 
bool contains (const std::string &typeName) const
 Determine whether or not a Type is available using its type name.
 
bool contains (const std::size_t typeIndex) const
 Determine whether or not a Type is available using its type index.
 
std::unique_ptr< Type > create (Args &&... args) const
 Create an instance of a Type.
 
std::unique_ptr< BaseType > createFromName (const std::string &typeName, Args &&... args) const
 Create an instance of a Type using its type name.
 
std::unique_ptr< BaseType > createFromIndex (const std::size_t &typeIndex, Args &&... args) const
 Create an instance of a Type using its type name.
 
std::shared_ptr< Type > make (Args &&... args) const
 Make a shared instance of a Type.
 
std::shared_ptr< BaseType > makeFromName (const std::string &typeName, Args &&... args) const
 Make a shared instance of a Type using its type name.
 
std::shared_ptr< BaseType > makeFromIndex (const std::size_t &typeIndex, Args &&... args) const
 Create an instance of a Type using its type name.
 
Interface< TagType, true > get () const
 Access a convenience Interface for creating objects that singles out one of the three modes of creation: by type, by type name and by type index.
 

Detailed Description

template<typename BaseType, typename... InputTypes>
class smtk::common::Instances< BaseType, InputTypes >

The Instances class is used to manage instances of objects which share an inherited base type (the BaseType template parameter).

It owns references to the instances, which keeps them alive. It provides methods to observe when instances are managed (added to Instances) and unmanaged (removed from Instances — at which point their destructor is usually called, although destruction only occurs if no other shared pointers to the object exist).

Instances are created via smtk::common::Factory, which this class inherits, and observers are invoked via smtk::common::Observers. The Instances class mutates the signature of its parent Factory class's creation methods so that they return shared pointers.

Member Function Documentation

◆ manage()

template<typename BaseType , typename... InputTypes>
bool smtk::common::Instances< BaseType, InputTypes >::manage ( const std::shared_ptr< BaseType > &  instance)
inline

Manage an already-created instance of a class.

This returns true if the instance was added and false otherwise (which can occur if passed a null pointer or an already-managed instance).

◆ unmanage()

template<typename BaseType , typename... InputTypes>
bool smtk::common::Instances< BaseType, InputTypes >::unmanage ( const std::shared_ptr< BaseType > &  instance)
inline

Unmanage (drop the reference to) an instance.

This may result in the destruction of instance but is not guaranteed to do so (i.e., when other shared-pointers to instance exist).

◆ visit()

template<typename BaseType , typename... InputTypes>
smtk::common::Visit smtk::common::Instances< BaseType, InputTypes >::visit ( Visitor  visitor) const
inline

Iterate over the collection of instances, invoking a visitor on each.

The return value indicates whether iteration was terminated early or not.


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