KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright The 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef PARAMETERS_H
22#define PARAMETERS_H
23
24#include <set>
25#include <string>
26#include <utility>
27#include <math/util.h>
28
29#include <optional>
30#include <json_common.h>
31#include <gal/color4d.h>
34#include <kicommon.h>
35
37{
38public:
39 PARAM_BASE( std::string aJsonPath, bool aReadOnly ) :
40 m_path( std::move( aJsonPath ) ),
41 m_readOnly( aReadOnly ),
42 m_clearUnknownKeys( false )
43 {}
44
45 virtual ~PARAM_BASE() = default;
46
52 virtual void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const = 0;
53
58 virtual void Store( JSON_SETTINGS* aSettings ) const = 0;
59
60 virtual void SetDefault() = 0;
61
69 virtual bool MatchesFile( const JSON_SETTINGS& aSettings ) const = 0;
70
75 const std::string& GetJsonPath() const { return m_path; }
76
81 bool ClearUnknownKeys() const { return m_clearUnknownKeys; }
82
83 void SetClearUnknownKeys( bool aSet = true ) { m_clearUnknownKeys = aSet; }
84
85protected:
86 std::string m_path;
91};
92
93
94template<typename ValueType>
95class PARAM : public PARAM_BASE
96{
97public:
98 PARAM( const std::string& aJsonPath, ValueType* aPtr, const ValueType& aDefault,
99 bool aReadOnly = false ) :
100 PARAM_BASE( aJsonPath, aReadOnly ),
101 m_min(),
102 m_max(),
103 m_use_minmax( false ),
104 m_ptr( aPtr ),
105 m_default( aDefault )
106 { }
107
108 PARAM( const std::string& aJsonPath, ValueType* aPtr, const ValueType& aDefault,
109 const ValueType& aMin, const ValueType& aMax, bool aReadOnly = false ) :
110 PARAM_BASE( aJsonPath, aReadOnly ),
111 m_min( aMin ),
112 m_max( aMax ),
113 m_use_minmax( true ),
114 m_ptr( aPtr ),
115 m_default( aDefault )
116 { }
117
118 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
119 {
120 if( m_readOnly )
121 return;
122
123 if( std::optional<ValueType> optval = aSettings.Get<ValueType>( m_path ) )
124 {
125 ValueType val = *optval;
126
127 if( m_use_minmax )
128 {
129 if( m_max < val || val < m_min )
130 val = m_default;
131 }
132
133 *m_ptr = val;
134 }
135 else if( aResetIfMissing )
136 {
137 *m_ptr = m_default;
138 }
139 }
140
141 void Store( JSON_SETTINGS* aSettings ) const override
142 {
143 aSettings->Set<ValueType>( m_path, *m_ptr );
144 }
145
146 ValueType GetDefault() const
147 {
148 return m_default;
149 }
150
151 void SetDefault() override
152 {
153 *m_ptr = m_default;
154 }
155
156 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
157 {
158 if( std::optional<ValueType> optval = aSettings.Get<ValueType>( m_path ) )
159 return *optval == *m_ptr;
160
161 return aSettings.ResetsParamsIfMissing() && *m_ptr == m_default;
162 }
163
164private:
165 ValueType m_min;
166 ValueType m_max;
168
169protected:
170 ValueType* m_ptr;
171 ValueType m_default;
172};
173
177class KICOMMON_API PARAM_PATH : public PARAM<wxString>
178{
179public:
180 PARAM_PATH( const std::string& aJsonPath, wxString* aPtr, const wxString& aDefault,
181 bool aReadOnly = false ) :
182 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
183 { }
184
185 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
186 {
187 if( m_readOnly )
188 return;
189
190 PARAM::Load( aSettings, aResetIfMissing );
191
193 }
194
195 void Store( JSON_SETTINGS* aSettings ) const override
196 {
197 aSettings->Set<wxString>( m_path, toFileFormat( *m_ptr ) );
198 }
199
200 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
201 {
202 if( std::optional<wxString> optval = aSettings.Get<wxString>( m_path ) )
203 return fromFileFormat( *optval ) == *m_ptr;
204
205 return aSettings.ResetsParamsIfMissing() && *m_ptr == fromFileFormat( m_default );
206 }
207
208private:
209 wxString toFileFormat( const wxString& aString ) const
210 {
211 wxString ret = aString;
212 ret.Replace( wxT( "\\" ), wxT( "/" ) );
213 return ret;
214 }
215
216 wxString fromFileFormat( const wxString& aString ) const
217 {
218 wxString ret = aString;
219#ifdef __WINDOWS__
220 if( !ret.Contains( wxT( "://" ) ) )
221 ret.Replace( wxT( "/" ), wxT( "\\" ) );
222#endif
223 return ret;
224 }
225};
226
230template<typename EnumType>
231class PARAM_ENUM : public PARAM_BASE
232{
233public:
234 PARAM_ENUM( const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
235 EnumType aMin, EnumType aMax, bool aReadOnly = false ) :
236 PARAM_BASE( aJsonPath, aReadOnly ),
237 m_ptr( aPtr ),
238 m_min( aMin ),
239 m_max( aMax ),
240 m_default( aDefault )
241 {
242 }
243
244 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
245 {
246 if( m_readOnly )
247 return;
248
249 if( std::optional<int> val = aSettings.Get<int>( m_path ) )
250 {
251 if( *val >= static_cast<int>( m_min ) && *val <= static_cast<int>( m_max ) )
252 *m_ptr = static_cast<EnumType>( *val );
253 else if( aResetIfMissing )
254 *m_ptr = m_default;
255
256 }
257 else if( aResetIfMissing )
258 {
259 *m_ptr = m_default;
260 }
261 }
262
263 void Store( JSON_SETTINGS* aSettings ) const override
264 {
265 aSettings->Set<int>( m_path, static_cast<int>( *m_ptr ) );
266 }
267
268 EnumType GetDefault() const
269 {
270 return m_default;
271 }
272
273 void SetDefault() override
274 {
275 *m_ptr = m_default;
276 }
277
278 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
279 {
280 if( std::optional<int> val = aSettings.Get<int>( m_path ) )
281 return *val == static_cast<int>( *m_ptr );
282
283 return aSettings.ResetsParamsIfMissing() && *m_ptr == m_default;
284 }
285
286private:
287 EnumType* m_ptr;
288 EnumType m_min;
289 EnumType m_max;
290 EnumType m_default;
291};
292
297template<typename ValueType>
299{
300public:
301 PARAM_LAMBDA( const std::string& aJsonPath, std::function<ValueType()> aGetter,
302 std::function<void( ValueType )> aSetter, ValueType aDefault,
303 bool aReadOnly = false ) :
304 PARAM_BASE( aJsonPath, aReadOnly ),
305 m_default( std::move( aDefault ) ),
306 m_getter( std::move( aGetter ) ),
307 m_setter( std::move( aSetter ) )
308 {
309 }
310
311 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
312 {
313 if( m_readOnly )
314 return;
315
316 if( std::is_same<ValueType, nlohmann::json>::value )
317 {
318 if( std::optional<nlohmann::json> optval = aSettings.GetJson( m_path ) )
319 m_setter( *optval );
320 else
322 }
323 else
324 {
325 if( std::optional<ValueType> optval = aSettings.Get<ValueType>( m_path ) )
326 m_setter( *optval );
327 else
329 }
330 }
331
332 void Store( JSON_SETTINGS* aSettings ) const override
333 {
334 try
335 {
336 aSettings->Set<ValueType>( m_path, m_getter() );
337 }
338 catch( ... )
339 {
340 }
341 }
342
343 ValueType GetDefault() const
344 {
345 return m_default;
346 }
347
348 void SetDefault() override
349 {
351 }
352
353 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
354 {
355 if( std::is_same<ValueType, nlohmann::json>::value )
356 {
357 if( std::optional<nlohmann::json> optval = aSettings.GetJson( m_path ) )
358 return *optval == m_getter();
359 }
360 else
361 {
362 if( std::optional<ValueType> optval = aSettings.Get<ValueType>( m_path ) )
363 return *optval == m_getter();
364 }
365
366 // Absent from the file counts as a match when the value is still default and missing keys
367 // reset on load. Many json defaults are null while the getter emits an empty array or
368 // object for the same empty state, so treat an empty getter result against an empty default
369 // as a match too.
370 if( !aSettings.ResetsParamsIfMissing() )
371 return false;
372
373 ValueType current = m_getter();
374
375 if( current == m_default )
376 return true;
377
378 if constexpr( std::is_same_v<ValueType, nlohmann::json> )
379 return current.empty() && ( m_default.is_null() || m_default.empty() );
380
381 return false;
382 }
383
384private:
385 ValueType m_default;
386 std::function<ValueType()> m_getter;
387 std::function<void( ValueType )> m_setter;
388};
389
390#ifdef __WINDOWS__
391template class KICOMMON_API PARAM_LAMBDA<bool>;
392template class KICOMMON_API PARAM_LAMBDA<int>;
395#else
396extern template class APIVISIBLE PARAM_LAMBDA<bool>;
397extern template class APIVISIBLE PARAM_LAMBDA<int>;
398extern template class APIVISIBLE PARAM_LAMBDA<nlohmann::json>;
399extern template class APIVISIBLE PARAM_LAMBDA<std::string>;
400#endif
401
408template<typename ValueType>
410{
411public:
412 PARAM_SCALED( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
413 double aScale = 1.0, bool aReadOnly = false ) :
414 PARAM_BASE( aJsonPath, aReadOnly ),
415 m_ptr( aPtr ),
416 m_default( aDefault ),
417 m_min(),
418 m_max(),
419 m_use_minmax( false ),
420 m_scale( aScale ),
421 m_invScale( 1.0 / aScale )
422 { }
423
424 PARAM_SCALED( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
425 ValueType aMin, ValueType aMax, double aScale = 1.0, bool aReadOnly = false ) :
426 PARAM_BASE( aJsonPath, aReadOnly ),
427 m_ptr( aPtr ),
428 m_default( aDefault ),
429 m_min( aMin ),
430 m_max( aMax ),
431 m_use_minmax( true ),
432 m_scale( aScale ),
433 m_invScale( 1.0 / aScale )
434 { }
435
436 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
437 {
438 if( m_readOnly )
439 return;
440
441 double dval = m_default / m_invScale;
442
443 if( std::optional<double> optval = aSettings.Get<double>( m_path ) )
444 dval = *optval;
445 else if( !aResetIfMissing )
446 return;
447
448 ValueType val = KiROUND<double, ValueType>( dval * m_invScale );
449
450 if( m_use_minmax )
451 {
452 if( val > m_max || val < m_min )
453 val = m_default;
454 }
455
456 *m_ptr = val;
457 }
458
459 void Store( JSON_SETTINGS* aSettings) const override
460 {
461 aSettings->Set<double>( m_path, *m_ptr / m_invScale );
462 }
463
464 ValueType GetDefault() const
465 {
466 return m_default;
467 }
468
469 virtual void SetDefault() override
470 {
471 *m_ptr = m_default;
472 }
473
474 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
475 {
476 if( std::optional<double> optval = aSettings.Get<double>( m_path ) )
477 return *optval == ( *m_ptr / m_invScale );
478
479 return aSettings.ResetsParamsIfMissing() && *m_ptr == m_default;
480 }
481
482private:
483 ValueType* m_ptr;
484 ValueType m_default;
485 ValueType m_min;
486 ValueType m_max;
488 double m_scale;
490};
491
492template<typename Type>
493class PARAM_LIST : public PARAM_BASE
494{
495public:
496 PARAM_LIST( const std::string& aJsonPath, std::vector<Type>* aPtr,
497 std::initializer_list<Type> aDefault, bool aResetIfEmpty = false ) :
498 PARAM_BASE( aJsonPath, false ),
499 m_ptr( aPtr ),
500 m_default( aDefault ),
501 m_resetIfEmpty( aResetIfEmpty )
502 { }
503
504 PARAM_LIST( const std::string& aJsonPath, std::vector<Type>* aPtr,
505 std::vector<Type> aDefault, bool aResetIfEmpty = false ) :
506 PARAM_BASE( aJsonPath, false ),
507 m_ptr( aPtr ),
508 m_default( std::move( aDefault ) ),
509 m_resetIfEmpty( aResetIfEmpty )
510 { }
511
512 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
513 {
514 if( m_readOnly )
515 return;
516
517 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
518 {
519 std::vector<Type> val;
520
521 if( js->is_array() )
522 {
523 for( const auto& el : js->items() )
524 val.push_back( el.value().get<Type>() );
525 }
526
527 if( val.empty() && m_resetIfEmpty )
528 *m_ptr = m_default;
529 else
530 *m_ptr = val;
531 }
532 else if( aResetIfMissing )
533 {
534 *m_ptr = m_default;
535 }
536 }
537
538 void Store( JSON_SETTINGS* aSettings ) const override
539 {
540 nlohmann::json js = nlohmann::json::array();
541
542 for( const auto& el : *m_ptr )
543 js.push_back( el );
544
545 aSettings->Set<nlohmann::json>( m_path, js );
546 }
547
548 void SetDefault() override
549 {
550 *m_ptr = m_default;
551 }
552
553 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
554 {
555 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
556 {
557 if( js->is_array() )
558 {
559 std::vector<Type> val;
560
561 for( const auto& el : js->items() )
562 {
563 try
564 {
565 val.emplace_back( el.value().get<Type>() );
566 }
567 catch( ... )
568 {
569 // Probably typecast didn't work; skip this element
570 }
571 }
572
573 return val == *m_ptr;
574 }
575 }
576
577 return aSettings.ResetsParamsIfMissing() && *m_ptr == m_default;
578 }
579
580protected:
581 std::vector<Type>* m_ptr;
582 std::vector<Type> m_default;
584};
585
586
587#ifdef __WINDOWS__
588template class KICOMMON_API PARAM_LIST<bool>;
589template class KICOMMON_API PARAM_LIST<int>;
590template class KICOMMON_API PARAM_LIST<double>;
592template class KICOMMON_API PARAM_LIST<GRID>;
594#else
595extern template class APIVISIBLE PARAM_LIST<bool>;
596extern template class APIVISIBLE PARAM_LIST<int>;
597extern template class APIVISIBLE PARAM_LIST<double>;
598extern template class APIVISIBLE PARAM_LIST<KIGFX::COLOR4D>;
599extern template class APIVISIBLE PARAM_LIST<GRID>;
600extern template class APIVISIBLE PARAM_LIST<wxString>;
601#endif
602
603
604template<typename Type>
605class PARAM_SET : public PARAM_BASE
606{
607public:
608 PARAM_SET( const std::string& aJsonPath, std::set<Type>* aPtr,
609 std::initializer_list<Type> aDefault, bool aReadOnly = false ) :
610 PARAM_BASE( aJsonPath, aReadOnly ),
611 m_ptr( aPtr ),
612 m_default( aDefault )
613 { }
614
615 PARAM_SET( const std::string& aJsonPath, std::set<Type>* aPtr,
616 std::set<Type> aDefault, bool aReadOnly = false ) :
617 PARAM_BASE( aJsonPath, aReadOnly ),
618 m_ptr( aPtr ),
619 m_default( aDefault )
620 { }
621
622 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
623 {
624 if( m_readOnly )
625 return;
626
627 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
628 {
629 std::set<Type> val;
630
631 if( js->is_array() )
632 {
633 for( const auto& el : js->items() )
634 val.insert( el.value().get<Type>() );
635 }
636
637 *m_ptr = val;
638 }
639 else if( aResetIfMissing )
640 *m_ptr = m_default;
641 }
642
643 void Store( JSON_SETTINGS* aSettings) const override
644 {
645 nlohmann::json js = nlohmann::json::array();
646
647 for( const auto& el : *m_ptr )
648 js.push_back( el );
649
650 aSettings->Set<nlohmann::json>( m_path, js );
651 }
652
653
654 void SetDefault() override
655 {
656 *m_ptr = m_default;
657 }
658
659 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
660 {
661 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
662 {
663 if( js->is_array() )
664 {
665 std::set<Type> val;
666
667 for( const auto& el : js->items() )
668 val.insert( el.value().get<Type>() );
669
670 return val == *m_ptr;
671 }
672 }
673
674 return aSettings.ResetsParamsIfMissing() && *m_ptr == m_default;
675 }
676
677protected:
678 std::set<Type>* m_ptr;
679 std::set<Type> m_default;
680};
681
682#ifdef __WINDOWS__
683template class KICOMMON_API PARAM_SET<wxString>;
684#else
685extern template class APIVISIBLE PARAM_SET<wxString>;
686#endif
687
693{
694public:
695 PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
696 std::initializer_list<wxString> aDefault ) :
697 PARAM_LIST( aJsonPath, aPtr, aDefault )
698 { }
699
700 PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
701 std::vector<wxString> aDefault ) :
702 PARAM_LIST( aJsonPath, aPtr, aDefault )
703 { }
704
705 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
706 {
707 if( m_readOnly )
708 return;
709
710 PARAM_LIST::Load( aSettings, aResetIfMissing );
711
712 for( size_t i = 0; i < m_ptr->size(); i++ )
713 ( *m_ptr )[i] = fromFileFormat( ( *m_ptr )[i] );
714 }
715
716 void Store( JSON_SETTINGS* aSettings) const override;
717
718 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override;
719
720private:
721 wxString toFileFormat( const wxString& aString ) const
722 {
723 wxString ret = aString;
724 ret.Replace( wxT( "\\" ), wxT( "/" ) );
725 return ret;
726 }
727
728 wxString fromFileFormat( const wxString& aString ) const
729 {
730 wxString ret = aString;
731#ifdef __WINDOWS__
732 ret.Replace( wxT( "/" ), wxT( "\\" ) );
733#endif
734 return ret;
735 }
736};
737
750template<typename Value>
751class PARAM_MAP : public PARAM_BASE
752{
753public:
754 PARAM_MAP( const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
755 std::initializer_list<std::pair<const std::string, Value>> aDefault,
756 bool aReadOnly = false ) :
757 PARAM_BASE( aJsonPath, aReadOnly ),
758 m_ptr( aPtr ),
759 m_default( aDefault )
760 {
761 SetClearUnknownKeys( true );
762 }
763
764 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
765 {
766 if( m_readOnly )
767 return;
768
769 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
770 {
771 if( js->is_object() )
772 {
773 m_ptr->clear();
774
775 for( const auto& el : js->items() )
776 ( *m_ptr )[el.key()] = el.value().get<Value>();
777 }
778 }
779 else if( aResetIfMissing )
780 *m_ptr = m_default;
781 }
782
783 void Store( JSON_SETTINGS* aSettings) const override
784 {
785 nlohmann::json js( {} );
786
787 for( const auto& el : *m_ptr )
788 js[el.first] = el.second;
789
790 aSettings->Set<nlohmann::json>( m_path, js );
791 }
792
793 virtual void SetDefault() override
794 {
795 *m_ptr = m_default;
796 }
797
798 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
799 {
800 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
801 {
802 if( js->is_object() )
803 {
804 if( m_ptr->size() != js->size() )
805 return false;
806
807 std::map<std::string, Value> val;
808
809 for( const auto& el : js->items() )
810 val[el.key()] = el.value().get<Value>();
811
812 return val == *m_ptr;
813 }
814 }
815
816 return aSettings.ResetsParamsIfMissing() && *m_ptr == m_default;
817 }
818
819private:
820 std::map<std::string, Value>* m_ptr;
821 std::map<std::string, Value> m_default;
822};
823
824
825#ifdef __WINDOWS__
826template class KICOMMON_API PARAM_MAP<int>;
827template class KICOMMON_API PARAM_MAP<double>;
828template class KICOMMON_API PARAM_MAP<bool>;
829#else
830extern template class APIVISIBLE PARAM_MAP<int>;
831extern template class APIVISIBLE PARAM_MAP<double>;
832extern template class APIVISIBLE PARAM_MAP<bool>;
833#endif
834
835
840{
841public:
842 PARAM_WXSTRING_MAP( const std::string& aJsonPath, std::map<wxString, wxString>* aPtr,
843 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
844 bool aReadOnly = false, bool aArrayBehavior = false ) :
845 PARAM_BASE( aJsonPath, aReadOnly ),
846 m_ptr( aPtr ),
847 m_default( aDefault )
848 {
849 m_clearUnknownKeys = aArrayBehavior;
850 }
851
852 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override;
853
854 void Store( JSON_SETTINGS* aSettings) const override;
855
856 virtual void SetDefault() override
857 {
858 *m_ptr = m_default;
859 }
860
861 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override;
862
863private:
864 std::map<wxString, wxString>* m_ptr;
865 std::map<wxString, wxString> m_default;
866};
867
868#endif
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
Read a model file and creates a generic display structure.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
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...
std::optional< 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::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
bool ResetsParamsIfMissing() const
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
Definition parameters.h:39
bool m_readOnly
Indicates param pointer should never be overwritten.
Definition parameters.h:87
const std::string & GetJsonPath() const
Definition parameters.h:75
void SetClearUnknownKeys(bool aSet=true)
Definition parameters.h:83
virtual void SetDefault()=0
bool m_clearUnknownKeys
Keys should be cleared from source rather than merged.
Definition parameters.h:88
bool ClearUnknownKeys() const
Definition parameters.h:81
virtual void Store(JSON_SETTINGS *aSettings) const =0
Stores the value of this parameter to the given JSON_SETTINGS object.
virtual ~PARAM_BASE()=default
virtual bool MatchesFile(const JSON_SETTINGS &aSettings) const =0
Checks whether persisting the parameter would leave the file unchanged.
std::string m_path
Address of the param in the json files.
Definition parameters.h:86
virtual void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const =0
Loads the value of this parameter from JSON to the underlying storage.
EnumType m_default
Definition parameters.h:290
void SetDefault() override
Definition parameters.h:273
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:244
EnumType GetDefault() const
Definition parameters.h:268
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether persisting the parameter would leave the file unchanged.
Definition parameters.h:278
EnumType * m_ptr
Definition parameters.h:287
PARAM_ENUM(const std::string &aJsonPath, EnumType *aPtr, EnumType aDefault, EnumType aMin, EnumType aMax, bool aReadOnly=false)
Definition parameters.h:234
EnumType m_min
Definition parameters.h:288
EnumType m_max
Definition parameters.h:289
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition parameters.h:263
Like a normal param, but with custom getter and setter functions.
Definition parameters.h:299
std::function< void(ValueType)> m_setter
Definition parameters.h:387
std::function< ValueType()> m_getter
Definition parameters.h:386
ValueType m_default
Definition parameters.h:385
void SetDefault() override
Definition parameters.h:348
ValueType GetDefault() const
Definition parameters.h:343
PARAM_LAMBDA(const std::string &aJsonPath, std::function< ValueType()> aGetter, std::function< void(ValueType)> aSetter, ValueType aDefault, bool aReadOnly=false)
Definition parameters.h:301
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:311
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether persisting the parameter would leave the file unchanged.
Definition parameters.h:353
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition parameters.h:332
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:512
bool m_resetIfEmpty
Definition parameters.h:583
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition parameters.h:538
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether persisting the parameter would leave the file unchanged.
Definition parameters.h:553
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::vector< Type > aDefault, bool aResetIfEmpty=false)
Definition parameters.h:504
std::vector< Type > * m_ptr
Definition parameters.h:581
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::initializer_list< Type > aDefault, bool aResetIfEmpty=false)
Definition parameters.h:496
std::vector< Type > m_default
Definition parameters.h:582
void SetDefault() override
Definition parameters.h:548
Represents a map of <std::string, Value>.
Definition parameters.h:752
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:764
virtual void SetDefault() override
Definition parameters.h:793
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:754
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition parameters.h:783
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether persisting the parameter would leave the file unchanged.
Definition parameters.h:798
std::map< std::string, Value > m_default
Definition parameters.h:821
std::map< std::string, Value > * m_ptr
Definition parameters.h:820
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > aDefault)
Definition parameters.h:700
wxString toFileFormat(const wxString &aString) const
Definition parameters.h:721
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault)
Definition parameters.h:695
wxString fromFileFormat(const wxString &aString) const
Definition parameters.h:728
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:705
PARAM_PATH(const std::string &aJsonPath, wxString *aPtr, const wxString &aDefault, bool aReadOnly=false)
Definition parameters.h:180
wxString fromFileFormat(const wxString &aString) const
Definition parameters.h:216
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether persisting the parameter would leave the file unchanged.
Definition parameters.h:200
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition parameters.h:195
wxString toFileFormat(const wxString &aString) const
Definition parameters.h:209
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:185
ValueType GetDefault() const
Definition parameters.h:464
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:436
bool m_use_minmax
Definition parameters.h:487
ValueType m_default
Definition parameters.h:484
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition parameters.h:459
ValueType m_max
Definition parameters.h:486
double m_scale
Definition parameters.h:488
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether persisting the parameter would leave the file unchanged.
Definition parameters.h:474
ValueType * m_ptr
Definition parameters.h:483
double m_invScale
Definition parameters.h:489
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, double aScale=1.0, bool aReadOnly=false)
Definition parameters.h:412
virtual void SetDefault() override
Definition parameters.h:469
ValueType m_min
Definition parameters.h:485
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, double aScale=1.0, bool aReadOnly=false)
Definition parameters.h:424
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether persisting the parameter would leave the file unchanged.
Definition parameters.h:659
PARAM_SET(const std::string &aJsonPath, std::set< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
Definition parameters.h:608
PARAM_SET(const std::string &aJsonPath, std::set< Type > *aPtr, std::set< Type > aDefault, bool aReadOnly=false)
Definition parameters.h:615
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:622
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition parameters.h:643
std::set< Type > * m_ptr
Definition parameters.h:678
void SetDefault() override
Definition parameters.h:654
std::set< Type > m_default
Definition parameters.h:679
virtual void SetDefault() override
Definition parameters.h:856
std::map< wxString, wxString > * m_ptr
Definition parameters.h:864
PARAM_WXSTRING_MAP(const std::string &aJsonPath, std::map< wxString, wxString > *aPtr, std::initializer_list< std::pair< const wxString, wxString > > aDefault, bool aReadOnly=false, bool aArrayBehavior=false)
Definition parameters.h:842
std::map< wxString, wxString > m_default
Definition parameters.h:865
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Definition parameters.h:118
PARAM(const std::string &aJsonPath, ValueType *aPtr, const ValueType &aDefault, bool aReadOnly=false)
Definition parameters.h:98
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether persisting the parameter would leave the file unchanged.
Definition parameters.h:156
void SetDefault() override
Definition parameters.h:151
ValueType * m_ptr
Definition parameters.h:170
ValueType m_default
Definition parameters.h:171
bool m_use_minmax
Definition parameters.h:167
PARAM(const std::string &aJsonPath, ValueType *aPtr, const ValueType &aDefault, const ValueType &aMin, const ValueType &aMax, bool aReadOnly=false)
Definition parameters.h:108
ValueType GetDefault() const
Definition parameters.h:146
ValueType m_min
Definition parameters.h:165
ValueType m_max
Definition parameters.h:166
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition parameters.h:141
#define APIVISIBLE
#define KICOMMON_API
Definition kicommon.h:27
STL namespace.