KiCad PCB EDA Suite
parameters.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef _PARAMETERS_H
22 #define _PARAMETERS_H
23 
24 #include <string>
25 #include <utility>
26 #include <math/util.h>
27 
28 #include <core/optional.h>
29 #include <settings/json_settings.h>
30 
31 
33 {
34 public:
35  PARAM_BASE( std::string aJsonPath, bool aReadOnly ) :
36  m_path( std::move( aJsonPath ) ),
37  m_readOnly( aReadOnly )
38  {}
39 
40  virtual ~PARAM_BASE() = default;
41 
47  virtual void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const = 0;
48 
53  virtual void Store( JSON_SETTINGS* aSettings ) const = 0;
54 
55  virtual void SetDefault() = 0;
56 
61  virtual bool IsDefault() const = 0;
62 
68  virtual bool MatchesFile( JSON_SETTINGS* aSettings ) const = 0;
69 
74  const std::string& GetJsonPath() const { return m_path; }
75 
76 protected:
80  std::string m_path;
81 
83  bool m_readOnly;
84 };
85 
86 
87 template<typename ValueType>
88 class PARAM : public PARAM_BASE
89 {
90 public:
91  PARAM( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
92  bool aReadOnly = false ) :
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  { }
100 
101  PARAM( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault, ValueType aMin,
102  ValueType aMax, bool aReadOnly = false ) :
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  { }
110 
111  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
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  }
131 
132  void Store( JSON_SETTINGS* aSettings ) const override
133  {
134  aSettings->Set<ValueType>( m_path, *m_ptr );
135  }
136 
137  ValueType GetDefault() const
138  {
139  return m_default;
140  }
141 
142  void SetDefault() override
143  {
144  *m_ptr = m_default;
145  }
146 
147  bool IsDefault() const override
148  {
149  return *m_ptr == m_default;
150  }
151 
152  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
153  {
154  if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
155  return *optval == *m_ptr;
156 
157  return false;
158  }
159 
160 private:
161  ValueType m_min;
162  ValueType m_max;
164 
165 protected:
166  ValueType* m_ptr;
167  ValueType m_default;
168 };
169 
173 class PARAM_PATH : public PARAM<wxString>
174 {
175 public:
176  PARAM_PATH( const std::string& aJsonPath, wxString* aPtr, const wxString& aDefault,
177  bool aReadOnly = false ) :
178  PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
179  { }
180 
181  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
182  {
183  if( m_readOnly )
184  return;
185 
186  PARAM::Load( aSettings, aResetIfMissing );
187 
188  *m_ptr = fromFileFormat( *m_ptr );
189  }
190 
191  void Store( JSON_SETTINGS* aSettings ) const override
192  {
193  aSettings->Set<wxString>( m_path, toFileFormat( *m_ptr ) );
194  }
195 
196  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
197  {
198  if( OPT<wxString> optval = aSettings->Get<wxString>( m_path ) )
199  return fromFileFormat( *optval ) == *m_ptr;
200 
201  return false;
202  }
203 
204 private:
205  wxString toFileFormat( const wxString& aString ) const
206  {
207  wxString ret = aString;
208  ret.Replace( wxT( "\\" ), wxT( "/" ) );
209  return ret;
210  }
211 
212  wxString fromFileFormat( const wxString& aString ) const
213  {
214  wxString ret = aString;
215 #ifdef __WINDOWS__
216  ret.Replace( wxT( "/" ), wxT( "\\" ) );
217 #endif
218  return ret;
219  }
220 };
221 
225 template<typename EnumType>
226 class PARAM_ENUM : public PARAM_BASE
227 {
228 public:
229  PARAM_ENUM( const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
230  EnumType aMin, EnumType aMax, bool aReadOnly = false ) :
231  PARAM_BASE( aJsonPath, aReadOnly ),
232  m_ptr( aPtr ),
233  m_min( aMin ),
234  m_max( aMax ),
235  m_default( aDefault )
236  {
237  }
238 
239  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
240  {
241  if( m_readOnly )
242  return;
243 
244  if( OPT<int> val = aSettings->Get<int>( m_path ) )
245  {
246  if( *val >= static_cast<int>( m_min ) && *val <= static_cast<int>( m_max ) )
247  *m_ptr = static_cast<EnumType>( *val );
248  else if( aResetIfMissing )
249  *m_ptr = m_default;
250 
251  }
252  else if( aResetIfMissing )
253  *m_ptr = m_default;
254  }
255 
256  void Store( JSON_SETTINGS* aSettings ) const override
257  {
258  aSettings->Set<int>( m_path, static_cast<int>( *m_ptr ) );
259  }
260 
261  EnumType GetDefault() const
262  {
263  return m_default;
264  }
265 
266  void SetDefault() override
267  {
268  *m_ptr = m_default;
269  }
270 
271  bool IsDefault() const override
272  {
273  return *m_ptr == m_default;
274  }
275 
276  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
277  {
278  if( OPT<int> val = aSettings->Get<int>( m_path ) )
279  return *val == static_cast<int>( *m_ptr );
280 
281  return false;
282  }
283 
284 private:
285  EnumType* m_ptr;
286  EnumType m_min;
287  EnumType m_max;
288  EnumType m_default;
289 };
290 
295 template<typename ValueType>
296 class PARAM_LAMBDA : public PARAM_BASE
297 {
298 public:
299  PARAM_LAMBDA( const std::string& aJsonPath, std::function<ValueType()> aGetter,
300  std::function<void( ValueType )> aSetter, ValueType aDefault,
301  bool aReadOnly = false ) :
302  PARAM_BASE( aJsonPath, aReadOnly ),
303  m_default( aDefault ),
304  m_getter( aGetter ),
305  m_setter( aSetter )
306  { }
307 
308  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
309 
310  void Store( JSON_SETTINGS* aSettings ) const override
311  {
312  try
313  {
314  aSettings->Set<ValueType>( m_path, m_getter() );
315  }
316  catch( ... )
317  {
318  }
319  }
320 
321  ValueType GetDefault() const
322  {
323  return m_default;
324  }
325 
326  void SetDefault() override
327  {
328  m_setter( m_default );
329  }
330 
331  bool IsDefault() const override
332  {
333  return m_getter() == m_default;
334  }
335 
336  bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
337 
338 private:
339  ValueType m_default;
340 
341  std::function<ValueType()> m_getter;
342 
343  std::function<void( ValueType )> m_setter;
344 };
345 
346 
353 template<typename ValueType>
355 {
356 public:
357  PARAM_SCALED( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
358  double aScale = 1.0, bool aReadOnly = false ) :
359  PARAM_BASE( aJsonPath, aReadOnly ),
360  m_ptr( aPtr ),
361  m_default( aDefault ),
362  m_min(),
363  m_max(),
364  m_use_minmax( false ),
365  m_scale( aScale )
366  { }
367 
368  PARAM_SCALED( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
369  ValueType aMin, ValueType aMax, double aScale = 1.0, bool aReadOnly = false ) :
370  PARAM_BASE( aJsonPath, aReadOnly ),
371  m_ptr( aPtr ),
372  m_default( aDefault ),
373  m_min( aMin ),
374  m_max( aMax ),
375  m_use_minmax( true ),
376  m_scale( aScale )
377  { }
378 
379  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
380  {
381  if( m_readOnly )
382  return;
383 
384  double dval = m_default * m_scale;
385 
386  if( OPT<double> optval = aSettings->Get<double>( m_path ) )
387  dval = *optval;
388  else if( !aResetIfMissing )
389  return;
390 
391  ValueType val = KiROUND<ValueType>( dval / m_scale );
392 
393  if( m_use_minmax )
394  {
395  if( val > m_max || val < m_min )
396  val = m_default;
397  }
398 
399  *m_ptr = val;
400  }
401 
402  void Store( JSON_SETTINGS* aSettings) const override
403  {
404  aSettings->Set<double>( m_path, *m_ptr * m_scale );
405  }
406 
407  ValueType GetDefault() const
408  {
409  return m_default;
410  }
411 
412  virtual void SetDefault() override
413  {
414  *m_ptr = m_default;
415  }
416 
417  bool IsDefault() const override
418  {
419  return *m_ptr == m_default;
420  }
421 
422  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
423  {
424  if( OPT<double> optval = aSettings->Get<double>( m_path ) )
425  return *optval == ( *m_ptr * m_scale );
426 
427  return false;
428  }
429 
430 private:
431  ValueType* m_ptr;
432  ValueType m_default;
433  ValueType m_min;
434  ValueType m_max;
436  double m_scale;
437 };
438 
439 template<typename Type>
440 class PARAM_LIST : public PARAM_BASE
441 {
442 public:
443  PARAM_LIST( const std::string& aJsonPath, std::vector<Type>* aPtr,
444  std::initializer_list<Type> aDefault, bool aReadOnly = false ) :
445  PARAM_BASE( aJsonPath, aReadOnly ),
446  m_ptr( aPtr ),
447  m_default( aDefault )
448  { }
449 
450  PARAM_LIST( const std::string& aJsonPath, std::vector<Type>* aPtr,
451  std::vector<Type> aDefault, bool aReadOnly = false ) :
452  PARAM_BASE( aJsonPath, aReadOnly ),
453  m_ptr( aPtr ),
454  m_default( aDefault )
455  { }
456 
457  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
458 
459  void Store( JSON_SETTINGS* aSettings) const override;
460 
461  void SetDefault() override
462  {
463  *m_ptr = m_default;
464  }
465 
466  bool IsDefault() const override
467  {
468  return *m_ptr == m_default;
469  }
470 
471  bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
472 
473 protected:
474  std::vector<Type>* m_ptr;
475 
476  std::vector<Type> m_default;
477 };
478 
483 class PARAM_PATH_LIST : public PARAM_LIST<wxString>
484 {
485 public:
486  PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
487  std::initializer_list<wxString> aDefault, bool aReadOnly = false ) :
488  PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
489  { }
490 
491  PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
492  std::vector<wxString> aDefault, bool aReadOnly = false ) :
493  PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
494  { }
495 
496  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
497  {
498  if( m_readOnly )
499  return;
500 
501  PARAM_LIST::Load( aSettings, aResetIfMissing );
502 
503  for( size_t i = 0; i < m_ptr->size(); i++ )
504  ( *m_ptr )[i] = fromFileFormat( ( *m_ptr )[i] );
505  }
506 
507  void Store( JSON_SETTINGS* aSettings) const override;
508 
509  bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
510 
511 private:
512  wxString toFileFormat( const wxString& aString ) const
513  {
514  wxString ret = aString;
515  ret.Replace( wxT( "\\" ), wxT( "/" ) );
516  return ret;
517  }
518 
519  wxString fromFileFormat( const wxString& aString ) const
520  {
521  wxString ret = aString;
522 #ifdef __WINDOWS__
523  ret.Replace( wxT( "/" ), wxT( "\\" ) );
524 #endif
525  return ret;
526  }
527 };
528 
541 template<typename Value>
542 class PARAM_MAP : public PARAM_BASE
543 {
544 public:
545  PARAM_MAP( const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
546  std::initializer_list<std::pair<const std::string, Value>> aDefault,
547  bool aReadOnly = false ) :
548  PARAM_BASE( aJsonPath, aReadOnly ),
549  m_ptr( aPtr ),
550  m_default( aDefault )
551  { }
552 
553  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
554 
555  void Store( JSON_SETTINGS* aSettings) const override;
556 
557  virtual void SetDefault() override
558  {
559  *m_ptr = m_default;
560  }
561 
562  bool IsDefault() const override
563  {
564  return *m_ptr == m_default;
565  }
566 
567  bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
568 
569 private:
570  std::map<std::string, Value>* m_ptr;
571 
572  std::map<std::string, Value> m_default;
573 };
574 
575 
580 {
581 public:
582  PARAM_WXSTRING_MAP( const std::string& aJsonPath, std::map<wxString, wxString>* aPtr,
583  std::initializer_list<std::pair<const wxString, wxString>> aDefault,
584  bool aReadOnly = false ) :
585  PARAM_BASE( aJsonPath, aReadOnly ),
586  m_ptr( aPtr ),
587  m_default( aDefault )
588  { }
589 
590  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
591 
592  void Store( JSON_SETTINGS* aSettings) const override;
593 
594  virtual void SetDefault() override
595  {
596  *m_ptr = m_default;
597  }
598 
599  bool IsDefault() const override
600  {
601  return *m_ptr == m_default;
602  }
603 
604  bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
605 
606 private:
607  std::map<wxString, wxString>* m_ptr;
608 
609  std::map<wxString, wxString> m_default;
610 };
611 
612 #endif
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition: parameters.cpp:172
ValueType m_min
Definition: parameters.h:161
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:181
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...
ValueType m_default
Definition: parameters.h:432
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > aDefault, bool aReadOnly=false)
Definition: parameters.h:491
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:417
virtual void SetDefault() override
Definition: parameters.h:412
virtual void SetDefault() override
Definition: parameters.h:594
Like a normal param, but with custom getter and setter functions.
Definition: parameters.h:296
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:147
std::map< std::string, Value > m_default
Definition: parameters.h:572
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:402
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.cpp:268
ValueType m_max
Definition: parameters.h:162
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, double aScale=1.0, bool aReadOnly=false)
Definition: parameters.h:357
virtual bool IsDefault() const =0
Checks whether or not this param has been changed from its default value.
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:331
EnumType GetDefault() const
Definition: parameters.h:261
std::string m_path
the string used to store the param in json files
Definition: parameters.h:80
Represents a map of <std::string, Value>.
Definition: parameters.h:542
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:196
void SetDefault() override
Definition: parameters.h:461
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.cpp:152
std::map< wxString, wxString > * m_ptr
Definition: parameters.h:607
double m_scale
Definition: parameters.h:436
EnumType m_default
Definition: parameters.h:288
Definition: bitmap.cpp:64
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.cpp:193
bool m_use_minmax
Definition: parameters.h:163
Stores an enum as an integer.
Definition: parameters.h:226
std::map< wxString, wxString > m_default
Definition: parameters.h:609
EnumType m_max
Definition: parameters.h:287
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:191
std::function< ValueType()> m_getter
Definition: parameters.h:341
PARAM_LAMBDA(const std::string &aJsonPath, std::function< ValueType()> aGetter, std::function< void(ValueType)> aSetter, ValueType aDefault, bool aReadOnly=false)
Definition: parameters.h:299
virtual void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const =0
Loads the value of this parameter from JSON to the underlying storage.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.cpp:54
std::function< void(ValueType)> m_setter
Definition: parameters.h:343
PARAM_PATH(const std::string &aJsonPath, wxString *aPtr, const wxString &aDefault, bool aReadOnly=false)
Definition: parameters.h:176
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault, bool aReadOnly=false)
Definition: parameters.h:486
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.cpp:254
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:422
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition: parameters.cpp:31
Stores a path as a string with directory separators normalized to unix-style.
Definition: parameters.h:173
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, bool aReadOnly=false)
Definition: parameters.h:91
void SetDefault() override
Definition: parameters.h:142
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:599
bool m_use_minmax
Definition: parameters.h:435
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:496
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.cpp:141
wxString fromFileFormat(const wxString &aString) const
Definition: parameters.h:519
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:152
void SetDefault() override
Definition: parameters.h:266
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition: parameters.cpp:80
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:132
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition: parameters.h:354
PARAM_ENUM(const std::string &aJsonPath, EnumType *aPtr, EnumType aDefault, EnumType aMin, EnumType aMax, bool aReadOnly=false)
Definition: parameters.h:229
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:276
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition: parameters.cpp:232
virtual ~PARAM_BASE()=default
virtual void SetDefault() override
Definition: parameters.h:557
wxString toFileFormat(const wxString &aString) const
Definition: parameters.h:512
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:310
virtual void Store(JSON_SETTINGS *aSettings) const =0
Stores the value of this parameter to the given JSON_SETTINGS object.
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:562
std::vector< Type > * m_ptr
Definition: parameters.h:474
PARAM_MAP(const std::string &aJsonPath, std::map< std::string, Value > *aPtr, std::initializer_list< std::pair< const std::string, Value >> aDefault, bool aReadOnly=false)
Definition: parameters.h:545
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
ValueType m_default
Definition: parameters.h:339
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, double aScale=1.0, bool aReadOnly=false)
Definition: parameters.h:368
EnumType m_min
Definition: parameters.h:286
virtual void SetDefault()=0
std::map< std::string, Value > * m_ptr
Definition: parameters.h:570
A helper for <wxString, wxString> maps.
Definition: parameters.h:579
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.cpp:205
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:239
OPT< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
ValueType m_min
Definition: parameters.h:433
bool m_readOnly
! True if the parameter pointer should never be overwritten
Definition: parameters.h:83
ValueType GetDefault() const
Definition: parameters.h:321
virtual bool MatchesFile(JSON_SETTINGS *aSettings) const =0
Checks whether the parameter in memory matches the one in a given JSON file.
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::vector< Type > aDefault, bool aReadOnly=false)
Definition: parameters.h:450
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:379
wxString fromFileFormat(const wxString &aString) const
Definition: parameters.h:212
boost::optional< T > OPT
Definition: optional.h:7
PARAM_WXSTRING_MAP(const std::string &aJsonPath, std::map< wxString, wxString > *aPtr, std::initializer_list< std::pair< const wxString, wxString >> aDefault, bool aReadOnly=false)
Definition: parameters.h:582
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:466
ValueType m_max
Definition: parameters.h:434
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:271
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
Definition: parameters.h:443
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:256
ValueType GetDefault() const
Definition: parameters.h:407
Represents a list of strings holding directory paths.
Definition: parameters.h:483
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, bool aReadOnly=false)
Definition: parameters.h:101
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.cpp:115
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.cpp:103
EnumType * m_ptr
Definition: parameters.h:285
wxString toFileFormat(const wxString &aString) const
Definition: parameters.h:205
ValueType * m_ptr
Definition: parameters.h:431
void SetDefault() override
Definition: parameters.h:326
const std::string & GetJsonPath() const
Definition: parameters.h:74
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:111
std::vector< Type > m_default
Definition: parameters.h:476
ValueType GetDefault() const
Definition: parameters.h:137