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
18
persist_manager::persist_manager
()
19
: in_transaction_(false)
20
, contexts_()
21
{}
22
23
persist_manager::~persist_manager
() {
24
cancel_transaction
();
25
for
(
context_map::iterator
i
=
contexts_
.begin();
i
!=
contexts_
.end(); ++
i
)
26
delete
(
i
->second);
27
}
28
29
persist_context
&
persist_manager::get_context
(
const
std::string
&ns)
30
{
31
persist_context::name_space
name
(ns,
true
);
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
44
bool
persist_manager::start_transaction
() {
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
54
bool
persist_manager::end_transaction
() {
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
64
bool
persist_manager::cancel_transaction
() {
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
persist_manager::contexts_
context_map contexts_
Definition:
persist_manager.hpp:28
persist_context::name_space
Definition:
persist_context.hpp:29
persist_manager::~persist_manager
virtual ~persist_manager()
Definition:
persist_manager.cpp:23
persist_manager::end_transaction
bool end_transaction()
Definition:
persist_manager.cpp:54
persist_manager::start_transaction
bool start_transaction()
Definition:
persist_manager.cpp:44
result
GLuint64EXT * result
Definition:
glew.h:10727
persist_context::name_space::root_
std::string root_
Definition:
persist_context.hpp:31
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:34
persist_context.hpp
persist_context
Definition:
persist_context.hpp:24
persist_manager::persist_manager
persist_manager()
Definition:
persist_manager.cpp:18
persist_file_context
Definition:
persist_context.hpp:163
persist_manager::get_context
persist_context & get_context(const std::string &ns)
Definition:
persist_manager.cpp:29
i
size_t i
Definition:
function.cpp:1057
name
GLuint const GLchar * name
Definition:
glew.h:1782
persist_context::set_node
void set_node(const std::string &)
Definition:
persist_context.cpp:246
persist_context::get_node
config * get_node(config &cfg, name_space &ns, bool force=false)
Definition:
persist_context.hpp:121
persist_manager::cancel_transaction
bool cancel_transaction()
Definition:
persist_manager.cpp:64
formula_tokenizer::iterator
std::string::const_iterator iterator
Definition:
tokenizer.hpp:21
string
GLsizei const GLcharARB ** string
Definition:
glew.h:4503
Generated by
1.8.8