SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Classes | Public Types | Public Member Functions | List of all members
smtk::common::TypeContainer Class Reference

A container for caching and retrieving instances of types. More...

#include <TypeContainer.h>

Inheritance diagram for smtk::common::TypeContainer:
[legend]

Classes

class  BadTypeError
 

Public Types

using KeyType = smtk::string::Hash
 

Public Member Functions

 TypeContainer ()=default
 Construct an empty TypeContainer.
 
 TypeContainer (const TypeContainer &)
 Construct a TypeContainer whose contents are copied from an existing TypeContainer.
 
 TypeContainer (TypeContainer &&)=default
 Move the contents of one TypeContainer into a new TypeContainer.
 
TypeContaineroperator= (const TypeContainer &)
 Copy the contents of an existing TypeContainer into this one.
 
TypeContaineroperator= (TypeContainer &&)=default
 Move the contents of an existing TypeContainer into this one.
 
template<typename Arg , typename... Args, typename std::enable_if<!std::is_base_of< TypeContainer, Arg >::value, int >::type = 0>
 TypeContainer (const Arg &arg, const Args &... args)
 Construct a TypeContainer instance from any number of elements. More...
 
template<typename Type >
KeyType keyId () const
 Return the ID used to index a given Type.
 
template<typename Type >
bool contains () const
 Check if a Type is present in the TypeContainer.
 
template<typename Type >
bool insert (const Type &value)
 Insert a Type instance into the TypeContainer. More...
 
template<typename Type >
bool insert_or_assign (const Type &value)
 Insert a Type instance into the TypeContainer if it does not exist already or replace it if it does.
 
template<typename Type , typename... Args>
bool emplace (Args &&... args)
 Emplace a Type instance into the TypeContainer.
 
template<typename Type >
const Type & get () const
 Access a Type instance, and throw if it is not in the TypeContainer.
 
template<typename Type >
std::enable_if< std::is_default_constructible< Type >::value, Type & >::type get () noexcept
 For default-constructible types, access a Type instance, creating one if it is not in the TypeContainer.
 
template<typename Type >
std::enable_if<!std::is_default_constructible< Type >::value, Type & >::type get ()
 For non-default-constructible types, access a Type instance; throw if it is not in the TypeContainer.
 
template<typename Type >
bool erase ()
 Remove a specific type of object from the container.
 
bool empty () const noexcept
 Return true if the container holds no objects and false otherwise.
 
std::size_t size () const noexcept
 Return the nubmer of objects held by the container.
 
void clear () noexcept
 Erase all objects held by the container.
 
std::set< smtk::string::Tokenkeys () const
 Return a set of keys corresponding to the values in the container. More...
 

Detailed Description

A container for caching and retrieving instances of types.

Instances are retrieved using type information as a key, allowing for simultaneous lookup and static downcast into that type. TypeContainer supports copying by cloning its elements using thier copy constructors.

Constructor & Destructor Documentation

◆ TypeContainer()

template<typename Arg , typename... Args, typename std::enable_if<!std::is_base_of< TypeContainer, Arg >::value, int >::type = 0>
smtk::common::TypeContainer::TypeContainer ( const Arg &  arg,
const Args &...  args 
)
inline

Construct a TypeContainer instance from any number of elements.

Elements are added in the order they appear in the constructor, so subsequent values for the same type will be ignored.

Member Function Documentation

◆ insert()

template<typename Type >
bool smtk::common::TypeContainer::insert ( const Type &  value)
inline

Insert a Type instance into the TypeContainer.

Note that if the type already exists in the container, the insertion will fail.

◆ keys()

std::set<smtk::string::Token> smtk::common::TypeContainer::keys ( ) const
inline

Return a set of keys corresponding to the values in the container.

There is no run-time method to extract the values given just a key since the type is unknown; however, this does make it possible for the python layer to invoke a function adapter for specific types of objects held in the container to be fetched.


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