openMSX
Public Types | Public Member Functions | Protected Member Functions | List of all members
openmsx::Setting Class Reference

#include <Setting.hh>

Inheritance diagram for openmsx::Setting:
Inheritance graph
[legend]
Collaboration diagram for openmsx::Setting:
Collaboration graph
[legend]

Public Types

enum class  Save { YES , NO , NO_AND_DONT_TRANSFER }
 

Public Member Functions

 Setting (const Setting &)=delete
 
 Setting (Setting &&)=delete
 
Settingoperator= (const Setting &)=delete
 
Settingoperator= (Setting &&)=delete
 
virtual ~Setting ()
 
const TclObjectgetValue () const final
 Gets the current value of this setting as a TclObject.
 
std::optional< TclObjectgetOptionalValue () const final
 Like getValue(), but in case of error returns an empty optional instead of throwing an exception.
 
void setChecker (std::function< void(TclObject &)> checkFunc_)
 Set value-check-callback.
 
void setValue (const TclObject &newValue) final
 Change the value of this setting to the given value.
 
std::string_view getDescription () const final
 pure virtual methods ///
 
TclObject getDefaultValue () const final
 Get the default value of this setting.
 
void setValueDirect (const TclObject &newValue) final
 Similar to setValue(), but doesn't trigger Tcl traces.
 
void tabCompletion (std::vector< std::string > &tokens) const override
 Complete a partly typed value.
 
bool needLoadSave () const final
 Does this setting need to be loaded or saved (settings.xml).
 
void additionalInfo (TclObject &result) const override
 Helper method for info().
 
bool needTransfer () const final
 Does this setting need to be transfered on reverse.
 
CommandControllergetCommandController () const
 
InterpretergetInterpreter () const
 
- Public Member Functions inherited from openmsx::BaseSetting
const TclObjectgetFullNameObj () const
 Get the name of this setting.
 
const TclObjectgetBaseNameObj () const
 
std::string_view getFullName () const
 
std::string_view getBaseName () const
 
void setPrefix (std::string_view prefix)
 Set a machine specific prefix.
 
void info (TclObject &result) const
 For SettingInfo.
 
virtual std::string_view getTypeString () const =0
 Returns a string describing the setting type (integer, string, ..) Could be used in a GUI to pick an appropriate setting widget.
 
- Public Member Functions inherited from openmsx::Subject< Setting >
 Subject (const Subject &)=delete
 
 Subject (Subject &&)=delete
 
Subjectoperator= (const Subject &)=delete
 
Subjectoperator= (Subject &&)=delete
 
void attach (Observer< Setting > &observer)
 
void detach (Observer< Setting > &observer)
 
bool anyObservers () const
 

Protected Member Functions

 Setting (CommandController &commandController, std::string_view name, static_string_view description, const TclObject &initialValue, Save save=Save::YES)
 
void init ()
 
void notifyPropertyChange () const
 
- Protected Member Functions inherited from openmsx::BaseSetting
 BaseSetting (std::string_view name)
 
 BaseSetting (TclObject name)
 
 ~BaseSetting ()=default
 
- Protected Member Functions inherited from openmsx::Subject< Setting >
 Subject ()=default
 
 ~Subject ()
 
void notify () const
 

Detailed Description

Definition at line 117 of file Setting.hh.

Member Enumeration Documentation

◆ Save

enum class openmsx::Setting::Save
strong
Enumerator
YES 
NO 
NO_AND_DONT_TRANSFER 

Definition at line 120 of file Setting.hh.

Constructor & Destructor Documentation

◆ Setting() [1/3]

openmsx::Setting::Setting ( const Setting )
delete

◆ Setting() [2/3]

openmsx::Setting::Setting ( Setting &&  )
delete

◆ ~Setting()

openmsx::Setting::~Setting ( )
virtual

◆ Setting() [3/3]

openmsx::Setting::Setting ( CommandController commandController,
std::string_view  name,
static_string_view  description,
const TclObject initialValue,
Save  save = Save::YES 
)
protected

Definition at line 36 of file Setting.cc.

Member Function Documentation

◆ additionalInfo()

void openmsx::Setting::additionalInfo ( TclObject result) const
overridevirtual

Helper method for info().

Implements openmsx::BaseSetting.

Reimplemented in openmsx::VideoSourceSetting.

Definition at line 149 of file Setting.cc.

◆ getCommandController()

CommandController & openmsx::Setting::getCommandController ( ) const
inline

Definition at line 161 of file Setting.hh.

Referenced by init(), setValueDirect(), and ~Setting().

◆ getDefaultValue()

TclObject openmsx::Setting::getDefaultValue ( ) const
inlinefinalvirtual

Get the default value of this setting.

This is the initial value of the setting. Default values don't get saved in 'settings.xml'. This is also the value used for a Tcl 'unset' command.

Implements openmsx::BaseSetting.

Definition at line 153 of file Setting.hh.

Referenced by openmsx::CommandLineParser::parse().

◆ getDescription()

std::string_view openmsx::Setting::getDescription ( ) const
finalvirtual

pure virtual methods ///

Get a description of this setting that can be presented to the user.

Implements openmsx::BaseSetting.

Definition at line 76 of file Setting.cc.

◆ getInterpreter()

Interpreter & openmsx::Setting::getInterpreter ( ) const

◆ getOptionalValue()

std::optional< TclObject > openmsx::Setting::getOptionalValue ( ) const
inlinefinalvirtual

Like getValue(), but in case of error returns an empty optional instead of throwing an exception.

Implements openmsx::BaseSetting.

Definition at line 135 of file Setting.hh.

◆ getValue()

const TclObject & openmsx::Setting::getValue ( ) const
inlinefinalvirtual

◆ init()

void openmsx::Setting::init ( )
protected

◆ needLoadSave()

bool openmsx::Setting::needLoadSave ( ) const
finalvirtual

Does this setting need to be loaded or saved (settings.xml).

Implements openmsx::BaseSetting.

Definition at line 119 of file Setting.cc.

References YES.

Referenced by init().

◆ needTransfer()

bool openmsx::Setting::needTransfer ( ) const
finalvirtual

Does this setting need to be transfered on reverse.

Implements openmsx::BaseSetting.

Definition at line 123 of file Setting.cc.

References NO_AND_DONT_TRANSFER.

◆ notifyPropertyChange()

void openmsx::Setting::notifyPropertyChange ( ) const
protected

◆ operator=() [1/2]

Setting & openmsx::Setting::operator= ( const Setting )
delete

◆ operator=() [2/2]

Setting & openmsx::Setting::operator= ( Setting &&  )
delete

◆ setChecker()

void openmsx::Setting::setChecker ( std::function< void(TclObject &)>  checkFunc_)
inline

Set value-check-callback.

The callback is called on each change of this settings value. The callback has the possibility to

  • change the value (modify the parameter)
  • disallow the change (throw an exception) The callback is only executed on each value change, even if the new value is the same as the current value. However the callback is not immediately executed once it's set (via this method).

Definition at line 146 of file Setting.hh.

Referenced by openmsx::BooleanSetting::BooleanSetting(), openmsx::EnumSetting< T >::EnumSetting(), openmsx::FloatSetting::FloatSetting(), openmsx::IntegerSetting::IntegerSetting(), openmsx::JoyMega::JoyMega(), openmsx::KeyCodeSetting::KeyCodeSetting(), openmsx::MSXJoystick::MSXJoystick(), openmsx::ReadOnlySetting::ReadOnlySetting(), openmsx::Touchpad::Touchpad(), and openmsx::VideoSourceSetting::VideoSourceSetting().

◆ setValue()

void openmsx::Setting::setValue ( const TclObject value)
finalvirtual

Change the value of this setting to the given value.

This method will trigger Tcl traces. This value still passes via the 'checker-callback' (see below), so the value may be adjusted. Or in case of an invalid value this method may throw.

Implements openmsx::BaseSetting.

Definition at line 81 of file Setting.cc.

References openmsx::BaseSetting::getFullNameObj(), getInterpreter(), and openmsx::Interpreter::setVariable().

Referenced by openmsx::BooleanSetting::setBoolean(), openmsx::FloatSetting::setDouble(), openmsx::EnumSetting< T >::setEnum(), openmsx::IntegerSetting::setInt(), openmsx::ReadOnlySetting::setReadOnlyValue(), openmsx::VideoSourceSetting::setSource(), openmsx::FilenameSetting::setString(), and openmsx::StringSetting::setString().

◆ setValueDirect()

void openmsx::Setting::setValueDirect ( const TclObject value)
finalvirtual

Similar to setValue(), but doesn't trigger Tcl traces.

Like setValue(), the given value may be adjusted or rejected. Should only be used by the Interpreter class.

Implements openmsx::BaseSetting.

Definition at line 155 of file Setting.cc.

References openmsx::BaseSetting::getBaseNameObj(), getCommandController(), getInterpreter(), getValue(), and openmsx::Interpreter::setVariable().

Referenced by init().

◆ tabCompletion()

void openmsx::Setting::tabCompletion ( std::vector< std::string > &  tokens) const
overridevirtual

Complete a partly typed value.

Default implementation does not complete anything, subclasses can override this to complete according to their specific value type.

Implements openmsx::BaseSetting.

Reimplemented in openmsx::VideoSourceSetting.

Definition at line 144 of file Setting.cc.


The documentation for this class was generated from the following files: