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 (C) 2020-2024 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 <set>
25#include <string>
26#include <utility>
27#include <math/util.h>
28
29#include <optional>
30#include <gal/color4d.h>
33#include <kicommon.h>
34
36{
37public:
38 PARAM_BASE( std::string aJsonPath, bool aReadOnly ) :
39 m_path( std::move( aJsonPath ) ),
40 m_readOnly( aReadOnly ),
41 m_clearUnknownKeys( false )
42 {}
43
44 virtual ~PARAM_BASE() = default;
45
51 virtual void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const = 0;
52
57 virtual void Store( JSON_SETTINGS* aSettings ) const = 0;
58
59 virtual void SetDefault() = 0;
60
66 virtual bool MatchesFile( const JSON_SETTINGS& aSettings ) const = 0;
67
72 const std::string& GetJsonPath() const { return m_path; }
73
78 bool ClearUnknownKeys() const { return m_clearUnknownKeys; }
79
80 void SetClearUnknownKeys( bool aSet = true ) { m_clearUnknownKeys = aSet; }
81
82protected:
83 std::string m_path;
88};
89
90
91template<typename ValueType>
92class PARAM : public PARAM_BASE
93{
94public:
95 PARAM( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
96 bool aReadOnly = false ) :
97 PARAM_BASE( aJsonPath, aReadOnly ),
98 m_min(),
99 m_max(),
100 m_use_minmax( false ),
101 m_ptr( aPtr ),
102 m_default( std::move( aDefault ) )
103 { }
104
105 PARAM( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault, ValueType aMin,
106 ValueType aMax, bool aReadOnly = false ) :
107 PARAM_BASE( aJsonPath, aReadOnly ),
108 m_min( std::move( aMin ) ),
109 m_max( std::move( aMax ) ),
110 m_use_minmax( true ),
111 m_ptr( aPtr ),
112 m_default( std::move( aDefault ) )
113 { }
114
115 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
116 {
117 if( m_readOnly )
118 return;
119
120 if( std::optional<ValueType> optval = aSettings.Get<ValueType>( m_path ) )
121 {
122 ValueType val = *optval;
123
124 if( m_use_minmax )
125 {
126 if( m_max < val || val < m_min )
127 val = m_default;
128 }
129
130 *m_ptr = val;
131 }
132 else if( aResetIfMissing )
133 {
134 *m_ptr = m_default;
135 }
136 }
137
138 void Store( JSON_SETTINGS* aSettings ) const override
139 {
140 aSettings->Set<ValueType>( m_path, *m_ptr );
141 }
142
143 ValueType GetDefault() const
144 {
145 return m_default;
146 }
147
148 void SetDefault() override
149 {
150 *m_ptr = m_default;
151 }
152
153 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
154 {
155 if( std::optional<ValueType> optval = aSettings.Get<ValueType>( m_path ) )
156 return *optval == *m_ptr;
157
158 return false;
159 }
160
161private:
162 ValueType m_min;
163 ValueType m_max;
165
166protected:
167 ValueType* m_ptr;
168 ValueType m_default;
169};
170
174class KICOMMON_API PARAM_PATH : public PARAM<wxString>
175{
176public:
177 PARAM_PATH( const std::string& aJsonPath, wxString* aPtr, const wxString& aDefault,
178 bool aReadOnly = false ) :
179 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
180 { }
181
182 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
183 {
184 if( m_readOnly )
185 return;
186
187 PARAM::Load( aSettings, aResetIfMissing );
188
189 *m_ptr = fromFileFormat( *m_ptr );
190 }
191
192 void Store( JSON_SETTINGS* aSettings ) const override
193 {
194 aSettings->Set<wxString>( m_path, toFileFormat( *m_ptr ) );
195 }
196
197 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
198 {
199 if( std::optional<wxString> optval = aSettings.Get<wxString>( m_path ) )
200 return fromFileFormat( *optval ) == *m_ptr;
201
202 return false;
203 }
204
205private:
206 wxString toFileFormat( const wxString& aString ) const
207 {
208 wxString ret = aString;
209 ret.Replace( wxT( "\\" ), wxT( "/" ) );
210 return ret;
211 }
212
213 wxString fromFileFormat( const wxString& aString ) const
214 {
215 wxString ret = aString;
216#ifdef __WINDOWS__
217 ret.Replace( wxT( "/" ), wxT( "\\" ) );
218#endif
219 return ret;
220 }
221};
222
226template<typename EnumType>
227class PARAM_ENUM : public PARAM_BASE
228{
229public:
230 PARAM_ENUM( const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
231 EnumType aMin, EnumType aMax, bool aReadOnly = false ) :
232 PARAM_BASE( aJsonPath, aReadOnly ),
233 m_ptr( aPtr ),
234 m_min( aMin ),
235 m_max( aMax ),
236 m_default( aDefault )
237 {
238 }
239
240 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
241 {
242 if( m_readOnly )
243 return;
244
245 if( std::optional<int> val = aSettings.Get<int>( m_path ) )
246 {
247 if( *val >= static_cast<int>( m_min ) && *val <= static_cast<int>( m_max ) )
248 *m_ptr = static_cast<EnumType>( *val );
249 else if( aResetIfMissing )
250 *m_ptr = m_default;
251
252 }
253 else if( aResetIfMissing )
254 {
255 *m_ptr = m_default;
256 }
257 }
258
259 void Store( JSON_SETTINGS* aSettings ) const override
260 {
261 aSettings->Set<int>( m_path, static_cast<int>( *m_ptr ) );
262 }
263
264 EnumType GetDefault() const
265 {
266 return m_default;
267 }
268
269 void SetDefault() override
270 {
271 *m_ptr = m_default;
272 }
273
274 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
275 {
276 if( std::optional<int> val = aSettings.Get<int>( m_path ) )
277 return *val == static_cast<int>( *m_ptr );
278
279 return false;
280 }
281
282private:
283 EnumType* m_ptr;
284 EnumType m_min;
285 EnumType m_max;
286 EnumType m_default;
287};
288
293template<typename ValueType>
295{
296public:
297 PARAM_LAMBDA( const std::string& aJsonPath, std::function<ValueType()> aGetter,
298 std::function<void( ValueType )> aSetter, ValueType aDefault,
299 bool aReadOnly = false ) :
300 PARAM_BASE( aJsonPath, aReadOnly ),
301 m_default( std::move( aDefault ) ),
302 m_getter( std::move( aGetter ) ),
303 m_setter( std::move( aSetter ) )
304 {
305 }
306
307 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
308 {
309 if( m_readOnly )
310 return;
311
312 if( std::is_same<ValueType, nlohmann::json>::value )
313 {
314 if( std::optional<nlohmann::json> optval = aSettings.GetJson( m_path ) )
315 m_setter( *optval );
316 else
318 }
319 else
320 {
321 if( std::optional<ValueType> optval = aSettings.Get<ValueType>( m_path ) )
322 m_setter( *optval );
323 else
325 }
326 }
327
328 void Store( JSON_SETTINGS* aSettings ) const override
329 {
330 try
331 {
332 aSettings->Set<ValueType>( m_path, m_getter() );
333 }
334 catch( ... )
335 {
336 }
337 }
338
339 ValueType GetDefault() const
340 {
341 return m_default;
342 }
343
344 void SetDefault() override
345 {
347 }
348
349 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
350 {
351 if( std::is_same<ValueType, nlohmann::json>::value )
352 {
353 if( std::optional<nlohmann::json> optval = aSettings.GetJson( m_path ) )
354 return *optval == m_getter();
355 }
356 else
357 {
358 if( std::optional<ValueType> optval = aSettings.Get<ValueType>( m_path ) )
359 return *optval == m_getter();
360 }
361
362 // Not in file
363 return false;
364 }
365
366private:
367 ValueType m_default;
368 std::function<ValueType()> m_getter;
369 std::function<void( ValueType )> m_setter;
370};
371
372#ifdef __WINDOWS__
373template class KICOMMON_API PARAM_LAMBDA<bool>;
374template class KICOMMON_API PARAM_LAMBDA<int>;
377#else
378extern template class APIVISIBLE PARAM_LAMBDA<bool>;
379extern template class APIVISIBLE PARAM_LAMBDA<int>;
380extern template class APIVISIBLE PARAM_LAMBDA<nlohmann::json>;
381extern template class APIVISIBLE PARAM_LAMBDA<std::string>;
382#endif
383
390template<typename ValueType>
392{
393public:
394 PARAM_SCALED( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
395 double aScale = 1.0, bool aReadOnly = false ) :
396 PARAM_BASE( aJsonPath, aReadOnly ),
397 m_ptr( aPtr ),
398 m_default( aDefault ),
399 m_min(),
400 m_max(),
401 m_use_minmax( false ),
402 m_scale( aScale ),
403 m_invScale( 1.0 / aScale )
404 { }
405
406 PARAM_SCALED( const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
407 ValueType aMin, ValueType aMax, double aScale = 1.0, bool aReadOnly = false ) :
408 PARAM_BASE( aJsonPath, aReadOnly ),
409 m_ptr( aPtr ),
410 m_default( aDefault ),
411 m_min( aMin ),
412 m_max( aMax ),
413 m_use_minmax( true ),
414 m_scale( aScale ),
415 m_invScale( 1.0 / aScale )
416 { }
417
418 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
419 {
420 if( m_readOnly )
421 return;
422
423 double dval = m_default / m_invScale;
424
425 if( std::optional<double> optval = aSettings.Get<double>( m_path ) )
426 dval = *optval;
427 else if( !aResetIfMissing )
428 return;
429
430 ValueType val = KiROUND<double, ValueType>( dval * m_invScale );
431
432 if( m_use_minmax )
433 {
434 if( val > m_max || val < m_min )
435 val = m_default;
436 }
437
438 *m_ptr = val;
439 }
440
441 void Store( JSON_SETTINGS* aSettings) const override
442 {
443 aSettings->Set<double>( m_path, *m_ptr / m_invScale );
444 }
445
446 ValueType GetDefault() const
447 {
448 return m_default;
449 }
450
451 virtual void SetDefault() override
452 {
453 *m_ptr = m_default;
454 }
455
456 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
457 {
458 if( std::optional<double> optval = aSettings.Get<double>( m_path ) )
459 return *optval == ( *m_ptr / m_invScale );
460
461 return false;
462 }
463
464private:
465 ValueType* m_ptr;
466 ValueType m_default;
467 ValueType m_min;
468 ValueType m_max;
470 double m_scale;
472};
473
474template<typename Type>
475class PARAM_LIST : public PARAM_BASE
476{
477public:
478 PARAM_LIST( const std::string& aJsonPath, std::vector<Type>* aPtr,
479 std::initializer_list<Type> aDefault, bool aReadOnly = false ) :
480 PARAM_BASE( aJsonPath, aReadOnly ),
481 m_ptr( aPtr ),
482 m_default( aDefault )
483 { }
484
485 PARAM_LIST( const std::string& aJsonPath, std::vector<Type>* aPtr,
486 std::vector<Type> aDefault, bool aReadOnly = false ) :
487 PARAM_BASE( aJsonPath, aReadOnly ),
488 m_ptr( aPtr ),
489 m_default( std::move( aDefault ) )
490 { }
491
492 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
493 {
494 if( m_readOnly )
495 return;
496
497 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
498 {
499 std::vector<Type> val;
500
501 if( js->is_array() )
502 {
503 for( const auto& el : js->items() )
504 val.push_back( el.value().get<Type>() );
505 }
506
507 *m_ptr = val;
508 }
509 else if( aResetIfMissing )
510 *m_ptr = m_default;
511 }
512
513 void Store( JSON_SETTINGS* aSettings ) const override
514 {
515 nlohmann::json js = nlohmann::json::array();
516
517 for( const auto& el : *m_ptr )
518 js.push_back( el );
519
520 aSettings->Set<nlohmann::json>( m_path, js );
521 }
522
523 void SetDefault() override
524 {
525 *m_ptr = m_default;
526 }
527
528 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
529 {
530 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
531 {
532 if( js->is_array() )
533 {
534 std::vector<Type> val;
535
536 for( const auto& el : js->items() )
537 {
538 try
539 {
540 val.emplace_back( el.value().get<Type>() );
541 }
542 catch( ... )
543 {
544 // Probably typecast didn't work; skip this element
545 }
546 }
547
548 return val == *m_ptr;
549 }
550 }
551
552 return false;
553 }
554
555protected:
556 std::vector<Type>* m_ptr;
557 std::vector<Type> m_default;
558};
559
560
561#ifdef __WINDOWS__
562template class KICOMMON_API PARAM_LIST<bool>;
563template class KICOMMON_API PARAM_LIST<int>;
564template class KICOMMON_API PARAM_LIST<double>;
566template class KICOMMON_API PARAM_LIST<GRID>;
568#else
569extern template class APIVISIBLE PARAM_LIST<bool>;
570extern template class APIVISIBLE PARAM_LIST<int>;
571extern template class APIVISIBLE PARAM_LIST<double>;
572extern template class APIVISIBLE PARAM_LIST<KIGFX::COLOR4D>;
573extern template class APIVISIBLE PARAM_LIST<GRID>;
574extern template class APIVISIBLE PARAM_LIST<wxString>;
575#endif
576
577
578template<typename Type>
579class PARAM_SET : public PARAM_BASE
580{
581public:
582 PARAM_SET( const std::string& aJsonPath, std::set<Type>* aPtr,
583 std::initializer_list<Type> aDefault, bool aReadOnly = false ) :
584 PARAM_BASE( aJsonPath, aReadOnly ),
585 m_ptr( aPtr ),
586 m_default( aDefault )
587 { }
588
589 PARAM_SET( const std::string& aJsonPath, std::set<Type>* aPtr,
590 std::set<Type> aDefault, bool aReadOnly = false ) :
591 PARAM_BASE( aJsonPath, aReadOnly ),
592 m_ptr( aPtr ),
593 m_default( aDefault )
594 { }
595
596 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
597 {
598 if( m_readOnly )
599 return;
600
601 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
602 {
603 std::set<Type> val;
604
605 if( js->is_array() )
606 {
607 for( const auto& el : js->items() )
608 val.insert( el.value().get<Type>() );
609 }
610
611 *m_ptr = val;
612 }
613 else if( aResetIfMissing )
614 *m_ptr = m_default;
615 }
616
617 void Store( JSON_SETTINGS* aSettings) const override
618 {
619 nlohmann::json js = nlohmann::json::array();
620
621 for( const auto& el : *m_ptr )
622 js.push_back( el );
623
624 aSettings->Set<nlohmann::json>( m_path, js );
625 }
626
627
628 void SetDefault() override
629 {
630 *m_ptr = m_default;
631 }
632
633 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
634 {
635 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
636 {
637 if( js->is_array() )
638 {
639 std::set<Type> val;
640
641 for( const auto& el : js->items() )
642 val.insert( el.value().get<Type>() );
643
644 return val == *m_ptr;
645 }
646 }
647
648 return false;
649 }
650
651protected:
652 std::set<Type>* m_ptr;
653 std::set<Type> m_default;
654};
655
656#ifdef __WINDOWS__
657template class KICOMMON_API PARAM_SET<wxString>;
658#else
659extern template class APIVISIBLE PARAM_SET<wxString>;
660#endif
661
667{
668public:
669 PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
670 std::initializer_list<wxString> aDefault, bool aReadOnly = false ) :
671 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
672 { }
673
674 PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
675 std::vector<wxString> aDefault, bool aReadOnly = false ) :
676 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
677 { }
678
679 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
680 {
681 if( m_readOnly )
682 return;
683
684 PARAM_LIST::Load( aSettings, aResetIfMissing );
685
686 for( size_t i = 0; i < m_ptr->size(); i++ )
687 ( *m_ptr )[i] = fromFileFormat( ( *m_ptr )[i] );
688 }
689
690 void Store( JSON_SETTINGS* aSettings) const override;
691
692 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override;
693
694private:
695 wxString toFileFormat( const wxString& aString ) const
696 {
697 wxString ret = aString;
698 ret.Replace( wxT( "\\" ), wxT( "/" ) );
699 return ret;
700 }
701
702 wxString fromFileFormat( const wxString& aString ) const
703 {
704 wxString ret = aString;
705#ifdef __WINDOWS__
706 ret.Replace( wxT( "/" ), wxT( "\\" ) );
707#endif
708 return ret;
709 }
710};
711
724template<typename Value>
725class PARAM_MAP : public PARAM_BASE
726{
727public:
728 PARAM_MAP( const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
729 std::initializer_list<std::pair<const std::string, Value>> aDefault,
730 bool aReadOnly = false ) :
731 PARAM_BASE( aJsonPath, aReadOnly ),
732 m_ptr( aPtr ),
733 m_default( aDefault )
734 { }
735
736 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override
737 {
738 if( m_readOnly )
739 return;
740
741 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
742 {
743 if( js->is_object() )
744 {
745 m_ptr->clear();
746
747 for( const auto& el : js->items() )
748 ( *m_ptr )[el.key()] = el.value().get<Value>();
749 }
750 }
751 else if( aResetIfMissing )
752 *m_ptr = m_default;
753 }
754
755 void Store( JSON_SETTINGS* aSettings) const override
756 {
757 nlohmann::json js( {} );
758
759 for( const auto& el : *m_ptr )
760 js[el.first] = el.second;
761
762 aSettings->Set<nlohmann::json>( m_path, js );
763 }
764
765 virtual void SetDefault() override
766 {
767 *m_ptr = m_default;
768 }
769
770 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override
771 {
772 if( std::optional<nlohmann::json> js = aSettings.GetJson( m_path ) )
773 {
774 if( js->is_object() )
775 {
776 if( m_ptr->size() != js->size() )
777 return false;
778
779 std::map<std::string, Value> val;
780
781 for( const auto& el : js->items() )
782 val[el.key()] = el.value().get<Value>();
783
784 return val == *m_ptr;
785 }
786 }
787
788 return false;
789 }
790
791private:
792 std::map<std::string, Value>* m_ptr;
793 std::map<std::string, Value> m_default;
794};
795
796
797#ifdef __WINDOWS__
798template class KICOMMON_API PARAM_MAP<int>;
799template class KICOMMON_API PARAM_MAP<double>;
800template class KICOMMON_API PARAM_MAP<bool>;
801#else
802extern template class APIVISIBLE PARAM_MAP<int>;
803extern template class APIVISIBLE PARAM_MAP<double>;
804extern template class APIVISIBLE PARAM_MAP<bool>;
805#endif
806
807
812{
813public:
814 PARAM_WXSTRING_MAP( const std::string& aJsonPath, std::map<wxString, wxString>* aPtr,
815 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
816 bool aReadOnly = false, bool aArrayBehavior = false ) :
817 PARAM_BASE( aJsonPath, aReadOnly ),
818 m_ptr( aPtr ),
819 m_default( aDefault )
820 {
821 m_clearUnknownKeys = aArrayBehavior;
822 }
823
824 void Load( const JSON_SETTINGS& aSettings, bool aResetIfMissing = true ) const override;
825
826 void Store( JSON_SETTINGS* aSettings) const override;
827
828 virtual void SetDefault() override
829 {
830 *m_ptr = m_default;
831 }
832
833 bool MatchesFile( const JSON_SETTINGS& aSettings ) const override;
834
835private:
836 std::map<wxString, wxString>* m_ptr;
837 std::map<wxString, wxString> m_default;
838};
839
840#endif
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
reads a model file and creates a generic display structure
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.
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
Definition: parameters.h:38
bool m_readOnly
Indicates param pointer should never be overwritten.
Definition: parameters.h:84
const std::string & GetJsonPath() const
Definition: parameters.h:72
void SetClearUnknownKeys(bool aSet=true)
Definition: parameters.h:80
virtual void SetDefault()=0
bool m_clearUnknownKeys
Keys should be cleared from source rather than merged.
Definition: parameters.h:85
bool ClearUnknownKeys() const
Definition: parameters.h:78
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 the parameter in memory matches the one in a given JSON file.
std::string m_path
Address of the param in the json files.
Definition: parameters.h:83
virtual void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const =0
Loads the value of this parameter from JSON to the underlying storage.
Stores an enum as an integer.
Definition: parameters.h:228
EnumType m_default
Definition: parameters.h:286
void SetDefault() override
Definition: parameters.h:269
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:240
EnumType GetDefault() const
Definition: parameters.h:264
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:274
EnumType * m_ptr
Definition: parameters.h:283
PARAM_ENUM(const std::string &aJsonPath, EnumType *aPtr, EnumType aDefault, EnumType aMin, EnumType aMax, bool aReadOnly=false)
Definition: parameters.h:230
EnumType m_min
Definition: parameters.h:284
EnumType m_max
Definition: parameters.h:285
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:259
Like a normal param, but with custom getter and setter functions.
Definition: parameters.h:295
std::function< void(ValueType)> m_setter
Definition: parameters.h:369
std::function< ValueType()> m_getter
Definition: parameters.h:368
ValueType m_default
Definition: parameters.h:367
void SetDefault() override
Definition: parameters.h:344
ValueType GetDefault() const
Definition: parameters.h:339
PARAM_LAMBDA(const std::string &aJsonPath, std::function< ValueType()> aGetter, std::function< void(ValueType)> aSetter, ValueType aDefault, bool aReadOnly=false)
Definition: parameters.h:297
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:307
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:349
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:328
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:492
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:513
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:528
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
Definition: parameters.h:478
std::vector< Type > * m_ptr
Definition: parameters.h:556
std::vector< Type > m_default
Definition: parameters.h:557
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::vector< Type > aDefault, bool aReadOnly=false)
Definition: parameters.h:485
void SetDefault() override
Definition: parameters.h:523
Represents a map of <std::string, Value>.
Definition: parameters.h:726
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:736
virtual void SetDefault() override
Definition: parameters.h:765
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:728
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:755
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:770
std::map< std::string, Value > m_default
Definition: parameters.h:793
std::map< std::string, Value > * m_ptr
Definition: parameters.h:792
Represents a list of strings holding directory paths.
Definition: parameters.h:667
wxString toFileFormat(const wxString &aString) const
Definition: parameters.h:695
wxString fromFileFormat(const wxString &aString) const
Definition: parameters.h:702
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:679
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault, bool aReadOnly=false)
Definition: parameters.h:669
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > aDefault, bool aReadOnly=false)
Definition: parameters.h:674
Stores a path as a string with directory separators normalized to unix-style.
Definition: parameters.h:175
PARAM_PATH(const std::string &aJsonPath, wxString *aPtr, const wxString &aDefault, bool aReadOnly=false)
Definition: parameters.h:177
wxString fromFileFormat(const wxString &aString) const
Definition: parameters.h:213
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:197
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:192
wxString toFileFormat(const wxString &aString) const
Definition: parameters.h:206
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:182
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition: parameters.h:392
ValueType GetDefault() const
Definition: parameters.h:446
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:418
bool m_use_minmax
Definition: parameters.h:469
ValueType m_default
Definition: parameters.h:466
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:441
ValueType m_max
Definition: parameters.h:468
double m_scale
Definition: parameters.h:470
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:456
ValueType * m_ptr
Definition: parameters.h:465
double m_invScale
Definition: parameters.h:471
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, double aScale=1.0, bool aReadOnly=false)
Definition: parameters.h:394
virtual void SetDefault() override
Definition: parameters.h:451
ValueType m_min
Definition: parameters.h:467
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, double aScale=1.0, bool aReadOnly=false)
Definition: parameters.h:406
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:633
PARAM_SET(const std::string &aJsonPath, std::set< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
Definition: parameters.h:582
PARAM_SET(const std::string &aJsonPath, std::set< Type > *aPtr, std::set< Type > aDefault, bool aReadOnly=false)
Definition: parameters.h:589
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:596
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:617
std::set< Type > * m_ptr
Definition: parameters.h:652
void SetDefault() override
Definition: parameters.h:628
std::set< Type > m_default
Definition: parameters.h:653
A helper for <wxString, wxString> maps.
Definition: parameters.h:812
virtual void SetDefault() override
Definition: parameters.h:828
std::map< wxString, wxString > * m_ptr
Definition: parameters.h:836
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:814
std::map< wxString, wxString > m_default
Definition: parameters.h:837
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:115
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
Definition: parameters.h:153
void SetDefault() override
Definition: parameters.h:148
ValueType * m_ptr
Definition: parameters.h:167
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, bool aReadOnly=false)
Definition: parameters.h:105
ValueType m_default
Definition: parameters.h:168
bool m_use_minmax
Definition: parameters.h:164
ValueType GetDefault() const
Definition: parameters.h:143
ValueType m_min
Definition: parameters.h:162
ValueType m_max
Definition: parameters.h:163
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, bool aReadOnly=false)
Definition: parameters.h:95
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Definition: parameters.h:138
#define APIVISIBLE
Definition: import_export.h:55
#define KICOMMON_API
Definition: kicommon.h:28
STL namespace.