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 IsDefault () const override
 Checks whether or not this param has been changed from its default value. More...
 
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 ()
 

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

92  :
93  PARAM_BASE( aJsonPath, aReadOnly ),
94  m_min(),
95  m_max(),
96  m_use_minmax( false ),
97  m_ptr( aPtr ),
98  m_default( aDefault )
99  { }
ValueType m_min
Definition: parameters.h:161
ValueType m_max
Definition: parameters.h:162
bool m_use_minmax
Definition: parameters.h:163
ValueType * m_ptr
Definition: parameters.h:166
ValueType m_default
Definition: parameters.h:167
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 101 of file parameters.h.

102  :
103  PARAM_BASE( aJsonPath, aReadOnly ),
104  m_min( aMin ),
105  m_max( aMax ),
106  m_use_minmax( true ),
107  m_ptr( aPtr ),
108  m_default( aDefault )
109  { }
ValueType m_min
Definition: parameters.h:161
ValueType m_max
Definition: parameters.h:162
bool m_use_minmax
Definition: parameters.h:163
ValueType * m_ptr
Definition: parameters.h:166
ValueType m_default
Definition: parameters.h:167
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 137 of file parameters.h.

138  {
139  return m_default;
140  }
ValueType m_default
Definition: parameters.h:167

◆ GetJsonPath()

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

Definition at line 74 of file parameters.h.

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

References PARAM_BASE::m_path.

◆ IsDefault()

template<typename ValueType>
bool PARAM< ValueType >::IsDefault ( ) const
inlineoverridevirtual

Checks whether or not this param has been changed from its default value.

Returns
true if the parameter in memory matches its default value

Implements PARAM_BASE.

Definition at line 147 of file parameters.h.

148  {
149  return *m_ptr == m_default;
150  }
ValueType * m_ptr
Definition: parameters.h:166
ValueType m_default
Definition: parameters.h:167

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

112  {
113  if( m_readOnly )
114  return;
115 
116  if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
117  {
118  ValueType val = *optval;
119 
120  if( m_use_minmax )
121  {
122  if( m_max < val || val < m_min )
123  val = m_default;
124  }
125 
126  *m_ptr = val;
127  }
128  else if( aResetIfMissing )
129  *m_ptr = m_default;
130  }
ValueType m_min
Definition: parameters.h:161
ValueType m_max
Definition: parameters.h:162
std::string m_path
the string used to store the param in json files
Definition: parameters.h:80
bool m_use_minmax
Definition: parameters.h:163
OPT< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
ValueType * m_ptr
Definition: parameters.h:166
ValueType m_default
Definition: parameters.h:167
bool m_readOnly
! True if the parameter pointer should never be overwritten
Definition: parameters.h:83
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 152 of file parameters.h.

153  {
154  if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
155  return *optval == *m_ptr;
156 
157  return false;
158  }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:80
OPT< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
ValueType * m_ptr
Definition: parameters.h:166
boost::optional< T > OPT
Definition: optional.h:7

◆ SetDefault()

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

Implements PARAM_BASE.

Definition at line 142 of file parameters.h.

143  {
144  *m_ptr = m_default;
145  }
ValueType * m_ptr
Definition: parameters.h:166
ValueType m_default
Definition: parameters.h:167

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

133  {
134  aSettings->Set<ValueType>( m_path, *m_ptr );
135  }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:80
ValueType * m_ptr
Definition: parameters.h:166
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...

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

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

◆ m_min

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

Definition at line 161 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 163 of file parameters.h.

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


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