Skip to content

Commit

Permalink
move options to their own header file.
Browse files Browse the repository at this point in the history
silence clang -Winconsistent-missing-override warnings for now.
  • Loading branch information
scamille committed Oct 7, 2015
1 parent b85c140 commit 19a4c05
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 88 deletions.
2 changes: 1 addition & 1 deletion engine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ endif

MKDIR = mkdir
CXX = g++
CPP_FLAGS = -Wall -Wextra -Woverloaded-virtual -W -I. -DSC_SHARED_DATA=\"$(SHARED_DATA)\" --std=c++0x -O3
CPP_FLAGS = -Wall -Wextra -Woverloaded-virtual -W -I. -DSC_SHARED_DATA=\"$(SHARED_DATA)\" --std=c++0x -O3 -Wno-inconsistent-missing-override
OPTS =

LINK_LIBS =
Expand Down
6 changes: 5 additions & 1 deletion engine/sc_timespan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ class timespan_t
return timespan_t( std::numeric_limits<time_t>::min() );
}
};

inline std::ostream& operator<<(std::ostream &os, const timespan_t& x )
{
os << x.total_seconds() << "seconds";
return os;
}
} // namespace timespan_adl_barrier =========================================

using timespan_adl_barrier::timespan_t;
Expand Down
5 changes: 5 additions & 0 deletions engine/sc_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

#include "config.hpp"

#include "sc_enums.hpp"
#include "dbc/data_enums.hh"
#include "dbc/specialization.hpp"
#include <sstream>
#include <vector>
#include <string>

// Forward delcarations
struct player_t;
Expand Down
8 changes: 7 additions & 1 deletion engine/sim/sc_option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
// Send questions to [email protected]
// ==========================================================================

#include "simulationcraft.hpp"
#include "sc_option.hpp"

#include <sstream>
#include <iostream>

#include "util/io.hpp"
#include "sc_util.hpp"

namespace { // UNNAMED NAMESPACE ============================================

Expand Down
96 changes: 96 additions & 0 deletions engine/sim/sc_option.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 );
};
85 changes: 2 additions & 83 deletions engine/simulationcraft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ class xml_writer_t;

// Time class representing ingame time
#include "sc_timespan.hpp"
inline std::ostream& operator<<(std::ostream &os, const timespan_t& x )
{
os << x.total_seconds() << "seconds";
return os;
}

// Generic programming tools
#include "util/generic.hpp"
Expand Down Expand Up @@ -227,60 +222,7 @@ struct stopwatch_t
stopwatch_t( stopwatch_e t = STOPWATCH_CPU ) : type( t ) { mark(); }
};
#include "sc_util.hpp"

// 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::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 );

#include "sim/sc_option.hpp"

// Data Access ==============================================================
const int MAX_LEVEL = 100;
Expand Down Expand Up @@ -1302,29 +1244,6 @@ struct iteration_data_entry_t

// Simulation Setup =========================================================

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 );
};

struct player_description_t
{
// Add just enough to describe a player
Expand Down Expand Up @@ -3627,7 +3546,7 @@ struct player_t : public actor_t
action_priority_list_t* active_action_list;
action_priority_list_t* active_off_gcd_list;
action_priority_list_t* restore_action_list;
std::map<std::string, std::string> alist_map;
std::unordered_map<std::string, std::string> alist_map;
std::string action_list_information; // comment displayed in profile
bool no_action_list_provided;

Expand Down
1 change: 1 addition & 0 deletions source_files/QT_engine.pri
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
HEADERS += engine/util/generic.hpp
HEADERS += engine/util/concurrency.hpp
HEADERS += engine/util/cache.hpp
HEADERS += engine/sim/sc_option.hpp
HEADERS += engine/report/sc_report.hpp
HEADERS += engine/dbc/specialization.hpp
HEADERS += engine/dbc/dbc.hpp
Expand Down
5 changes: 3 additions & 2 deletions source_files/VS_engine.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ To change the list of source files, update the QT_ files and run synchronize.py
<ClInclude Include="..\engine\util\generic.hpp" />
<ClInclude Include="..\engine\util\concurrency.hpp" />
<ClInclude Include="..\engine\util\cache.hpp" />
<ClInclude Include="..\engine\sim\sc_option.hpp" />
<ClInclude Include="..\engine\report\sc_report.hpp" />
<ClInclude Include="..\engine\dbc\specialization.hpp" />
<ClInclude Include="..\engine\dbc\dbc.hpp" />
Expand Down Expand Up @@ -63,7 +64,7 @@ To change the list of source files, update the QT_ files and run synchronize.py

</ClCompile>
<ClCompile Include="..\engine\sim\sc_option.cpp">

<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\engine\sim\sc_gear_stats.cpp">

Expand Down Expand Up @@ -147,7 +148,7 @@ To change the list of source files, update the QT_ files and run synchronize.py

</ClCompile>
<ClCompile Include="..\engine\dbc\sc_item_data_import_ptr.cpp">

<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\engine\dbc\sc_item_data_import_noptr.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
Expand Down
1 change: 1 addition & 0 deletions source_files/engine_make
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SRC += \
util$(PATHSEP)generic.hpp \
util$(PATHSEP)concurrency.hpp \
util$(PATHSEP)cache.hpp \
sim$(PATHSEP)sc_option.hpp \
report$(PATHSEP)sc_report.hpp \
dbc$(PATHSEP)specialization.hpp \
dbc$(PATHSEP)dbc.hpp \
Expand Down

0 comments on commit 19a4c05

Please sign in to comment.