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

Public Member Functions

const preproc_mapget_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_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 (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_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 90 of file config_cache.hpp.

Constructor & Destructor Documentation

game_config::config_cache::config_cache ( )
protected

Definition at line 46 of file config_cache.cpp.

References cache_file_prefix_, clear_defines(), and game_config::revision.

Member Function Documentation

void game_config::config_cache::add_define ( const std::string define)
void game_config::config_cache::add_defines_map_diff ( preproc_map defines_map)
private
bool game_config::config_cache::clean_cache ( )
void game_config::config_cache::clear_defines ( )
bool game_config::config_cache::delete_cache_files ( const std::vector< std::string > &  paths,
const std::string exclude_pattern = "" 
)
private
void game_config::config_cache::get_config ( const std::string path,
config cfg 
)

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.

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
config_cache & game_config::config_cache::instance ( )
static
void game_config::config_cache::load_configs ( const std::string path,
config cfg 
)
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().

preproc_map & game_config::config_cache::make_copy_map ( )
private
bool game_config::config_cache::purge_cache ( )
void game_config::config_cache::read_cache ( const std::string path,
config cfg 
)
private
void game_config::config_cache::read_configs ( const std::string path,
config cfg,
preproc_map defines 
)
private

Definition at line 135 of file config_cache.cpp.

References preprocess_file(), and read().

Referenced by load_configs(), and read_cache().

void game_config::config_cache::read_defines_file ( const std::string path)
private
void game_config::config_cache::read_defines_queue ( )
private
void game_config::config_cache::read_file ( const std::string file,
config cfg 
)
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)
void game_config::config_cache::set_force_invalid_cache ( bool  force)
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().

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

Member Data Documentation

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

Definition at line 154 of file config_cache.hpp.

Referenced by clean_cache(), config_cache(), and read_cache().

preproc_map game_config::config_cache::defines_map_
private
bool game_config::config_cache::fake_invalid_cache_
private

Definition at line 150 of file config_cache.hpp.

Referenced by read_cache(), and set_force_invalid_cache().

bool game_config::config_cache::force_valid_cache_
private

Definition at line 148 of file config_cache.hpp.

Referenced by read_cache(), and set_force_valid_cache().

bool game_config::config_cache::use_cache_
private

Definition at line 149 of file config_cache.hpp.

Referenced by load_configs(), and set_use_cache().


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