KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PARAM_LAMBDA< ValueType > Class Template Reference

Like a normal param, but with custom getter and setter functions. More...

#include <parameters.h>

Inheritance diagram for PARAM_LAMBDA< ValueType >:
PARAM_BASE

Public Member Functions

 PARAM_LAMBDA (const std::string &aJsonPath, std::function< ValueType()> aGetter, std::function< void(ValueType)> aSetter, ValueType aDefault, bool aReadOnly=false)
 
void Load (JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
 Loads the value of this parameter from JSON to the underlying storage. More...
 
void Store (JSON_SETTINGS *aSettings) const override
 Stores the value of this parameter to the given JSON_SETTINGS object. More...
 
ValueType GetDefault () const
 
void SetDefault () override
 
bool MatchesFile (JSON_SETTINGS *aSettings) const override
 Checks whether the parameter in memory matches the one in a given JSON file. More...
 
const std::string & GetJsonPath () const
 

Protected Attributes

std::string m_path
 the string used to store the param in json files More...
 
bool m_readOnly
 ! True if the parameter pointer should never be overwritten More...
 

Private Attributes

ValueType m_default
 
std::function< ValueType()> m_getter
 
std::function< void(ValueType)> m_setter
 

Detailed Description

template<typename ValueType>
class PARAM_LAMBDA< ValueType >

Like a normal param, but with custom getter and setter functions.

Template Parameters
ValueTypeis the value to store

Definition at line 281 of file parameters.h.

Constructor & Destructor Documentation

◆ PARAM_LAMBDA()

template<typename ValueType >
PARAM_LAMBDA< ValueType >::PARAM_LAMBDA ( const std::string &  aJsonPath,
std::function< ValueType()>  aGetter,
std::function< void(ValueType)>  aSetter,
ValueType  aDefault,
bool  aReadOnly = false 
)
inline

Definition at line 284 of file parameters.h.

Member Function Documentation

◆ GetDefault()

template<typename ValueType >
ValueType PARAM_LAMBDA< ValueType >::GetDefault ( ) const
inline

Definition at line 306 of file parameters.h.

References PARAM_LAMBDA< ValueType >::m_default.

◆ GetJsonPath()

const std::string & PARAM_BASE::GetJsonPath ( ) const
inlineinherited
Returns
the path name of the parameter used to store it in the json file mainly useful in error messages

Definition at line 69 of file parameters.h.

References PARAM_BASE::m_path.

◆ Load()

template<typename ValueType >
void PARAM_LAMBDA< ValueType >::Load ( JSON_SETTINGS aSettings,
bool  aResetIfMissing = true 
) const
overridevirtual

Loads the value of this parameter from JSON to the underlying storage.

Parameters
aSettingsis the JSON_SETTINGS object to load from.
aResetIfMissingif true will set the parameter to its default value if load fails

Implements PARAM_BASE.

Definition at line 32 of file parameters.cpp.

References JSON_SETTINGS::Get(), and JSON_SETTINGS::GetJson().

◆ MatchesFile()

template<typename ValueType >
bool PARAM_LAMBDA< ValueType >::MatchesFile ( JSON_SETTINGS aSettings) const
overridevirtual

Checks whether the parameter in memory matches the one in a given JSON file.

Parameters
aSettingsis a JSON_SETTINGS to check the JSON file contents of
Returns
true if the parameter in memory matches its value in the file

Implements PARAM_BASE.

Definition at line 55 of file parameters.cpp.

References JSON_SETTINGS::Get(), and JSON_SETTINGS::GetJson().

◆ SetDefault()

template<typename ValueType >
void PARAM_LAMBDA< ValueType >::SetDefault ( )
inlineoverridevirtual

◆ Store()

template<typename ValueType >
void PARAM_LAMBDA< ValueType >::Store ( JSON_SETTINGS aSettings) const
inlineoverridevirtual

Stores the value of this parameter to the given JSON_SETTINGS object.

Parameters
aSettingsis the JSON_SETTINGS object to store into.

Implements PARAM_BASE.

Definition at line 295 of file parameters.h.

References PARAM_LAMBDA< ValueType >::m_getter, PARAM_BASE::m_path, and JSON_SETTINGS::Set().

Member Data Documentation

◆ m_default

template<typename ValueType >
ValueType PARAM_LAMBDA< ValueType >::m_default
private

◆ m_getter

template<typename ValueType >
std::function<ValueType()> PARAM_LAMBDA< ValueType >::m_getter
private

Definition at line 321 of file parameters.h.

Referenced by PARAM_LAMBDA< ValueType >::Store().

◆ m_path

◆ m_readOnly

bool PARAM_BASE::m_readOnly
protectedinherited

◆ m_setter

template<typename ValueType >
std::function<void( ValueType )> PARAM_LAMBDA< ValueType >::m_setter
private

Definition at line 323 of file parameters.h.

Referenced by PARAM_LAMBDA< ValueType >::SetDefault().


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