📄 conflict.cxx
字号:
//{{{ Banner //============================================================================//// conflict.cxx//// The CdlConflict 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/01/28// Version: 0.02////####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. It also brings// in <tcl.h>#include <cdlcore.hxx>//}}}//{{{ Statics // ----------------------------------------------------------------------------CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflictBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_UnresolvedBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_IllegalValueBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_EvalExceptionBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_RequiresBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_DataBody);//}}}//{{{ CdlConflict //{{{ Creation and destruction // ----------------------------------------------------------------------------// The basic conflicts. Conflicts are created in the context of a transaction.// If the transaction gets committed then they are transferred to a toplevel.// If the transaction gets cancelled then they just disappear.//// A conflict that is only part of a transaction may go away as that// transaction proceeds, in which case it can be deleted immediately.// A conflict that is already part of the toplevel cannot be// destroyed, instead it gets marked in the transaction object. Only// when the transaction is committed does the object get deleted.// In addition within the context of a transaction old conflicts// may hang around for a while.//CdlConflictBody::CdlConflictBody(CdlTransaction trans_arg, CdlNode node_arg, CdlProperty property_arg, bool structural_arg){ CYG_REPORT_FUNCNAME("CdlConflict:: constructor"); CYG_REPORT_FUNCARG4XV(this, trans_arg, node_arg, property_arg); CYG_PRECONDITION_CLASSC(trans_arg); CYG_PRECONDITION_CLASSC(node_arg); CYG_PRECONDITION_CLASSC(property_arg); node = node_arg; property = property_arg; transaction = trans_arg; structural = structural_arg; no_solution = false; // The vectors take care of themselves enabled = true; reason = ""; transaction->dirty = true; if (structural_arg) { transaction->new_structural_conflicts.push_back(this); } else { transaction->new_conflicts.push_back(this); } cdlconflictbody_cookie = CdlConflictBody_Magic; CYGDBG_MEMLEAK_CONSTRUCTOR(); CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------// The destructor can get invoked during a transaction commit, in the// case of a global conflict, or from inside clear() for a per-transaction// conflict. In all cases the calling code is responsible for removing// the conflict from any STL containers.CdlConflictBody::~CdlConflictBody(){ CYG_REPORT_FUNCNAME("CdlConflict:: destructor"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); cdlconflictbody_cookie = CdlConflictBody_Invalid; reason = ""; enabled = false; no_solution = false; solution.clear(); solution_references.clear(); structural = false; transaction = 0; property = 0; node = 0; CYGDBG_MEMLEAK_DESTRUCTOR(); CYG_REPORT_RETURN();}//}}}//{{{ Solution support // ----------------------------------------------------------------------------boolCdlConflictBody::has_known_solution() const{ CYG_REPORT_FUNCNAMETYPE("CdlConflict::has_solution", "result %d"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); bool result = (0 != solution.size()); CYG_REPORT_RETVAL(result); return result;}boolCdlConflictBody::has_no_solution() const{ CYG_REPORT_FUNCNAMETYPE("CdlConflict::has_no_solution", "result %d"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); bool result = no_solution; CYG_REPORT_RETVAL(result); return result;}const std::vector<std::pair<CdlValuable, CdlValue> >&CdlConflictBody::get_solution() const{ CYG_REPORT_FUNCNAME("CdlConflict::get_solution"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CYG_REPORT_RETURN(); return solution;}const std::set<CdlValuable>&CdlConflictBody::get_solution_references() const{ CYG_REPORT_FUNCNAME("CdlConflict::get_solution_references"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CYG_REPORT_RETURN(); return solution_references;}// ----------------------------------------------------------------------------// Try to resolve a conflict. If the conflict was created in a transaction,// use that transaction. More commonly the conflict will be global and// a new transaction will have to be created specially for it. Either// way the conflict may cease to exist.voidCdlConflictBody::resolve(){ CYG_REPORT_FUNCNAME("CdlConflict::resolve"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CYG_PRECONDITIONC(0 == transaction); if (this->resolution_implemented()) { CdlTransaction transact = CdlTransactionBody::make(this->get_node()->get_toplevel()); transact->resolve(this); transact->body(); delete transact; } CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------// A valuable has just been changed. If this value was relevant to the// current solution (or lack thereof) then an update is necessary.voidCdlConflictBody::update_solution_validity(CdlValuable valuable){ CYG_REPORT_FUNCNAME("CdlConflict::update_solution_validity"); CYG_REPORT_FUNCARG2XV(this, valuable); CYG_PRECONDITION_THISC(); if (solution_references.find(valuable) != solution_references.end()) { no_solution = false; solution.clear(); solution_references.clear(); } CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------// Default implementations of the inference engine do not do a lot...boolCdlConflictBody::inner_resolve(CdlTransaction trans_arg, int level){ CYG_REPORT_FUNCNAMETYPE("CdlConflict::inner_resolve", "result false"); CYG_REPORT_FUNCARG3XV(this, trans_arg, level); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_CLASSC(trans_arg); // Setting the no_solution flag while keeping a clear // solution_accessed vector means that the no_solution flag should // always remain set, and hence no further inference attempts will be made. no_solution = true; CYG_REPORT_RETURN(); return false;}boolCdlConflictBody::resolution_implemented() const{ CYG_REPORT_FUNCNAMETYPE("CdlConflict::resolution_implemented", "result %d"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CYG_REPORT_RETVAL(false); return false;}// ----------------------------------------------------------------------------// Clearing a solution. This is needed if the inference engine has// failed to find a complete solution, because in attempting this the// solution_references vector will have been filled in anyway. It may// have some other uses as well.voidCdlConflictBody::clear_solution(){ CYG_REPORT_FUNCNAME("CdlConflict::clear_solution"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); no_solution = false; solution.clear(); solution_references.clear(); CYG_REPORT_RETURN();}//}}}//{{{ Basics // ----------------------------------------------------------------------------CdlNodeCdlConflictBody::get_node() const{ CYG_REPORT_FUNCNAMETYPE("CdlConflict::get_node", "result %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlNode result = node; CYG_REPORT_RETVAL(result); return result;}CdlPropertyCdlConflictBody::get_property() const{ CYG_REPORT_FUNCNAMETYPE("CdlConflict::get_property", "result %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlProperty result = property; CYG_REPORT_RETVAL(result); return result;}boolCdlConflictBody::is_structural() const{ CYG_REPORT_FUNCNAMETYPE("CdlConflict::is_structural", "result %d"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); bool result = structural; CYG_REPORT_RETVAL(result); return result;}CdlTransactionCdlConflictBody::get_transaction() const{ CYG_REPORT_FUNCNAMETYPE("CdlConflict::get_transaction", "result %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlTransaction result = transaction; CYG_REPORT_RETVAL(result); return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -