The Battle for Wesnoth  1.15.1+dev
Classes | Macros | Functions
wml_exception.hpp File Reference

Add a special kind of assert to validate whether the input from WML doesn't contain any problems that might crash the game. More...

#include "config.hpp"
#include "lua_jailbreak_exception.hpp"
#include <string>
Include dependency graph for wml_exception.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  wml_exception
 Helper class, don't construct this directly. More...
 

Macros

#define VALIDATE(cond, message)
 The macro to use for the validation of WML. More...
 
#define VALIDATE_WITH_DEV_MESSAGE(cond, message, dev_message)
 
#define FAIL(message)
 
#define FAIL_WITH_DEV_MESSAGE(message, dev_message)
 

Functions

void throw_wml_exception (const char *cond, const char *file, int line, const char *function, const std::string &message, const std::string &dev_message="")
 Helper function, don't call this directly. More...
 
std::string missing_mandatory_wml_key (const std::string &section, const std::string &key, const std::string &primary_key="", const std::string &primary_value="")
 Returns a standard message for a missing wml key. More...
 
std::string deprecate_wml_key_warning (const std::string &key, const std::string &removal_version)
 Returns a standard warning message for using a deprecated wml key. More...
 
std::string deprecated_renamed_wml_key_warning (const std::string &deprecated_key, const std::string &key, const std::string &removal_version)
 Returns a standard warning message for using a deprecated renamed wml key. More...
 
const config::attribute_valueget_renamed_config_attribute (const config &cfg, const std::string &deprecated_key, const std::string &key, const std::string &removal_version)
 Returns a config attribute, using either the old name or the new one. More...
 

Detailed Description

Add a special kind of assert to validate whether the input from WML doesn't contain any problems that might crash the game.

Definition in file wml_exception.hpp.

Macro Definition Documentation

◆ FAIL

#define FAIL (   message)

◆ FAIL_WITH_DEV_MESSAGE

#define FAIL_WITH_DEV_MESSAGE (   message,
  dev_message 
)
Value:
do { \
throw_wml_exception(nullptr \
, __FILE__ \
, __LINE__ \
, __func__ \
, message \
, dev_message); \
} while(0)

Definition at line 64 of file wml_exception.hpp.

Referenced by gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::get_selected_item(), and gui2::tree_view_node::tree_view_node().

◆ VALIDATE

#define VALIDATE (   cond,
  message 
)
Value:
do { \
if(!(cond)) { \
throw_wml_exception(#cond, __FILE__, __LINE__, __func__, message); \
} \
} while(0)
static int cond(LexState *ls)
Definition: lparser.cpp:1177

The macro to use for the validation of WML.

Parameters
condThe condition to test, if false and exception is generated.
messageThe translatable message to show at the user.

Definition at line 40 of file wml_exception.hpp.

Referenced by gui2::dialogs::mp_options_helper::add_node_and_get_widget(), gui2::multi_page::add_page(), theme::border_t::border_t(), gui2::implementation::builder_slider::build(), gui2::build_single_widget_instance_helper(), gui2::builder_grid::builder_grid(), gui2::implementation::builder_grid_listbox::builder_grid_listbox(), gui2::implementation::builder_horizontal_listbox::builder_horizontal_listbox(), gui2::implementation::builder_listbox::builder_listbox(), gui2::implementation::builder_multi_page::builder_multi_page(), gui2::implementation::builder_pane::builder_pane(), gui2::implementation::builder_panel::builder_panel(), gui2::implementation::builder_scrollbar_panel::builder_scrollbar_panel(), gui2::implementation::builder_size_lock::builder_size_lock(), gui2::implementation::builder_stacked_widget::builder_stacked_widget(), gui2::implementation::builder_toggle_panel::builder_toggle_panel(), gui2::implementation::builder_tree_view::builder_tree_view(), gui2::size_lock::calculate_best_size(), battle_context::choose_defender_weapon(), pathfind::shortest_path_calculator::cost(), gui2::create_widget_builder(), default_map_generator_job::default_generate_map(), gui2::line_shape::draw(), gui2::rectangle_shape::draw(), gui2::round_rectangle_shape::draw(), gui2::text_shape::draw(), expand_partialresolution(), gui2::find_widget(), gui2::get_control(), gui2::get_window_builder(), gui2::gui_definition::gui_definition(), gui2::init(), gui2::window::layout(), gui2::parse_linked_group_definitions(), gui2::implementation::parse_list_data(), gui2::dialogs::game_version::pre_show(), gui2::dialogs::preferences_dialog::pre_show(), gui2::builder_window::read(), gui2::scrollbar_panel_definition::resolution::resolution(), gui2::vertical_scrollbar_definition::resolution::resolution(), gui2::horizontal_scrollbar_definition::resolution::resolution(), gui2::size_lock_definition::resolution::resolution(), gui2::unit_preview_pane_definition::resolution::resolution(), gui2::scroll_label_definition::resolution::resolution(), gui2::stacked_widget_definition::resolution::resolution(), gui2::addon_list_definition::resolution::resolution(), gui2::tree_view_definition::resolution::resolution(), gui2::multi_page_definition::resolution::resolution(), gui2::slider_definition::resolution::resolution(), gui2::chatbox_definition::resolution::resolution(), gui2::listbox_definition::resolution::resolution(), preferences::server_list(), gui2::slider::set_value_range(), gui2::dialogs::advanced_graphics_options::setup_scale_case(), gui2::state_definition::state_definition(), t_translation::string_to_layer_(), gui2::styled_widget_definition::styled_widget_definition(), terrain_type::terrain_type(), gui2::text_shape::text_shape(), gui2::builder_window::window_resolution::tooltip_info::tooltip_info(), gui2::implementation::tree_node::tree_node(), gui2::builder_window::window_resolution::window_resolution(), and font::word_wrap_text().

◆ VALIDATE_WITH_DEV_MESSAGE

#define VALIDATE_WITH_DEV_MESSAGE (   cond,
  message,
  dev_message 
)
Value:
do { \
if(!(cond)) { \
throw_wml_exception(#cond \
, __FILE__ \
, __LINE__ \
, __func__ \
, message \
, dev_message); \
} \
} while(0)
static int cond(LexState *ls)
Definition: lparser.cpp:1177

