The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
movetype::terrain_info::data Class Reference

Public Member Functions

 data (const parameters &params)
 Constructor. More...
 
 data (const config &cfg, const parameters &params)
 Constructor. More...
 
 data (const data &that)
 
void clear_cache (const terrain_info *cascade) const
 Clears the cached data (presumably our fallback has changed). More...
 
bool config_has_changes (const config &new_values, bool overwrite) const
 Tests if merging new_values would result in changes. More...
 
bool empty () const
 Tests for no data in this object. More...
 
void merge (const config &new_values, bool overwrite, const terrain_info *cascade)
 Merges the given config over the existing costs. More...
 
const parametersparams () const
 Read-only access to our parameters. More...
 
int value (const t_translation::t_terrain &terrain, const terrain_info *fallback) const
 Returns the value associated with the given terrain. More...
 
void write (config &out_cfg, const std::string &child_name) const
 If there is data, writes it to the config. More...
 
void write (config &out_cfg, const std::string &child_name, const terrain_info *fallback) const
 If there is (merged) data, writes it to the config. More...
 

Private Types

typedef std::map
< t_translation::t_terrain,
int
cache_t
 

Private Member Functions

int calc_value (const t_translation::t_terrain &terrain, const terrain_info *fallback, unsigned recurse_count) const
 Calculates the value associated with the given terrain. More...
 
int value (const t_translation::t_terrain &terrain, const terrain_info *fallback, unsigned recurse_count) const
 Returns the value associated with the given terrain (possibly cached). More...
 

Private Attributes

config cfg_
 Config describing the terrain values. More...
 
cache_t cache_
 Cache of values based on the config. More...
 
const parametersparams_
 Various parameters used when calculating values. More...
 

Detailed Description

Definition at line 89 of file movetype.cpp.

Member Typedef Documentation

typedef std::map<t_translation::t_terrain, int> movetype::terrain_info::data::cache_t
private

Definition at line 139 of file movetype.cpp.

Constructor & Destructor Documentation

movetype::terrain_info::data::data ( const parameters params)
inlineexplicit

Constructor.

params must be long-lived (typically a static variable).

Definition at line 94 of file movetype.cpp.

movetype::terrain_info::data::data ( const config cfg,
const parameters params 
)
inline

Constructor.

params must be long-lived (typically a static variable).

Definition at line 99 of file movetype.cpp.

movetype::terrain_info::data::data ( const data that)
inline

Definition at line 105 of file movetype.cpp.

Member Function Documentation

int movetype::terrain_info::data::calc_value ( const t_translation::t_terrain terrain,
const terrain_info fallback,
unsigned  recurse_count 
) const
private

Calculates the value associated with the given terrain.

This is separate from value() to separate the calculating of the value from the caching of it.

Parameters
[in]terrainThe terrain whose value is requested.
[in]fallbackConsulted if we are missing data.
[in]recurse_countDetects (probable) infinite recursion.

Definition at line 272 of file movetype.cpp.

References ERR_CF, game_config_manager::get(), i, t_translation::MINUS, t_translation::PLUS, gui2::terrain, game_config_manager::terrain_types(), movetype::terrain_info::value(), t_translation::write_terrain_code(), and WRN_CF.

void movetype::terrain_info::data::clear_cache ( const terrain_info cascade) const

Clears the cached data (presumably our fallback has changed).

Parameters
[in]cascadeCache clearing will be cascaded into this terrain_info.

Definition at line 154 of file movetype.cpp.

References cache_, and movetype::terrain_info::clear_cache().

bool movetype::terrain_info::data::config_has_changes ( const config new_values,
bool  overwrite 
) const

Tests if merging new_values would result in changes.

This allows the shared data to actually work, as otherwise each unit created via WML (including unstored units) would "overwrite" its movement data with a usually identical copy and thus break the sharing.

Definition at line 169 of file movetype.cpp.

References config::attribute_range().

bool movetype::terrain_info::data::empty ( ) const
inline

Tests for no data in this object.

Definition at line 114 of file movetype.cpp.

References cfg_, and config::empty().

void movetype::terrain_info::data::merge ( const config new_values,
bool  overwrite,
const terrain_info cascade 
)

Merges the given config over the existing costs.

Parameters
[in]new_valuesThe new values.
[in]overwriteIf true, the new values overwrite the old. If false, the new values are added to the old.
[in]cascadeCache clearing will be cascaded into this terrain_info.

Definition at line 195 of file movetype.cpp.

References config::attribute_range(), movetype::terrain_info::clear_cache(), config::attribute_value::to_int(), and movetype::terrain_info::value().

const parameters& movetype::terrain_info::data::params ( ) const
inline

Read-only access to our parameters.

Definition at line 119 of file movetype.cpp.

References params_.

int movetype::terrain_info::data::value ( const t_translation::t_terrain terrain,
const terrain_info fallback 
) const
inline

Returns the value associated with the given terrain.

Definition at line 121 of file movetype.cpp.

int movetype::terrain_info::data::value ( const t_translation::t_terrain terrain,
const terrain_info fallback,
unsigned  recurse_count 
) const
private

Returns the value associated with the given terrain (possibly cached).

Parameters
[in]terrainThe terrain whose value is requested.
[in]fallbackConsulted if we are missing data.
[in]recurse_countDetects (probable) infinite recursion.

Definition at line 377 of file movetype.cpp.

References cache_.

void movetype::terrain_info::data::write ( config out_cfg,
const std::string child_name 
) const

If there is data, writes it to the config.

If there is data, writes it to a config.

Parameters
[out]out_cfgThe config that will receive the data.
[in]child_nameIf not empty, create and write to a child config with this tag. This child will not be created if there is no data to write.

Definition at line 232 of file movetype.cpp.

References config::add_child(), and config::merge_with().

void movetype::terrain_info::data::write ( config out_cfg,
const std::string child_name,
const terrain_info fallback 
) const

If there is (merged) data, writes it to the config.

Writes merged data to a config.

Parameters
[out]out_cfgThe config that will receive the data.
[in]child_nameIf not empty, create and write to a child config with this tag. This will be created even if there is no data to write.
[in]fallbackIf not nullptr, its data will be merged with ours for the write.

Definition at line 252 of file movetype.cpp.

References config::add_child(), config::empty(), config::merge_with(), and movetype::terrain_info::write().

Member Data Documentation

cache_t movetype::terrain_info::data::cache_
mutableprivate

Cache of values based on the config.

Definition at line 144 of file movetype.cpp.

Referenced by clear_cache().

config movetype::terrain_info::data::cfg_
private

Config describing the terrain values.

Definition at line 142 of file movetype.cpp.

Referenced by empty().

const parameters& movetype::terrain_info::data::params_
private

Various parameters used when calculating values.

Definition at line 146 of file movetype.cpp.

Referenced by params().


The documentation for this class was generated from the following file: