📄 transact.cxx
字号:
//{{{ Banner //============================================================================//// transaction.cxx//// Implementation of the CdlTransaction class////============================================================================//####COPYRIGHTBEGIN####// // ----------------------------------------------------------------------------// Copyright (C) 1999, 2000 Red Hat, Inc.//// This file is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------// //####COPYRIGHTEND####//============================================================================//#####DESCRIPTIONBEGIN####//// Author(s): bartv// Contact(s): bartv// Date: 1999/07/16// Version: 0.01////####DESCRIPTIONEND####//============================================================================//}}}//{{{ #include's // ----------------------------------------------------------------------------#include "cdlconfig.h"// Get the infrastructure types, assertions, tracing and similar// facilities.#include <cyg/infra/cyg_ass.h>#include <cyg/infra/cyg_trac.h>// <cdlcore.hxx> defines everything implemented in this module.// It implicitly supplies <string>, <vector> and <map> because// the class definitions rely on these headers.#include <cdlcore.hxx>//}}}//{{{ CdlTransactionCallback class // ----------------------------------------------------------------------------// The callback class is very straightforward. The hard work is done in// the transaction class.CdlTransactionCallback::CdlTransactionCallback(){ CYG_REPORT_FUNCNAME("CdlTransactionCallback:: constructor"); CYG_REPORT_FUNCARG1XV(this); // The vectors etc. will take care of themselves. cdltransactioncallback_cookie = CdlTransactionCallback_Magic; CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN();}CdlTransactionCallback::~CdlTransactionCallback(){ CYG_REPORT_FUNCNAME("CdlTransactionCallback:: destructor"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); cdltransactioncallback_cookie = CdlTransactionCallback_Invalid; value_changes.clear(); active_changes.clear(); legal_values_changes.clear(); value_source_changes.clear(); new_conflicts.clear(); new_structural_conflicts.clear(); nodes_with_resolved_conflicts.clear(); nodes_with_resolved_structural_conflicts.clear(); CYG_REPORT_RETURN();}voidCdlTransactionCallback::set_callback_fn(void (*fn)(const CdlTransactionCallback&)){ CYG_REPORT_FUNCNAME("CdlTransactionCallback::set_callback_fn"); CYG_REPORT_FUNCARG1XV(fn); CdlTransactionBody::set_callback_fn(fn); CYG_REPORT_RETURN();}void (*CdlTransactionCallback::get_callback_fn())(const CdlTransactionCallback&){ CYG_REPORT_FUNCNAMETYPE("CdlTransactionCallback::get_callback_fn", "result %p"); void (*result)(const CdlTransactionCallback&) = CdlTransactionBody::get_callback_fn(); CYG_REPORT_RETVAL(result); return result;}boolCdlTransactionCallback::check_this(cyg_assert_class_zeal zeal) const{ if (CdlTransactionCallback_Magic != cdltransactioncallback_cookie) { return false; } return true;}//}}}//{{{ CdlTransaction statics // ----------------------------------------------------------------------------void (*CdlTransactionBody::callback_fn)(const CdlTransactionCallback&) = 0;CdlInferenceCallback CdlTransactionBody::inference_callback = 0;bool CdlTransactionBody::inference_enabled = true;int CdlTransactionBody::inference_recursion_limit = 3;CdlValueSource CdlTransactionBody::inference_override = CdlValueSource_Inferred;CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlTransactionBody);//}}}//{{{ Transaction creation and destruction // ----------------------------------------------------------------------------CdlTransactionCdlTransactionBody::make(CdlToplevel toplevel){ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::make", "result %p"); CYG_REPORT_FUNCARG1XV(toplevel); CYG_PRECONDITION_CLASSC(toplevel); CYG_PRECONDITIONC(0 == toplevel->transaction); CdlTransaction result = new CdlTransactionBody(toplevel, 0, 0); toplevel->transaction = result; CYG_REPORT_RETVAL(result); return result;}CdlTransactionCdlTransactionBody::make(CdlConflict conflict){ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::make (sub-transaction)", "result %p"); CYG_REPORT_FUNCARG2XV(this, conflict); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_ZERO_OR_CLASSC(conflict); CdlTransaction result = new CdlTransactionBody(0, this, conflict); CYG_REPORT_RETVAL(result); return result;} CdlTransactionBody::CdlTransactionBody(CdlToplevel toplevel_arg, CdlTransaction parent_arg, CdlConflict conflict_arg){ CYG_REPORT_FUNCNAME("CdlTransaction:: constructor"); CYG_REPORT_FUNCARG4XV(this, toplevel_arg, parent_arg, conflict_arg); CYG_PRECONDITION_ZERO_OR_CLASSC(toplevel_arg); CYG_PRECONDITION_ZERO_OR_CLASSC(parent_arg); CYG_PRECONDITION_ZERO_OR_CLASSC(conflict_arg); CYG_PRECONDITIONC( ((0 == toplevel_arg) && (0 != parent_arg)) || ((0 == parent_arg) && (0 != toplevel_arg))); // The containers will take care of themselves, as will all_changes toplevel = toplevel_arg; parent = parent_arg; conflict = conflict_arg; dirty = false; cdltransactionbody_cookie = CdlTransactionBody_Magic; CYGDBG_MEMLEAK_CONSTRUCTOR(); CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------CdlTransactionBody::~CdlTransactionBody(){ CYG_REPORT_FUNCNAME("CdlTransaction:: destructor"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); // The transaction must have been either committed or cancelled. // This means that various of the STL containers should be empty CYG_ASSERTC(0 == commit_cancel_ops.size()); CYG_ASSERTC(0 == changes.size()); CYG_ASSERTC(0 == deleted_conflicts.size()); CYG_ASSERTC(0 == deleted_structural_conflicts.size()); CYG_ASSERTC(0 == new_conflicts.size()); CYG_ASSERTC(0 == new_structural_conflicts.size()); CYG_ASSERTC(0 == resolved_conflicts.size()); CYG_ASSERTC(0 == global_conflicts_with_solutions.size()); CYG_ASSERTC(0 == activated.size()); CYG_ASSERTC(0 == deactivated.size()); CYG_ASSERTC(0 == legal_values_changes.size()); CYG_ASSERTC(0 == value_changes.size()); CYG_ASSERTC(0 == active_changes.size()); // If this was a toplevel transaction, the toplevel knows // about the transaction. if (0 != toplevel) { CYG_ASSERTC(toplevel->transaction == this); toplevel->transaction = 0; } cdltransactionbody_cookie = CdlTransactionBody_Invalid; toplevel = 0; parent = 0; conflict = 0; dirty = false; CYGDBG_MEMLEAK_DESTRUCTOR(); CYG_REPORT_RETURN();}//}}}//{{{ check_this() // ----------------------------------------------------------------------------boolCdlTransactionBody::check_this(cyg_assert_class_zeal zeal) const{ if (CdlTransactionBody_Magic != cdltransactionbody_cookie) { return false; } CYGDBG_MEMLEAK_CHECKTHIS(); //zeal = cyg_extreme; switch(zeal) { case cyg_system_test: case cyg_extreme : { std::map<CdlValuable,CdlValue>::const_iterator map_i; for (map_i = changes.begin(); map_i != changes.end(); map_i++) { if (!map_i->first->check_this(cyg_quick) || !map_i->second.check_this(cyg_quick)) { return false; } } std::list<CdlConflict>::const_iterator conf_i; for (conf_i = new_conflicts.begin(); conf_i != new_conflicts.end(); conf_i++) { if (!(*conf_i)->check_this(cyg_quick)) { return false; } } for (conf_i = new_structural_conflicts.begin(); conf_i != new_structural_conflicts.end(); conf_i++) { if (!(*conf_i)->check_this(cyg_quick)) { return false; } } std::vector<CdlConflict>::const_iterator conf_i2; for (conf_i2 = deleted_conflicts.begin(); conf_i2 != deleted_conflicts.end(); conf_i2++) { if (!(*conf_i2)->check_this(cyg_quick)) { return false; } } for (conf_i2 = resolved_conflicts.begin(); conf_i2 != resolved_conflicts.end(); conf_i2++) { if (!(*conf_i2)->check_this(cyg_quick)) { return false; } } for (conf_i2 = deleted_structural_conflicts.begin(); conf_i2 != deleted_structural_conflicts.end(); conf_i2++) { if (!(*conf_i2)->check_this(cyg_quick)) { return false; } } for (conf_i = global_conflicts_with_solutions.begin(); conf_i != global_conflicts_with_solutions.end(); conf_i++) { if (!(*conf_i)->check_this(cyg_quick)) { return false; } if (0 != (*conf_i)->transaction) { return false; } } // Nodes cannot have been both activated and deactivated in one transaction std::set<CdlNode>::const_iterator node_i; for (node_i = activated.begin(); node_i != activated.end(); node_i++) { if (!(*node_i)->check_this(cyg_quick)) { return false; } if (deactivated.end() != deactivated.find(*node_i)) { return false; } } for (node_i = deactivated.begin(); node_i != deactivated.end(); node_i++) { if (!(*node_i)->check_this(cyg_quick)) { return false; } if (activated.end() != activated.find(*node_i)) { return false; } } std::set<CdlValuable>::const_iterator val_i; for (val_i = legal_values_changes.begin(); val_i != legal_values_changes.end(); val_i++) { if (!(*val_i)->check_this(cyg_quick)) { return false; } } std::deque<CdlValuable>::const_iterator val_i2; for (val_i2 = value_changes.begin(); val_i2 != value_changes.end(); val_i2++) { if (!(*val_i2)->check_this(cyg_quick)) { return false; } } std::deque<CdlNode>::const_iterator active_i; for (active_i = active_changes.begin(); active_i != active_changes.end(); active_i++) { if (!(*active_i)->check_this(cyg_quick)) { return false; } } } case cyg_thorough: if ((0 != toplevel) && !toplevel->check_this(cyg_quick)) { return false; } if ((0 != parent) && !parent->check_this(cyg_quick)) { return false; } if ((0 != conflict) && !conflict->check_this(cyg_quick)) { return false; } case cyg_quick: case cyg_trivial : if ((0 == toplevel) && (0 == parent)) { return false; } if (this == parent) { return false; } case cyg_none : break; } return true;}//}}}//{{{ Misc // ----------------------------------------------------------------------------CdlToplevelCdlTransactionBody::get_toplevel() const{ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_toplevel", "result %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlToplevel result = toplevel; CYG_REPORT_RETVAL(result); return result;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -