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

This reverts commit 4d54b2a7fd.
This commit is contained in:
Celtic Minstrel 2024-07-23 09:03:13 -04:00
parent 740aadb273
commit 62d9ebecc2
45 changed files with 224 additions and 168 deletions

View file

@ -46,6 +46,7 @@
#include "units/udisplay.hpp"
#include "units/unit.hpp"
#include "units/types.hpp"
#include "utils/optional_fwd.hpp"
#include "whiteboard/manager.hpp"
#include "wml_exception.hpp"
@ -131,7 +132,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);
std::optional<decltype(ctx)> opp_ctx;
utils::optional<decltype(ctx)> opp_ctx;
if(opp_weapon) {
opp_ctx.emplace(opp_weapon->specials_context(oppp, up, opp_loc, u_loc, !attacking, weapon));
@ -281,7 +282,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);
std::optional<decltype(ctx)> opp_ctx;
utils::optional<decltype(ctx)> opp_ctx;
if(opp_weapon) {
opp_ctx.emplace(opp_weapon->specials_context(*opp_type, map_location::null_location(), !attacking));
@ -864,7 +865,7 @@ void attack::fire_event_impl(const std::string& n, bool reverse)
config& d_weapon_cfg = ev_data.add_child(reverse ? "first" : "second");
// Need these to ensure weapon filters work correctly
std::optional<attack_type::specials_context_t> a_ctx, d_ctx;
utils::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

@ -17,7 +17,7 @@
#include "log.hpp" // for logger, set_strict_severity, etc
#include <optional>
#include "utils/optional_fwd.hpp"
#include <boost/program_options/options_description.hpp>
#include <iosfwd> // for ostream
@ -54,21 +54,21 @@ public:
bool any_validation_option() const;
/** Non-empty if --campaign was given on the command line. ID of the campaign we want to start. */
std::optional<std::string> campaign;
utils::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. */
std::optional<int> campaign_difficulty;
utils::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. */
std::optional<std::string> campaign_scenario;
utils::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. */
std::optional<std::string> core_id;
utils::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. */
std::optional<std::string> data_dir;
utils::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. */
@ -83,12 +83,12 @@ public:
bool allow_insecure;
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
/** Non-empty if --debug-dot-domain was given on the command line. */
std::optional<std::string> debug_dot_domain;
utils::optional<std::string> debug_dot_domain;
/** Non-empty if --debug-dot-level was given on the command line. */
std::optional<std::string> debug_dot_level;
utils::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. */
std::optional<std::string> editor;
utils::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. */
@ -96,48 +96,48 @@ public:
/** 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. */
std::optional<std::string> language;
utils::optional<std::string> language;
/**
* Contains parsed arguments of --log-* (e.g. --log-debug).
* Vector of pairs (severity, log domain).
*/
std::optional<std::vector<std::pair<lg::severity, std::string>>> log;
utils::optional<std::vector<std::pair<lg::severity, std::string>>> log;
/** Non-empty if --log-strict was given */
std::optional<int> log_strict_level;
utils::optional<int> log_strict_level;
/** Non-empty if --load was given on the command line. Savegame specified to load after start. */
std::optional<std::string> load;
utils::optional<std::string> load;
/** Non-empty if --logdomains was given on the command line. Prints possible logdomains filtered by given string and exits. */
std::optional<std::string> logdomains;
utils::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. */
std::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_ai_config;
utils::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. */
std::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_algorithm;
utils::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. */
std::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_controller;
utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_controller;
/** Non-empty if --era was given on the command line. Dependent on --multiplayer. */
std::optional<std::string> multiplayer_era;
utils::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. */
std::optional<std::string> multiplayer_label;
utils::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. */
std::optional<std::vector<std::tuple<unsigned int, std::string, std::string>>> multiplayer_parm;
utils::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. */
std::optional<unsigned int> multiplayer_repeat;
utils::optional<unsigned int> multiplayer_repeat;
/** Non-empty if --scenario was given on the command line. Dependent on --multiplayer. */
std::optional<std::string> multiplayer_scenario;
utils::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. */
std::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_side;
utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_side;
/** Non-empty if --turns was given on the command line. Dependent on --multiplayer. */
std::optional<std::string> multiplayer_turns;
utils::optional<std::string> multiplayer_turns;
/** Max FPS specified by --max-fps option. */
std::optional<int> max_fps;
utils::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. */
@ -157,45 +157,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. */
std::optional<std::vector<std::string>> preprocess_defines;
utils::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. */
std::optional<std::string> preprocess_input_macros;
utils::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. */
std::optional<std::string> preprocess_output_macros;
utils::optional<std::string> preprocess_output_macros;
/** Path to parse that was given to the --preprocess option. */
std::optional<std::string> preprocess_path;
utils::optional<std::string> preprocess_path;
/** Target (output) path that was given to the --preprocess option. */
std::optional<std::string> preprocess_target;
utils::optional<std::string> preprocess_target;
/** Pair of AxB values specified after --resolution. Changes Wesnoth resolution. */
std::optional<std::pair<int,int>> resolution;
utils::optional<std::pair<int,int>> resolution;
/** RNG seed specified by --rng-seed option. Initializes RNG with given seed. */
std::optional<unsigned int> rng_seed;
utils::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. */
std::optional<std::string> server;
utils::optional<std::string> server;
/** Non-empty if --username was given on the command line. Forces Wesnoth to use this network username. */
std::optional<std::string> username;
utils::optional<std::string> username;
/** Non-empty if --password was given on the command line. Forces Wesnoth to use this network password. */
std::optional<std::string> password;
utils::optional<std::string> password;
/** Image path to render. First parameter after --render-image */
std::optional<std::string> render_image;
utils::optional<std::string> render_image;
/** Output file to put rendered image path in. Optional second parameter after --render-image */
std::optional<std::string> render_image_dst;
utils::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. */
std::optional<std::string> screenshot_map_file;
utils::optional<std::string> screenshot_map_file;
/** Output file to put screenshot in. Second parameter given after --screenshot. */
std::optional<std::string> screenshot_output_file;
utils::optional<std::string> screenshot_output_file;
/** File to load lua script from. */
std::optional<std::string> script_file;
utils::optional<std::string> script_file;
/** File to load a lua plugin (similar to a script) from. Experimental / may replace script. */
std::optional<std::string> plugin_file;
utils::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. */
std::optional<std::string> test;
utils::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. */
@ -207,25 +207,25 @@ public:
/** True if --usercache-path was given on the command line. Prints path to cache directory and exits. */
bool usercache_path;
/** Non-empty if --usercache-dir was given on the command line. Sets the cache dir to the specified one. */
std::optional<std::string> usercache_dir;
utils::optional<std::string> usercache_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. */
std::optional<std::string> userdata_dir;
utils::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. */
std::optional<std::string> validate_addon;
utils::optional<std::string> validate_addon;
/** Non-empty if --validate-schema was given on the command line. Makes Wesnoth validate a WML schema. */
std::optional<std::string> validate_schema;
utils::optional<std::string> validate_schema;
/** Non-empty if --validate was given on the command line. Makes Wesnoth validate a WML file against a schema. */
std::optional<std::string> validate_wml;
utils::optional<std::string> validate_wml;
/** Non-empty if --use-schema was given on the command line. Specifies the schema for use with --validate. */
std::optional<std::string> validate_with;
utils::optional<std::string> validate_with;
/** Output filename for WML diff or preprocessing */
std::optional<std::string> output_file;
utils::optional<std::string> output_file;
bool do_diff, do_patch;
/** Files for diffing or patching */
std::string diff_left, diff_right;
@ -255,7 +255,7 @@ public:
/** final result of determining whether to log to file or not */
bool final_log_redirect_to_file;
/** Non-empty if --all-translations or --translations-over is given on the command line. */
std::optional<unsigned int> translation_percent;
utils::optional<unsigned int> translation_percent;
private:
void parse_log_domains_(const std::string &domains_string, const lg::severity severity);
void parse_log_strictness (const std::string &severity);

View file

@ -26,8 +26,8 @@
#include "team.hpp"
#include "tod_manager.hpp"
#include "units/map.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <vector>
class game_config_view;
@ -301,7 +301,7 @@ public:
const t_string get_default_context_name() const;
std::optional<int> get_xp_mod() const { return xp_mod_; }
utils::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_; }
@ -500,8 +500,8 @@ private:
std::optional<config> previous_cfg_;
std::string scenario_id_, scenario_name_, scenario_description_;
std::optional<int> xp_mod_;
std::optional<bool> victory_defeated_;
utils::optional<int> xp_mod_;
utils::optional<bool> victory_defeated_;
bool random_time_;
int active_area_;

