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 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() { 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, 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  if( m_readOnly )
311  return;
312 
313  if( std::is_same<ValueType, nlohmann::json>::value )
314  {
315  if( OPT<nlohmann::json> optval = aSettings->GetJson( m_path ) )
316  m_setter( *optval );
317  else
318  m_setter( m_default );
319  }
320  else
321  {
322  if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
323  m_setter( *optval );
324  else
325  m_setter( m_default );
326  }
327  }
328 
329  void Store( JSON_SETTINGS* aSettings ) const override
330  {
331  try
332  {
333  aSettings->Set<ValueType>( m_path, m_getter() );
334  }
335  catch( ... )
336  {
337  }
338  }
339 
340  ValueType GetDefault() const
341  {
342  return m_default;
343  }
344 
345  void SetDefault() override
346  {
347  m_setter( m_default );
348  }
349 
350  bool IsDefault() const override
351  {
352  return m_getter() == m_default;
353  }
354 
355  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
356  {
357  if( std::is_same<ValueType, nlohmann::json>::value )
358  {
359  if( OPT<nlohmann::json> optval = aSettings->GetJson( m_path ) )
360  return *optval == m_default;
361  }
362  else
363  {
364  if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
365  return *optval == m_default;
366  }
367 
368  // Not in file
369  return false;
370  }
371 
372 private:
373  ValueType m_default;
374 
375  std::function<ValueType()> m_getter;
376 
377  std::function<void( ValueType )> m_setter;
378 };
379 
380 
387 template<typename ValueType>
389 {
390 public:
391  PARAM_SCALED( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
392  double aScale = 1.0, bool aReadOnly = false ) :
393  PARAM_BASE( aJsonPath, aReadOnly ),
394  m_ptr( aPtr ),
395  m_default( aDefault ),
396  m_min(),
397  m_max(),
398  m_use_minmax( false ),
399  m_scale( aScale )
400  { }
401 
402  PARAM_SCALED( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
403  ValueType aMin, ValueType aMax, double aScale = 1.0, bool aReadOnly = false ) :
404  PARAM_BASE( aJsonPath, aReadOnly ),
405  m_ptr( aPtr ),
406  m_default( aDefault ),
407  m_min( aMin ),
408  m_max( aMax ),
409  m_use_minmax( true ),
410  m_scale( aScale )
411  { }
412 
413  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
414  {
415  if( m_readOnly )
416  return;
417 
418  double dval = m_default * m_scale;
419 
420  if( OPT<double> optval = aSettings->Get<double>( m_path ) )
421  dval = *optval;
422  else if( !aResetIfMissing )
423  return;
424 
425  ValueType val = KiROUND<ValueType>( dval / m_scale );
426 
427  if( m_use_minmax )
428  {
429  if( val > m_max || val < m_min )
430  val = m_default;
431  }
432 
433  *m_ptr = val;
434  }
435 
436  void Store( JSON_SETTINGS* aSettings) const override
437  {
438  aSettings->Set<double>( m_path, *m_ptr * m_scale );
439  }
440 
441  ValueType GetDefault() const
442  {
443  return m_default;
444  }
445 
446  virtual void SetDefault() override
447  {
448  *m_ptr = m_default;
449  }
450 
451  bool IsDefault() const override
452  {
453  return *m_ptr == m_default;
454  }
455 
456  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
457  {
458  if( OPT<double> optval = aSettings->Get<double>( m_path ) )
459  return *optval == ( *m_ptr * m_scale );
460 
461  return false;
462  }
463 
464 private:
465  ValueType* m_ptr;
466  ValueType m_default;
467  ValueType m_min;
468  ValueType m_max;
470  double m_scale;
471 };
472 
473 template<typename Type>
474 class PARAM_LIST : public PARAM_BASE
475 {
476 public:
477  PARAM_LIST( const std::string& aJsonPath, std::vector<Type>* aPtr,
478  std::initializer_list<Type> aDefault, bool aReadOnly = false ) :
479  PARAM_BASE( aJsonPath, aReadOnly ),
480  m_ptr( aPtr ),
481  m_default( aDefault )
482  { }
483 
484  PARAM_LIST( const std::string& aJsonPath, std::vector<Type>* aPtr,
485  std::vector<Type> aDefault, bool aReadOnly = false ) :
486  PARAM_BASE( aJsonPath, aReadOnly ),
487  m_ptr( aPtr ),
488  m_default( aDefault )
489  { }
490 
491  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
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  }
511 
512  void Store( JSON_SETTINGS* aSettings) const override
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  }
521 
522  void SetDefault() override
523  {
524  *m_ptr = m_default;
525  }
526 
527  bool IsDefault() const override
528  {
529  return *m_ptr == m_default;
530  }
531 
532  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
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  }
549 
550 protected:
551  std::vector<Type>* m_ptr;
552 
553  std::vector<Type> m_default;
554 };
555 
560 class PARAM_PATH_LIST : public PARAM_LIST<wxString>
561 {
562 public:
563  PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
564  std::initializer_list<wxString> aDefault, bool aReadOnly = false ) :
565  PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
566  { }
567 
568  PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
569  std::vector<wxString> aDefault, bool aReadOnly = false ) :
570  PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
571  { }
572 
573  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
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  }
583 
584  void Store( JSON_SETTINGS* aSettings) const override
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  }
593 
594  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
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  }
611 
612 private:
613  wxString toFileFormat( const wxString& aString ) const
614  {
615  wxString ret = aString;
616  ret.Replace( wxT( "\\" ), wxT( "/" ) );
617  return ret;
618  }
619 
620  wxString fromFileFormat( const wxString& aString ) const
621  {
622  wxString ret = aString;
623 #ifdef __WINDOWS__
624  ret.Replace( wxT( "/" ), wxT( "\\" ) );
625 #endif
626  return ret;
627  }
628 };
629 
642 template<typename Value>
643 class PARAM_MAP : public PARAM_BASE
644 {
645 public:
646  PARAM_MAP( const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
647  std::initializer_list<std::pair<const std::string, Value>> aDefault,
648  bool aReadOnly = false ) :
649  PARAM_BASE( aJsonPath, aReadOnly ),
650  m_ptr( aPtr ),
651  m_default( aDefault )
652  { }
653 
654  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
655  {
656  if( m_readOnly )
657  return;
658 
659  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
660  {
661  if( js->is_object() )
662  {
663  m_ptr->clear();
664 
665  for( const auto& el : js->items() )
666  ( *m_ptr )[ el.key() ] = el.value().get<Value>();
667  }
668  }
669  else if( aResetIfMissing )
670  *m_ptr = m_default;
671  }
672 
673  void Store( JSON_SETTINGS* aSettings) const override
674  {
675  nlohmann::json js( {} );
676 
677  for( const auto& el : *m_ptr )
678  js[ el.first ] = el.second;
679 
680  aSettings->Set<nlohmann::json>( m_path, js );
681  }
682 
683  virtual void SetDefault() override
684  {
685  *m_ptr = m_default;
686  }
687 
688  bool IsDefault() const override
689  {
690  return *m_ptr == m_default;
691  }
692 
693  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
694  {
695  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
696  {
697  if( js->is_object() )
698  {
699  if( m_ptr->size() != js->size() )
700  return false;
701 
702  std::map<std::string, Value> val;
703 
704  for( const auto& el : js->items() )
705  val[ el.key() ] = el.value().get<Value>();
706 
707  return val == *m_ptr;
708  }
709  }
710 
711  return false;
712  }
713 
714 private:
715  std::map<std::string, Value>* m_ptr;
716 
717  std::map<std::string, Value> m_default;
718 };
719 
720 
725 {
726 public:
727  PARAM_WXSTRING_MAP( const std::string& aJsonPath, std::map<wxString, wxString>* aPtr,
728  std::initializer_list<std::pair<const wxString, wxString>> aDefault,
729  bool aReadOnly = false ) :
730  PARAM_BASE( aJsonPath, aReadOnly ),
731  m_ptr( aPtr ),
732  m_default( aDefault )
733  { }
734 
735  void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
736  {
737  if( m_readOnly )
738  return;
739 
740  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
741  {
742  if( js->is_object() )
743  {
744  m_ptr->clear();
745 
746  for( const auto& el : js->items() )
747  {
748  ( *m_ptr )[wxString( el.key().c_str(), wxConvUTF8 )] =
749  el.value().get<wxString>();
750  }
751  }
752  }
753  else if( aResetIfMissing )
754  *m_ptr = m_default;
755  }
756 
757  void Store( JSON_SETTINGS* aSettings) const override
758  {
759  nlohmann::json js( {} );
760 
761  for( const auto& el : *m_ptr )
762  {
763  std::string key( el.first.ToUTF8() );
764  js[ key ] = el.second;
765  }
766 
767  aSettings->Set<nlohmann::json>( m_path, js );
768  }
769 
770  virtual void SetDefault() override
771  {
772  *m_ptr = m_default;
773  }
774 
775  bool IsDefault() const override
776  {
777  return *m_ptr == m_default;
778  }
779 
780  bool MatchesFile( JSON_SETTINGS* aSettings ) const override
781  {
782  if( OPT<nlohmann::json> js = aSettings->GetJson( m_path ) )
783  {
784  if( js->is_object() )
785  {
786  if( m_ptr->size() != js->size() )
787  return false;
788 
789  std::map<wxString, wxString> val;
790 
791  for( const auto& el : js->items() )
792  {
793  wxString key( el.key().c_str(), wxConvUTF8 );
794  val[key] = el.value().get<wxString>();
795  }
796 
797  return val == *m_ptr;
798  }
799  }
800 
801  return false;
802  }
803 
804 private:
805  std::map<wxString, wxString>* m_ptr;
806 
807  std::map<wxString, wxString> m_default;
808 };
809 
810 #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.h:654
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
ValueType m_default
Definition: parameters.h:466
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > aDefault, bool aReadOnly=false)
Definition: parameters.h:568
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:451
virtual void SetDefault() override
Definition: parameters.h:446
virtual void SetDefault() override
Definition: parameters.h:770
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:717
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:436
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:780
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:391
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:350
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:532
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:643
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:522
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:594
std::map< wxString, wxString > * m_ptr
Definition: parameters.h:805
double m_scale
Definition: parameters.h:470
EnumType m_default
Definition: parameters.h:288
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:56
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:673
bool m_use_minmax
Definition: parameters.h:163
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....
Stores an enum as an integer.
Definition: parameters.h:226
std::map< wxString, wxString > m_default
Definition: parameters.h:807
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:375
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.h:355
std::function< void(ValueType)> m_setter
Definition: parameters.h:377
nlohmann::json json
Definition: gerbview.cpp:40
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault, bool aReadOnly=false)
Definition: parameters.h:563
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
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:757
OPT< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:456
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:308
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:775
bool m_use_minmax
Definition: parameters.h:469
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:573
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:584
wxString fromFileFormat(const wxString &aString) const
Definition: parameters.h:620
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 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:388
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.h:735
const std::string & GetJsonPath()
Definition: parameters.h:74
virtual ~PARAM_BASE()=default
virtual void SetDefault() override
Definition: parameters.h:683
wxString toFileFormat(const wxString &aString) const
Definition: parameters.h:613
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:329
virtual void Store(JSON_SETTINGS *aSettings) const =0
Stores the value of this parameter to the given JSON_SETTINGS object.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:512
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:688
std::vector< Type > * m_ptr
Definition: parameters.h:551
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:646
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:373
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, double aScale=1.0, bool aReadOnly=false)
Definition: parameters.h:402
EnumType m_min
Definition: parameters.h:286
virtual void SetDefault()=0
std::map< std::string, Value > * m_ptr
Definition: parameters.h:715
A helper for <wxString, wxString> maps.
Definition: parameters.h:724
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:693
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
ValueType m_min
Definition: parameters.h:467
bool m_readOnly
! True if the parameter pointer should never be overwritten
Definition: parameters.h:83
ValueType GetDefault() const
Definition: parameters.h:340
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:484
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:413
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:727
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
Definition: parameters.h:527
ValueType m_max
Definition: parameters.h:468
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:477
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:441
Represents a list of strings holding directory paths.
Definition: parameters.h:560
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, bool aReadOnly=false)
Definition: parameters.h:101
EnumType * m_ptr
Definition: parameters.h:285
wxString toFileFormat(const wxString &aString) const
Definition: parameters.h:205
ValueType * m_ptr
Definition: parameters.h:465
void SetDefault() override
Definition: parameters.h:345
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...
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:553
ValueType GetDefault() const
Definition: parameters.h:137
PARAM_PATH(const std::string &aJsonPath, wxString *aPtr, wxString aDefault, bool aReadOnly=false)
Definition: parameters.h:176