forked from simulationcraft/simc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc_option.hpp
96 lines (82 loc) · 3.87 KB
/
sc_option.hpp
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
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to [email protected]
// ==========================================================================
#pragma once
#include "config.hpp"
#include <string>
#include <iostream>
#include <unordered_map>
#include <functional>
#include <vector>
#include <memory>
#include <cstring>
#include "sc_timespan.hpp"
struct sim_t;
// Options ==================================================================
struct option_t
{
public:
option_t( const std::string& name ) :
_name( name )
{ }
virtual ~option_t() { }
bool parse_option( sim_t* sim , const std::string& n, const std::string& value ) const
{ return parse( sim, n, value ); }
std::string name() const
{ return _name; }
std::ostream& print_option( std::ostream& stream ) const
{ return print( stream ); }
protected:
virtual bool parse( sim_t*, const std::string& name, const std::string& value ) const = 0;
virtual std::ostream& print( std::ostream& stream ) const = 0;
private:
std::string _name;
};
namespace opts {
typedef std::unordered_map<std::string, std::string> map_t;
typedef std::function<bool(sim_t*,const std::string&, const std::string&)> function_t;
typedef std::vector<std::string> list_t;
bool parse( sim_t*, const std::vector<std::unique_ptr<option_t>>&, const std::string& name, const std::string& value );
void parse( sim_t*, const std::string& context, const std::vector<std::unique_ptr<option_t>>&, const std::string& options_str );
void parse( sim_t*, const std::string& context, const std::vector<std::unique_ptr<option_t>>&, const std::vector<std::string>& strings );
}
inline std::ostream& operator<<( std::ostream& stream, const std::unique_ptr<option_t>& opt )
{ return opt -> print_option( stream ); }
std::unique_ptr<option_t> opt_string( const std::string& n, std::string& v );
std::unique_ptr<option_t> opt_append( const std::string& n, std::string& v );
std::unique_ptr<option_t> opt_bool( const std::string& n, int& v );
std::unique_ptr<option_t> opt_bool( const std::string& n, bool& v );
std::unique_ptr<option_t> opt_uint64( const std::string& n, uint64_t& v );
std::unique_ptr<option_t> opt_int( const std::string& n, int& v );
std::unique_ptr<option_t> opt_int( const std::string& n, int& v, int , int );
std::unique_ptr<option_t> opt_uint( const std::string& n, unsigned& v );
std::unique_ptr<option_t> opt_uint( const std::string& n, unsigned& v, unsigned , unsigned );
std::unique_ptr<option_t> opt_float( const std::string& n, double& v );
std::unique_ptr<option_t> opt_float( const std::string& n, double& v, double , double );
std::unique_ptr<option_t> opt_timespan( const std::string& n, timespan_t& v );
std::unique_ptr<option_t> opt_timespan( const std::string& n, timespan_t& v, timespan_t , timespan_t );
std::unique_ptr<option_t> opt_list( const std::string& n, opts::list_t& v );
std::unique_ptr<option_t> opt_map( const std::string& n, opts::map_t& v );
std::unique_ptr<option_t> opt_func( const std::string& n, const opts::function_t& f );
std::unique_ptr<option_t> opt_deprecated( const std::string& n, const std::string& new_option );
struct option_tuple_t
{
std::string scope, name, value;
option_tuple_t( const std::string& s, const std::string& n, const std::string& v ) : scope( s ), name( n ), value( v ) {}
};
struct option_db_t : public std::vector<option_tuple_t>
{
std::vector<std::string> auto_path;
std::unordered_map<std::string, std::string> var_map;
option_db_t();
void add( const std::string& scope, const std::string& name, const std::string& value )
{
push_back( option_tuple_t( scope, name, value ) );
}
bool parse_file( FILE* file );
void parse_token( const std::string& token );
void parse_line( const std::string& line );
void parse_text( const std::string& text );
void parse_args( const std::vector<std::string>& args );
};