View file

@ -18,7 +18,7 @@
#include "config.hpp"
#include "lexical_cast.hpp"
#include "serialization/string_utils.hpp"
#include <optional>
#include "utils/optional_fwd.hpp"
#include <string>
#include <utility>
@ -54,8 +54,8 @@ struct subset_descriptor
}
std::string 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;
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;
};
} // end namespace font

View file

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

View file

@ -21,6 +21,7 @@
#include "terrain/type_data.hpp"
#include "units/map.hpp"
#include "units/id.hpp"
#include "utils/optional_fwd.hpp"
#include <optional>
#include <set>
@ -152,7 +153,7 @@ public:
// Manipulator from actionwml
bool try_add_unit_to_recall_list(const map_location& loc, const unit_ptr u);
std::optional<std::string> replace_map(const gamemap & r);
utils::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
bool change_terrain(const map_location &loc, const t_translation::terrain_code &t, terrain_type_data::merge_mode& mode, bool replace_if_failed); //used only by lua and debug commands

View file

@ -102,9 +102,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", cmdline_opts_.test.has_value());
game_config::scoped_preproc_define test("TEST", utils::has_optional_value(cmdline_opts_.test));
game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest);
game_config::scoped_preproc_define editor("EDITOR", cmdline_opts_.editor.has_value());
game_config::scoped_preproc_define editor("EDITOR", utils::has_optional_value(cmdline_opts_.editor));
game_config::scoped_preproc_define title_screen("TITLE_SCREEN",
!cmdline_opts_.multiplayer && !cmdline_opts_.test && !cmdline_opts_.editor);

View file

@ -22,7 +22,7 @@
#include "filesystem.hpp"
#include "game_config_view.hpp"
#include "terrain/type_data.hpp"
#include "utils/optional_fwd.hpp"
class game_classification;
class game_config_manager

View file

@ -614,7 +614,7 @@ WML_HANDLER_FUNCTION(replace_map,, cfg)
}
}
std::optional<std::string> errmsg = resources::gameboard->replace_map(map);
utils::optional<std::string> errmsg = resources::gameboard->replace_map(map);
if (errmsg) {
lg::log_to_chat() << *errmsg << '\n';

View file

@ -676,7 +676,7 @@ bool game_launcher::play_render_image_mode()
bool game_launcher::has_load_data() const
{
return load_data_.has_value();
return utils::has_optional_value(load_data_);
}
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 <optional>
#include "utils/optional_fwd.hpp"
#include <string> // for string
#include <vector> // for vector
@ -149,5 +149,5 @@ private:
jump_to_campaign_info jump_to_campaign_;
bool jump_to_editor_;
std::optional<savegame::load_game_metadata> load_data_;
utils::optional<savegame::load_game_metadata> load_data_;
};

View file

@ -61,7 +61,7 @@ public:
bool victory_when_enemies_defeated_;
bool remove_from_carryover_on_defeat_;
std::optional<end_level_data> end_level_data_;
utils::optional<end_level_data> end_level_data_;
// used to sync with the mpserver
int server_request_number_;

View file

@ -73,19 +73,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(std::optional<uint32_t> randomseed)
std::string cave_map_generator::create_map(utils::optional<uint32_t> randomseed)
{
const config res = create_scenario(randomseed);
return res["map_data"];
}
config cave_map_generator::create_scenario(std::optional<uint32_t> randomseed)
config cave_map_generator::create_scenario(utils::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, std::optional<uint32_t> randomseed)
cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_map_generator& pparams, utils::optional<uint32_t> randomseed)
: params(pparams)
, flipx_(false)
, flipy_(false)

