📄 base.cxx
字号:
//{{{ Banner //============================================================================//// base.cxx//// Implementations of the various base classes////============================================================================//####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/02/18// Version: 0.02// Description: libcdl defines a hierarchy of base classes, used for// constructing higher-level entities such as options// and packages.////####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>// <cdl.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>//}}}//{{{ Statics // ----------------------------------------------------------------------------CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlNodeBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlContainerBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlLoadableBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlToplevelBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlUserVisibleBody);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlParentableBody);//}}}//{{{ CdlNodeBody //{{{ Construction // ----------------------------------------------------------------------------// The real constructor takes a string argument and should get invoked first.// Because of the way virtual inheritance is used it is also necessary to have// a default constructor, but that need not do anything. A newly constructed// object does not yet live in the hierarchy.CdlNodeBody::CdlNodeBody(std::string name_arg){ CYG_REPORT_FUNCNAME("CdlNode:: constructor"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITIONC("" != name_arg); name = name_arg; parent = 0; owner = 0; toplevel = 0; active = false; remove_node_container_position = -1; // The STL containers will take care of themselves. cdlnodebody_cookie = CdlNodeBody_Magic; CYGDBG_MEMLEAK_CONSTRUCTOR(); CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN();}CdlNodeBody::CdlNodeBody(){ CYG_PRECONDITION_THISC();}//}}}//{{{ Destructor // ----------------------------------------------------------------------------// By the time the destructor gets invoked the node should already// have been unbound and removed from the hierarchy.CdlNodeBody::~CdlNodeBody(){ CYG_REPORT_FUNCNAME("CdlNode:: destructor"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); // Make sure that the node is unbound: all references to and from // this node should have been destroyed already inside a // transaction. CYG_PRECONDITIONC(0 == referrers.size()); // Make sure that the node has been removed from the hierarchy CYG_PRECONDITIONC(0 == toplevel); CYG_PRECONDITIONC(0 == owner); CYG_PRECONDITIONC(0 == parent); // Destroy all properties associated with this object. std::vector<CdlProperty>::iterator prop_i; for (prop_i= properties.begin(); prop_i != properties.end(); prop_i++) { delete *prop_i; *prop_i = 0; } properties.clear(); cdlnodebody_cookie = CdlNodeBody_Invalid; name = ""; active = false; unsupported_savefile_strings.clear(); CYGDBG_MEMLEAK_DESTRUCTOR(); CYG_REPORT_RETURN();}//}}}//{{{ Trivial data access // ----------------------------------------------------------------------------std::stringCdlNodeBody::get_name() const{ CYG_REPORT_FUNCNAME("CdlNode::get_name"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CYG_REPORT_RETURN(); return name;}voidCdlNodeBody::set_name(std::string name_arg){ CYG_REPORT_FUNCNAME("CdlNode::set_name"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); name = name_arg; CYG_REPORT_RETURN();}CdlContainerCdlNodeBody::get_parent() const{ CYG_REPORT_FUNCNAMETYPE("CdlNode::get_parent", "parent %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlContainer result = parent; CYG_REPORT_RETVAL(result); return result;}CdlLoadableCdlNodeBody::get_owner() const{ CYG_REPORT_FUNCNAMETYPE("CdlNode::get_owner", "owner %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlLoadable result = owner; CYG_REPORT_RETVAL(result); return result;}CdlToplevelCdlNodeBody::get_toplevel() const{ CYG_REPORT_FUNCNAMETYPE("CdlNode::get_toplevel", "toplevel %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlToplevel result = toplevel; CYG_REPORT_RETVAL(result); return result;}std::stringCdlNodeBody::get_class_name() const{ CYG_REPORT_FUNCNAME("CdlNode::get_class_name"); CYG_PRECONDITION_THISC(); CYG_REPORT_RETURN(); return "node";}//}}}//{{{ The properties vector // ----------------------------------------------------------------------------// Trivial manipulation of the properties vector.const std::vector<CdlProperty>&CdlNodeBody::get_properties() const{ CYG_REPORT_FUNCNAME("CdlNode::get_properties"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CYG_REPORT_RETURN(); return properties;}CdlPropertyCdlNodeBody::get_property(std::string id) const{ CYG_REPORT_FUNCNAMETYPE("CdlNode::get_property", "result %p"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlProperty result = 0; std::vector<CdlProperty>::const_iterator prop_i; for (prop_i = properties.begin(); prop_i != properties.end(); prop_i++) { if ((*prop_i)->get_property_name() == id) { result = *prop_i; break; } } CYG_REPORT_RETVAL(result); return result;}voidCdlNodeBody::get_properties(std::string id, std::vector<CdlProperty>& result) const{ CYG_REPORT_FUNCNAME("CdlNode::get_properties"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); std::vector<CdlProperty>::const_iterator prop_i; for (prop_i = properties.begin(); prop_i != properties.end(); prop_i++) { if ((*prop_i)->get_property_name() == id) { result.push_back(*prop_i); } } CYG_REPORT_RETURN();}std::vector<CdlProperty>CdlNodeBody::get_properties(std::string id) const{ CYG_REPORT_FUNCNAME("CdlNode::get_properties"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); std::vector<CdlProperty> result; std::vector<CdlProperty>::const_iterator prop_i; for (prop_i = properties.begin(); prop_i != properties.end(); prop_i++) { if ((*prop_i)->get_property_name() == id) { result.push_back(*prop_i); } } CYG_REPORT_RETURN(); return result;}boolCdlNodeBody::has_property(std::string id) const{ CYG_REPORT_FUNCNAMETYPE("CdlNode::has_property", "result %d"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); bool result = false; std::vector<CdlProperty>::const_iterator prop_i; for (prop_i = properties.begin(); prop_i != properties.end(); prop_i++) { if ((*prop_i)->get_property_name() == id) { result = true; break; } } CYG_REPORT_RETVAL(result); return result;}intCdlNodeBody::count_properties(std::string id) const{ CYG_REPORT_FUNCNAMETYPE("CdlNode::count_properties", "result %d"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); int result = 0; std::vector<CdlProperty>::const_iterator prop_i; for (prop_i = properties.begin(); prop_i != properties.end(); prop_i++) { if ((*prop_i)->get_property_name() == id) { result++; } } CYG_REPORT_RETVAL(result); return result;}//}}}//{{{ Conflicts // ----------------------------------------------------------------------------// Provide access to the current set of conflicts. This operates on the global// state, more commonly these changes happen in the context of a transaction.voidCdlNodeBody::get_conflicts(std::vector<CdlConflict>& result) const{ CYG_REPORT_FUNCNAME("CdlNode::get_conflicts"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); const std::list<CdlConflict>& conflicts = toplevel->get_all_conflicts(); std::list<CdlConflict>::const_iterator conf_i; for (conf_i = conflicts.begin(); conf_i != conflicts.end(); conf_i++) { if ((*conf_i)->get_node() == this) { result.push_back(*conf_i); } } CYG_REPORT_RETURN();}voidCdlNodeBody::get_conflicts(bool (*fn)(CdlConflict), std::vector<CdlConflict>& result) const{ CYG_REPORT_FUNCNAME("CdlNode::get_conflicts"); CYG_REPORT_FUNCARG2XV(this, fn); CYG_PRECONDITION_THISC(); CYG_CHECK_FUNC_PTRC(fn); const std::list<CdlConflict>& conflicts = toplevel->get_all_conflicts(); std::list<CdlConflict>::const_iterator conf_i; for (conf_i = conflicts.begin(); conf_i != conflicts.end(); conf_i++) { if (((*conf_i)->get_node() == this) && ((*fn)(*conf_i))) { result.push_back(*conf_i); } } CYG_REPORT_RETURN();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -