jubilant-funicular
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
utils::TypeMap Class Reference

#include <TypeMap.h>

Collaboration diagram for utils::TypeMap:
Collaboration graph
[legend]

Public Types

using iterator = std::unordered_map< TypeInfo, void * >::iterator
 
using const_iterator = std::unordered_map< TypeInfo, void * >::const_iterator
 

Public Member Functions

template<typename T >
bool contains () const
 
template<typename T >
void insert (T data)
 
template<typename T >
std::add_lvalue_reference< T >::type find () const
 
void * find (const TypeInfo &info) const
 
template<typename T >
std::add_lvalue_reference< T >::type get ()
 
template<typename T >
void erase ()
 
void erase (const TypeInfo &info)
 
bool empty () const
 
bool is_empty () const
 
std::size_t size () const
 
void clear ()
 
iterator begin ()
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator cend () const
 

Private Member Functions

void destroy (const TypeInfo &info)
 

Private Attributes

std::unordered_map< TypeInfo, void * > m_map
 

Detailed Description

A map from types to values of the given type

Note: Only one value of a given type may be stored

Definition at line 74 of file TypeMap.h.

Member Function Documentation

◆ find() [1/2]

template<typename T >
std::add_lvalue_reference< T >::type utils::TypeMap::find

find is the same as get except a element of type T must already exist in the TypeMap. If not, it will crash.

Definition at line 133 of file TypeMap.h.

Referenced by nta::ECS::add_component(), nta::ECS::get_component(), nta::ECS::get_component_list(), and nta::ECS::has_component().

◆ find() [2/2]

void * utils::TypeMap::find ( const TypeInfo info) const

This version of find returns a nullptr if the key does not already exist

Properly using this function requires some knowledge of how TypeMap works internally

Definition at line 4 of file TypeMap.cpp.

◆ get()

template<typename T >
std::add_lvalue_reference< T >::type utils::TypeMap::get
Note
Only call this if T has a (public) constructor taking no arguments

Definition at line 148 of file TypeMap.h.


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