View file

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

View file

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

View file

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

View file

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

View file

@ -35,8 +35,8 @@ public:
std::string config_name() const override { return config_name_; }
virtual void user_config() override;
virtual std::string create_map(std::optional<uint32_t> randomseed) override;
virtual config create_scenario(std::optional<uint32_t> randomseed) override;
virtual std::string create_map(utils::optional<uint32_t> randomseed) override;
virtual config create_scenario(utils::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(std::optional<uint32_t> randomseed)
config map_generator::create_scenario(utils::optional<uint32_t> randomseed)
{
config res;
res["map_data"] = create_map(randomseed);
return res;
}
std::string map_generator::create_map(std::optional<uint32_t> randomseed)
std::string map_generator::create_map(utils::optional<uint32_t> randomseed)
{
return create_scenario(randomseed)["map_data"];
}

View file

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

View file

@ -127,7 +127,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);
std::optional<decltype(ctx)> opp_ctx;
utils::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 @@
#pragma once
#include "gui/dialogs/modal_dialog.hpp"
#include <optional>
#include "utils/optional_fwd.hpp"
#include <boost/dynamic_bitset.hpp>
@ -54,19 +54,19 @@ private:
entry_data(const config& cfg);
/** If present, column 1 will have a toggle button. The value indicates its initial state. */
std::optional<bool> checkbox;
utils::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. */
std::optional<std::string> image;
utils::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. */
std::optional<t_string> details;
utils::optional<t_string> details;
/** Tooltip text for the entire row. */
t_string tooltip;

View file

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

View file

@ -16,7 +16,7 @@
#pragma once
#include "gui/dialogs/modal_dialog.hpp"
#include <optional>
#include "utils/optional_fwd.hpp"
#include <cstdint>
#include <memory>
@ -43,7 +43,7 @@ public:
void select_map_generator(map_generator* mg);
std::optional<uint32_t> get_seed();
utils::optional<uint32_t> get_seed();
private:
virtual const std::string& window_id() const override;

View file

@ -31,7 +31,7 @@
#include "sdl/rect.hpp"
#include "wml_exception.hpp"
#include <functional>
#include <optional>
#include "utils/optional_fwd.hpp"
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
@ -343,7 +343,7 @@ bool listbox::update_content_size()
void listbox::place(const point& origin, const point& size)
{
std::optional<unsigned> vertical_scrollbar_position, horizontal_scrollbar_position;
utils::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

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

View file

@ -37,7 +37,8 @@
#include "font/constants.hpp"
#include "font/standard_colors.hpp"
#include "gettext.hpp"
#include <optional>
#include "utils/optional_fwd.hpp"
#include <cstring>
#include <list> // for list
#include <memory>
#include <sstream>
@ -420,6 +421,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 std::optional<std::string> &image = {}, unsigned padding = 0);
void push_tab_pair(std::vector<help::item> &v, const std::string &s, const utils::optional<std::string> &image = {}, unsigned padding = 0);
} // end namespace help

View file

