util.hpp File Reference

Templates and utility-routines for strings and numbers. More...

#include "global.hpp"
#include <cmath>
#include <map>
#include <sstream>
#include <SDL_types.h>

Include dependency graph for util.hpp:

Go to the source code of this file.

Classes

struct  bad_lexical_cast

Defines

#define LIKELY(a)   a
#define UNLIKELY(a)   a
#define fxp_shift   8
#define fxp_base   (1 << fxp_shift)
#define ftofxp(x)   (fixed_t((x) * fxp_base))
 IN: float or int - OUT: fixed_t.
#define fxpmult(x, y)   (((x)*(y)) >> fxp_shift)
 IN: unsigned and fixed_t - OUT: unsigned.
#define fxpdiv(x, y)   (((x) << fxp_shift) / (y))
 IN: unsigned and int - OUT: fixed_t.
#define fxptoi(x)   ( ((x)>0) ? ((x) >> fxp_shift) : (-((-(x)) >> fxp_shift)) )
 IN: fixed_t - OUT: int.

Typedefs

typedef Sint32 fixed_t

Functions

template<typename T>
T & minimum (T &a, T &b)
 Replacement for VC++'s definitions of min and max.
template<typename T>
const T & minimum (const T &a, const T &b)
template<typename T>
T & maximum (T &a, T &b)
template<typename T>
const T & maximum (const T &a, const T &b)
template<typename T>
bool is_odd (T num)
template<typename T>
bool is_even (T num)
int div100rounded (int num)
 Guarantees portable results for division by 100; round towards 0.
int round_damage (int base_damage, int bonus, int divisor)
 round (base_damage * bonus / divisor) to the closest integer, but up or down towards base_damage
int round_double (double d)
template<typename To, typename From>
To lexical_cast (From a)
template<typename To, typename From>
To lexical_cast_default (From a, To def=To())
template<>
int lexical_cast< int, const std::string & > (const std::string &a)
template<>
int lexical_cast< int, const char * > (const char *a)
template<>
int lexical_cast_default< int, const std::string & > (const std::string &a, int def)
template<>
int lexical_cast_default< int, const char * > (const char *a, int def)
template<typename From>
std::string str_cast (From a)
template<typename To, typename From>
To lexical_cast_in_range (From a, To def, To min, To max)
bool chars_equal_insensitive (char a, char b)
bool chars_less_insensitive (char a, char b)
template<typename T, typename C>
void push_back (T &str, C c)
 A definition of 'push_back' for strings, since some implementations don't support string::push_back.


Detailed Description

Templates and utility-routines for strings and numbers.

Definition in file util.hpp.


Define Documentation

#define ftofxp (  )     (fixed_t((x) * fxp_base))

#define fxp_base   (1 << fxp_shift)

Definition at line 167 of file util.hpp.

#define fxp_shift   8

Definition at line 166 of file util.hpp.

#define fxpdiv ( x,
 )     (((x) << fxp_shift) / (y))

IN: unsigned and int - OUT: fixed_t.

Definition at line 176 of file util.hpp.

Referenced by game_display::draw_bar(), game_display::new_turn(), and scale_surface().

#define fxpmult ( x,
 )     (((x)*(y)) >> fxp_shift)

IN: unsigned and fixed_t - OUT: unsigned.

Definition at line 173 of file util.hpp.

Referenced by adjust_surface_alpha(), brighten_image(), and game_display::draw_bar().

#define fxptoi (  )     ( ((x)>0) ? ((x) >> fxp_shift) : (-((-(x)) >> fxp_shift)) )

IN: fixed_t - OUT: int.

Definition at line 179 of file util.hpp.

Referenced by game_display::draw_bar(), and scale_surface().

#define LIKELY ( a   )     a

Definition at line 158 of file util.hpp.

Referenced by tokenizer::next_char_fast().

#define UNLIKELY ( a   )     a

Definition at line 159 of file util.hpp.

Referenced by tokenizer::next_char(), and tokenizer::next_char_fast().


Typedef Documentation

typedef Sint32 fixed_t

Definition at line 165 of file util.hpp.


