The Battle for Wesnoth  1.19.6+dev
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
savegame::save_index_class Class Reference

#include <save_index.hpp>

Inheritance diagram for savegame::save_index_class:

Public Types

enum class  create_for_default_saves_dir { yes }
 Syntatic sugar for choosing which constructor to use. More...
 

Public Member Functions

 save_index_class (const std::string &dir)
 Constructor for a read-only instance. More...
 
 save_index_class (create_for_default_saves_dir)
 
std::vector< save_infoget_saves_list (const std::string *filter=nullptr)
 Get a list of available saves. More...
 
void delete_game (const std::string &name)
 Delete a savegame, including deleting the underlying file. More...
 
void rebuild (const std::string &name)
 
void rebuild (const std::string &name, const std::time_t &modified)
 
void remove (const std::string &name)
 Delete a savegame from the index, without deleting the underlying file. More...
 
void set_modified (const std::string &name, const std::time_t &modified)
 
configget (const std::string &name)
 
const std::string & dir () const
 
void delete_old_auto_saves (const int autosavemax, const int infinite_auto_saves)
 Delete autosaves that are no longer needed (according to the autosave policy in the preferences). More...
 
void write_save_index ()
 Sync to disk, no-op if read_only_ is set. More...
 
bool read_only ()
 If true, all of delete_game, delete_old_auto_saves and write_save_index will be no-ops. More...
 

Static Public Member Functions

static std::shared_ptr< save_index_classdefault_saves_dir ()
 Returns an instance for managing saves in filesystem::get_saves_dir() More...
 

Private Member Functions

configdata (const std::string &name)
 
configdata ()
 
void clean_up_index ()
 Deletes non-existent save files from the index. More...
 

Static Private Member Functions

static void fix_leader_image_path (config &data)
 

Private Attributes

bool loaded_
 
config data_
 
std::map< std::string, std::time_t > modified_
 
const std::string dir_
 
bool read_only_
 The instance for default_saves_dir() writes a cache file. More...
 
bool clean_up_index_
 Flag to only run the clean_up_index method once. More...
 

Detailed Description

Definition at line 78 of file save_index.hpp.

Member Enumeration Documentation

◆ create_for_default_saves_dir

Syntatic sugar for choosing which constructor to use.

Enumerator
yes 

Definition at line 86 of file save_index.hpp.

Constructor & Destructor Documentation

◆ save_index_class() [1/2]

savegame::save_index_class::save_index_class ( const std::string &  dir)
explicit

Constructor for a read-only instance.

To get a writable instance, call default_saves_dir().

Definition at line 143 of file save_index.cpp.

◆ save_index_class() [2/2]

savegame::save_index_class::save_index_class ( create_for_default_saves_dir  )
explicit

Definition at line 153 of file save_index.cpp.

References read_only_.

Member Function Documentation

◆ clean_up_index()

void savegame::save_index_class::clean_up_index ( )
private

Deletes non-existent save files from the index.

Definition at line 99 of file save_index.cpp.

References config::all_children_count(), d, data(), dir(), utils::find(), filesystem::get_files_in_dir(), and config::remove_children().

Referenced by write_save_index().

◆ data() [1/2]

config & savegame::save_index_class::data ( )
private

◆ data() [2/2]

config & savegame::save_index_class::data ( const std::string &  name)
private

◆ default_saves_dir()

std::shared_ptr< save_index_class > savegame::save_index_class::default_saves_dir ( )
static

◆ delete_game()

void savegame::save_index_class::delete_game ( const std::string &  name)

Delete a savegame, including deleting the underlying file.

Definition at line 376 of file save_index.cpp.

References filesystem::delete_file(), dir(), LOG_SAVE, log_scope, read_only_, and remove().

Referenced by delete_old_auto_saves().

◆ delete_old_auto_saves()

void savegame::save_index_class::delete_old_auto_saves ( const int  autosavemax,
const int  infinite_auto_saves 
)

Delete autosaves that are no longer needed (according to the autosave policy in the preferences).

Definition at line 352 of file save_index.cpp.

References _(), delete_game(), get_saves_list(), i, LOG_SAVE, log_scope, and read_only_.

◆ dir()

const std::string & savegame::save_index_class::dir ( ) const

Definition at line 94 of file save_index.cpp.

References dir_.

Referenced by clean_up_index(), delete_game(), and get_saves_list().

◆ fix_leader_image_path()

void savegame::save_index_class::fix_leader_image_path ( config data)
staticprivate

Definition at line 199 of file save_index.cpp.

References config::child_range(), and data().

Referenced by data().

◆ get()

config & savegame::save_index_class::get ( const std::string &  name)

◆ get_saves_list()

std::vector< save_info > savegame::save_index_class::get_saves_list ( const std::string *  filter = nullptr)

Get a list of available saves.

Definition at line 216 of file save_index.cpp.

References dir(), utils::erase_if(), filename, utils::find(), and filesystem::get_files_in_dir().

Referenced by delete_old_auto_saves().

◆ read_only()

bool savegame::save_index_class::read_only ( )
inline

If true, all of delete_game, delete_old_auto_saves and write_save_index will be no-ops.

Definition at line 116 of file save_index.hpp.

References read_only_.

◆ rebuild() [1/2]

void savegame::save_index_class::rebuild ( const std::string &  name)

Definition at line 43 of file save_index.cpp.

References dir_, and filesystem::file_modified_time().

Referenced by get().

◆ rebuild() [2/2]

void savegame::save_index_class::rebuild ( const std::string &  name,
const std::time_t &  modified 
)

◆ remove()

void savegame::save_index_class::remove ( const std::string &  name)

Delete a savegame from the index, without deleting the underlying file.

Definition at line 69 of file save_index.cpp.

References d, data(), config::remove_children(), and write_save_index().

Referenced by delete_game().

◆ set_modified()

void savegame::save_index_class::set_modified ( const std::string &  name,
const std::time_t &  modified 
)

Definition at line 76 of file save_index.cpp.

References modified_.

◆ write_save_index()

void savegame::save_index_class::write_save_index ( )

Member Data Documentation

◆ clean_up_index_

bool savegame::save_index_class::clean_up_index_
private

Flag to only run the clean_up_index method once.

Definition at line 139 of file save_index.hpp.

Referenced by write_save_index().

◆ data_

config savegame::save_index_class::data_
private

Definition at line 130 of file save_index.hpp.

Referenced by data().

◆ dir_

const std::string savegame::save_index_class::dir_
private

Definition at line 132 of file save_index.hpp.

Referenced by dir(), and rebuild().

◆ loaded_

bool savegame::save_index_class::loaded_
private

Definition at line 129 of file save_index.hpp.

Referenced by data().

◆ modified_

std::map<std::string, std::time_t> savegame::save_index_class::modified_
private

Definition at line 131 of file save_index.hpp.

Referenced by get(), and set_modified().

◆ read_only_

bool savegame::save_index_class::read_only_
private

The instance for default_saves_dir() writes a cache file.

For other instances, write_save_index() and delete() are no-ops.

Definition at line 137 of file save_index.hpp.

Referenced by delete_game(), delete_old_auto_saves(), read_only(), save_index_class(), and write_save_index().


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