Used std::optional directly since we support C++17 now

This commit is contained in:
Charles Dang 2021-01-17 10:06:22 +11:00
parent 8433134e53
commit 4d54b2a7fd
45 changed files with 177 additions and 229 deletions

View file

@ -51,7 +51,7 @@
#include "units/udisplay.hpp"
#include "units/unit.hpp"
#include "units/types.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include "whiteboard/manager.hpp"
#include "wml_exception.hpp"
@ -137,7 +137,7 @@ battle_context_unit_stats::battle_context_unit_stats(nonempty_unit_const_ptr up,
// Get the weapon characteristics as appropriate.
auto ctx = weapon->specials_context(up, oppp, u_loc, opp_loc, attacking, opp_weapon);
utils::optional<decltype(ctx)> opp_ctx;
std::optional<decltype(ctx)> opp_ctx;
if(opp_weapon) {
opp_ctx.emplace(opp_weapon->specials_context(oppp, up, opp_loc, u_loc, !attacking, weapon));
@ -299,7 +299,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
// Get the weapon characteristics as appropriate.
auto ctx = weapon->specials_context(*u_type, map_location::null_location(), attacking);
utils::optional<decltype(ctx)> opp_ctx;
std::optional<decltype(ctx)> opp_ctx;
if(opp_weapon) {
opp_ctx.emplace(opp_weapon->specials_context(*opp_type, map_location::null_location(), !attacking));
@ -881,7 +881,7 @@ void attack::fire_event(const std::string& n)
config& d_weapon_cfg = ev_data.add_child("second");
// Need these to ensure weapon filters work correctly
utils::optional<attack_type::specials_context_t> a_ctx, d_ctx;
std::optional<attack_type::specials_context_t> a_ctx, d_ctx;
if(a_stats_->weapon != nullptr && a_.valid()) {
if(d_stats_->weapon != nullptr && d_.valid()) {

View file

@ -14,7 +14,7 @@
#pragma once
#include "utils/optional_fwd.hpp"
#include <optional>
#include <boost/program_options/options_description.hpp>
#include <iosfwd> // for ostream
@ -51,90 +51,90 @@ public:
bool any_validation_option() const;
/** Non-empty if --bunzip2 was given on the command line. Uncompresses a .bz2 file and exits. */
utils::optional<std::string> bunzip2;
std::optional<std::string> bunzip2;
/** Non-empty if --bzip2 was given on the command line. Compresses a file to .bz2 and exits. */
utils::optional<std::string> bzip2;
std::optional<std::string> bzip2;
/** Non-empty if --campaign was given on the command line. ID of the campaign we want to start. */
utils::optional<std::string> campaign;
std::optional<std::string> campaign;
/** Non-empty if --campaign-difficulty was given on the command line. Numerical difficulty of the campaign to be played. Dependent on --campaign. */
utils::optional<int> campaign_difficulty;
std::optional<int> campaign_difficulty;
/** Non-empty if --campaign-scenario was given on the command line. Chooses starting scenario in the campaign to be played. Dependent on --campaign. */
utils::optional<std::string> campaign_scenario;
std::optional<std::string> campaign_scenario;
/** True if --skip-story was given on the command line. Skips [story] and [message]s through the end of the "start" event. Dependent on --campaign. */
bool campaign_skip_story;
/** True if --clock was given on the command line. Enables */
bool clock;
/** Non-empty if --core was given on the command line. Chooses the core to be loaded. */
utils::optional<std::string> core_id;
std::optional<std::string> core_id;
/** True if --data-path was given on the command line. Prints path to data directory and exits. */
bool data_path;
/** Non-empty if --data-dir was given on the command line. Sets the config dir to the specified one. */
utils::optional<std::string> data_dir;
std::optional<std::string> data_dir;
/** True if --debug was given on the command line. Enables debug mode. */
bool debug;
/** True if --debug-lua was given in the commandline. Enables some Lua debugging mechanisms. */
bool debug_lua;
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
/** Non-empty if --debug-dot-domain was given on the command line. */
utils::optional<std::string> debug_dot_domain;
std::optional<std::string> debug_dot_domain;
/** Non-empty if --debug-dot-level was given on the command line. */
utils::optional<std::string> debug_dot_level;
std::optional<std::string> debug_dot_level;
#endif
/** Non-empty if --editor was given on the command line. Goes directly into editor. If string is longer than 0, it contains path to the file to edit. */
utils::optional<std::string> editor;
std::optional<std::string> editor;
/** True if --fps was given on the command line. Shows number of fps. */
bool fps;
/** True if --fullscreen was given on the command line. Starts Wesnoth in fullscreen mode. */
bool fullscreen;
/** Non-empty if --gunzip was given on the command line. Uncompresses a .gz file and exits. */
utils::optional<std::string> gunzip;
std::optional<std::string> gunzip;
/** Non-empty if --gzip was given on the command line. Compresses a file to .gz and exits. */
utils::optional<std::string> gzip;
std::optional<std::string> gzip;
/** True if --help was given on the command line. Prints help and exits. */
bool help;
/** Non-empty if --language was given on the command line. Sets the language for this session. */
utils::optional<std::string> language;
std::optional<std::string> language;
/**
* Contains parsed arguments of --log-* (e.g. --log-debug).
* Vector of pairs (severity, log domain).
*/
utils::optional<std::vector<std::pair<int, std::string>>> log;
std::optional<std::vector<std::pair<int, std::string>>> log;
/** Non-empty if --log-strict was given */
utils::optional<int> log_strict_level;
std::optional<int> log_strict_level;
/** Non-empty if --load was given on the command line. Savegame specified to load after start. */
utils::optional<std::string> load;
std::optional<std::string> load;
/** Non-empty if --logdomains was given on the command line. Prints possible logdomains filtered by given string and exits. */
utils::optional<std::string> logdomains;
std::optional<std::string> logdomains;
/** True if --log-precise was given on the command line. Shows timestamps in log with more precision. */
bool log_precise_timestamps;
/** True if --multiplayer was given on the command line. Goes directly into multiplayer mode. */
bool multiplayer;
/** Non-empty if --ai-config was given on the command line. Vector of pairs (side number, value). Dependent on --multiplayer. */
utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_ai_config;
std::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_ai_config;
/** Non-empty if --algorithm was given on the command line. Vector of pairs (side number, value). Dependent on --multiplayer. */
utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_algorithm;
std::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_algorithm;
/** Non-empty if --controller was given on the command line. Vector of pairs (side number, controller). Dependent on --multiplayer. */
utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_controller;
std::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_controller;
/** Non-empty if --era was given on the command line. Dependent on --multiplayer. */
utils::optional<std::string> multiplayer_era;
std::optional<std::string> multiplayer_era;
/** True if --exit-at-and was given on the command line. Dependent on --multiplayer. */
bool multiplayer_exit_at_end;
/** True if --ignore-map-settings was given at the command line. Do not use map settings. */
bool multiplayer_ignore_map_settings;
/** Non-empty if --label was given on the command line. Dependent on --multiplayer. */
utils::optional<std::string> multiplayer_label;
std::optional<std::string> multiplayer_label;
/** Non-empty if --parm was given on the command line. Vector of pairs (side number, parm name, parm value). Dependent on --multiplayer. */
utils::optional<std::vector<std::tuple<unsigned int, std::string, std::string>>> multiplayer_parm;
std::optional<std::vector<std::tuple<unsigned int, std::string, std::string>>> multiplayer_parm;
/** Repeats specified by --multiplayer-repeat option. Repeats a multiplayer game after it is finished. Dependent on --multiplayer. */
utils::optional<unsigned int> multiplayer_repeat;
std::optional<unsigned int> multiplayer_repeat;
/** Non-empty if --scenario was given on the command line. Dependent on --multiplayer. */
utils::optional<std::string> multiplayer_scenario;
std::optional<std::string> multiplayer_scenario;
/** Non-empty if --side was given on the command line. Vector of pairs (side number, faction id). Dependent on --multiplayer. */
utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_side;
std::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_side;
/** Non-empty if --turns was given on the command line. Dependent on --multiplayer. */
utils::optional<std::string> multiplayer_turns;
std::optional<std::string> multiplayer_turns;
/** Max FPS specified by --max-fps option. */
utils::optional<int> max_fps;
std::optional<int> max_fps;
/** True if --noaddons was given on the command line. Disables the loading of all add-ons. */
bool noaddons;
/** True if --nocache was given on the command line. Disables cache usage. */
@ -152,45 +152,45 @@ public:
/** True if --preprocess was given on the command line. Starts Wesnoth in preprocessor-only mode. */
bool preprocess;
/** Defines that were given to the --preprocess option. */
utils::optional<std::vector<std::string>> preprocess_defines;
std::optional<std::vector<std::string>> preprocess_defines;
/** Non-empty if --preprocess-input-macros was given on the command line. Specifies a file that contains [preproc_define]s to be included before preprocessing. Dependent on --preprocess. */
utils::optional<std::string> preprocess_input_macros;
std::optional<std::string> preprocess_input_macros;
/** Non-empty if --preprocess-output-macros was given on the command line. Outputs all preprocessed macros to the specified file. Dependent on --preprocess. */
utils::optional<std::string> preprocess_output_macros;
std::optional<std::string> preprocess_output_macros;
/** Path to parse that was given to the --preprocess option. */
utils::optional<std::string> preprocess_path;
std::optional<std::string> preprocess_path;
/** Target (output) path that was given to the --preprocess option. */
utils::optional<std::string> preprocess_target;
std::optional<std::string> preprocess_target;
/** Pair of AxB values specified after --resolution. Changes Wesnoth resolution. */
utils::optional<std::pair<int,int>> resolution;
std::optional<std::pair<int,int>> resolution;
/** RNG seed specified by --rng-seed option. Initializes RNG with given seed. */
utils::optional<unsigned int> rng_seed;
std::optional<unsigned int> rng_seed;
/** Non-empty if --server was given on the command line. Connects Wesnoth to specified server. If no server was specified afterwards, contains an empty string. */
utils::optional<std::string> server;
std::optional<std::string> server;
/** Non-empty if --username was given on the command line. Forces Wesnoth to use this network username. */
utils::optional<std::string> username;
std::optional<std::string> username;
/** Non-empty if --password was given on the command line. Forces Wesnoth to use this network password. */
utils::optional<std::string> password;
std::optional<std::string> password;
/** Image path to render. First parameter after --render-image */
utils::optional<std::string> render_image;
std::optional<std::string> render_image;
/** Output file to put rendered image path in. Optional second parameter after --render-image */
utils::optional<std::string> render_image_dst;
std::optional<std::string> render_image_dst;
/** True if --screenshot was given on the command line. Starts Wesnoth in screenshot mode. */
bool screenshot;
/** Map file to make a screenshot of. First parameter given after --screenshot. */
utils::optional<std::string> screenshot_map_file;
std::optional<std::string> screenshot_map_file;
/** Output file to put screenshot in. Second parameter given after --screenshot. */
utils::optional<std::string> screenshot_output_file;
std::optional<std::string> screenshot_output_file;
/** File to load lua script from. */
utils::optional<std::string> script_file;
std::optional<std::string> script_file;
/** File to load a lua plugin (similar to a script) from. Experimental / may replace script. */
utils::optional<std::string> plugin_file;
std::optional<std::string> plugin_file;
/** Whether to load the "package" package for the scripting environment. (This allows to load arbitrary lua packages, and gives untrusted lua the same permissions as wesnoth executable) */
bool script_unsafe_mode;
/** True if --strict-validation was given on the command line. Makes Wesnoth trust validation errors as fatal WML errors and create WML exception, if so. */
bool strict_validation;
/** Non-empty if --test was given on the command line. Goes directly into test mode, into a scenario, if specified. */
utils::optional<std::string> test;
std::optional<std::string> test;
/** Non-empty if --unit was given on the command line. Goes directly into unit test mode, into a scenario, if specified. */
std::vector<std::string> unit_test;
/** True if --unit is used and --showgui is not present. */
@ -202,25 +202,25 @@ public:
/** True if --userconfig-path was given on the command line. Prints path to user config directory and exits. */
bool userconfig_path;
/** Non-empty if --userconfig-dir was given on the command line. Sets the user config dir to the specified one. */
utils::optional<std::string> userconfig_dir;
std::optional<std::string> userconfig_dir;
/** True if --userdata-path was given on the command line. Prints path to user data directory and exits. */
bool userdata_path;
/** Non-empty if --userdata-dir was given on the command line. Sets the user data dir to the specified one. */
utils::optional<std::string> userdata_dir;
std::optional<std::string> userdata_dir;
/** True if --validcache was given on the command line. Makes Wesnoth assume the cache is valid. */
bool validcache;
/** True if --validate-core was given on the command line. Makes Wesnoth validate the core WML. */
bool validate_core;
/** Non-empty if --validate-addon was given on the command line. Makes Wesnoth validate an addon's WML. */
utils::optional<std::string> validate_addon;
std::optional<std::string> validate_addon;
/** Non-empty if --validate-schema was given on the command line. Makes Wesnoth validate a WML schema. */
utils::optional<std::string> validate_schema;
std::optional<std::string> validate_schema;
/** Non-empty if --validate was given on the command line. Makes Wesnoth validate a WML file against a schema. */
utils::optional<std::string> validate_wml;
std::optional<std::string> validate_wml;
/** Non-empty if --use-schema was given on the command line. Specifies the schema for use with --validate. */
utils::optional<std::string> validate_with;
std::optional<std::string> validate_with;
/** Output filename for WML diff or preprocessing */
utils::optional<std::string> output_file;
std::optional<std::string> output_file;
bool do_diff, do_patch;
/** Files for diffing or patching */
std::string diff_left, diff_right;
@ -233,7 +233,7 @@ public:
/** True if --with-replay was given on the command line. Shows replay of the loaded file. */
bool with_replay;
/** Non-empty if --all-translations or --translations-over is given on the command line. */
utils::optional<unsigned int> translation_percent;
std::optional<unsigned int> translation_percent;
private:
void parse_log_domains_(const std::string &domains_string, const int severity);
void parse_log_strictness (const std::string &severity);

View file

@ -24,7 +24,7 @@
#include "team.hpp"
#include "tod_manager.hpp"
#include "units/map.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <vector>
class game_config_view;
@ -313,7 +313,7 @@ public:
const t_string get_default_context_name() const;
utils::optional<int> get_xp_mod() const { return xp_mod_; }
std::optional<int> get_xp_mod() const { return xp_mod_; }
bool random_start_time() const { return random_time_; }
bool victory_defeated() const { return !victory_defeated_ || *victory_defeated_; }
@ -494,8 +494,8 @@ private:
std::string scenario_id_, scenario_name_, scenario_description_;
utils::optional<int> xp_mod_;
utils::optional<bool> victory_defeated_;
std::optional<int> xp_mod_;
std::optional<bool> victory_defeated_;
bool random_time_;
int active_area_;

View file

@ -17,7 +17,7 @@
#include "config.hpp"
#include "lexical_cast.hpp"
#include "serialization/string_utils.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <string>
#include <utility>
@ -53,8 +53,8 @@ struct subset_descriptor
}
std::string name;
utils::optional<std::string> bold_name; //If we are using another font for styled characters in this font, rather than SDL TTF method
utils::optional<std::string> italic_name;
std::optional<std::string> bold_name; //If we are using another font for styled characters in this font, rather than SDL TTF method
std::optional<std::string> italic_name;
};
} // end namespace font

View file

@ -286,9 +286,9 @@ bool game_board::try_add_unit_to_recall_list(const map_location&, const unit_ptr
return true;
}
utils::optional<std::string> game_board::replace_map(const gamemap& newmap)
std::optional<std::string> game_board::replace_map(const gamemap& newmap)
{
utils::optional<std::string> ret;
std::optional<std::string> ret;
/* Remember the locations where a village is owned by a side. */
std::map<map_location, int> villages;

View file

@ -18,7 +18,7 @@
#include "team.hpp"
#include "units/map.hpp"
#include "units/id.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <set>
#include <vector>
@ -155,7 +155,7 @@ public:
// Manipulator from actionwml
bool try_add_unit_to_recall_list(const map_location& loc, const unit_ptr u);
utils::optional<std::string> replace_map(const gamemap & r);
std::optional<std::string> replace_map(const gamemap & r);
bool change_terrain(const map_location &loc, const std::string &t,
const std::string & mode, bool replace_if_failed); //used only by lua and debug commands

View file

@ -87,9 +87,9 @@ bool game_config_manager::init_game_config(FORCE_RELOAD_CONFIG force_reload)
{
// Add preproc defines according to the command line arguments.
game_config::scoped_preproc_define multiplayer("MULTIPLAYER", cmdline_opts_.multiplayer);
game_config::scoped_preproc_define test("TEST", utils::has_optional_value(cmdline_opts_.test));
game_config::scoped_preproc_define test("TEST", cmdline_opts_.test.has_value());
game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest);
game_config::scoped_preproc_define editor("EDITOR", utils::has_optional_value(cmdline_opts_.editor));
game_config::scoped_preproc_define editor("EDITOR", cmdline_opts_.editor.has_value());
game_config::scoped_preproc_define title_screen("TITLE_SCREEN",
!cmdline_opts_.multiplayer && !cmdline_opts_.test && !cmdline_opts_.editor);
@ -129,7 +129,7 @@ bool map_includes(const preproc_map& general, const preproc_map& special)
} // end anonymous namespace
void game_config_manager::load_game_config_with_loadscreen(
FORCE_RELOAD_CONFIG force_reload, game_classification const*, utils::optional<std::set<std::string>> active_addons)
FORCE_RELOAD_CONFIG force_reload, game_classification const*, std::optional<std::set<std::string>> active_addons)
{
if(!lg::info().dont_log(log_config)) {
auto out = formatter();

View file

@ -20,7 +20,7 @@
#include "filesystem.hpp"
#include "game_config_view.hpp"
#include "terrain/type_data.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
class game_classification;
class game_config_manager
@ -62,7 +62,7 @@ private:
void load_game_config(bool reload_everything);
void load_game_config_with_loadscreen(FORCE_RELOAD_CONFIG force_reload,
game_classification const* classification = nullptr, utils::optional<std::set<std::string>> active_addons = {});
game_classification const* classification = nullptr, std::optional<std::set<std::string>> active_addons = {});
// load_game_config() helper functions.
void load_addons_cfg();
@ -75,7 +75,7 @@ private:
game_config_view game_config_view_;
std::map<std::string, config> addon_cfgs_;
utils::optional<std::set<std::string>> active_addons_;
std::optional<std::set<std::string>> active_addons_;
preproc_map old_defines_map_;

View file

@ -635,7 +635,7 @@ WML_HANDLER_FUNCTION(replace_map,, cfg)
}
}
utils::optional<std::string> errmsg = resources::gameboard->replace_map(map);
std::optional<std::string> errmsg = resources::gameboard->replace_map(map);
if (errmsg) {
lg::wml_error() << *errmsg << std::endl;

View file

@ -649,7 +649,7 @@ bool game_launcher::play_render_image_mode()
bool game_launcher::has_load_data() const
{
return utils::has_optional_value(load_data_);
return load_data_.has_value();
}
bool game_launcher::load_game()

View file

@ -24,7 +24,7 @@
#include "saved_game.hpp" // for saved_game
#include "savegame.hpp" // for clean_saves, etc
#include "sound.hpp" // for music_thinker
#include "utils/optional_fwd.hpp"
#include <optional>
#include <string> // for string
#include <vector> // for vector
@ -149,5 +149,5 @@ private:
jump_to_campaign_info jump_to_campaign_;
bool jump_to_editor_;
utils::optional<savegame::load_game_metadata> load_data_;
std::optional<savegame::load_game_metadata> load_data_;
};

