The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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:

Go to the source code of this file.

Classes

struct  twml_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 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

#define FAIL (   message)
Value:
do { \
wml_exception(nullptr, __FILE__, __LINE__, __func__, message); \
/* wml_exception never returns. */ \
/* Help the compiler to figure that out */ \
throw 42; \
} while(0)
void 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.
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499

Definition at line 68 of file wml_exception.hpp.

Referenced by make_enum_detail::debug_conversion_error(), and basic_unit_filter_impl::internal_matches_filter().

#define FAIL_WITH_DEV_MESSAGE (   message,
  dev_message 
)
Value:
do { \
wml_exception(nullptr \
, __FILE__ \
, __LINE__ \
, __func__ \
, message \
, dev_message); \
/* wml_exception never returns. */ \
/* Help the compiler to figure that out */ \
throw 42; \
} while(0)
void 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.
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499

Definition at line 76 of file wml_exception.hpp.

#define VALIDATE (   cond,
  message 
)
Value:
do { \
if(!(cond)) { \
wml_exception(#cond, __FILE__, __LINE__, __func__, message); \
} \
} while(0)
void 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.
static int cond(LexState *ls)
Definition: lparser.cpp:1168
CALLABLE_WRAPPER_INPUT_END if(key=="terrain")
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499

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

Referenced by battle_context::battle_context(), gui2::build(), gui2::implementation::tbuilder_slider::build(), battle_context::choose_defender_weapon(), pathfind::shortest_path_calculator::cost(), gui2::create_builder_widget(), default_map_generator_job::default_generate_map(), expand_partialresolution(), gui2::find_widget(), gui2::policy::select_action::tselect::init(), gui2::twindow::layout(), gui2::load_settings(), gui2::tgui_definition::load_widget_definitions(), gui2::tcampaign_selection::pre_show(), gui2::tgame_version::pre_show(), gui2::tgui_definition::read(), gui2::twindow_builder::read(), preferences::server_list(), t_translation::string_to_layer_(), theme::tborder::tborder(), gui2::tbuilder_grid::tbuilder_grid(), gui2::implementation::tbuilder_horizontal_listbox::tbuilder_horizontal_listbox(), gui2::implementation::tbuilder_listbox::tbuilder_listbox(), gui2::implementation::tbuilder_multi_page::tbuilder_multi_page(), gui2::implementation::tbuilder_pane::tbuilder_pane(), gui2::implementation::tbuilder_panel::tbuilder_panel(), gui2::implementation::tbuilder_scrollbar_panel::tbuilder_scrollbar_panel(), gui2::implementation::tbuilder_stacked_widget::tbuilder_stacked_widget(), gui2::implementation::tbuilder_toggle_panel::tbuilder_toggle_panel(), gui2::implementation::tbuilder_tree_view::tbuilder_tree_view(), gui2::tcontrol_definition::tcontrol_definition(), terrain_type::terrain_type(), gui2::tscrollbar_panel_definition::tresolution::tresolution(), gui2::tvertical_scrollbar_definition::tresolution::tresolution(), gui2::thorizontal_scrollbar_definition::tresolution::tresolution(), gui2::tunit_preview_pane_definition::tresolution::tresolution(), gui2::tscroll_label_definition::tresolution::tresolution(), gui2::tstacked_widget_definition::tresolution::tresolution(), gui2::twindow_builder::tresolution::tresolution(), gui2::ttree_view_definition::tresolution::tresolution(), gui2::tmulti_page_definition::tresolution::tresolution(), gui2::tslider_definition::tresolution::tresolution(), gui2::tlistbox_definition::tresolution::tresolution(), gui2::tstate_definition::tstate_definition(), gui2::twindow_builder::tresolution::ttip::ttip(), gui2::implementation::ttree_node::ttree_node(), gui2::ttree_view_node::ttree_view_node(), and font::word_wrap_text().

#define VALIDATE_WITH_DEV_MESSAGE (   cond,
  message,
  dev_message 
)
Value:
do { \
if(!(cond)) { \
, __FILE__ \
, __LINE__ \
, __func__ \
, message \
, dev_message); \
} \
} while(0)
void 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.
static int cond(LexState *ls)
Definition: lparser.cpp:1168
CALLABLE_WRAPPER_INPUT_END if(key=="terrain")
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499

Definition at line 56 of file wml_exception.hpp.

Referenced by gui2::implementation::tbuilder_control::tbuilder_control().

Function Documentation

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 key.
Returns
The warning message.

Definition at line 103 of file wml_exception.cpp.

References vgettext().

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 key.
Returns
The warning message.

Definition at line 118 of file wml_exception.cpp.

References vgettext().

Referenced by 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 139 of file wml_exception.cpp.

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

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 71 of file wml_exception.cpp.

References vgettext(), and WRN_NG.

Referenced by expand_partialresolution(), gui2::tgui_definition::read(), gui2::twindow_builder::read(), gui2::tcontrol_definition::tcontrol_definition(), terrain_type::terrain_type(), gui2::tvertical_scrollbar_definition::tresolution::tresolution(), gui2::thorizontal_scrollbar_definition::tresolution::tresolution(), gui2::twindow_builder::tresolution::tresolution(), gui2::tslider_definition::tresolution::tresolution(), gui2::twindow_builder::tresolution::ttip::ttip(), and gui2::implementation::ttree_node::ttree_node().

void 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 33 of file wml_exception.cpp.