stmm-games-doc  0.32.0
Public Member Functions | List of all members
stmg::EnumOption Class Reference
Inheritance diagram for stmg::EnumOption:
Inheritance graph
[legend]

Public Member Functions

 EnumOption (OwnerType eOwnerType, const std::string &sName, int32_t nDefaultEnum, const std::string &sDesc, const std::vector< std::tuple< int32_t, std::string, std::string > > &aEnum) noexcept
 Constructor. More...
 
 EnumOption (OwnerType eOwnerType, const std::string &sName, int32_t nDefaultEnum, const std::string &sDesc, bool bReadOnly, bool bVisible, const shared_ptr< Option > &refMaster, const std::vector< Variant > &aMasterValues, const std::vector< std::tuple< int32_t, std::string, std::string > > &aEnum) noexcept
 Constructor. More...
 
 EnumOption (OwnerType eOwnerType, const std::string &sName, int32_t nDefaultEnum, const std::string &sDesc, bool bReadOnly, bool bVisible, const std::vector< std::pair< shared_ptr< Option >, std::vector< Variant >>> &aMastersValues, const std::vector< std::tuple< int32_t, std::string, std::string > > &aEnum) noexcept
 Constructor. More...
 
bool isValidValue (const Variant &oValue) const noexcept override
 Whether the value is valid for this option. More...
 
std::string getValueAsCode (const Variant &oValue) const noexcept override
 Return a value as code. More...
 
std::pair< Variant, std::string > getValueFromCode (const std::string &sCode) const noexcept override
 Convert code to value. More...
 
std::string getValueAsDescriptive (const Variant &oValue) const noexcept override
 Return the value as a human readable string. More...
 
std::pair< Variant, std::string > getValueFromString (const std::string &sValue) const noexcept override
 Convert string to value. More...
 
int32_t size () const noexcept
 The total number of enums. More...
 
std::tuple< int32_t, std::string, std::string > get (int32_t nIdx) const noexcept
 Returns enum data for a given index. More...
 
int32_t getEnum (int32_t nIdx) const noexcept
 
const std::string & getEnumName (int32_t nIdx) const noexcept
 
const std::string & getEnumDesc (int32_t nIdx) const noexcept
 
int32_t getIdx (int32_t nEnum) const noexcept
 The index of an enum value. More...
 
const std::string & getName (int32_t nEnum) const noexcept
 
int32_t getEnum (const std::string &sEnumName) const noexcept
 Get the enum value from the enum name. More...
 
- Public Member Functions inherited from stmg::Option
OwnerType getOwnerType () const noexcept
 
const std::string & getName () const noexcept
 
Variant getDefaultValue () const noexcept
 
const std::string & getDesc () const noexcept
 
virtual bool allowsRange () const noexcept
 Whether range of values is supported. More...
 
bool isReadonly () const noexcept
 
bool isVisible () const noexcept
 
const std::vector< std::pair< shared_ptr< Option >, std::vector< Variant > > > & getMastersValues () const noexcept
 Get the masters and their corresonding values for which this option is enabled. More...
 
bool isSlave () const noexcept
 

Additional Inherited Members

- Protected Member Functions inherited from stmg::Option
virtual ~Option ()=default
 
 Option (OwnerType eOwnerType, const std::string &sName, const Variant &oDefaultValue, const std::string &sDesc) noexcept
 Constructor. More...
 
 Option (OwnerType eOwnerType, const std::string &sName, const Variant &oDefaultValue, const std::string &sDesc, bool bReadOnly, bool bVisible, const shared_ptr< Option > &refMaster, const std::vector< Variant > &aMasterValues) noexcept
 One master constructor. More...
 
 Option (OwnerType eOwnerType, const std::string &sName, const Variant &oDefaultValue, const std::string &sDesc, bool bReadOnly, bool bVisible, const std::vector< std::pair< shared_ptr< Option >, std::vector< Variant >>> &aMastersValues) noexcept
 Generic constructor. More...
 

Constructor & Destructor Documentation

◆ EnumOption() [1/3]

stmg::EnumOption::EnumOption ( OwnerType  eOwnerType,
const std::string &  sName,
int32_t  nDefaultEnum,
const std::string &  sDesc,
const std::vector< std::tuple< int32_t, std::string, std::string > > &  aEnum 
)
inlinenoexcept

Constructor.

Parameter aEnum is a vector of tuple<nEnum, sEnumName, sDesc> where

  • nEnum is the value (must be unique among all tuples, cannot be std::numeric_limits<int32_t>::min()),
  • sEnumName is a string name (must be unique among all tuples),
  • sDesc is a description (maybe localized)

nDefaultEnum must be one of the nEnum values in aEnum.

Parameters
eOwnerTypeThe owner type.
sNameThe option name.
nDefaultEnumThe default value.
sDescThe description of the option.
aEnumThe array of values with their name and description.

◆ EnumOption() [2/3]

stmg::EnumOption::EnumOption ( OwnerType  eOwnerType,
const std::string &  sName,
int32_t  nDefaultEnum,
const std::string &  sDesc,
bool  bReadOnly,
bool  bVisible,
const shared_ptr< Option > &  refMaster,
const std::vector< Variant > &  aMasterValues,
const std::vector< std::tuple< int32_t, std::string, std::string > > &  aEnum 
)
noexcept

