Singleton class to manage game config file caching. More...
#include <config_cache.hpp>
Public Member Functions | |
const preproc_map & | get_preproc_map () const |
void | get_config (const std::string &path, config &cfg) |
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_cache & | instance () |
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 (std::string file, const config &cfg) |
void | write_file (std::string file, const preproc_map &defines) |
void | read_cache (const std::string &path, config &cfg) |
void | read_configs (const std::string &path, config &cfg, preproc_map &defines) |
void | load_configs (const std::string &path, config &cfg) |
void | read_defines_queue () |
void | read_defines_file (const std::string &path) |
preproc_map & | make_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_ |
Singleton class to manage game config file caching.
It uses paths to config files as key to find correct cache
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 90 of file config_cache.hpp.
|
protected |
Definition at line 46 of file config_cache.cpp.
References cache_file_prefix_, clear_defines(), and game_config::revision.
void game_config::config_cache::add_define | ( | const std::string & | define | ) |
Add a entry to preproc defines map.
Definition at line 313 of file config_cache.cpp.
References DBG_CACHE, defines_map_, game_config::config_cache_transaction::get_active_map(), game_config::config_cache_transaction::instance(), and game_config::config_cache_transaction::is_active().
Referenced by BOOST_AUTO_TEST_CASE(), and test_utils::game_config_manager::game_config_manager().
|
private |
Definition at line 130 of file config_cache.cpp.
References game_config::config_cache_transaction::add_defines_map_diff(), and game_config::config_cache_transaction::instance().
Referenced by load_configs(), and read_cache().
bool game_config::config_cache::clean_cache | ( | ) |
Deletes stale cache files not in use by the game.
Definition at line 337 of file config_cache.cpp.
References cache_file_prefix_, delete_cache_files(), filesystem::ENTIRE_FILE_PATH, filesystem::get_cache_dir(), filesystem::get_files_in_dir(), and LOG_CACHE.
Referenced by gui2::tgame_cache_options::clean_cache().
void game_config::config_cache::clear_defines | ( | ) |
Clear stored defines map to default values.
Definition at line 68 of file config_cache.cpp.
References defines_map_, LOG_CACHE, and game_config::wesnoth_version.
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().
|
private |
Definition at line 374 of file config_cache.cpp.
References filesystem::base_name(), filesystem::delete_directory(), ERR_CACHE, LOG_CACHE, and utils::wildcard_string_match().
Referenced by clean_cache(), and purge_cache().
void game_config::config_cache::get_config | ( | const std::string & | path, |
config & | cfg | ||
) |
Gets a config object from given path.
path | file to load. Should be _main.cfg. |
cfg | config object that is written to. Should be empty on entry. |
Definition at line 89 of file config_cache.cpp.
References load_configs().
Referenced by 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().
const preproc_map & game_config::config_cache::get_preproc_map | ( | ) | const |
Definition at line 63 of file config_cache.cpp.
References defines_map_.
Referenced by BOOST_AUTO_TEST_CASE(), game_config_manager::load_game_config(), game_config_manager::load_game_config_for_create(), and game_config_manager::load_game_config_with_loadscreen().
|
static |
Get reference to the singleton object.
Definition at line 40 of file config_cache.cpp.
References gui2::cache.
Referenced by BOOST_AUTO_TEST_CASE(), gui2::tgame_cache_options::clean_cache(), test_utils::game_config_manager::game_config_manager(), gui2::load_settings(), main(), gui2::tgame_cache_options::purge_cache(), and schema_validation::schema_validator::read_config_file().
|
private |
Definition at line 279 of file config_cache.cpp.
References add_defines_map_diff(), make_copy_map(), read_cache(), read_configs(), and use_cache_.
Referenced by get_config().
|
private |
Definition at line 125 of file config_cache.cpp.
References defines_map_, game_config::config_cache_transaction::get_active_map(), and game_config::config_cache_transaction::instance().
Referenced by load_configs(), and read_cache().
bool game_config::config_cache::purge_cache | ( | ) |
Deletes all cache files.
Definition at line 357 of file config_cache.cpp.
References delete_cache_files(), filesystem::ENTIRE_FILE_PATH, filesystem::get_cache_dir(), filesystem::get_files_in_dir(), and LOG_CACHE.
Referenced by gui2::tgame_cache_options::purge_cache().
|
private |
Definition at line 142 of file config_cache.cpp.
References game_config::config_cache_transaction::add_define_file(), add_defines_map_diff(), cache_file_prefix_, d, filesystem::data_tree_checksum(), DBG_CACHE, defines_map_, e, ERR_CACHE, fake_invalid_cache_, filesystem::file_exists(), force_valid_cache_, filesystem::get_cache_dir(), game_config::config_cache_transaction::instance(), LOG_CACHE, log_scope, make_copy_map(), game::error::message, game_config::path, read_configs(), read_defines_queue(), read_file(), filesystem::file_tree_checksum::write(), and write_file().
Referenced by load_configs().
|
private |
Definition at line 135 of file config_cache.cpp.
References preprocess_file(), and read().
Referenced by load_configs(), and read_cache().
|
private |
Definition at line 255 of file config_cache.cpp.
References config::all_children_range(), DBG_CACHE, game_config::config_cache_transaction::insert_to_active(), game_config::config_cache_transaction::instance(), read_file(), and preproc_define::read_pair().
Referenced by read_defines_queue().
|
private |
Definition at line 270 of file config_cache.cpp.
References game_config::config_cache_transaction::get_define_files(), game_config::config_cache_transaction::instance(), and read_defines_file().
Referenced by read_cache().
|
private |
Definition at line 119 of file config_cache.cpp.
References filesystem::istream_file(), and read_gz().
Referenced by read_cache(), and read_defines_file().
void game_config::config_cache::recheck_filetree_checksum | ( | ) |
Force cache checksum validation.
Definition at line 308 of file config_cache.cpp.
References filesystem::data_tree_checksum().
Referenced by game_config_manager::reload_changed_game_config().
void game_config::config_cache::remove_define | ( | const std::string & | define | ) |
Remove a entry to preproc defines map.
Definition at line 326 of file config_cache.cpp.
References DBG_CACHE, defines_map_, game_config::config_cache_transaction::get_active_map(), game_config::config_cache_transaction::instance(), and game_config::config_cache_transaction::is_active().
Referenced by BOOST_AUTO_TEST_CASE().
|
protected |
Definition at line 293 of file config_cache.cpp.
References fake_invalid_cache_.
Referenced by test_config_cache::set_force_invalid_cache().
void game_config::config_cache::set_force_valid_cache | ( | bool | force | ) |
Enable/disable cache validation.
Definition at line 303 of file config_cache.cpp.
References force_valid_cache_.
Referenced by game_config_manager::game_config_manager().
void game_config::config_cache::set_use_cache | ( | bool | use | ) |
Enable/disable caching.
Definition at line 298 of file config_cache.cpp.
References use_cache_.
Referenced by game_config_manager::game_config_manager().
|
private |
Definition at line 94 of file config_cache.cpp.
References game_config::cache_compression_level, filesystem::ostream_file(), config_writer::write(), and writer().
Referenced by read_cache().
|
private |
Definition at line 101 of file config_cache.cpp.
References game_config::cache_compression_level, filesystem::delete_directory(), filesystem::file_exists(), filesystem::ostream_file(), and writer().
|
private |
Definition at line 154 of file config_cache.hpp.
Referenced by clean_cache(), config_cache(), and read_cache().
|
private |
Definition at line 152 of file config_cache.hpp.
Referenced by add_define(), clear_defines(), get_preproc_map(), make_copy_map(), read_cache(), and remove_define().
|
private |
Definition at line 150 of file config_cache.hpp.
Referenced by read_cache(), and set_force_invalid_cache().
|
private |
Definition at line 148 of file config_cache.hpp.
Referenced by read_cache(), and set_force_valid_cache().
|
private |
Definition at line 149 of file config_cache.hpp.
Referenced by load_configs(), and set_use_cache().