ENUM_MAP: support reverse (string-to-enum) mapping

This commit is contained in:
Tomasz Wlostowski 2020-06-18 00:35:32 +02:00
parent 5372daaedf
commit 7e8e02072e
1 changed files with 7 additions and 0 deletions

View File

@ -522,6 +522,7 @@ public:
{ {
wxASSERT_MSG( m_choices.Index( aName ) == wxNOT_FOUND, "Redefined string for a value in ENUM_MAP" ); wxASSERT_MSG( m_choices.Index( aName ) == wxNOT_FOUND, "Redefined string for a value in ENUM_MAP" );
m_choices.Add( aName, static_cast<int>( aValue ) ); m_choices.Add( aName, static_cast<int>( aValue ) );
m_reverseMap[ aName ] = aValue;
return *this; return *this;
} }
@ -530,6 +531,11 @@ public:
return m_choices.GetLabel( static_cast<int>( value ) ); return m_choices.GetLabel( static_cast<int>( value ) );
} }
const T ToEnum( const wxString value )
{
return m_reverseMap[value];
}
const wxPGChoices& Choices() const const wxPGChoices& Choices() const
{ {
return m_choices; return m_choices;
@ -537,6 +543,7 @@ public:
private: private:
wxPGChoices m_choices; wxPGChoices m_choices;
std::unordered_map<wxString, T> m_reverseMap;
ENUM_MAP<T>() ENUM_MAP<T>()
{ {