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

Public Member Functions

OwnerType getOwnerType () const noexcept
 
const std::string & getName () const noexcept
 
Variant getDefaultValue () const noexcept
 
const std::string & getDesc () const noexcept
 
virtual bool isValidValue (const Variant &oValue) const noexcept=0
 Whether the value is valid for this option. More...
 
virtual std::string getValueAsCode (const Variant &oValue) const noexcept=0
 Return a value as code. More...
 
virtual std::pair< Variant, std::string > getValueFromCode (const std::string &sCode) const noexcept=0
 Convert code to value. More...
 
virtual std::string getValueAsDescriptive (const Variant &oValue) const noexcept=0
 Return the value as a human readable string. More...
 
virtual bool allowsRange () const noexcept
 Whether range of values is supported. More...
 
virtual std::pair< Variant, std::string > getValueFromString (const std::string &sValue) const noexcept=0
 Convert string to value. 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
 

Protected Member Functions

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

◆ ~Option()

virtual stmg::Option::~Option ( )
protectedvirtualdefault

◆ Option() [1/3]

stmg::Option::Option ( OwnerType  eOwnerType,
const std::string &  sName,
const Variant oDefaultValue,
const std::string &  sDesc 
)
protectednoexcept

Constructor.

The option is created visible and not readonly.

Parameters
eOwnerTypeThe owner type.
sNameThe option name.
oDefaultValueThe default value.
sDescThe description of the option.

◆ Option() [2/3]

stmg::Option::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 
)
protectednoexcept

One master constructor.

If bReadOnly is true the preferences dialog might show it but not allow to set its value.

If bVisible is false the preferences dialog doesn't show the option.

If the instance has a master (it's a slave) it keeps a strong reference to it. A master option cannot be slave itself. If refMaster is not null aMasterValues cannot contain duplicates.

Parameters
eOwnerTypeThe owner type.
sNameThe option name.
oDefaultValueThe default value.
sDescThe description of the option.
bReadOnlyWhether readonly.
bVisibleWhether visible.
refMasterThe master option. Can be null.
aMasterValuesThe values of the master option for which this option is enabled. Must be empty if refMaster is null.

◆ Option() [3/3]

stmg::Option::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 
)
protectednoexcept

Generic constructor.

If bReadOnly is true the preferences dialog might show it but not allow to set its value.

If bVisible is false the preferences dialog doesn't show the option.

If the instance has at least a master (aMastersValues is not empty) it is a slave, and it keeps a strong reference to those masters. A master option cannot be slave itself. For each master the values for which the slave is enabled cannot contain duplicates.

Parameters
eOwnerTypeThe owner type.
sNameThe option name.
oDefaultValueThe default value.
sDescThe description of the option.
bReadOnlyWhether readonly.
bVisibleWhether visible.
aMastersValuesThe values for each master option for which this option is enabled. Can be empty. Value: (refMaster, aMasterValues).

Member Function Documentation

◆ allowsRange()

virtual bool stmg::Option::allowsRange ( ) const
inlinevirtualnoexcept

Whether range of values is supported.

The default implementation returns false.

Returns
Whether it makes sense to take a range of the values.

Reimplemented in stmg::IntOption.

◆ getDefaultValue()

Variant stmg::Option::getDefaultValue ( ) const
inlinenoexcept

◆ getDesc()

const std::string& stmg::Option::getDesc ( ) const
inlinenoexcept

◆ getMastersValues()

const std::vector<std::pair<shared_ptr<Option>, std::vector<Variant> > >& stmg::Option::getMastersValues ( ) const
inlinenoexcept

Get the masters and their corresonding values for which this option is enabled.

All masters must have one of the given values for this option to be enabled.

Returns
The masters and their values.

◆ getName()

const std::string& stmg::Option::getName ( ) const
inlinenoexcept

◆ getOwnerType()

OwnerType stmg::Option::getOwnerType ( ) const
inlinenoexcept

◆ getValueAsCode()

virtual std::string stmg::Option::getValueAsCode ( const Variant oValue) const
pure virtualnoexcept

Return a value as code.

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

Implemented in stmg::EnumOption, stmg::IntOption, and stmg::BoolOption.

◆ getValueAsDescriptive()

virtual std::string stmg::Option::getValueAsDescriptive ( const Variant oValue) const
pure virtualnoexcept

Return the value as a human readable string.

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

Implemented in stmg::EnumOption, stmg::IntOption, and stmg::BoolOption.

◆ getValueFromCode()

virtual std::pair<Variant, std::string> stmg::Option::getValueFromCode ( const std::string &  sCode) const
pure virtualnoexcept

Convert code to value.

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

Implemented in stmg::EnumOption, stmg::IntOption, and stmg::BoolOption.

◆ getValueFromString()

virtual std::pair<Variant, std::string> stmg::Option::getValueFromString ( const std::string &  sValue) const
pure virtualnoexcept

Convert string to value.

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

Implemented in stmg::EnumOption, stmg::IntOption, and stmg::BoolOption.

◆ isReadonly()

bool stmg::Option::isReadonly ( ) const
inlinenoexcept

◆ isSlave()

bool stmg::Option::isSlave ( ) const
inlinenoexcept

◆ isValidValue()

virtual bool stmg::Option::isValidValue ( const Variant oValue) const
pure virtualnoexcept

Whether the value is valid for this option.

Parameters
oValueThe value.
Returns
Whether valid.

Implemented in stmg::EnumOption, stmg::IntOption, and stmg::BoolOption.

◆ isVisible()

bool stmg::Option::isVisible ( ) const
inlinenoexcept