@ -32,9 +32,9 @@
#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 "video.hpp" // for game_canvas_size
#include "utils/optional_fwd.hpp"
#include "video.hpp" // fore current_resolution
#include <optional>
#include <set>
static lg::log_domain log_help("help");
@ -74,7 +74,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.
std::optional<ter_iter> last_change_pos;
utils::optional<ter_iter> last_change_pos;
bool best = begin_best;
for (ter_iter i = start; i != end; ++i) {

View file

@ -42,7 +42,7 @@
#define DEBUG_THROW(id) throw id;
#else
#include <optional>
#include "utils/optional_fwd.hpp"
#include <cstdlib>
#include <limits>
@ -85,7 +85,7 @@ namespace implementation {
template<typename To, typename From>
inline To lexical_cast(From value)
{
return implementation::lexical_caster<To, From>().operator()(value, std::nullopt);
return implementation::lexical_caster<To, From>().operator()(value, utils::nullopt);
}
/**
@ -135,7 +135,7 @@ template<
>
struct lexical_caster
{
To operator()(From value, std::optional<To> fallback) const
To operator()(From value, utils::optional<To> fallback) const
{
DEBUG_THROW("generic");
@ -166,7 +166,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_integral_v<std::remove_pointer_t<From>>>
>
{
std::string operator()(From value, std::optional<std::string>) const
std::string operator()(From value, utils::optional<std::string>) const
{
DEBUG_THROW("specialized - To std::string - From integral (pointer)");
@ -191,7 +191,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
long long operator()(From value, std::optional<long long> fallback) const
long long operator()(From value, utils::optional<long long> fallback) const
{
DEBUG_THROW("specialized - To long long - From (const) char*");
@ -216,7 +216,7 @@ struct lexical_caster<
, std::string
>
{
long long operator()(const std::string& value, std::optional<long long> fallback) const
long long operator()(const std::string& value, utils::optional<long long> fallback) const
{
DEBUG_THROW("specialized - To long long - From std::string");
@ -255,7 +255,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
To operator()(From value, std::optional<To> fallback) const
To operator()(From value, utils::optional<To> fallback) const
{
DEBUG_THROW("specialized - To signed - From (const) char*");
@ -279,7 +279,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_integral_v<To> && std::is_signed_v<To> && !std::is_same_v<To, long long>>
>
{
To operator()(const std::string& value, std::optional<To> fallback) const
To operator()(const std::string& value, utils::optional<To> fallback) const
{
DEBUG_THROW("specialized - To signed - From std::string");
@ -321,7 +321,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
To operator()(From value, std::optional<To> fallback) const
To operator()(From value, utils::optional<To> fallback) const
{
DEBUG_THROW("specialized - To floating point - From (const) char*");
@ -345,7 +345,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_floating_point_v<To>>
>
{
To operator()(const std::string& value, std::optional<To> fallback) const
To operator()(const std::string& value, utils::optional<To> fallback) const
{
DEBUG_THROW("specialized - To floating point - From std::string");
@ -398,7 +398,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
unsigned long long operator()(From value, std::optional<unsigned long long> fallback) const
unsigned long long operator()(From value, utils::optional<unsigned long long> fallback) const
{
DEBUG_THROW(
"specialized - To unsigned long long - From (const) char*");
@ -424,7 +424,7 @@ struct lexical_caster<
, std::string
>
{
unsigned long long operator()(const std::string& value, std::optional<unsigned long long> fallback) const
unsigned long long operator()(const std::string& value, utils::optional<unsigned long long> fallback) const
{
DEBUG_THROW("specialized - To unsigned long long - From std::string");
@ -463,7 +463,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
To operator()(From value, std::optional<To> fallback) const
To operator()(From value, utils::optional<To> fallback) const
{
DEBUG_THROW("specialized - To unsigned - From (const) char*");
@ -487,7 +487,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_unsigned_v<To>>
>
{
To operator()(const std::string& value, std::optional<To> fallback) const
To operator()(const std::string& value, utils::optional<To> fallback) const
{
DEBUG_THROW("specialized - To unsigned - From std::string");
@ -526,7 +526,7 @@ struct lexical_caster<
template <>
struct lexical_caster<bool, std::string>
{
bool operator()(const std::string& value, std::optional<bool>) const
bool operator()(const std::string& value, utils::optional<bool>) const
{
DEBUG_THROW("specialized - To bool - From std::string");
@ -548,7 +548,7 @@ struct lexical_caster<
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
bool operator()(From value, std::optional<bool>) const
bool operator()(From value, utils::optional<bool>) const
{
DEBUG_THROW("specialized - To bool - From (const) char*");

View file

@ -20,7 +20,7 @@ class config;
#include "map/location.hpp"
#include "terrain/translation.hpp"
#include "terrain/type_data.hpp"
#include <optional>
#include "utils/optional_fwd.hpp"
//class terrain_type_data; Can't forward declare because of enum

View file

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

View file

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

View file

@ -45,7 +45,7 @@ public:
bool should_stop() const { return stop_condition_->should_stop(); }
bool can_execute_command(const hotkey::ui_command& cmd) const;
bool is_controlling_view() const {
return vision_.has_value();
return utils::has_optional_value(vision_);
}
bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
const std::shared_ptr<config>& get_reset_state() const { return reset_state_; }
@ -83,7 +83,7 @@ private:
CURRENT_TEAM,
SHOW_ALL,
};
std::optional<REPLAY_VISION> vision_;
utils::optional<REPLAY_VISION> vision_;
/// When the "Reset" button is pressed reset the gamestate to this
/// serialized gamestaten, the initial gamestate.
std::shared_ptr<config> reset_state_;

View file

@ -39,7 +39,7 @@
#include "sdl/input.hpp" // get_mouse_state
#include <functional>
#include <optional>
#include "utils/optional_fwd.hpp"
#include <vector>
@ -206,7 +206,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;
std::optional<button_style> style;
utils::optional<button_style> style;
if(btn_style.empty()) {
style = button_style::auto_close;
} else if(btn_style == "ok") {

View file

@ -184,7 +184,7 @@ static int intf_find_path(lua_State *L)
const char *msg = lua_pushfstring(L, "%s expected, got %s", lua_typename(L, LUA_TFUNCTION), luaL_typename(L, 3));
return luaL_argerror(L, 3, msg);
}
std::optional<lua_pathfind_cost_calculator> calc;
utils::optional<lua_pathfind_cost_calculator> calc;
int width, height;
bool border = false;
if(lua_istable(L, 3)) {
@ -322,7 +322,7 @@ int mapgen_lua_kernel::intf_get_all_vars(lua_State *L) {
return 1;
}
std::string mapgen_lua_kernel::create_map(const char * prog, const config & generator, std::optional<uint32_t> seed) // throws game::lua_error
std::string mapgen_lua_kernel::create_map(const char * prog, const config & generator, utils::optional<uint32_t> seed) // throws game::lua_error
{
random_seed_ = seed;
default_rng_ = std::mt19937(get_random_seed());
@ -338,7 +338,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, std::optional<uint32_t> seed) // throws game::lua_error
config mapgen_lua_kernel::create_scenario(const char * prog, const config & generator, utils::optional<uint32_t> seed) // throws game::lua_error
{
random_seed_ = seed;
default_rng_ = std::mt19937(get_random_seed());

View file

@ -16,7 +16,7 @@
#pragma once
#include "scripting/lua_kernel_base.hpp"
#include <optional>
#include "utils/optional_fwd.hpp"
#include <cstdint>
#include <random>
@ -32,8 +32,8 @@ 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, 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
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
virtual uint32_t get_random_seed();
std::mt19937& get_default_rng();
@ -41,7 +41,7 @@ private:
void run_generator(const char * prog, const config & generator);
int intf_get_variable(lua_State *L);
int intf_get_all_vars(lua_State *L);
std::optional<uint32_t> random_seed_;
std::optional<std::mt19937> default_rng_;
utils::optional<uint32_t> random_seed_;
utils::optional<std::mt19937> default_rng_;
const config* vars_;
};

View file

@ -1190,7 +1190,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;
std::optional<DEP_LEVEL> deprecation_level;
utils::optional<DEP_LEVEL> deprecation_level;
std::string buffer, deprecation_detail;
version_info deprecation_version = game_config::wesnoth_version;
while(true) {

View file

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

View file

@ -21,7 +21,7 @@
#include "serialization/schema/type.hpp"
#include "config.hpp"
#include <optional>
#include "utils/optional_fwd.hpp"
#include "utils/variant.hpp"
struct is_translatable
@ -52,7 +52,7 @@ namespace schema_validation
std::shared_ptr<wml_type> wml_type::from_config(const config& cfg)
{
std::optional<config::const_child_itors> composite_range;
utils::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

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

View file

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

View file

@ -17,7 +17,7 @@
#include "events.hpp"
#include "sound_music_track.hpp"
#include <optional>
#include "utils/optional_fwd.hpp"
#include <string>
@ -120,7 +120,7 @@ void set_sound_volume(int vol);
void set_bell_volume(int vol);
void set_UI_volume(int vol);
std::optional<unsigned int> get_current_track_index();
utils::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

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

View file

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

View file

@ -0,0 +1,52 @@
/*
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