-
Notifications
You must be signed in to change notification settings - Fork 761
Expand file tree
/
Copy pathoption.cpp
More file actions
984 lines (828 loc) · 25.8 KB
/
option.cpp
File metadata and controls
984 lines (828 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to natehieter@gmail.com
// ==========================================================================
#include "option.hpp"
#include "config.hpp"
#include "fmt/format.h"
#include "lib/utf8-cpp/utf8.h"
#include "sim.hpp"
#include "util/generic.hpp"
#include "util/io.hpp"
#include "util/util.hpp"
#include <iostream>
#include <utility>
namespace { // UNNAMED NAMESPACE ============================================
template <typename Range>
inline bool is_valid_utf8(const Range& r)
{
return utf8::is_valid(range::begin(r), range::end(r));
}
bool is_white_space( char c )
{
return ( c == ' ' || c == '\t' || c == '\n' || c == '\r' );
}
void open_file( io::ifstream& f, util::span<const std::string> splits, const std::string& name, std::string& actual_name )
{
for ( auto& split : splits )
{
auto file_path = split + "/" + name;
f.open( file_path );
if ( f.is_open() )
{
actual_name = file_path;
return;
}
}
actual_name = name;
f.open( name );
}
std::string base_name( const std::string& file_path )
{
#if defined( SC_WINDOWS )
auto base_it = file_path.rfind('\\');
#else
auto base_it = file_path.rfind('/');
#endif
std::string file_name;
if ( base_it != std::string::npos )
{
file_name = file_path.substr( base_it + 1 );
}
else
{
file_name = file_path;
}
auto extension_it = file_name.find('.');
std::string base_name;
if ( extension_it != std::string::npos )
{
base_name = file_name.substr( 0, extension_it );
}
else
{
base_name = file_name;
}
return base_name;
}
void do_replace( const option_db_t& opts, std::string& str, std::string::size_type begin, int depth )
{
static const int max_depth = 10;
if ( depth > max_depth )
{
throw std::invalid_argument( fmt::format( "Nesting depth exceeded for: '{}' (max: {})", str, max_depth ) );
}
if ( begin == std::string::npos )
{
return;
}
auto next = str.find( "$(", begin + 2 );
if ( next != std::string::npos )
{
do_replace( opts, str, next, ++depth );
}
auto end = str.find( ')', begin + 2 );
if ( end == std::string::npos )
{
throw std::invalid_argument( fmt::format( "Unbalanced parenthesis in template variable for: '{}'", str ) );
}
auto var = str.substr( begin + 2, ( end - begin ) - 2 );
if ( opts.var_map.find( var ) == opts.var_map.end() )
{
throw std::invalid_argument( fmt::format( "Missing template variable: '{}'", var ) );
}
str.replace( begin, end - begin + 1, opts.var_map.at( var ) );
}
// Shared data base path
#ifndef SC_SHARED_DATA
#if defined( SC_LINUX_PACKAGING )
const char* SC_SHARED_DATA SC_LINUX_PACKAGING = "/profiles";
#else
const char* SC_SHARED_DATA = "";
#endif
#endif
struct converter_uint64_t
{
static uint64_t convert( util::string_view v )
{
return std::stoull( std::string( v ) );
}
};
struct converter_int_t
{
static int convert( util::string_view v )
{
return util::to_int( v );
}
};
struct converter_uint_t
{
static unsigned int convert( util::string_view v )
{
return util::to_unsigned( v );
}
};
struct converter_double_t
{
static double convert( util::string_view v )
{
return util::to_double( v );
}
};
struct converter_timespan_t
{
static timespan_t convert( util::string_view v )
{
return timespan_t::from_seconds( util::to_double( v ) );
}
};
/* Option helper class
* Stores a reference of given type T
*/
template<class T>
struct opts_helper_t : public option_t
{
using base_t = opts_helper_t<T>;
opts_helper_t( util::string_view name, T& ref ) :
option_t( name ),
_ref( ref )
{ }
protected:
T& _ref;
};
struct opt_string_t : public option_t
{
opt_string_t( util::string_view name, std::string& addr, bool warn = false )
: option_t( name ), _ref( addr ), _warn( warn )
{}
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
if ( n != name() )
return opts::parse_status::CONTINUE;
bool do_warn = _warn && !_ref.empty();
_ref = std::string( v );
return do_warn ? opts::parse_status::WARNING : opts::parse_status::OK;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "{}={}\n", name(), _ref );
}
private:
std::string& _ref;
bool _warn;
};
struct opt_append_t : public option_t
{
opt_append_t( util::string_view name, std::string& addr ) :
option_t( name ),
_ref( addr )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
if ( n != name() )
return opts::parse_status::CONTINUE;
_ref += std::string( v );
return opts::parse_status::OK;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "{}+={}\n", name(), _ref );
}
private:
std::string& _ref;
};
/**
* Option template for converting numeric type (unsigned, int, double, etc.)
*
* Empty input string is silently interpreted as 0, allowing for options with empty value.
*/
template<typename T, typename Converter>
struct opt_numeric_t : public option_t
{
opt_numeric_t( util::string_view name, T& addr ) :
option_t( name ),
_ref( addr )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
if ( n != name() )
return opts::parse_status::CONTINUE;
if ( v.empty() )
_ref = {};
else
_ref = Converter::convert( v );
return opts::parse_status::OK;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "{}={}\n", name(), _ref );
}
private:
T& _ref;
};
/**
* Option template for converting numeric type (unsigned, int, double, etc.) with min/max check
*
* Throws std::invalid_argument if value is out of min/max bounds.
* Empty input string is silently interpreted as 0, allowing for options with empty value.
*/
template<typename T, typename Converter>
struct opt_numeric_mm_t : public option_t
{
opt_numeric_mm_t( util::string_view name, T& addr, T min, T max ) :
option_t( name ),
_ref( addr ),
_min( min ),
_max( max )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
if ( n != name() )
return opts::parse_status::CONTINUE;
T tmp;
if ( v.empty() )
tmp = {};
else
tmp = Converter::convert( v );
// Range checking
if ( tmp < _min || tmp > _max ) {
throw std::invalid_argument( fmt::format(
"Option '{}' with value '{}' not within valid boundaries [{}..{}]", n, v, _min, _max ) );
}
_ref = tmp;
return opts::parse_status::OK;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "{}={}\n", name(), _ref );
}
private:
T& _ref;
T _min, _max;
};
struct opt_bool_t : public option_t
{
opt_bool_t( util::string_view name, bool& addr ) :
option_t( name ),
_ref( addr )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
if ( n != name() )
return opts::parse_status::CONTINUE;
if ( v != "0" && v != "1" )
{
throw std::invalid_argument( fmt::format( "Acceptable values for '{}' are '1' or '0'", n ) );
}
_ref = util::to_int( v ) != 0;
return opts::parse_status::OK;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "{}={:d}\n", name(), _ref );
}
private:
bool& _ref;
};
struct opt_bool_int_t : public option_t
{
opt_bool_int_t( util::string_view name, int& addr ) :
option_t( name ),
_ref( addr )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
if ( n != name() )
return opts::parse_status::CONTINUE;
if ( v != "0" && v != "1" )
{
throw std::invalid_argument( fmt::format( "Acceptable values for '{}' are '1' or '0'", n ) );
}
_ref = util::to_int( v );
return opts::parse_status::OK;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "{}={}\n", name(), _ref );
}
private:
int& _ref;
};
struct opts_sim_func_t : public option_t
{
opts_sim_func_t( util::string_view name, opts::function_t ref ) :
option_t( name ),
_fun(std::move( ref ))
{ }
protected:
opts::parse_status do_parse( sim_t* sim, util::string_view n, util::string_view value ) const override
{
if ( name() != n )
return opts::parse_status::CONTINUE;
return _fun( sim, n, value ) ? opts::parse_status::OK : opts::parse_status::FAILURE;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "function option: {}\n", name() );
}
private:
opts::function_t _fun;
};
struct opts_map_t : public option_t
{
opts_map_t( util::string_view name, opts::map_t& ref ) :
option_t( name ),
_ref( ref )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
std::string::size_type last = n.size() - 1;
bool append = false;
if ( n[ last ] == '+' )
{
append = true;
--last;
}
auto dot = n.rfind( ".", last );
if ( dot != std::string::npos )
{
if ( name() == n.substr( 0, dot + 1 ) )
{
auto key = n.substr( dot + 1, last - dot );
if ( key.empty() )
{
return opts::parse_status::FAILURE;
}
std::string& value = _ref[ std::string(key) ];
auto new_value = std::string( v );
value = append ? ( value + new_value ) : new_value;
return opts::parse_status::OK;
}
}
return opts::parse_status::CONTINUE;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
for ( const auto& entry : _ref )
{
fmt::format_to( out, "{}{}={}", name(), entry.first, entry.second );
}
}
opts::map_t& _ref;
};
struct opts_map_list_t : public option_t
{
opts_map_list_t( util::string_view name, opts::map_list_t& ref ) :
option_t( name ), _ref( ref )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
std::string::size_type last = n.size() - 1;
bool append = false;
if ( n[ last ] == '+' )
{
append = true;
--last;
}
auto dot = n.rfind( ".", last );
if ( dot != std::string::npos )
{
if ( name() == n.substr( 0, dot + 1 ) )
{
auto listname = n.substr( dot + 1, last - dot );
if ( listname.empty() )
{
return opts::parse_status::FAILURE;
}
auto& vec = _ref[ std::string(listname) ];
if ( ! append )
{
vec.clear();
}
if ( !v.empty() )
{
vec.emplace_back( v );
}
return opts::parse_status::OK;
}
}
return opts::parse_status::CONTINUE;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
for ( auto& entry : _ref )
{
for ( auto i = 0U; i < entry.second.size(); ++i )
{
fmt::format_to( out, "{}{}{}{}\n", name(), entry.first, i == 0 ? "=" : "+=", entry.second[ i ] );
}
}
}
opts::map_list_t& _ref;
};
struct opts_list_t : public option_t
{
opts_list_t( util::string_view name, opts::list_t& ref ) :
option_t( name ),
_ref( ref )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view n, util::string_view v ) const override
{
if ( name() != n )
return opts::parse_status::CONTINUE;
_ref.emplace_back( v );
return opts::parse_status::OK;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "{}=", name() );
for ( auto& entry : _ref )
fmt::format_to( out, "{}{} ", name(), entry );
fmt::format_to( out, "\n" );
}
private:
opts::list_t& _ref;
};
struct opts_deperecated_t : public option_t
{
opts_deperecated_t( util::string_view name, util::string_view new_option ) :
option_t( name ),
_new_option( new_option )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view name, util::string_view ) const override
{
if ( name != this -> name() )
return opts::parse_status::CONTINUE;
throw std::invalid_argument( fmt::format(
"Option '{}' has been deprecated. Please use option '{}' instead.", name, _new_option ) );
return opts::parse_status::DEPRECATED;
}
void do_format_to( fmt::format_context::iterator out ) const override
{
fmt::format_to( out, "Option '{}' has been deprecated. Please use '{}'.\n", name(), _new_option );
}
private:
std::string _new_option;
};
struct opts_obsoleted_t : public option_t
{
opts_obsoleted_t( util::string_view name ) :
option_t( name )
{ }
protected:
opts::parse_status do_parse( sim_t*, util::string_view name, util::string_view ) const override
{
if ( name != this -> name() )
return opts::parse_status::CONTINUE;
fmt::print( stderr, "Option '{}' has been obsoleted and will be removed in the future.\n", name );
return opts::parse_status::OK;
}
void do_format_to( fmt::format_context::iterator ) const override
{
// do nothing
}
};
} // opts
opts::parse_status option_t::parse( sim_t* sim, util::string_view name, util::string_view value ) const
{
try
{
return do_parse( sim, name, value );
}
catch ( const std::exception& )
{
std::throw_with_nested( std::invalid_argument( fmt::format( "Option '{}' with value '{}'", name, value ) ) );
}
}
void sc_format_to( const option_t& option, fmt::format_context::iterator out )
{
option.do_format_to( out );
}
// option_t::parse ==========================================================
opts::parse_status opts::parse( sim_t* sim,
util::span<const std::unique_ptr<option_t>> options,
util::string_view name,
util::string_view value,
const parse_status_fn_t& status_fn )
{
for ( auto& option : options )
{
auto ret = option->parse( sim, name, value );
if ( ret != parse_status::CONTINUE )
{
if ( status_fn )
{
ret = status_fn( ret, name, value );
}
return ret;
}
}
auto ret = parse_status::NOT_FOUND;
if ( status_fn )
{
ret = status_fn( parse_status::NOT_FOUND, name, value );
}
return ret;
}
// option_t::parse ==========================================================
void opts::parse( sim_t* sim, util::string_view /* context */, util::span<const std::unique_ptr<option_t>> options,
util::string_view options_str, const parse_status_fn_t& status_fn )
{
for ( auto& split : util::string_split<util::string_view>( options_str, "," ) )
{
auto index = split.find_first_of( '=' );
if ( index == std::string::npos )
{
throw std::invalid_argument( fmt::format( "Unexpected parameter '{}'. Expected format: name=value", split ) );
}
auto name = split.substr( 0, index );
auto value = split.substr( index + 1 );
auto status = opts::parse( sim, options, name, value, status_fn );
if ( status == parse_status::FAILURE )
{
throw std::invalid_argument( fmt::format( "Unexpected parameter '{}'.", name ) );
}
}
}
// option_db_t::parse_file ==================================================
bool option_db_t::parse_file( std::istream& input )
{
std::string buffer;
bool first = true;
while ( input.good() )
{
std::getline( input, buffer );
auto it = buffer.begin();
auto end = buffer.end();
if ( first )
{
first = false;
// Skip the UTF-8 BOM, if any.
if ( utf8::starts_with_bom( it, end ) )
{
it += std::size( utf8::bom );
}
}
while ( it != end && is_white_space( *it ) )
{
++it;
}
if ( it == end || *it == '#' )
{
continue;
}
auto len = std::distance( buffer.begin(), it );
assert(len >= 0 && as<size_t>(len) <= buffer.size());
auto substring = buffer.substr(len);
parse_line( io::maybe_latin1_to_utf8( substring ) );
}
return true;
}
// option_db_t::parse_text ==================================================
void option_db_t::parse_text( util::string_view text )
{
// Split a chunk of text into lines to parse.
std::string::size_type first = 0;
while ( true )
{
while ( first < text.size() && is_white_space( text[ first ] ) )
{
++first;
}
if ( first >= text.size() )
{
break;
}
auto last = text.find( '\n', first );
if ( text[ first ] != '#' )
{
parse_line( text.substr( first, last - first ) );
}
first = last;
}
}
// option_db_t::parse_line ==================================================
void option_db_t::parse_line( util::string_view line )
{
if ( line[ 0 ] == '#' )
{
return;
}
// Strip whitespace outside of double-quoted regions.
// Since spaces are never valid within option tokens (they are
// already used as token separators), this is a lossless operation
// that allows users to write readable .simc files with spaces.
std::string stripped;
stripped.reserve( line.size() );
bool in_quotes = false;
for ( char c : line )
{
if ( c == '"' )
{
in_quotes = !in_quotes;
stripped += c;
}
else if ( in_quotes || !is_white_space( c ) )
{
stripped += c;
}
}
auto tokens = util::string_split_allow_quotes( stripped, " \t\n\r" );
for ( const auto& token : tokens )
{
parse_token( token );
}
}
// option_db_t::parse_token =================================================
void option_db_t::parse_token( util::string_view token )
{
if ( token == "-" )
{
parse_file( std::cin );
return;
}
std::string parsed_token = std::string( token );
std::string::size_type cut_pt = parsed_token.find( '=' );
// Expand the token with template variables, and try to find '=' again
if ( cut_pt == std::string::npos )
{
do_replace( *this, parsed_token, parsed_token.find( "$(" ), 1 );
cut_pt = parsed_token.find( '=' );
}
if ( cut_pt == token.npos )
{
std::string actual_name;
io::ifstream input;
open_file( input, auto_path, parsed_token, actual_name );
if ( !input.is_open() )
{
throw sc_network_error( fmt::format( "Unable to open input parameter file '{}'.", parsed_token ) );
}
parse_file( input );
return;
}
std::string name( parsed_token, 0, cut_pt );
std::string value( parsed_token, cut_pt + 1, std::string::npos );
do_replace( *this, value, value.find( "$(" ), 1 );
if ( !name.empty() && name[ 0 ] == '$' )
{
if ( name.size() < 3 || name[ 1 ] != '(' || name[ name.size() - 1 ] != ')' )
{
throw std::invalid_argument( fmt::format( "Variable syntax error: '{}", parsed_token ) );
}
auto var_name = name.substr( 2, name.size() - 3 );
do_replace( *this, var_name, var_name.find( "$(" ), 1 );
var_map[ var_name ] = value;
}
else if ( name == "input" )
{
std::string current_base_name;
auto base_name_it = var_map.find( "current_base_name" );
if ( base_name_it != var_map.end() )
{
current_base_name = base_name_it -> second;
}
std::string actual_name;
io::ifstream input;
open_file( input, auto_path, value, actual_name );
if ( !input.is_open() )
{
throw sc_network_error( fmt::format("Unable to open input parameter file '{}'.", value) );
}
else
{
var_map[ "current_base_name" ] = base_name( actual_name );
}
parse_file( input );
if ( base_name_it != var_map.end() )
{
var_map[ "current_base_name" ] = current_base_name;
}
}
else
{
// Replace any template variable in the name portion of the option, if found
do_replace( *this, name, name.find( "$(" ), 1 );
add( "global", name, value );
}
}
// option_db_t::parse_args ==================================================
void option_db_t::parse_args( util::span<const std::string> args )
{
for ( auto& arg : args )
{
parse_token( arg );
}
}
// option_db_t::option_db_t =================================================
option_db_t::option_db_t()
{
std::vector<std::string> paths = { "..", "./profiles", "../profiles", SC_SHARED_DATA };
#if defined(SC_LINUX)
paths.emplace_back("~/.local/share/SimulationCraft/SimulationCraft/profiles");
paths.emplace_back("/usr/local/share/SimulationCraft/SimulationCraft/profiles");
paths.emplace_back("/usr/share/SimulationCraft/SimulationCraft/profiles");
paths.emplace_back("./share/SimulationCraft/SimulationCraft/profiles");
#endif
// This makes baby pandas cry a bit less, but still makes them weep.
// Add current directory automagically.
auto_path.emplace_back("." );
// Automatically add "./profiles" and "../profiles", because the command line
// client is ran both from the engine/ subdirectory, as well as the source
// root directory, depending on whether the user issues make install or not.
// In addition, if SC_SHARED_DATA is given, search our profile directory
// structure directly from there as well.
for ( auto path : paths )
{
// Skip empty SHARED_DATA define, as the default ("..") is already
// included.
if ( path.empty() )
continue;
// Skip current path, we arleady have that
if ( path == "." )
continue;
auto_path.push_back( path );
path += "/";
// Add profiles that doesn't match the tier pattern
auto_path.push_back( path + "generators" );
auto_path.push_back( path + "generators/PreRaids" );
auto_path.push_back( path + "PreRaids" );
auto_path.push_back( path + "generators/DungeonSlice" );
auto_path.push_back( path + "DungeonSlice" );
// Add profiles for each season
// MID1, MID2, MID3, ...
std::string expansion = "MID";
for ( unsigned i = 0; i < N_SEASON; ++i )
{
auto_path.push_back( fmt::format( "{}generators/{}{}", path, expansion, MIN_SEASON + i ) );
auto_path.push_back( fmt::format( "{}{}{}", path, expansion, MIN_SEASON + i ) );
}
}
// Bossevents
for ( auto path : paths )
{
// Skip empty SHARED_DATA define, as the default ("..") is already
// included.
if ( path.empty() )
continue;
// Skip current path, we arleady have that
if ( path == "." )
continue;
path += "/Bossevents";
auto_path.push_back( path );
path += "/";
}
// Make sure we only have unique entries
auto it = std::unique(auto_path.begin(), auto_path.end());
auto_path.resize( std::distance(auto_path.begin(), it) );
}
std::unique_ptr<option_t> opt_string( std::string_view n, std::string& v )
{ return std::unique_ptr<option_t>( new opt_string_t( n, v ) ); }
std::unique_ptr<option_t> opt_string_warn( std::string_view n, std::string& v )
{ return std::unique_ptr<option_t>( new opt_string_t( n, v, true ) ); }
std::unique_ptr<option_t> opt_append( std::string_view n, std::string& v )
{ return std::unique_ptr<option_t>( new opt_append_t( n, v ) ); }
std::unique_ptr<option_t> opt_bool( std::string_view n, int& v )
{ return std::unique_ptr<option_t>( new opt_bool_int_t( n, v ) ); }
std::unique_ptr<option_t> opt_bool( std::string_view n, bool& v )
{ return std::unique_ptr<option_t>( new opt_bool_t( n, v ) ); }
std::unique_ptr<option_t> opt_uint64( std::string_view n, uint64_t& v )
{ return std::unique_ptr<option_t>( new opt_numeric_t<uint64_t, converter_uint64_t>( n, v ) ); }
std::unique_ptr<option_t> opt_int( std::string_view n, int& v )
{ return std::unique_ptr<option_t>( new opt_numeric_t<int, converter_int_t>( n, v ) ); }
std::unique_ptr<option_t> opt_int( std::string_view n, int& v, int min, int max )
{ return std::unique_ptr<option_t>( new opt_numeric_mm_t<int, converter_int_t>( n, v, min, max ) ); }
std::unique_ptr<option_t> opt_uint( std::string_view n, unsigned& v )
{ return std::unique_ptr<option_t>( new opt_numeric_t<unsigned, converter_uint_t>( n, v ) ); }
std::unique_ptr<option_t> opt_uint( std::string_view n, unsigned& v, unsigned min, unsigned max )
{ return std::unique_ptr<option_t>( new opt_numeric_mm_t<unsigned, converter_uint_t>( n, v, min, max ) ); }
std::unique_ptr<option_t> opt_float( std::string_view n, double& v )
{ return std::unique_ptr<option_t>( new opt_numeric_t<double, converter_double_t>( n, v ) ); }
std::unique_ptr<option_t> opt_float( std::string_view n, double& v, double min, double max )
{ return std::unique_ptr<option_t>( new opt_numeric_mm_t<double, converter_double_t>( n, v, min, max ) ); }
std::unique_ptr<option_t> opt_timespan( std::string_view n, timespan_t& v )
{ return std::unique_ptr<option_t>( new opt_numeric_t<timespan_t, converter_timespan_t>( n, v ) ); }
std::unique_ptr<option_t> opt_timespan( std::string_view n, timespan_t& v, timespan_t min, timespan_t max )
{ return std::unique_ptr<option_t>( new opt_numeric_mm_t<timespan_t, converter_timespan_t>( n, v, min, max ) ); }
std::unique_ptr<option_t> opt_list( std::string_view n, opts::list_t& v )
{ return std::unique_ptr<option_t>( new opts_list_t( n, v ) ); }
std::unique_ptr<option_t> opt_map( std::string_view n, opts::map_t& v )
{ return std::unique_ptr<option_t>( new opts_map_t( n, v ) ); }
std::unique_ptr<option_t> opt_map_list( std::string_view n, opts::map_list_t& v )
{ return std::unique_ptr<option_t>( new opts_map_list_t( n, v ) ); }
std::unique_ptr<option_t> opt_func( std::string_view n, const opts::function_t& f )
{ return std::unique_ptr<option_t>( new opts_sim_func_t( n, f ) ); }
std::unique_ptr<option_t> opt_deprecated( std::string_view n, std::string_view new_option )
{ return std::unique_ptr<option_t>( new opts_deperecated_t( n, new_option ) ); }
std::unique_ptr<option_t> opt_obsoleted( std::string_view n )
{ return std::unique_ptr<option_t>( new opts_obsoleted_t( n ) ); }