The Battle for Wesnoth
1.17.12+dev
persist_manager.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2010 - 2022
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
19
persist_manager::persist_manager
()
20
: in_transaction_(false)
21
, contexts_()
22
{}
23
24
persist_manager::~persist_manager
() {
25
cancel_transaction
();
26
for
(
context_map::iterator
i
=
contexts_
.begin();
i
!=
contexts_
.end(); ++
i
)
27
delete
(
i
->second);
28
}
29
30
persist_context
&
persist_manager::get_context
(
const
std::string &ns)
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
45
bool
persist_manager::start_transaction
() {
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
55
bool
persist_manager::end_transaction
() {
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
65
bool
persist_manager::cancel_transaction
() {
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
}
persist_manager::contexts_
context_map contexts_
Definition:
persist_manager.hpp:28
persist_context::name_space
Definition:
persist_context.hpp:30
persist_manager::~persist_manager
virtual ~persist_manager()
Definition:
persist_manager.cpp:24
persist_manager::end_transaction
bool end_transaction()
Definition:
persist_manager.cpp:55
persist_manager::start_transaction
bool start_transaction()
Definition:
persist_manager.cpp:45
persist_context::name_space::root_
std::string root_
Definition:
persist_context.hpp:32
persist_manager::in_transaction_
bool in_transaction_
Definition:
persist_manager.hpp:27
persist_manager.hpp
persist_context::name_space::descendants_
std::string descendants_
Definition:
persist_context.hpp:35
persist_context.hpp
persist_context
Definition:
persist_context.hpp:25
persist_manager::persist_manager
persist_manager()
Definition:
persist_manager.cpp:19
i
std::size_t i
Definition:
function.cpp:968
persist_file_context
Definition:
persist_context.hpp:164
persist_manager::get_context
persist_context & get_context(const std::string &ns)
Definition:
persist_manager.cpp:30
persist_context::set_node
void set_node(const std::string &)
Definition:
persist_context.cpp:245
persist_context::get_node
config * get_node(config &cfg, name_space &ns, bool force=false)
Definition:
persist_context.hpp:122
persist_manager::cancel_transaction
bool cancel_transaction()
Definition:
persist_manager.cpp:65
wfl::tokenizer::iterator
std::string::const_iterator iterator
Definition:
tokenizer.hpp:25
Generated by
1.8.13