Definition at line 47 of file wml_exception.hpp.

Referenced by gui2::implementation::builder_styled_widget::builder_styled_widget(), gui2::image_shape::dimension_validation(), and gui2::circle_shape::draw().

Function Documentation

◆ deprecate_wml_key_warning()

std::string deprecate_wml_key_warning ( const std::string &  key,
const std::string &  removal_version 
)

Returns a standard warning message for using a deprecated wml key.

Parameters
keyThe deprecated key.
removal_versionThe version in which the key will be removed.
Returns
The warning message.

Definition at line 102 of file wml_exception.cpp.

References VGETTEXT.

◆ deprecated_renamed_wml_key_warning()

std::string deprecated_renamed_wml_key_warning ( const std::string &  deprecated_key,
const std::string &  key,
const std::string &  removal_version 
)

Returns a standard warning message for using a deprecated renamed wml key.

Parameters
deprecated_keyThe deprecated key.
keyThe new key to be used.
removal_versionThe version in which the key will be removed.
Returns
The warning message.

Definition at line 117 of file wml_exception.cpp.

References VGETTEXT.

Referenced by get_renamed_config_attribute().

◆ get_renamed_config_attribute()

const config::attribute_value& get_renamed_config_attribute ( const config cfg,
const std::string &  deprecated_key,
const std::string &  key,
const std::string &  removal_version 
)

Returns a config attribute, using either the old name or the new one.

The function first tries the find the attribute using key and if that doesn't find the attribute it tries deprecated_key. If that test finds an attribute it will issue a warning and return the result. Else returns an empty attribute.

Note
This function is not a member of config, since that would add additional dependencies to the core library.
Parameters
cfgThe config to get the attribute from.
deprecated_keyThe deprecated key.
keyThe new key to be used.
removal_versionThe version in which the key will be removed key.
Returns
The attribute found as described above.

Definition at line 138 of file wml_exception.cpp.

References deprecated_renamed_wml_key_warning(), config::get(), and lg::wml_error().

◆ missing_mandatory_wml_key()

std::string missing_mandatory_wml_key ( const std::string &  section,
const std::string &  key,
const std::string &  primary_key = "",
const std::string &  primary_value = "" 
)

Returns a standard message for a missing wml key.

Parameters
sectionThe section is which the key should appear (this should include the section brackets). It may contain parent sections to make it easier to find the wanted sections. They are listed like [parent][child][section].
keyThe omitted key.
primary_keyThe primary key of the section.
primary_valueThe value of the primary key (mandatory if primary key isn't empty).
Returns
The error message.

Definition at line 70 of file wml_exception.cpp.

References VGETTEXT, and WRN_NG.

Referenced by expand_partialresolution(), gui2::gui_definition::gui_definition(), gui2::parse_linked_group_definitions(), gui2::implementation::parse_list_data(), gui2::builder_window::read(), gui2::vertical_scrollbar_definition::resolution::resolution(), gui2::horizontal_scrollbar_definition::resolution::resolution(), gui2::slider_definition::resolution::resolution(), gui2::styled_widget_definition::styled_widget_definition(), terrain_type::terrain_type(), gui2::builder_window::window_resolution::tooltip_info::tooltip_info(), gui2::implementation::tree_node::tree_node(), and gui2::builder_window::window_resolution::window_resolution().

◆ throw_wml_exception()

void throw_wml_exception ( const char *  cond,
const char *  file,
int  line,
const char *  function,
const std::string &  message,
const std::string &  dev_message = "" 
)

Helper function, don't call this directly.

Parameters
condThe textual presentation of the test that failed.
fileThe file in which the test failed.
lineThe line at which the test failed.
functionThe function in which the test failed.
messageThe translated message to show the user.

Definition at line 32 of file wml_exception.cpp.