persist_manager.cpp

Go to the documentation of this file.
00001 /* $Id: persist_manager.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2010 - 2012 by Jody Northup
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #include "persist_context.hpp"
00017 #include "persist_manager.hpp"
00018 
00019 #include "foreach.hpp"
00020 
00021 persist_context &persist_manager::get_context(const std::string &ns)
00022 {
00023     persist_context::name_space name(ns,true);
00024     std::string key(name.root_);
00025     context_map::iterator i = contexts_.find(key);
00026     if (i == contexts_.end()) {
00027         contexts_[key] = new persist_file_context(key);
00028         if (in_transaction_) contexts_[key]->start_transaction();
00029     }
00030     persist_context *ret = contexts_[key];
00031     if (ret->get_node() != ns)
00032         ret->set_node(name.descendants_);
00033     return *ret;
00034 }
00035 
00036 bool persist_manager::start_transaction() {
00037     if (in_transaction_) return false;
00038     bool result = true;
00039     foreach (context_map::reference ctx, contexts_){
00040         result &= ctx.second->start_transaction();
00041     }
00042     in_transaction_ = true;
00043     return result;
00044 }
00045 
00046 bool persist_manager::end_transaction() {
00047     if (!in_transaction_) return false;
00048     bool result = true;
00049     foreach (context_map::reference ctx, contexts_){
00050         result &= ctx.second->end_transaction();
00051     }
00052     in_transaction_ = !result;
00053     return result;
00054 }
00055 
00056 bool persist_manager::cancel_transaction() {
00057     if (!in_transaction_) return false;
00058     bool result = true;
00059     foreach (context_map::reference ctx, contexts_){
00060         result &= ctx.second->cancel_transaction();
00061     }
00062     in_transaction_ = false;
00063     return result;
00064 }
00065 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:07 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs