KiCad PCB EDA Suite
PARAM< ValueType > Class Template Reference

#include <parameters.h>

Inheritance diagram for PARAM< ValueType >:
PARAM_BASE

Public Member Functions

 PARAM (const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, bool aReadOnly=false)
 
 PARAM (const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, 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

ValueType * m_ptr
 
ValueType m_default
 
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_min
 
ValueType m_max
 
bool m_use_minmax
 

Detailed Description

template<typename ValueType>
class PARAM< ValueType >

Definition at line 82 of file parameters.h.

Constructor & Destructor Documentation

◆ PARAM() [1/2]

template<typename ValueType>
PARAM< ValueType >::PARAM ( const std::string &  aJsonPath,
ValueType *  aPtr,
ValueType  aDefault,
bool  aReadOnly = false 
)
inline

Definition at line 85 of file parameters.h.

86  :
87  PARAM_BASE( aJsonPath, aReadOnly ),
88  m_min(),
89  m_max(),
90  m_use_minmax( false ),
91  m_ptr( aPtr ),
92  m_default( aDefault )
93  { }
ValueType m_min
Definition: parameters.h:150
ValueType m_max
Definition: parameters.h:151
bool m_use_minmax
Definition: parameters.h:152
ValueType * m_ptr
Definition: parameters.h:155
ValueType m_default
Definition: parameters.h:156
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
Definition: parameters.h:35

◆ PARAM() [2/2]

template<typename ValueType>
PARAM< ValueType >::PARAM ( const std::string &  aJsonPath,
ValueType *  aPtr,
ValueType  aDefault,
ValueType  aMin,
ValueType  aMax,
bool  aReadOnly = false 
)
inline

Definition at line 95 of file parameters.h.

96  :
97  PARAM_BASE( aJsonPath, aReadOnly ),
98  m_min( aMin ),
99  m_max( aMax ),
100  m_use_minmax( true ),
101  m_ptr( aPtr ),
102  m_default( aDefault )
103  { }
ValueType m_min
Definition: parameters.h:150
ValueType m_max
Definition: parameters.h:151
bool m_use_minmax
Definition: parameters.h:152
ValueType * m_ptr
Definition: parameters.h:155
ValueType m_default
Definition: parameters.h:156
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
Definition: parameters.h:35

Member Function Documentation

◆ GetDefault()

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

Definition at line 131 of file parameters.h.

132  {
133  return m_default;
134  }
ValueType m_default
Definition: parameters.h:156

◆ 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 68 of file parameters.h.

68 { return m_path; }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:74

References PARAM_BASE::m_path.

◆ Load()

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

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 105 of file parameters.h.

106  {
107  if( m_readOnly )
108  return;
109 
110  if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
111  {
112  ValueType val = *optval;
113 
114  if( m_use_minmax )
115  {
116  if( m_max < val || val < m_min )
117  val = m_default;
118  }
119 
120  *m_ptr = val;
121  }
122  else if( aResetIfMissing )
123  *m_ptr = m_default;
124  }
ValueType m_min
Definition: parameters.h:150
ValueType m_max
Definition: parameters.h:151
std::string m_path
the string used to store the param in json files
Definition: parameters.h:74
bool m_use_minmax
Definition: parameters.h:152
ValueType * m_ptr
Definition: parameters.h:155
ValueType m_default
Definition: parameters.h:156
OPT< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
bool m_readOnly
! True if the parameter pointer should never be overwritten
Definition: parameters.h:77
boost::optional< T > OPT
Definition: optional.h:7

Referenced by PARAM_PATH::Load().

◆ MatchesFile()

template<typename ValueType>
bool PARAM< ValueType >::MatchesFile ( JSON_SETTINGS aSettings) const
inlineoverridevirtual

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 141 of file parameters.h.

142  {
143  if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
144  return *optval == *m_ptr;
145 
146  return false;
147  }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:74
ValueType * m_ptr
Definition: parameters.h:155
OPT< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
boost::optional< T > OPT
Definition: optional.h:7

◆ SetDefault()

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

Implements PARAM_BASE.

Definition at line 136 of file parameters.h.

137  {
138  *m_ptr = m_default;
139  }
ValueType * m_ptr
Definition: parameters.h:155
ValueType m_default
Definition: parameters.h:156

◆ Store()

template<typename ValueType>
void PARAM< 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 126 of file parameters.h.

127  {
128  aSettings->Set<ValueType>( m_path, *m_ptr );
129  }
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...
std::string m_path
the string used to store the param in json files
Definition: parameters.h:74
ValueType * m_ptr
Definition: parameters.h:155

Member Data Documentation

◆ m_default

template<typename ValueType>
ValueType PARAM< ValueType >::m_default
protected

◆ m_max

template<typename ValueType>
ValueType PARAM< ValueType >::m_max
private

Definition at line 151 of file parameters.h.

Referenced by PARAM< wxString >::Load().

◆ m_min

template<typename ValueType>
ValueType PARAM< ValueType >::m_min
private

Definition at line 150 of file parameters.h.

Referenced by PARAM< wxString >::Load().

◆ m_path

◆ m_ptr

template<typename ValueType>
ValueType* PARAM< ValueType >::m_ptr
protected

◆ m_readOnly

bool PARAM_BASE::m_readOnly
protectedinherited

◆ m_use_minmax

template<typename ValueType>
bool PARAM< ValueType >::m_use_minmax
private

Definition at line 152 of file parameters.h.

Referenced by PARAM< wxString >::Load().


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