00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2004 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License Version 2.3 (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.systemc.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_attribute.cpp -- Attribute classes. 00021 00022 Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 00023 00024 *****************************************************************************/ 00025 00026 /***************************************************************************** 00027 00028 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00029 changes you are making here. 00030 00031 Name, Affiliation, Date: 00032 Description of Modification: 00033 00034 *****************************************************************************/ 00035 00036 #include "systemc/kernel/sc_attribute.h" 00037 00038 00039 // ---------------------------------------------------------------------------- 00040 // CLASS : sc_attr_base 00041 // 00042 // Attribute base class. 00043 // ---------------------------------------------------------------------------- 00044 00045 // constructors 00046 00047 sc_attr_base::sc_attr_base( const sc_string& name_ ) 00048 : m_name( name_ ) 00049 {} 00050 00051 sc_attr_base::sc_attr_base( const sc_attr_base& a ) 00052 : m_name( a.m_name ) 00053 {} 00054 00055 00056 // destructor (does nothing) 00057 00058 sc_attr_base::~sc_attr_base() 00059 {} 00060 00061 00062 // get the name 00063 const sc_string& 00064 sc_attr_base::name() const 00065 { 00066 return m_name; 00067 } 00068 00069 00070 // ---------------------------------------------------------------------------- 00071 // CLASS : sc_attr_cltn 00072 // 00073 // Attribute collection class. Stores pointers to attributes. 00074 // Note: iterate over the collection by using iterators. 00075 // ---------------------------------------------------------------------------- 00076 00077 // constructors 00078 00079 sc_attr_cltn::sc_attr_cltn() 00080 {} 00081 00082 sc_attr_cltn::sc_attr_cltn( const sc_attr_cltn& a ) 00083 : m_cltn( a.m_cltn ) 00084 {} 00085 00086 00087 // destructor 00088 sc_attr_cltn::~sc_attr_cltn() 00089 { 00090 remove_all(); 00091 } 00092 00093 00094 // add attribute to the collection. 00095 // returns 'true' if the name of the attribute is unique, 00096 // returns 'false' otherwise (attribute is not added). 00097 00098 bool 00099 sc_attr_cltn::push_back( sc_attr_base* attribute_ ) 00100 { 00101 if( attribute_ == 0 ) { 00102 return false; 00103 } 00104 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 00105 if( attribute_->name() == m_cltn[i]->name() ) { 00106 return false; 00107 } 00108 } 00109 m_cltn.push_back( attribute_ ); 00110 return true; 00111 } 00112 00113 00114 // get attribute by name. 00115 // returns pointer to attribute, or 0 if name does not exist. 00116 00117 sc_attr_base* 00118 sc_attr_cltn::operator [] ( const sc_string& name_ ) 00119 { 00120 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 00121 if( name_ == m_cltn[i]->name() ) { 00122 return m_cltn[i]; 00123 } 00124 } 00125 return 0; 00126 } 00127 00128 const sc_attr_base* 00129 sc_attr_cltn::operator [] ( const sc_string& name_ ) const 00130 { 00131 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 00132 if( name_ == m_cltn[i]->name() ) { 00133 return m_cltn[i]; 00134 } 00135 } 00136 return 0; 00137 } 00138 00139 00140 // remove attribute by name. 00141 // returns pointer to attribute, or 0 if name does not exist. 00142 00143 sc_attr_base* 00144 sc_attr_cltn::remove( const sc_string& name_ ) 00145 { 00146 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 00147 if( name_ == m_cltn[i]->name() ) { 00148 sc_attr_base* attribute = m_cltn[i]; 00149 m_cltn[i] = m_cltn[m_cltn.size() - 1]; 00150 m_cltn.decr_count(); 00151 return attribute; 00152 } 00153 } 00154 return 0; 00155 } 00156 00157 00158 // remove all attributes 00159 00160 void 00161 sc_attr_cltn::remove_all() 00162 { 00163 m_cltn.erase_all(); 00164 } 00165 00166 00167 // Taf!
1.2.18