The Battle for Wesnoth  1.19.5+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_WML_CHILD(cfg, key, message)
 
#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 (attribute). More...
 
std::string missing_mandatory_wml_tag (const std::string &section, const std::string &tag)
 Returns a standard message for a missing wml child (tag). 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)
Value:
do { \
throw_wml_exception(nullptr, __FILE__, __LINE__, __func__, message); \
} while(false)

Definition at line 65 of file wml_exception.hpp.

◆ 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 70 of file wml_exception.hpp.

◆ 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.

◆ 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 53 of file wml_exception.hpp.

◆ VALIDATE_WML_CHILD

#define VALIDATE_WML_CHILD (   cfg,
  key,
  message 
)
Value:
([](auto c, auto k) { \
if(auto child = c.optional_child(k)) { return *child; } \
throw_wml_exception( "Missing [" key "]", __FILE__, __LINE__, __func__, message); \
})(cfg, key) \
mock_char c

Definition at line 47 of file wml_exception.hpp.

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 (attribute).

Parameters
sectionThe section in which the key should appear. Shouldn't include leading or trailing brackets, as they're already in the translatable string; but if it has to include brackets in the middle, for example "parent][child][section", then it seems reasonable include the outer ones too.
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.

Referenced by expand_partialresolution(), gui2::gui_definition::gui_definition(), gui2::parse_linked_group_definitions(), gui2::implementation::parse_list_data(), gui2::builder_window::read(), gui2::horizontal_scrollbar_definition::resolution::resolution(), gui2::slider_definition::resolution::resolution(), gui2::vertical_scrollbar_definition::resolution::resolution(), gui2::styled_widget_definition::styled_widget_definition(), pathfind::teleport_group::teleport_group(), 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().

◆ missing_mandatory_wml_tag()

std::string missing_mandatory_wml_tag ( const std::string &  section,
const std::string &  tag 
)

Returns a standard message for a missing wml child (tag).

Parameters
sectionThe section in which the child should appear. Same meaning as for missing_mandatory_wml_key().
tagThe omitted tag.
Returns
The error message.

Definition at line 97 of file wml_exception.cpp.

References markup::tag(), and VGETTEXT.

Referenced by gui2::button_definition::resolution::resolution(), gui2::chatbox_definition::resolution::resolution(), gui2::combobox_definition::resolution::resolution(), gui2::horizontal_scrollbar_definition::resolution::resolution(), gui2::image_definition::resolution::resolution(), gui2::label_definition::resolution::resolution(), gui2::listbox_definition::resolution::resolution(), gui2::matrix_definition::resolution::resolution(), gui2::menu_button_definition::resolution::resolution(), gui2::minimap_definition::resolution::resolution(), gui2::multiline_text_definition::resolution::resolution(), gui2::multimenu_button_definition::resolution::resolution(), gui2::panel_definition::resolution::resolution(), gui2::progress_bar_definition::resolution::resolution(), gui2::repeating_button_definition::resolution::resolution(), gui2::rich_label_definition::resolution::resolution(), gui2::scroll_label_definition::resolution::resolution(), gui2::scroll_text_definition::resolution::resolution(), gui2::scrollbar_panel_definition::resolution::resolution(), gui2::slider_definition::resolution::resolution(), gui2::spinner_definition::resolution::resolution(), gui2::tab_container_definition::resolution::resolution(), gui2::text_box_definition::resolution::resolution(), gui2::toggle_button_definition::resolution::resolution(), gui2::toggle_panel_definition::resolution::resolution(), gui2::tree_view_definition::resolution::resolution(), gui2::unit_preview_pane_definition::resolution::resolution(), gui2::vertical_scrollbar_definition::resolution::resolution(), and gui2::implementation::tree_node::tree_node().

◆ 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.

References draw::line().