The Battle for Wesnoth  1.19.7+dev
persist_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
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 }
27 
29 {
30  persist_context::name_space name(ns,true);
31  std::string key(name.root_);
32  context_map::iterator iter = contexts_.find(key);
33  if (iter == contexts_.end()) {
34  auto pfc = std::make_unique<persist_file_context>(key);
35  if (in_transaction_) pfc->start_transaction();
36  std::tie(iter, std::ignore) = contexts_.emplace(key, std::move(pfc));
37  }
38  auto& ret = iter->second;
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_
persist_context & get_context(const std::string &ns)
virtual ~persist_manager()
std::string::const_iterator iterator
Definition: tokenizer.hpp:25