The Battle for Wesnoth  1.17.0-dev
persist_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2021
3  by Jody Northup
4  Part of the Battle for Wesnoth Project https://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 #include "persist_context.hpp"
17 #include "persist_manager.hpp"
18 
20  : in_transaction_(false)
21  , contexts_()
22 {}
23 
26  for (context_map::iterator i = contexts_.begin(); i != contexts_.end(); ++i)
27  delete (i->second);
28 }
29 
31 {
32  persist_context::name_space name(ns,true);
33  std::string key(name.root_);
34  context_map::iterator i = contexts_.find(key);
35  if (i == contexts_.end()) {
36  contexts_[key] = new persist_file_context(key);
37  if (in_transaction_) contexts_[key]->start_transaction();
38  }
39  persist_context *ret = contexts_[key];
40  if (ret->get_node() != ns)
41  ret->set_node(name.descendants_);
42  return *ret;
43 }
44 
46  if (in_transaction_) return false;
47  bool result = true;
48  for (context_map::reference ctx : contexts_) {
49  result &= ctx.second->start_transaction();
50  }
51  in_transaction_ = true;
52  return result;
53 }
54 
56  if (!in_transaction_) return false;
57  bool result = true;
58  for (context_map::reference ctx : contexts_) {
59  result &= ctx.second->end_transaction();
60  }
61  in_transaction_ = !result;
62  return result;
63 }
64 
66  if (!in_transaction_) return false;
67  bool result = true;
68  for (context_map::reference ctx : contexts_) {
69  result &= ctx.second->cancel_transaction();
70  }
71  in_transaction_ = false;
72  return result;
73 }
context_map contexts_
virtual ~persist_manager()
std::size_t i
Definition: function.cpp:967
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:25