Function Documentation

bool chars_equal_insensitive ( char  a,
char  b 
) [inline]

Definition at line 140 of file util.hpp.

Referenced by events::menu_handler::do_search(), and utils::word_completion().

bool chars_less_insensitive ( char  a,
char  b 
) [inline]

Definition at line 141 of file util.hpp.

Referenced by gui::menu::basic_sorter::less().

int div100rounded ( int  num  )  [inline]

Guarantees portable results for division by 100; round towards 0.

Definition at line 53 of file util.hpp.

Referenced by utils::apply_modifier().

template<typename T>
bool is_even ( num  )  [inline]

template<typename T>
bool is_odd ( num  )  [inline]

template<typename To, typename From>
To lexical_cast ( From  a  )  [inline]

Definition at line 78 of file util.hpp.

Referenced by scoped_xy_unit::activate(), upload_log::add_game_result(), config::apply_diff(), attack::attack(), events::menu_handler::autosave(), check_timeout(), events::console_handler::do_control(), events::console_handler::do_droid(), game_display::draw_movement_info(), play_controller::expand_autosaves(), mp::connect::side::get_config(), hotkey::get_hotkey(), get_player_info(), help::help_text_area::handle_format_cfg(), help::help_text_area::handle_jump_cfg(), game::is_on_team(), mp::wait::join_game(), mp::connect::lists_init(), mp::connect::load_game(), image::locator::load_image_sub_file(), move_unit(), game_logic::parse_expression(), font::parse_markup(), play_game(), mp::create::process_event(), turn_info::process_network_data(), upload_log::quit(), statistics::stats::read(), wesnothd::banned::read(), events::menu_handler::recall(), network::receive_data(), map_editor::resize_dialog(), server::run(), game::send_change_controller(), events::menu_handler::send_chat_message(), events::chat_handler::send_command(), variant::serialize_to_string(), preferences::set_editor_b(), preferences::set_editor_g(), preferences::set_editor_r(), mp::gamebrowser::set_game_items(), team::set_income(), hotkey::hotkey_item::set_key(), preferences::set_scroll_speed(), tokenizer::skip_comment(), str_cast(), string2rgb(), variant::string_cast(), t_translation::string_to_number_(), track_ok(), game::transfer_ai_sides(), unit_display::unit_attack(), variable_info::variable_info(), upload_log::victory(), gamemap::write(), write_game(), and upload_log::~upload_log().

template<>
int lexical_cast< int, const char * > ( const char *  a  )  [inline]

template<>
int lexical_cast< int, const std::string & > ( const std::string &  a  )  [inline]

template<typename To, typename From>
To lexical_cast_default ( From  a,
To  def = To() 
) [inline]

Definition at line 91 of file util.hpp.

Referenced by cfg_to_loc(), and t_translation::string_to_builder_number_().

template<>
int lexical_cast_default< int, const char * > ( const char *  a,
int  def 
) [inline]

template<>
int lexical_cast_default< int, const std::string & > ( const std::string &  a,
int  def 
) [inline]

template<typename To, typename From>
To lexical_cast_in_range ( From  a,
To  def,
To  min,
To  max 
) [inline]

Definition at line 122 of file util.hpp.

template<typename T>
const T& maximum ( const T &  a,
const T &  b 
) [inline]

Definition at line 41 of file util.hpp.

template<typename T>
T& maximum ( T &  a,
T &  b 
) [inline]

template<typename T>
const T& minimum ( const T &  a,
const T &  b 
) [inline]

Definition at line 35 of file util.hpp.

template<typename T>
T& minimum ( T &  a,
T &  b 
) [inline]

template<typename T, typename C>
void push_back ( T &  str,
c 
) [inline]

int round_damage ( int  base_damage,
int  bonus,
int  divisor 
) [inline]

round (base_damage * bonus / divisor) to the closest integer, but up or down towards base_damage

Definition at line 61 of file util.hpp.

Referenced by reports::generate_report(), and battle_context::unit_stats::unit_stats().

int round_double ( double  d  )  [inline]

template<typename From>
std::string str_cast ( From  a  )  [inline]


Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs