KiCad PCB EDA Suite
PARAM_PATH_LIST Class Reference

Represents a list of strings holding directory paths. More...

#include <parameters.h>

Inheritance diagram for PARAM_PATH_LIST:
PARAM_LIST< wxString > PARAM_BASE

Public Member Functions

 PARAM_PATH_LIST (const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault, bool aReadOnly=false)
 
 PARAM_PATH_LIST (const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > 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...
 
bool MatchesFile (JSON_SETTINGS *aSettings) const override
 Checks whether the parameter in memory matches the one in a given JSON file. More...
 
void SetDefault () override
 
bool IsDefault () const override
 Checks whether or not this param has been changed from its default value. More...
 
const std::string & GetJsonPath ()
 

Protected Attributes

std::vector< wxString > * m_ptr
 
std::vector< wxString > 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 Member Functions

wxString toFileFormat (const wxString &aString) const
 
wxString fromFileFormat (const wxString &aString) const
 

Detailed Description

Represents a list of strings holding directory paths.

Normalizes paths to unix directory separator style in the file.

Definition at line 560 of file parameters.h.

Constructor & Destructor Documentation

◆ PARAM_PATH_LIST() [1/2]

PARAM_PATH_LIST::PARAM_PATH_LIST ( const std::string &  aJsonPath,
std::vector< wxString > *  aPtr,
std::initializer_list< wxString >  aDefault,
bool  aReadOnly = false 
)
inline

Definition at line 563 of file parameters.h.

564  :
565  PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
566  { }
PARAM_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault, bool aReadOnly=false)
Definition: parameters.h:477

◆ PARAM_PATH_LIST() [2/2]

PARAM_PATH_LIST::PARAM_PATH_LIST ( const std::string &  aJsonPath,
std::vector< wxString > *  aPtr,
std::vector< wxString >  aDefault,
bool  aReadOnly = false 
)
inline

Definition at line 568 of file parameters.h.

569  :
570  PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
571  { }
PARAM_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault, bool aReadOnly=false)
Definition: parameters.h:477

Member Function Documentation

◆ fromFileFormat()

wxString PARAM_PATH_LIST::fromFileFormat ( const wxString &  aString) const
inlineprivate

Definition at line 620 of file parameters.h.

621  {
622  wxString ret = aString;
623 #ifdef __WINDOWS__
624  ret.Replace( wxT( "/" ), wxT( "\\" ) );
625 #endif
626  return ret;
627  }

Referenced by Load(), and MatchesFile().

◆ 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()

bool PARAM_LIST< wxString >::IsDefault ( ) const
inlineoverridevirtualinherited

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< wxString > * m_ptr
Definition: parameters.h:551
std::vector< wxString > m_default
Definition: parameters.h:553

◆ Load()

void PARAM_PATH_LIST::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 573 of file parameters.h.

574  {
575  if( m_readOnly )
576  return;
577 
578  PARAM_LIST::Load( aSettings, aResetIfMissing );
579 
580  for( size_t i = 0; i < m_ptr->size(); i++ )
581  ( *m_ptr )[i] = fromFileFormat( ( *m_ptr )[i] );
582  }
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition: parameters.h:491
wxString fromFileFormat(const wxString &aString) const
Definition: parameters.h:620
std::vector< wxString > * m_ptr
Definition: parameters.h:551
bool m_readOnly
! True if the parameter pointer should never be overwritten
Definition: parameters.h:83

References fromFileFormat(), PARAM_LIST< Type >::Load(), PARAM_LIST< wxString >::m_ptr, and PARAM_BASE::m_readOnly.

◆ MatchesFile()

bool PARAM_PATH_LIST::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 594 of file parameters.h.

595  {
596  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
597  {
598  if( js->is_array() )
599  {
600  std::vector<wxString> val;
601 
602  for( const auto& el : js->items() )
603  val.emplace_back( fromFileFormat( el.value().get<wxString>() ) );
604 
605  return val == *m_ptr;
606  }
607  }
608 
609  return false;
610  }
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....
wxString fromFileFormat(const wxString &aString) const
Definition: parameters.h:620
std::vector< wxString > * m_ptr
Definition: parameters.h:551
boost::optional< T > OPT
Definition: optional.h:7

References fromFileFormat(), JSON_SETTINGS::GetJson(), PARAM_BASE::m_path, and PARAM_LIST< wxString >::m_ptr.

◆ SetDefault()

void PARAM_LIST< wxString >::SetDefault ( )
inlineoverridevirtualinherited

Implements PARAM_BASE.

Definition at line 522 of file parameters.h.

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

◆ Store()

void PARAM_PATH_LIST::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 584 of file parameters.h.

585  {
586  nlohmann::json js = nlohmann::json::array();
587 
588  for( const auto& el : *m_ptr )
589  js.push_back( toFileFormat( el ) );
590 
591  aSettings->Set<nlohmann::json>( m_path, js );
592  }
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
wxString toFileFormat(const wxString &aString) const
Definition: parameters.h:613
std::vector< wxString > * 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...

References PARAM_BASE::m_path, PARAM_LIST< wxString >::m_ptr, JSON_SETTINGS::Set(), and toFileFormat().

◆ toFileFormat()

wxString PARAM_PATH_LIST::toFileFormat ( const wxString &  aString) const
inlineprivate

Definition at line 613 of file parameters.h.

614  {
615  wxString ret = aString;
616  ret.Replace( wxT( "\\" ), wxT( "/" ) );
617  return ret;
618  }

Referenced by Store().

Member Data Documentation

◆ m_default

std::vector<wxString > PARAM_LIST< wxString >::m_default
protectedinherited

Definition at line 553 of file parameters.h.

◆ m_path

◆ m_ptr

std::vector<wxString >* PARAM_LIST< wxString >::m_ptr
protectedinherited

Definition at line 551 of file parameters.h.

◆ m_readOnly


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