SOFA API  ca665544
Open source framework for multi-physics simuation
sofa::helper::SelectableItem< Derived, IdType > Class Template Reference

#include <SelectableItem.h>

Inheritance diagram for sofa::helper::SelectableItem< Derived, IdType >:

Detailed Description

template<class Derived, typename IdType = std::size_t>
class sofa::helper::SelectableItem< Derived, IdType >

Selection of an item among a fixed list of items.

The class is designed to have the list of items static, so the class can be used in a constexpr context. In particular, it can be used in a switch statement.

The helper macro @MAKE_SELECTABLE_ITEMS can be used to make the code more concise.

Template Parameters
DerivedThe class derived from SelectableItem. The CRTP must be used.
IdTypeA type for the indices

Classes

struct  has_deprecation_map
 
struct  has_deprecation_map< T, std::void_t< decltype(T::s_deprecationMap)> >
 

Protected Attributes

id_type m_selected_id {}
 

Public Member Functions

constexpr SelectableItem ()=default
 
constexpr SelectableItem (const std::string_view key)
 
std::string_view key () const
 
std::string_view description () const
 
 operator std::string_view () const
 
constexpr operator id_type () const
 
bool operator== (const std::string_view key)
 
bool operator== (const SelectableItem &other) const
 
bool operator!= (const SelectableItem &other) const
 
constexpr SelectableItemoperator= (const std::string_view key)
 
void print (std::ostream &out) const final
 
void readFromStream (std::istream &stream) final
 

Static Public Member Functions

static constexpr std::size_t numberOfItems ()
 
static constexpr const auto & items ()
 
static const std::string & allKeysAsString ()
 
static const std::string & dataDescription ()
 

Protected Member Functions

void keyError (const std::string_view key)
 

Static Protected Member Functions

static constexpr id_type findId (const std::string_view key)
 
template<id_type... Is>
static constexpr id_type findId_impl (const std::string_view key, std::index_sequence< Is... >)
 

Attribute details

◆ m_selected_id

template<class Derived , typename IdType = std::size_t>
id_type sofa::helper::SelectableItem< Derived, IdType >::m_selected_id {}
protected

Constructor details

◆ SelectableItem() [1/2]

template<class Derived , typename IdType = std::size_t>
constexpr sofa::helper::SelectableItem< Derived, IdType >::SelectableItem ( )
constexprdefault

◆ SelectableItem() [2/2]

template<class Derived , typename IdType = std::size_t>
constexpr sofa::helper::SelectableItem< Derived, IdType >::SelectableItem ( const std::string_view  key)
inlineconstexpr

Function details

◆ allKeysAsString()

template<class Derived , typename IdType = std::size_t>
static const std::string& sofa::helper::SelectableItem< Derived, IdType >::allKeysAsString ( )
inlinestatic

◆ dataDescription()

template<class Derived , typename IdType = std::size_t>
static const std::string& sofa::helper::SelectableItem< Derived, IdType >::dataDescription ( )
inlinestatic

◆ description()

template<class Derived , typename IdType = std::size_t>
std::string_view sofa::helper::SelectableItem< Derived, IdType >::description ( ) const
inline

◆ findId()

template<class Derived , typename IdType = std::size_t>
static constexpr id_type sofa::helper::SelectableItem< Derived, IdType >::findId ( const std::string_view  key)
inlinestaticconstexprprotected

◆ findId_impl()

template<class Derived , typename IdType = std::size_t>
template<id_type... Is>
static constexpr id_type sofa::helper::SelectableItem< Derived, IdType >::findId_impl ( const std::string_view  key,
std::index_sequence< Is... >   
)
inlinestaticconstexprprotected

◆ items()

template<class Derived , typename IdType = std::size_t>
static constexpr const auto& sofa::helper::SelectableItem< Derived, IdType >::items ( )
inlinestaticconstexpr

◆ key()

template<class Derived , typename IdType = std::size_t>
std::string_view sofa::helper::SelectableItem< Derived, IdType >::key ( ) const
inline

◆ keyError()

template<class Derived , typename IdType = std::size_t>
void sofa::helper::SelectableItem< Derived, IdType >::keyError ( const std::string_view  key)
inlineprotected

◆ numberOfItems()

template<class Derived , typename IdType = std::size_t>
static constexpr std::size_t sofa::helper::SelectableItem< Derived, IdType >::numberOfItems ( )
inlinestaticconstexpr

◆ operator id_type()

template<class Derived , typename IdType = std::size_t>
constexpr sofa::helper::SelectableItem< Derived, IdType >::operator id_type ( ) const
inlineconstexpr

◆ operator std::string_view()

template<class Derived , typename IdType = std::size_t>
sofa::helper::SelectableItem< Derived, IdType >::operator std::string_view ( ) const
inlineexplicit

◆ operator!=()

template<class Derived , typename IdType = std::size_t>
bool sofa::helper::SelectableItem< Derived, IdType >::operator!= ( const SelectableItem< Derived, IdType > &  other) const
inline

◆ operator=()

template<class Derived , typename IdType = std::size_t>
constexpr SelectableItem& sofa::helper::SelectableItem< Derived, IdType >::operator= ( const std::string_view  key)
inlineconstexpr

◆ operator==() [1/2]

template<class Derived , typename IdType = std::size_t>
bool sofa::helper::SelectableItem< Derived, IdType >::operator== ( const SelectableItem< Derived, IdType > &  other) const
inline

◆ operator==() [2/2]

template<class Derived , typename IdType = std::size_t>
bool sofa::helper::SelectableItem< Derived, IdType >::operator== ( const std::string_view  key)
inline

◆ print()

template<class Derived , typename IdType = std::size_t>
void sofa::helper::SelectableItem< Derived, IdType >::print ( std::ostream &  out) const
inlinefinalvirtual

Reimplemented from sofa::helper::BaseSelectableItem.

◆ readFromStream()

template<class Derived , typename IdType = std::size_t>
void sofa::helper::SelectableItem< Derived, IdType >::readFromStream ( std::istream &  stream)
inlinefinalvirtual

Reimplemented from sofa::helper::BaseSelectableItem.