The Battle for Wesnoth  1.17.12+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 "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...
 

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(false)

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(false)

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::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(), 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::server_info::pre_show(), gui2::dialogs::preferences_dialog::pre_show(), gui2::dialogs::game_version::pre_show(), gamemap::read(), 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::chatbox_definition::resolution::resolution(), gui2::slider_definition::resolution::resolution(), gui2::listbox_definition::resolution::resolution(), gui2::policy::select_action::selection::select(), gui2::slider::set_value_range(), gui2::state_definition::state_definition(), 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(), and gui2::builder_window::window_resolution::window_resolution().

◆ 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(false)

Definition at line 47 of file wml_exception.hpp.

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

Function Documentation

◆ 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 74 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.
dev_messageAny additional information that might be useful to a developer.

Definition at line 36 of file wml_exception.cpp.