The Battle for Wesnoth  1.19.6+dev
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
game_config::config_cache Class Reference

Singleton class to manage game config file caching. More...

#include <config_cache.hpp>

Inheritance diagram for game_config::config_cache:

Public Member Functions

 config_cache (const config_cache &)=delete
 
config_cacheoperator= (const config_cache &)=delete
 
const preproc_mapget_preproc_map () const
 
void get_config (const std::string &path, config &cfg, abstract_validator *validator=nullptr)
 Gets a config object from given path. More...
 
void clear_defines ()
 Clear stored defines map to default values. More...
 
void add_define (const std::string &define)
 Add a entry to preproc defines map. More...
 
void remove_define (const std::string &define)
 Remove a entry to preproc defines map. More...
 
void set_use_cache (bool use)
 Enable/disable caching. More...
 
void set_force_valid_cache (bool force)
 Enable/disable cache validation. More...
 
void recheck_filetree_checksum ()
 Force cache checksum validation. More...
 
bool clean_cache ()
 Deletes stale cache files not in use by the game. More...
 
bool purge_cache ()
 Deletes all cache files. More...
 

Static Public Member Functions

static config_cacheinstance ()
 Get reference to the singleton object. More...
 

Protected Member Functions

 config_cache ()
 
void set_force_invalid_cache (bool)
 

Private Member Functions

void read_file (const std::string &file, config &cfg)
 
void write_file (const std::string &file, const config &cfg)
 
void write_file (const std::string &file, const preproc_map &defines)
 
void read_cache (const std::string &path, config &cfg, abstract_validator *validator=nullptr)
 
void read_configs (const std::string &path, config &cfg, preproc_map &defines, abstract_validator *validator=nullptr)
 
void load_configs (const std::string &path, config &cfg, abstract_validator *validator=nullptr)
 
void read_defines_queue ()
 
void read_defines_file (const std::string &path)
 
preproc_mapmake_copy_map ()
 
void add_defines_map_diff (preproc_map &)
 
bool delete_cache_files (const std::vector< std::string > &paths, const std::string &exclude_pattern="")
 

Private Attributes

bool force_valid_cache_
 
bool use_cache_
 
bool fake_invalid_cache_
 
preproc_map defines_map_
 
std::string cache_file_prefix_
 

Detailed Description

Singleton class to manage game config file caching.

It uses paths to config files as key to find correct cache

Todo:

Make smarter filetree checksum caching so only required parts of tree are checked at startup. Trees are overlapping so have to split trees to subtrees to only do check once per file.

Make cache system easily allow validation of in memory cache objects using hash checksum of preproc_map.

Definition at line 92 of file config_cache.hpp.

Constructor & Destructor Documentation

◆ config_cache() [1/2]

game_config::config_cache::config_cache ( const config_cache )
delete

◆ config_cache() [2/2]

game_config::config_cache::config_cache ( )
protected

Definition at line 63 of file config_cache.cpp.

References clear_defines().

Member Function Documentation

◆ add_define()

void game_config::config_cache::add_define ( const std::string &  define)

◆ add_defines_map_diff()

void game_config::config_cache::add_defines_map_diff ( preproc_map defines_map)
private

◆ clean_cache()

bool game_config::config_cache::clean_cache ( )

◆ clear_defines()

void game_config::config_cache::clear_defines ( )

Clear stored defines map to default values.

Definition at line 79 of file config_cache.cpp.

References defines_map_, and LOG_CACHE.

Referenced by BOOST_AUTO_TEST_CASE(), config_cache(), game_config_manager::load_game_config_for_create(), and game_config_manager::load_game_config_for_game().

◆ delete_cache_files()

bool game_config::config_cache::delete_cache_files ( const std::vector< std::string > &  paths,
const std::string &  exclude_pattern = "" 
)
private

◆ get_config()

void game_config::config_cache::get_config ( const std::string &  path,
config cfg,
abstract_validator validator = nullptr 
)

Gets a config object from given path.

Parameters
pathfile to load. Should be _main.cfg.
cfgconfig object that is written to. Should be empty on entry.
validatorthe WML schema validator, if provided.

