3#include <Core/Containers/VariableSet.hpp>
4#include <Core/Utils/EnumConverter.hpp>
11namespace VariableSetEnumManagement {
19template <
typename EnumBaseType>
20void addEnumConverter( VariableSet& vs,
30template <
typename EnumBaseType>
31Core::Utils::optional<std::shared_ptr<Core::Utils::EnumConverter<EnumBaseType>>>
32getEnumConverter(
const VariableSet& vs,
const std::string& name );
41template <
typename Enum,
typename std::enable_if<std::is_enum<Enum> {},
bool>::type = true>
50template <
typename EnumBaseType>
52getEnumString(
const VariableSet& vs,
63void RA_CORE_API setEnumVariable( VariableSet& vs,
67void RA_CORE_API setEnumVariable( VariableSet& vs,
const std::string& name,
const char* value );
70void setEnumVariable( VariableSet& vs,
const std::string& name, T value ) {
72 vs.setVariable( name, v );
76auto getEnumVariable(
const VariableSet& vs,
const std::string& name ) ->
const T& {
78 return reinterpret_cast<const T&
>(
83auto getEnumVariable( VariableSet& vs,
const std::string& name ) -> T& {
84 return const_cast<T&
>( getEnumVariable<T>(
const_cast<const VariableSet&
>( vs ), name ) );
87template <
typename EnumBaseType>
88void addEnumConverter( VariableSet& vs,
93 auto converterHandle = vs.setVariable( name, converter );
97 convertingFunction = [converter_ = converterHandle.first]( Core::VariableSet& vs_,
100 vs_.setVariable( name_, converter_->second->getEnumerator( value_ ) );
102 vs.setVariable( name, convertingFunction );
105template <
typename EnumBaseType>
106Core::Utils::optional<std::shared_ptr<Core::Utils::EnumConverter<EnumBaseType>>>
107getEnumConverter(
const VariableSet& vs,
const std::string& name ) {
108 auto storedConverter =
110 if ( storedConverter ) {
return ( *storedConverter )->second; }
114template <
typename EnumBaseType>
119 auto storedConverter =
121 if ( storedConverter ) {
return ( *storedConverter )->second->getEnumerator( value ); }
122 LOG( Ra::Core::Utils::logWARNING ) << name +
" is not a registered Enum with underlying type " +
123 Ra::Core::Utils::demangleType<EnumBaseType>() +
".";
127template <
typename Enum,
typename std::enable_if<std::is_enum<Enum> {},
bool>::type>
129 using EnumBaseType =
typename std::underlying_type_t<Enum>;
130 return getEnumString( vs, name, EnumBaseType( value ) );
hepler function to manage enum as underlying types in VariableSet