Constructor.

Parameter aEnum is a vector of tuple<nEnum, sEnumName, sDesc> where

  • nEnum is the value (must be unique among all tuples, cannot be std::numeric_limits<int32_t>::min()),
  • sEnumName is a string name (must be unique among all tuples) and satisfy [A-Za-z0-9]+,
  • sDesc is a description (maybe localized)
Parameters
eOwnerTypeThe owner type.
sNameThe option name.
nDefaultEnumThe default value.
sDescThe description of the option.
bReadOnlyWhether the option is read-only.
bVisibleWhether the option is visible.
refMasterThe master option. Can be null.
aMasterValuesThe master option values for which this option is valid.
aEnumThe array of values with their name and description.

◆ EnumOption() [3/3]

stmg::EnumOption::EnumOption ( OwnerType  eOwnerType,
const std::string &  sName,
int32_t  nDefaultEnum,
const std::string &  sDesc,
bool  bReadOnly,
bool  bVisible,
const std::vector< std::pair< shared_ptr< Option >, std::vector< Variant >>> &  aMastersValues,
const std::vector< std::tuple< int32_t, std::string, std::string > > &  aEnum 
)
noexcept

Constructor.

Parameter aEnum is a vector of tuple<nEnum, sEnumName, sDesc> where

  • nEnum is the value (must be unique among all tuples, cannot be std::numeric_limits<int32_t>::min()),
  • sEnumName is a string name (must be unique among all tuples) and satisfy [A-Za-z0-9]+,
  • sDesc is a description (maybe localized)
Parameters
eOwnerTypeThe owner type.
sNameThe option name.
nDefaultEnumThe default value.
sDescThe description of the option.
bReadOnlyWhether the option is read-only.
bVisibleWhether the option is visible.
aMastersValuesThe values for each master option for which this option is enabled. Can be empty. Value: (refMaster, aMasterValues).
aEnumThe array of values with their name and description.

Member Function Documentation

◆ get()

std::tuple<int32_t, std::string, std::string> stmg::EnumOption::get ( int32_t  nIdx) const
noexcept

Returns enum data for a given index.

The order is the same as passed to the constructor.

Parameters
nIdxThe index must be >= 0 and < size().
Returns
The tuple containing enum value, enum name, enum description.

◆ getEnum() [1/2]

int32_t stmg::EnumOption::getEnum ( int32_t  nIdx) const
noexcept

◆ getEnum() [2/2]

int32_t stmg::EnumOption::getEnum ( const std::string &  sEnumName) const
noexcept

Get the enum value from the enum name.

Parameters
sEnumNameThe enum name.
Returns
The enum value or std::numeric_limits<int32_t>::min() if invalid.

◆ getEnumDesc()

const std::string& stmg::EnumOption::getEnumDesc ( int32_t  nIdx) const
noexcept

◆ getEnumName()

const std::string& stmg::EnumOption::getEnumName ( int32_t  nIdx) const
noexcept

◆ getIdx()

int32_t stmg::EnumOption::getIdx ( int32_t  nEnum) const
noexcept

The index of an enum value.

If the the enum value is valid the index is >= 0 and < size().

Parameters
nEnumThe enum value. Cannot be std::numeric_limits<int32_t>::min().
Returns
The index of the enum or -1 if not a valid value.

◆ getName()

const std::string& stmg::EnumOption::getName ( int32_t  nEnum) const
noexcept

◆ getValueAsCode()

std::string stmg::EnumOption::getValueAsCode ( const Variant oValue) const
overridevirtualnoexcept

Return a value as code.

Parameters
oValueThe value.
Returns
The code or empty string if invalid.

Implements stmg::Option.

◆ getValueAsDescriptive()

std::string stmg::EnumOption::getValueAsDescriptive ( const Variant oValue) const
overridevirtualnoexcept

Return the value as a human readable string.

Parameters
oValueThe value.
Returns
The descriptive string or empty string if invalid.

Implements stmg::Option.

◆ getValueFromCode()

std::pair<Variant, std::string> stmg::EnumOption::getValueFromCode ( const std::string &  sCode) const
overridevirtualnoexcept

Convert code to value.

Parameters
sCodeThe code.
Returns
The value and empty string or null and the error.

Implements stmg::Option.

◆ getValueFromString()

std::pair<Variant, std::string> stmg::EnumOption::getValueFromString ( const std::string &  sValue) const
overridevirtualnoexcept

Convert string to value.

Parameters
sValueThe string representation. Cannot be empty.
Returns
The value and an empty string ot null and the error string.

Implements stmg::Option.

◆ isValidValue()

bool stmg::EnumOption::isValidValue ( const Variant oValue) const
overridevirtualnoexcept

Whether the value is valid for this option.

Parameters
oValueThe value.
Returns
Whether valid.

Implements stmg::Option.

◆ size()

int32_t stmg::EnumOption::size ( ) const
inlinenoexcept

The total number of enums.

Returns
The total number of enum values.