Definition at line 92 of file config_cache.cpp.

References load_configs(), and validator.

Referenced by ad_hoc_addon_fetch_session(), BOOST_AUTO_TEST_CASE(), test_utils::game_config_manager::game_config_manager(), game_config_manager::load_addons_cfg(), and game_config_manager::load_game_config().

◆ get_preproc_map()

const preproc_map & game_config::config_cache::get_preproc_map ( ) const

◆ instance()

config_cache & game_config::config_cache::instance ( )
static

◆ load_configs()

void game_config::config_cache::load_configs ( const std::string &  path,
config cfg,
abstract_validator validator = nullptr 
)
private

◆ make_copy_map()

preproc_map & game_config::config_cache::make_copy_map ( )
private

◆ operator=()

config_cache& game_config::config_cache::operator= ( const config_cache )
delete

◆ purge_cache()

bool game_config::config_cache::purge_cache ( )

◆ read_cache()

void game_config::config_cache::read_cache ( const std::string &  path,
config cfg,
abstract_validator validator = nullptr 
)
private

◆ read_configs()

void game_config::config_cache::read_configs ( const std::string &  path,
config cfg,
preproc_map defines,
abstract_validator validator = nullptr 
)
private

Definition at line 142 of file config_cache.cpp.

References preprocess_file(), read(), and validator.

Referenced by load_configs(), and read_cache().

◆ read_defines_file()

void game_config::config_cache::read_defines_file ( const std::string &  path)
private

◆ read_defines_queue()

void game_config::config_cache::read_defines_queue ( )
private

◆ read_file()

void game_config::config_cache::read_file ( const std::string &  file,
config cfg 
)
private

Definition at line 122 of file config_cache.cpp.

References filesystem::istream_file(), and read_gz().

Referenced by read_cache(), and read_defines_file().

◆ recheck_filetree_checksum()

void game_config::config_cache::recheck_filetree_checksum ( )

Force cache checksum validation.

Definition at line 316 of file config_cache.cpp.

References filesystem::data_tree_checksum().

Referenced by game_config_manager::reload_changed_game_config().

◆ remove_define()

void game_config::config_cache::remove_define ( const std::string &  define)

◆ set_force_invalid_cache()

void game_config::config_cache::set_force_invalid_cache ( bool  force)
protected

Definition at line 301 of file config_cache.cpp.

References fake_invalid_cache_.

Referenced by test_config_cache::set_force_invalid_cache().

◆ set_force_valid_cache()

void game_config::config_cache::set_force_valid_cache ( bool  force)

Enable/disable cache validation.

Definition at line 311 of file config_cache.cpp.

References force_valid_cache_.

Referenced by game_config_manager::game_config_manager().

◆ set_use_cache()

void game_config::config_cache::set_use_cache ( bool  use)

Enable/disable caching.

Definition at line 306 of file config_cache.cpp.

References use_cache_.

Referenced by game_config_manager::game_config_manager().

◆ write_file() [1/2]

void game_config::config_cache::write_file ( const std::string &  file,
const config cfg 
)
private

◆ write_file() [2/2]

void game_config::config_cache::write_file ( const std::string &  file,
const preproc_map defines 
)
private

Member Data Documentation

◆ cache_file_prefix_

std::string game_config::config_cache::cache_file_prefix_
private

Definition at line 160 of file config_cache.hpp.

Referenced by clean_cache(), and read_cache().

◆ defines_map_

preproc_map game_config::config_cache::defines_map_
private

◆ fake_invalid_cache_

bool game_config::config_cache::fake_invalid_cache_
private

Definition at line 156 of file config_cache.hpp.

Referenced by read_cache(), and set_force_invalid_cache().

◆ force_valid_cache_

bool game_config::config_cache::force_valid_cache_
private

Definition at line 154 of file config_cache.hpp.

Referenced by read_cache(), and set_force_valid_cache().

◆ use_cache_

bool game_config::config_cache::use_cache_
private

Definition at line 155 of file config_cache.hpp.

Referenced by load_configs(), and set_use_cache().


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