The Battle for Wesnoth  1.15.1+dev
persist_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Jody Northup
3  Part of the Battle for Wesnoth Project https://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  }
60  in_transaction_ = !result;
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 }
context_map contexts_
virtual ~persist_manager()
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
std::size_t i
Definition: function.cpp:933
persist_context & get_context(const std::string &ns)
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:24