The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
persist_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Jody Northup
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "persist_context.hpp"
16 #include "persist_manager.hpp"
17 
19  : in_transaction_(false)
20  , contexts_()
21 {}
22 
25  for (context_map::iterator i = contexts_.begin(); i != contexts_.end(); ++i)
26  delete (i->second);
27 }
28 
30 {
32  std::string key(name.root_);
33  context_map::iterator i = contexts_.find(key);
34  if (i == contexts_.end()) {
35  contexts_[key] = new persist_file_context(key);
36  if (in_transaction_) contexts_[key]->start_transaction();
37  }
38  persist_context *ret = contexts_[key];
39  if (ret->get_node() != ns)
40  ret->set_node(name.descendants_);
41  return *ret;
42 }
43 
45  if (in_transaction_) return false;
46  bool result = true;
47  for (context_map::reference ctx : contexts_) {
48  result &= ctx.second->start_transaction();
49  }
50  in_transaction_ = true;
51  return result;
52 }
53 
55  if (!in_transaction_) return false;
56  bool result = true;
57  for (context_map::reference ctx : contexts_) {
58  result &= ctx.second->end_transaction();
59  }
61  return result;
62 }
63 
65  if (!in_transaction_) return false;
66  bool result = true;
67  for (context_map::reference ctx : contexts_) {
68  result &= ctx.second->cancel_transaction();
69  }
70  in_transaction_ = false;
71  return result;
72 }
73 
context_map contexts_
virtual ~persist_manager()
GLuint64EXT * result
Definition: glew.h:10727
persist_context & get_context(const std::string &ns)
size_t i
Definition: function.cpp:1057
GLuint const GLchar * name
Definition: glew.h:1782
void set_node(const std::string &)
config * get_node(config &cfg, name_space &ns, bool force=false)
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
GLsizei const GLcharARB ** string
Definition: glew.h:4503