📄 transact.cxx
字号:
}CdlTransactionCdlTransactionBody::get_parent() const{ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_parent", "result %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlTransaction result = parent; CYG_REPORT_RETVAL(result); return result;}CdlConflictCdlTransactionBody::get_conflict() const{ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_conflict", "result %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlConflict result = conflict; CYG_REPORT_RETVAL(result); return result;}// ----------------------------------------------------------------------------void (*CdlTransactionBody::get_callback_fn())(const CdlTransactionCallback&){ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_callback_fn", "result %p"); void (*result)(const CdlTransactionCallback&) = callback_fn; CYG_REPORT_RETVAL(result); return result;}voidCdlTransactionBody::set_callback_fn(void (*fn)(const CdlTransactionCallback&)){ CYG_REPORT_FUNCNAME("CdlTransaction::set_callback_fn"); CYG_REPORT_FUNCARG1XV(fn); callback_fn = fn; CYG_REPORT_RETURN();}CdlInferenceCallbackCdlTransactionBody::get_inference_callback_fn(){ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_inference_callback_fn", "result %p"); CdlInferenceCallback result = inference_callback; CYG_REPORT_RETVAL(result); return result;}voidCdlTransactionBody::set_inference_callback_fn(CdlInferenceCallback fn){ CYG_REPORT_FUNCNAME("CdlTransaction::set_inference_callback"); CYG_REPORT_FUNCARG1XV(fn); inference_callback = fn; CYG_REPORT_RETURN();}voidCdlTransactionBody::enable_automatic_inference(){ CYG_REPORT_FUNCNAME("CdlTransaction::enable_automatic_inference"); inference_enabled = true; CYG_REPORT_RETURN();}voidCdlTransactionBody::disable_automatic_inference(){ CYG_REPORT_FUNCNAME("CdlTransaction::disable_automatic_inference"); inference_enabled = false; CYG_REPORT_RETURN();}boolCdlTransactionBody::is_automatic_inference_enabled(){ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::is_automatic_inference_enabled", "result %d"); bool result = inference_enabled; CYG_REPORT_RETVAL(result); return result;}voidCdlTransactionBody::set_inference_recursion_limit(int limit){ CYG_REPORT_FUNCNAME("CdlTransaction::set_inference_recursion_limit"); CYG_REPORT_FUNCARG1XV(limit); CYG_PRECONDITIONC(0 < limit); CYG_PRECONDITIONC(limit < 16); // arbitrary number inference_recursion_limit = limit; CYG_REPORT_RETURN();}intCdlTransactionBody::get_inference_recursion_limit(){ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_inference_recursion_limit", "result %d"); int result = inference_recursion_limit; CYG_REPORT_RETVAL(result); return result;}voidCdlTransactionBody::set_inference_override(CdlValueSource source){ CYG_REPORT_FUNCNAME("CdlTransaction::set_inference_override"); CYG_REPORT_FUNCARG1XV(source); CYG_PRECONDITIONC((CdlValueSource_Invalid == source) || Cdl::is_valid_value_source(source)); inference_override = source; CYG_REPORT_RETURN();}CdlValueSourceCdlTransactionBody::get_inference_override(){ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_inference_override", "result %d"); CdlValueSource result = inference_override; CYG_REPORT_RETVAL((int) result); return result;}//}}}//{{{ Value access and updates // ----------------------------------------------------------------------------const CdlValue&CdlTransactionBody::get_whole_value(CdlConstValuable valuable_arg) const{ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_whole_value", "result %p"); CYG_REPORT_FUNCARG2XV(this, valuable_arg); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_CLASSC(valuable_arg); // Unfortunately I need a valuable rather than a const-valuable when // accessing the STL containers. CdlValuable valuable = const_cast<CdlValuable>(valuable_arg); // If we are trying to find a solution, keep track of all valuables // that were accessed. const CdlValue* result = 0; if (0 != conflict) { conflict->solution_references.insert(valuable); } std::map<CdlValuable,CdlValue>::const_iterator val_i; val_i = changes.find(valuable); if (val_i != changes.end()) { result = &(val_i->second); } else if (0 != parent) { result = &(parent->get_whole_value(valuable)); } else { result = &(valuable->get_whole_value()); } CYG_REPORT_RETVAL(result); return *result;}voidCdlTransactionBody::set_whole_value(CdlValuable valuable, const CdlValue& old_value, const CdlValue& new_value){ CYG_REPORT_FUNCNAME("CdlTransaction::set_whole_value"); CYG_REPORT_FUNCARG3XV(this, valuable, &new_value); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_CLASSC(valuable); CYG_PRECONDITION_CLASSOC(old_value); CYG_PRECONDITION_CLASSOC(new_value); CYG_PRECONDITIONC(&old_value != &new_value); CdlValueFlavor flavor = old_value.get_flavor(); CYG_ASSERTC(flavor == new_value.get_flavor()); CYG_ASSERTC(CdlValueFlavor_None != flavor); bool value_changed = false; bool bool_changed = false; if ((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)) { if (old_value.is_enabled() != new_value.is_enabled()) { value_changed = true; bool_changed = true; } } if (!value_changed && ((CdlValueFlavor_BoolData == flavor) || (CdlValueFlavor_Data == flavor))) { if (old_value.get_simple_value() != new_value.get_simple_value()) { value_changed = true; } } if (value_changed) { std::deque<CdlValuable>::const_iterator change_i; change_i = std::find(value_changes.begin(), value_changes.end(), valuable); if (change_i == value_changes.end()) { value_changes.push_back(valuable); } } // Actually do the update. This may modify old_value, so has to be // left to the end. changes[valuable] = new_value; // If there was a change to the boolean part of the value and the valuable // implements an interface, the interface value needs to be recalculated. if (bool_changed && valuable->has_property(CdlPropertyId_Implements)) { std::vector<CdlInterface> interfaces; std::vector<CdlInterface>::const_iterator interface_i; valuable->get_implemented_interfaces(interfaces); for (interface_i = interfaces.begin(); interface_i != interfaces.end(); interface_i++) { (*interface_i)->recalculate(this); } } CYG_REPORT_RETURN();}const std::map<CdlValuable, CdlValue>&CdlTransactionBody::get_changes() const{ CYG_REPORT_FUNCNAME("CdlTransaction::get_changes"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CYG_REPORT_RETURN(); return changes;}//}}}//{{{ Active access and updates // ----------------------------------------------------------------------------// Nodes can become active or inactive during transactions, and this affects// propagation and expression evaluationboolCdlTransactionBody::is_active(CdlNode node) const{ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::is_active", "result %d"); CYG_REPORT_FUNCARG2XV(this, node); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_CLASSC(node); bool result = false; if (activated.end() != activated.find(node)) { result = true; } else if (deactivated.end() != deactivated.find(node)) { result = false; } else if (0 != parent) { result = parent->is_active(node); } else { result = node->is_active(); } CYG_REPORT_RETVAL(result); return result;}voidCdlTransactionBody::set_active(CdlNode node, bool state){ CYG_REPORT_FUNCNAME("CdlTransaction::set_active"); CYG_REPORT_FUNCARG3XV(this, node, state); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_CLASSC(node); if (state) { activated.insert(node); std::set<CdlNode>::iterator node_i = deactivated.find(node); if (deactivated.end() != node_i) { deactivated.erase(node_i); } } else { deactivated.insert(node); std::set<CdlNode>::iterator node_i = activated.find(node); if (activated.end() != node_i) { activated.erase(node_i); } } active_changes.push_back(node); CdlValuable valuable = dynamic_cast<CdlValuable>(node); if ((0 != valuable) && valuable->has_property(CdlPropertyId_Implements)) { std::vector<CdlInterface> interfaces; std::vector<CdlInterface>::const_iterator interface_i; valuable->get_implemented_interfaces(interfaces); for (interface_i = interfaces.begin(); interface_i != interfaces.end(); interface_i++) { (*interface_i)->recalculate(this); } } CYG_REPORT_RETURN();}//}}}//{{{ Conflict access and updates //{{{ get_conflict() etc. // ----------------------------------------------------------------------------boolCdlTransactionBody::has_conflict(CdlNode node, bool (*pFn)(CdlConflict)){ CYG_REPORT_FUNCNAMETYPE("CdlTransaction::has_conflict", "result %d"); CYG_REPORT_FUNCARG3XV(this, node, pFn); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_CLASSC(node); // Because it is necessary to check whether or not any given // conflict has been cleared in the current transaction or any // parent transaction, recursion into the parent is not // appropriate. bool result = false; std::list<CdlConflict>::const_iterator conf_i; CdlTransaction current_transaction = this; CdlToplevel toplevel = this->toplevel; do { CYG_LOOP_INVARIANT_CLASSC(current_transaction); for (conf_i = current_transaction->new_conflicts.begin(); conf_i != current_transaction->new_conflicts.end(); conf_i++) { if ((node == (*conf_i)->get_node()) && !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) { result = true; break; } } toplevel = current_transaction->toplevel; current_transaction = current_transaction->parent; } while (!result && (0 != current_transaction)); if (!result) { CYG_ASSERT_CLASSC(toplevel); for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); conf_i++) { if ((node == (*conf_i)->get_node()) && !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) { result = true; break; } } } CYG_REPORT_RETVAL(result); return result;}CdlConflictCdlTransactionBody::get_conflict(CdlNode node, bool (*pFn)(CdlConflict)){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -