The Battle for Wesnoth  1.15.2+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:
Inheritance graph

Public Types

enum  create_for_default_saves_dir { 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 ()
 

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...
 

Detailed Description

Definition at line 79 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 87 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 123 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 132 of file save_index.cpp.

References read_only_.

Member Function Documentation

◆ data() [1/2]

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

◆ data() [2/2]

config & savegame::save_index_class::data ( )
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 361 of file save_index.cpp.

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

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 337 of file save_index.cpp.

References _(), preferences::autosavemax(), preferences::countdown(), 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 95 of file save_index.cpp.

References dir_.

Referenced by 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 178 of file save_index.cpp.

References config::child_range().

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 212 of file save_index.cpp.

References dir(), filesystem::get_files_in_dir(), and sort().

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 117 of file save_index.hpp.

◆ rebuild() [1/2]

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

Definition at line 44 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 70 of file save_index.cpp.

References data(), config::remove_attribute(), and write_save_index().

◆ set_modified()

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

Definition at line 77 of file save_index.cpp.

References modified_.

◆ write_save_index()

void savegame::save_index_class::write_save_index ( )

Member Data Documentation

◆ data_

config savegame::save_index_class::data_
private

Definition at line 129 of file save_index.hpp.

Referenced by data().

◆ dir_

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

Definition at line 131 of file save_index.hpp.

Referenced by dir(), and rebuild().

◆ loaded_

bool savegame::save_index_class::loaded_
private

Definition at line 128 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 130 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 136 of file save_index.hpp.

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


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