KiCad PCB EDA Suite
PARAM_LIST< Type > Class Template Reference

#include <parameters.h>

Inheritance diagram for PARAM_LIST< Type >:
PARAM_BASE

Public Member Functions

 PARAM_LIST (const std::string &aJsonPath, std::vector< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
 
 PARAM_LIST (const std::string &aJsonPath, std::vector< Type > *aPtr, std::vector< Type > 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...
 
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

std::vector< Type > * m_ptr
 
std::vector< Type > 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...
 

Detailed Description

template<typename Type>
class PARAM_LIST< Type >

Definition at line 405 of file parameters.h.

Constructor & Destructor Documentation

◆ PARAM_LIST() [1/2]

template<typename Type>
PARAM_LIST< Type >::PARAM_LIST ( const std::string &  aJsonPath,
std::vector< Type > *  aPtr,
std::initializer_list< Type >  aDefault,
bool  aReadOnly = false 
)
inline

Definition at line 408 of file parameters.h.

409  :
410  PARAM_BASE( aJsonPath, aReadOnly ),
411  m_ptr( aPtr ),
412  m_default( aDefault )
413  { }
std::vector< Type > * m_ptr
Definition: parameters.h:482
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
Definition: parameters.h:35
std::vector< Type > m_default
Definition: parameters.h:484

◆ PARAM_LIST() [2/2]

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

Definition at line 415 of file parameters.h.

416  :
417  PARAM_BASE( aJsonPath, aReadOnly ),
418  m_ptr( aPtr ),
419  m_default( aDefault )
420  { }
std::vector< Type > * m_ptr
Definition: parameters.h:482
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
Definition: parameters.h:35
std::vector< Type > m_default
Definition: parameters.h:484

Member Function Documentation

◆ 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 Type>
bool PARAM_LIST< Type >::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 458 of file parameters.h.

459  {
460  return *m_ptr == m_default;
461  }
std::vector< Type > * m_ptr
Definition: parameters.h:482
std::vector< Type > m_default
Definition: parameters.h:484

◆ Load()

template<typename Type>
void PARAM_LIST< Type >::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 422 of file parameters.h.

423  {
424  if( m_readOnly )
425  return;
426 
427  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
428  {
429  std::vector<Type> val;
430 
431  if( js->is_array() )
432  {
433  for( const auto& el : js->items() )
434  val.push_back( el.value().get<Type>() );
435  }
436 
437  *m_ptr = val;
438  }
439  else if( aResetIfMissing )
440  *m_ptr = m_default;
441  }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:80
OPT< nlohmann::json > GetJson(const std::string &aPath) const
Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1....
std::vector< Type > * m_ptr
Definition: parameters.h:482
bool m_readOnly
! True if the parameter pointer should never be overwritten
Definition: parameters.h:83
boost::optional< T > OPT
Definition: optional.h:7
std::vector< Type > m_default
Definition: parameters.h:484

Referenced by PARAM_PATH_LIST::Load().

◆ MatchesFile()

template<typename Type>
bool PARAM_LIST< Type >::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 463 of file parameters.h.

464  {
465  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
466  {
467  if( js->is_array() )
468  {
469  std::vector<Type> val;
470 
471  for( const auto& el : js->items() )
472  val.emplace_back( el.value().get<Type>() );
473 
474  return val == *m_ptr;
475  }
476  }
477 
478  return false;
479  }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:80
OPT< nlohmann::json > GetJson(const std::string &aPath) const
Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1....
std::vector< Type > * m_ptr
Definition: parameters.h:482
boost::optional< T > OPT
Definition: optional.h:7

◆ SetDefault()

template<typename Type>
void PARAM_LIST< Type >::SetDefault ( )
inlineoverridevirtual

Implements PARAM_BASE.

Definition at line 453 of file parameters.h.

454  {
455  *m_ptr = m_default;
456  }
std::vector< Type > * m_ptr
Definition: parameters.h:482
std::vector< Type > m_default
Definition: parameters.h:484

◆ Store()

template<typename Type>
void PARAM_LIST< Type >::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 443 of file parameters.h.

444  {
445  nlohmann::json js = nlohmann::json::array();
446 
447  for( const auto& el : *m_ptr )
448  js.push_back( el );
449 
450  aSettings->Set<nlohmann::json>( m_path, js );
451  }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:80
nlohmann::json json
Definition: gerbview.cpp:40
std::vector< Type > * m_ptr
Definition: parameters.h:482
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 Type>
std::vector<Type> PARAM_LIST< Type >::m_default
protected

◆ m_path

◆ m_ptr

◆ m_readOnly

bool PARAM_BASE::m_readOnly
protectedinherited

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