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

478  :
479  PARAM_BASE( aJsonPath, aReadOnly ),
480  m_ptr( aPtr ),
481  m_default( aDefault )
482  { }
std::vector< Type > * m_ptr
Definition: parameters.h:551
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
Definition: parameters.h:35
std::vector< Type > m_default
Definition: parameters.h:553

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

485  :
486  PARAM_BASE( aJsonPath, aReadOnly ),
487  m_ptr( aPtr ),
488  m_default( aDefault )
489  { }
std::vector< Type > * m_ptr
Definition: parameters.h:551
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
Definition: parameters.h:35
std::vector< Type > m_default
Definition: parameters.h:553

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

528  {
529  return *m_ptr == m_default;
530  }
std::vector< Type > * m_ptr
Definition: parameters.h:551
std::vector< Type > m_default
Definition: parameters.h:553

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

492  {
493  if( m_readOnly )
494  return;
495 
496  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
497  {
498  std::vector<Type> val;
499 
500  if( js->is_array() )
501  {
502  for( const auto& el : js->items() )
503  val.push_back( el.value().get<Type>() );
504  }
505 
506  *m_ptr = val;
507  }
508  else if( aResetIfMissing )
509  *m_ptr = m_default;
510  }
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:551
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:553

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

533  {
534  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
535  {
536  if( js->is_array() )
537  {
538  std::vector<Type> val;
539 
540  for( const auto& el : js->items() )
541  val.emplace_back( el.value().get<Type>() );
542 
543  return val == *m_ptr;
544  }
545  }
546 
547  return false;
548  }
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:551
boost::optional< T > OPT
Definition: optional.h:7

◆ SetDefault()

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

Implements PARAM_BASE.

Definition at line 522 of file parameters.h.

523  {
524  *m_ptr = m_default;
525  }
std::vector< Type > * m_ptr
Definition: parameters.h:551
std::vector< Type > m_default
Definition: parameters.h:553

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

513  {
514  nlohmann::json js = nlohmann::json::array();
515 
516  for( const auto& el : *m_ptr )
517  js.push_back( el );
518 
519  aSettings->Set<nlohmann::json>( m_path, js );
520  }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:80
nlohmann::json json
Definition: gerbview.cpp:39
std::vector< Type > * m_ptr
Definition: parameters.h:551
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


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