The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
save_index.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by Jörg Hinrichs, refactored from various
3  places formerly created by David White <[email protected]>
4  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #ifndef SAVE_INDEX_H_INCLUDED
17 #define SAVE_INDEX_H_INCLUDED
18 
19 #include "config.hpp"
21 
22 class config_writer;
23 class game_display;
24 
25 
26 namespace savegame {
27 
28 /** Filename and modification date for a file list */
29 class save_info {
30 private:
31  friend class create_save_info;
32 private:
33  save_info(const std::string& name, const time_t& modified) :
34  name_(name), modified_(modified)
35  {}
36 
37 public:
38  const std::string& name() const { return name_; }
39  const time_t& modified() const { return modified_; }
40 public:
43  const config& summary() const;
44 private:
46  time_t modified_;
47 };
48 
49 /**
50  * A structure for comparing to save_info objects based on their modified time.
51  * If the times are equal, will order based on the name.
52  */
54  bool operator()(const save_info& a, const save_info& b) const;
55 };
56 
57 std::vector<save_info> get_saves_list(const std::string* dir = nullptr, const std::string* filter = nullptr);
58 
59 /** Read the complete config information out of a savefile. */
60 void read_save_file(const std::string& name, config& cfg, std::string* error_log);
61 
62 /** Remove autosaves that are no longer needed (according to the autosave policy in the preferences). */
63 void remove_old_auto_saves(const int autosavemax, const int infinite_auto_saves);
64 
65 /** Delete a savegame. */
66 void delete_game(const std::string& name);
67 
68 
70 public:
71  create_save_info(const std::string* d = nullptr) ;
72  save_info operator()(const std::string& filename) const ;
74 };
75 
76 
78 {
79 public:
80  void rebuild(const std::string& name) ;
81  void rebuild(const std::string& name, const time_t& modified) ;
82  void remove(const std::string& name) ;
83  void set_modified(const std::string& name, const time_t& modified) ;
84  config& get(const std::string& name) ;
85 public:
86  void write_save_index() ;
87 
88 public:
90 private:
91  config& data(const std::string& name) ;
92  config& data() ;
93 private:
94  bool loaded_;
96  std::map< std::string, time_t > modified_;
97 };
99 } //end of namespace savegame
100 
103 
104 #endif
void remove_old_auto_saves(const int autosavemax, const int infinite_auto_saves)
Remove autosaves that are no longer needed (according to the autosave policy in the preferences)...
Definition: save_index.cpp:291
void rebuild(const std::string &name)
Definition: save_index.cpp:51
void read_save_file(const std::string &name, config &cfg, std::string *error_log)
Read the complete config information out of a savefile.
Definition: save_index.cpp:250
std::vector< save_info > get_saves_list(const std::string *dir, const std::string *filter)
Get a list of available saves.
Definition: save_index.cpp:161
#define d
Definitions for the interface to Wesnoth Markup Language (WML).
const std::string dir
Definition: save_index.hpp:73
std::string format_time_summary() const
Definition: save_index.cpp:209
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
const config & summary() const
Definition: save_index.cpp:187
Class for writing a config out to a file in pieces.
void delete_game(const std::string &name)
Delete a savegame.
Definition: save_index.cpp:307
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
std::string format_time_local() const
Definition: save_index.cpp:191
save_index_class save_index_manager
Definition: save_index.cpp:146
void replace_underbar2space(std::string &name)
Definition: save_index.cpp:40
std::string name_
Definition: save_index.hpp:45
std::map< std::string, time_t > modified_
Definition: save_index.hpp:96
bool operator()(const save_info &a, const save_info &b) const
Definition: save_index.cpp:215
save_info(const std::string &name, const time_t &modified)
Definition: save_index.hpp:33
void set_modified(const std::string &name, const time_t &modified)
Definition: save_index.cpp:79
GLuint const GLchar * name
Definition: glew.h:1782
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glew.h:3448
Filename and modification date for a file list.
Definition: save_index.hpp:29
create_save_info(const std::string *d=nullptr)
Definition: save_index.cpp:320
const std::string & name() const
Definition: save_index.hpp:38
const time_t & modified() const
Definition: save_index.hpp:39
save_info operator()(const std::string &filename) const
Definition: save_index.cpp:325
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
A structure for comparing to save_info objects based on their modified time.
Definition: save_index.hpp:53
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void replace_space2underbar(std::string &name)
Definition: save_index.cpp:43