View file

@ -61,7 +61,7 @@ public:
/** True if healing should be done at the beginning of the next side turn */
bool do_healing_;
utils::optional<end_level_data> end_level_data_;
std::optional<end_level_data> end_level_data_;
bool init_side_done_;
bool start_event_fired_;
// used to sync with the mpserver

View file

@ -69,19 +69,19 @@ std::size_t cave_map_generator::cave_map_generator_job::translate_y(std::size_t
return y;
}
std::string cave_map_generator::create_map(utils::optional<uint32_t> randomseed)
std::string cave_map_generator::create_map(std::optional<uint32_t> randomseed)
{
const config res = create_scenario(randomseed);
return res["map_data"];
}
config cave_map_generator::create_scenario(utils::optional<uint32_t> randomseed)
config cave_map_generator::create_scenario(std::optional<uint32_t> randomseed)
{
cave_map_generator_job job(*this, randomseed);
return job.res_;
}
cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_map_generator& pparams, utils::optional<uint32_t> randomseed)
cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_map_generator& pparams, std::optional<uint32_t> randomseed)
: params(pparams)
, flipx_(false)
, flipy_(false)

View file

@ -17,7 +17,7 @@
#include "config.hpp"
#include "generators/map_generator.hpp"
#include "terrain/translation.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <set>
#include <random>
@ -31,13 +31,13 @@ public:
std::string config_name() const;
std::string create_map(utils::optional<uint32_t> randomseed = {});
config create_scenario(utils::optional<uint32_t> randomseed = {});
std::string create_map(std::optional<uint32_t> randomseed = {});
config create_scenario(std::optional<uint32_t> randomseed = {});
private:
struct cave_map_generator_job
{
cave_map_generator_job(const cave_map_generator& params, utils::optional<uint32_t> randomseed = {});
cave_map_generator_job(const cave_map_generator& params, std::optional<uint32_t> randomseed = {});
struct chamber {
chamber()

View file

@ -72,12 +72,12 @@ std::string default_map_generator::config_name() const
return std::string();
}
std::string default_map_generator::create_map(utils::optional<uint32_t> randomseed)
std::string default_map_generator::create_map(std::optional<uint32_t> randomseed)
{
return generate_map(nullptr, randomseed);
}
std::string default_map_generator::generate_map(std::map<map_location,std::string>* labels, utils::optional<uint32_t> randomseed)
std::string default_map_generator::generate_map(std::map<map_location,std::string>* labels, std::optional<uint32_t> randomseed)
{
uint32_t seed;
if(randomseed) {
@ -165,7 +165,7 @@ std::string default_map_generator::generate_map(std::map<map_location,std::strin
return map;
}
config default_map_generator::create_scenario(utils::optional<uint32_t> randomseed)
config default_map_generator::create_scenario(std::optional<uint32_t> randomseed)
{
DBG_NG << "creating scenario...\n";

View file

@ -49,11 +49,11 @@ public:
std::string config_name() const override;
std::string create_map(utils::optional<uint32_t> randomseed) override;
config create_scenario(utils::optional<uint32_t> randomseed) override;
std::string create_map(std::optional<uint32_t> randomseed) override;
config create_scenario(std::optional<uint32_t> randomseed) override;
private:
std::string generate_map(std::map<map_location,std::string>* labels, utils::optional<uint32_t> randomseed);
std::string generate_map(std::map<map_location,std::string>* labels, std::optional<uint32_t> randomseed);
config cfg_;

View file

@ -58,7 +58,7 @@ void lua_map_generator::user_config()
}
}
std::string lua_map_generator::create_map(utils::optional<uint32_t> seed)
std::string lua_map_generator::create_map(std::optional<uint32_t> seed)
{
if(create_map_.empty()) {
return map_generator::create_map(seed);
@ -74,7 +74,7 @@ std::string lua_map_generator::create_map(utils::optional<uint32_t> seed)
}
}
config lua_map_generator::create_scenario(utils::optional<uint32_t> seed)
config lua_map_generator::create_scenario(std::optional<uint32_t> seed)
{
if(create_scenario_.empty()) {
return map_generator::create_scenario(seed);

View file

@ -34,8 +34,8 @@ public:
std::string config_name() const override { return config_name_; }
virtual void user_config() override;
virtual std::string create_map(utils::optional<uint32_t> randomseed) override;
virtual config create_scenario(utils::optional<uint32_t> randomseed) override;
virtual std::string create_map(std::optional<uint32_t> randomseed) override;
virtual config create_scenario(std::optional<uint32_t> randomseed) override;
private:
std::string id_, config_name_;

View file

@ -27,13 +27,13 @@ static lg::log_domain log_mapgen("mapgen");
#define ERR_NG LOG_STREAM(err, log_mapgen)
#define LOG_NG LOG_STREAM(info, log_mapgen)
config map_generator::create_scenario(utils::optional<uint32_t> randomseed)
config map_generator::create_scenario(std::optional<uint32_t> randomseed)
{
config res;
res["map_data"] = create_map(randomseed);
return res;
}
std::string map_generator::create_map(utils::optional<uint32_t> randomseed)
std::string map_generator::create_map(std::optional<uint32_t> randomseed)
{
return create_scenario(randomseed)["map_data"];
}

View file

@ -18,7 +18,7 @@ class config;
#include "exceptions.hpp"
#include "map/location.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <cstdint>
@ -63,7 +63,7 @@ public:
* Creates a new map and returns it.
* args may contain arguments to the map generator.
*/
virtual std::string create_map(utils::optional<uint32_t> randomseed = {}) = 0;
virtual std::string create_map(std::optional<uint32_t> randomseed = {}) = 0;
virtual config create_scenario(utils::optional<uint32_t> randomseed = {});
virtual config create_scenario(std::optional<uint32_t> randomseed = {});
};

View file

@ -128,7 +128,7 @@ void attack_predictions::set_data(window& window, const combatant_data& attacker
// Set specials context (for safety, it should not have changed normally).
const_attack_ptr weapon = attacker.stats_.weapon, opp_weapon = defender.stats_.weapon;
auto ctx = weapon->specials_context(attacker.unit_, defender.unit_, attacker.unit_->get_location(), defender.unit_->get_location(), attacker.stats_.is_attacker, opp_weapon);
utils::optional<decltype(ctx)> opp_ctx;
std::optional<decltype(ctx)> opp_ctx;
if(opp_weapon) {
opp_ctx.emplace(opp_weapon->specials_context(defender.unit_, attacker.unit_, defender.unit_->get_location(), attacker.unit_->get_location(), defender.stats_.is_attacker, weapon));

View file

@ -16,7 +16,7 @@
#include "gui/dialogs/modal_dialog.hpp"
#include "sdl/rect.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <boost/dynamic_bitset.hpp>
@ -55,19 +55,19 @@ private:
entry_data(const config& cfg);
/** If present, column 1 will have a toggle button. The value indicates its initial state. */
utils::optional<bool> checkbox;
std::optional<bool> checkbox;
/** If no checkbox is present, the icon at this path will be shown in column 1. */
std::string icon;
/** Is present, column 2 will display the image at this path. */
utils::optional<std::string> image;
std::optional<std::string> image;
/** If no image is present, this text will be shown in column 2. */
t_string label;
/** If present, this text will be shown in column 3. */
utils::optional<t_string> details;
std::optional<t_string> details;
/** Tooltip text for the entire row. */
t_string tooltip;

View file

@ -116,13 +116,13 @@ void editor_generate_map::pre_show(window& window)
std::bind(&editor_generate_map::do_settings,this));
}
utils::optional<uint32_t> editor_generate_map::get_seed()
std::optional<uint32_t> editor_generate_map::get_seed()
{
try {
return lexical_cast<uint32_t>(random_seed_);
}
catch(const bad_lexical_cast& ) {
return utils::nullopt;
return std::nullopt;
}
}

View file

@ -15,7 +15,7 @@
#pragma once
#include "gui/dialogs/modal_dialog.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <cstdint>
#include <memory>
@ -30,9 +30,9 @@ namespace dialogs
/**
* @ingroup GUIWindowDefinitionWML
*
*
* The dialog for selecting which random generator to use in the editor.
* Key |Type |Mandatory|Description
* Key |Type |Mandatory|Description
* ------------------|--------------|---------|-----------
* generators_list | @ref listbox |yes |Listbox displaying known map generators.
* settings | @ref button |yes |When clicked this button opens the generator settings dialog.
@ -52,7 +52,7 @@ public:
void select_map_generator(map_generator* mg);
utils::optional<uint32_t> get_seed();
std::optional<uint32_t> get_seed();
private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */

View file

@ -33,7 +33,7 @@
#include "gui/widgets/window.hpp"
#include "sdl/rect.hpp"
#include <functional>
#include "utils/optional_fwd.hpp"
#include <optional>
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
@ -351,7 +351,7 @@ bool listbox::update_content_size()
void listbox::place(const point& origin, const point& size)
{
utils::optional<unsigned> vertical_scrollbar_position, horizontal_scrollbar_position;
std::optional<unsigned> vertical_scrollbar_position, horizontal_scrollbar_position;
// Check if this is the first time placing the list box
if(get_origin() != point {-1, -1}) {

View file

@ -1502,7 +1502,7 @@ unsigned image_width(const std::string &filename)
return 0;
}
void push_tab_pair(std::vector<help::item> &v, const std::string &s, const utils::optional<std::string> &image, unsigned padding)
void push_tab_pair(std::vector<help::item> &v, const std::string &s, const std::optional<std::string> &image, unsigned padding)
{
help::item item(s, font::line_width(s, normal_font_size));
if (image) {

View file

@ -34,7 +34,7 @@
#include "exceptions.hpp" // for error
#include "font/sdl_ttf.hpp" // for line_width, relative_size
#include "gettext.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <cstring>
#include <list> // for list
#include <memory>
@ -418,6 +418,6 @@ std::string generate_table(const table_spec &tab, const unsigned int spacing=fon
unsigned image_width(const std::string &filename);
// Add to the vector v an help::item for the string s, preceded by the given image if any.
void push_tab_pair(std::vector<help::item> &v, const std::string &s, const utils::optional<std::string> &image = {}, unsigned padding = 0);
void push_tab_pair(std::vector<help::item> &v, const std::string &s, const std::optional<std::string> &image = {}, unsigned padding = 0);
} // end namespace help

View file

@ -30,7 +30,7 @@
#include "tstring.hpp" // for t_string, operator<<
#include "units/helper.hpp" // for resistance_color
#include "units/types.hpp" // for unit_type, unit_type_data, etc
#include "utils/optional_fwd.hpp"
#include <optional>
#include "video.hpp" // fore current_resolution
#include <iostream> // for operator<<, basic_ostream, etc
@ -75,7 +75,7 @@ static std::string print_behavior_description(ter_iter start, ter_iter end, cons
if (start == end) return "";
if (*start == t_translation::MINUS || *start == t_translation::PLUS) return print_behavior_description(start+1, end, tdata, first_level, *start == t_translation::PLUS); //absorb any leading mode changes by calling again, with a new default value begin_best.
utils::optional<ter_iter> last_change_pos;
std::optional<ter_iter> last_change_pos;
bool best = begin_best;
for (ter_iter i = start; i != end; ++i) {

View file

@ -46,7 +46,7 @@
#endif
#include "global.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <cstdlib>
#include <limits>
@ -89,7 +89,7 @@ namespace implementation {
template<typename To, typename From>
inline To lexical_cast(From value)
{
return implementation::lexical_caster<To, From>().operator()(value, utils::nullopt);
return implementation::lexical_caster<To, From>().operator()(value, std::nullopt);
}
/**
@ -139,7 +139,7 @@ template<
>
struct lexical_caster
{
To operator()(From value, utils::optional<To> fallback) const
To operator()(From value, std::optional<To> fallback) const
{
DEBUG_THROW("generic");
@ -170,7 +170,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_integral<std::remove_pointer_t<From>>::value>
>
{
std::string operator()(From value, utils::optional<std::string>) const
std::string operator()(From value, std::optional<std::string>) const
{
DEBUG_THROW("specialized - To std::string - From integral (pointer)");
@ -195,7 +195,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
>
{
long long operator()(From value, utils::optional<long long> fallback) const
long long operator()(From value, std::optional<long long> fallback) const
{
DEBUG_THROW("specialized - To long long - From (const) char*");
@ -220,7 +220,7 @@ struct lexical_caster<
, std::string
>
{
long long operator()(const std::string& value, utils::optional<long long> fallback) const
long long operator()(const std::string& value, std::optional<long long> fallback) const
{
DEBUG_THROW("specialized - To long long - From std::string");
@ -251,7 +251,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
>
{
To operator()(From value, utils::optional<To> fallback) const
To operator()(From value, std::optional<To> fallback) const
{
DEBUG_THROW("specialized - To signed - From (const) char*");
@ -275,7 +275,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_integral<To>::value && std::is_signed<To>::value && !std::is_same<To, long long>::value>
>
{
To operator()(const std::string& value, utils::optional<To> fallback) const
To operator()(const std::string& value, std::optional<To> fallback) const
{
DEBUG_THROW("specialized - To signed - From std::string");
@ -309,7 +309,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
>
{
To operator()(From value, utils::optional<To> fallback) const
To operator()(From value, std::optional<To> fallback) const
{
DEBUG_THROW("specialized - To floating point - From (const) char*");
@ -333,7 +333,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_floating_point<To>::value>
>
{
To operator()(const std::string& value, utils::optional<To> fallback) const
To operator()(const std::string& value, std::optional<To> fallback) const
{
DEBUG_THROW("specialized - To floating point - From std::string");
@ -378,7 +378,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
>
{
unsigned long long operator()(From value, utils::optional<unsigned long long> fallback) const
unsigned long long operator()(From value, std::optional<unsigned long long> fallback) const
{
DEBUG_THROW(
"specialized - To unsigned long long - From (const) char*");
@ -404,7 +404,7 @@ struct lexical_caster<
, std::string
>
{
unsigned long long operator()(const std::string& value, utils::optional<unsigned long long> fallback) const
unsigned long long operator()(const std::string& value, std::optional<unsigned long long> fallback) const
{
DEBUG_THROW("specialized - To unsigned long long - From std::string");
@ -435,7 +435,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
>
{
To operator()(From value, utils::optional<To> fallback) const
To operator()(From value, std::optional<To> fallback) const
{
DEBUG_THROW("specialized - To unsigned - From (const) char*");
@ -459,7 +459,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_unsigned<To>::value>
>
{
To operator()(const std::string& value, utils::optional<To> fallback) const
To operator()(const std::string& value, std::optional<To> fallback) const
{
DEBUG_THROW("specialized - To unsigned - From std::string");

View file

@ -19,7 +19,7 @@ class config;
#include "map/location.hpp"
#include "terrain/translation.hpp"
#include "terrain/type_data.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
//class terrain_type_data; Can't forward declare because of enum
@ -86,7 +86,7 @@ public:
t_translation::ter_list old_;
t_translation::ter_list new_;
terrain_type_data::merge_mode mode_;
utils::optional<t_translation::terrain_code> terrain_;
std::optional<t_translation::terrain_code> terrain_;
bool use_old_;
bool replace_if_failed_;

View file

@ -18,7 +18,7 @@
#include "game_version.hpp"
#include "gettext.hpp"
#include "utils/make_enum.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
struct mp_game_settings
{
@ -86,8 +86,8 @@ struct mp_game_settings
struct addon_version_info
{
utils::optional<version_info> version;
utils::optional<version_info> min_version;
std::optional<version_info> version;
std::optional<version_info> min_version;
std::string name;
bool required;
std::vector<addon_content> content;

View file

@ -24,7 +24,7 @@
#include "persist_manager.hpp"
#include "tod_manager.hpp"
#include "game_state.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <set>
@ -139,7 +139,7 @@ public:
bool is_regular_game_end() const
{
return utils::has_optional_value(gamestate().end_level_data_);
return gamestate().end_level_data_.has_value();
}
const end_level_data& get_end_level_data() const

View file

@ -48,7 +48,7 @@ public:
bool should_stop() const { return stop_condition_->should_stop(); }
bool can_execute_command(const hotkey::hotkey_command& cmd, int index) const;
bool is_controlling_view() const {
return utils::has_optional_value(vision_);
return vision_.has_value();
}
bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
const std::shared_ptr<config>& get_reset_state() const { return reset_state_; }
@ -86,7 +86,7 @@ private:
CURRENT_TEAM,
SHOW_ALL,
};
utils::optional<REPLAY_VISION> vision_;
std::optional<REPLAY_VISION> vision_;
std::shared_ptr<config> reset_state_;
std::function<void()> on_end_replay_;
bool return_to_play_side_;

View file

@ -40,7 +40,7 @@
#include "game_state.hpp"
#include <functional>
#include "utils/optional_fwd.hpp"
#include <optional>
#include <map>
#include <utility>
@ -211,7 +211,7 @@ int show_message_box(lua_State* L) {
std::transform(button.begin(), button.end(), std::inserter(btn_style, btn_style.begin()), [](char c) { return std::tolower(c); });
bool markup = lua_isnoneornil(L, 3) ? luaW_toboolean(L, 3) : luaW_toboolean(L, 4);
using button_style = gui2::dialogs::message::button_style;
utils::optional<button_style> style;
std::optional<button_style> style;
if(btn_style.empty()) {
style = button_style::auto_close;
} else if(btn_style == "ok") {

View file

@ -261,7 +261,7 @@ int mapgen_lua_kernel::intf_get_variable(lua_State *L)
variable_access_const v(m, vars_ ? *vars_ : empty_cfg);
return luaW_pushvariable(L, v) ? 1 : 0;
}
std::string mapgen_lua_kernel::create_map(const char * prog, const config & generator, utils::optional<uint32_t> seed) // throws game::lua_error
std::string mapgen_lua_kernel::create_map(const char * prog, const config & generator, std::optional<uint32_t> seed) // throws game::lua_error
{
random_seed_ = seed;
default_rng_ = std::mt19937(get_random_seed());
@ -277,7 +277,7 @@ std::string mapgen_lua_kernel::create_map(const char * prog, const config & gene
return lua_tostring(mState, -1);
}
config mapgen_lua_kernel::create_scenario(const char * prog, const config & generator, utils::optional<uint32_t> seed) // throws game::lua_error
config mapgen_lua_kernel::create_scenario(const char * prog, const config & generator, std::optional<uint32_t> seed) // throws game::lua_error
{
random_seed_ = seed;
default_rng_ = std::mt19937(get_random_seed());

View file

@ -15,7 +15,7 @@
#pragma once
#include "scripting/lua_kernel_base.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <cstdint>
#include <random>
@ -31,15 +31,15 @@ public:
virtual std::string my_name() { return "Mapgen Lua Kernel"; }
void user_config(const char * prog, const config & generator); // throws game::lua_error
std::string create_map(const char * prog, const config & generator, utils::optional<uint32_t> seed); // throws game::lua_error
config create_scenario(const char * prog, const config & generator, utils::optional<uint32_t> seed); // throws game::lua_error
std::string create_map(const char * prog, const config & generator, std::optional<uint32_t> seed); // throws game::lua_error
config create_scenario(const char * prog, const config & generator, std::optional<uint32_t> seed); // throws game::lua_error
virtual uint32_t get_random_seed();
std::mt19937& get_default_rng();
private:
void run_generator(const char * prog, const config & generator);
int intf_get_variable(lua_State *L);
utils::optional<uint32_t> random_seed_;
utils::optional<std::mt19937> default_rng_;
std::optional<uint32_t> random_seed_;
std::optional<std::mt19937> default_rng_;
const config* vars_;
};

View file

@ -1157,7 +1157,7 @@ bool preprocessor_data::get_chunk()
std::string symbol = items.front();
items.erase(items.begin());
int found_arg = 0, found_enddef = 0, found_deprecate = 0;
utils::optional<DEP_LEVEL> deprecation_level;
std::optional<DEP_LEVEL> deprecation_level;
std::string buffer, deprecation_detail;
version_info deprecation_version = game_config::wesnoth_version;
while(true) {

View file

@ -19,7 +19,7 @@
#include "exceptions.hpp"
#include "filesystem.hpp"
#include "game_version.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <iosfwd>
#include <map>
@ -59,7 +59,7 @@ struct preproc_define
int line,
const std::string& loc,
const std::string& dep_msg,
utils::optional<DEP_LEVEL> dep_lvl, const version_info& dep_ver)
std::optional<DEP_LEVEL> dep_lvl, const version_info& dep_ver)
: value(val)
, arguments(args)
, optional_arguments(optargs)
@ -86,12 +86,12 @@ struct preproc_define
std::string deprecation_message;
utils::optional<DEP_LEVEL> deprecation_level;
std::optional<DEP_LEVEL> deprecation_level;
version_info deprecation_version;
bool is_deprecated() const {
return utils::has_optional_value(deprecation_level);
return deprecation_level.has_value();
}
void write(config_writer&, const std::string&) const;

View file

@ -20,14 +20,14 @@
#include "serialization/schema/type.hpp"
#include "config.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
namespace schema_validation
{
std::shared_ptr<wml_type> wml_type::from_config(const config& cfg)
{
utils::optional<config::const_child_itors> composite_range;
std::optional<config::const_child_itors> composite_range;
std::shared_ptr<wml_type> type;
if(cfg.has_child("union")) {
type = std::make_shared<wml_type_union>(cfg["name"]);

View file

@ -19,7 +19,7 @@
#pragma once
#include "utils/optional_fwd.hpp"
#include <optional>
#include <boost/program_options/options_description.hpp>
#include <map>
@ -51,11 +51,11 @@ public:
bool version;
/** Path to the add-ons server configuration file. */
utils::optional<std::string> config_file;
std::optional<std::string> config_file;
/** Path to the add-ons server storage dir. */
utils::optional<std::string> server_dir;
std::optional<std::string> server_dir;
/** Port number on which the server will listen for incoming connections. */
utils::optional<unsigned short> port;
std::optional<unsigned short> port;
/** True if --logdomains was passed. */
bool show_log_domains;

View file

@ -197,7 +197,7 @@ void flush_cache()
music_cache.clear();
}
utils::optional<unsigned int> get_current_track_index()
std::optional<unsigned int> get_current_track_index()
{
if(current_track_index >= current_track_list.size()){
return {};

View file

@ -16,7 +16,7 @@
#include "events.hpp"
#include "sound_music_track.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <string>
@ -119,7 +119,7 @@ void set_sound_volume(int vol);
void set_bell_volume(int vol);
void set_UI_volume(int vol);
utils::optional<unsigned int> get_current_track_index();
std::optional<unsigned int> get_current_track_index();
std::shared_ptr<sound::music_track> get_current_track();
std::shared_ptr<sound::music_track> get_previous_music_track();
void set_previous_track(std::shared_ptr<music_track>);

View file

@ -24,7 +24,7 @@
#include "color.hpp"
#include "halo.hpp"
#include "picture.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <boost/logic/tribool.hpp>
@ -50,8 +50,8 @@ struct frame_parameters
std::string sound;
std::string text;
utils::optional<color_t> text_color;
utils::optional<color_t> blend_with;
std::optional<color_t> text_color;
std::optional<color_t> blend_with;
double blend_ratio;
double highlight_ratio;
@ -115,8 +115,8 @@ private:
std::string sound_;
std::string text_;
utils::optional<color_t> text_color_;
utils::optional<color_t> blend_with_;
std::optional<color_t> text_color_;
std::optional<color_t> blend_with_;
std::string blend_ratio_;
std::string highlight_ratio_;
@ -177,8 +177,8 @@ private:
std::string sound_;
std::string text_;
utils::optional<color_t> text_color_;
utils::optional<color_t> blend_with_;
std::optional<color_t> text_color_;
std::optional<color_t> blend_with_;
progressive_double blend_ratio_;
progressive_double highlight_ratio_;

View file

@ -21,7 +21,7 @@
#include "units/attack_type.hpp"
#include "units/race.hpp"
#include "units/alignment.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <bitset>
#include <boost/dynamic_bitset_fwd.hpp>
@ -1892,9 +1892,9 @@ private:
t_string description_;
std::vector<t_string> special_notes_;
utils::optional<std::string> usage_;
utils::optional<std::string> halo_;
utils::optional<std::string> ellipse_;
std::optional<std::string> usage_;
std::optional<std::string> halo_;
std::optional<std::string> ellipse_;
bool random_traits_;
bool generate_name_;

View file

@ -1,52 +0,0 @@
/*
Copyright (C) 2020 by the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "global.hpp"
#ifdef HAVE_CXX17
#include <optional>
#else
#include <boost/optional.hpp>
#endif
namespace utils
{
#ifdef HAVE_CXX17
using std::optional;
using std::make_optional;
using std::nullopt;
#else
using boost::optional;
using boost::make_optional;
// Create a new nullopt object equivalent to boost::none to match the STL interface
static const boost::none_t nullopt{boost::none_t::init_tag{}};
#endif
template<typename T>
bool has_optional_value(const optional<T>& opt)
{
#if defined HAVE_CXX17 || BOOST_VERSION >= 106800
return opt.has_value();
#else
return opt != nullopt;
#endif
}
} // end namespace utils