00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2006 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.4 (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 // $Log: sc_attribute.cpp,v $ 00037 // Revision 1.1.1.1 2006/12/15 20:31:36 acg 00038 // SystemC 2.2 00039 // 00040 // Revision 1.4 2006/01/16 22:27:08 acg 00041 // Test of $Log comment. 00042 // 00043 // Revision 1.3 2006/01/13 18:44:29 acg 00044 // Added $Log to record CVS changes into the source. 00045 00046 00047 #include "sysc/kernel/sc_attribute.h" 00048 00049 namespace sc_core { 00050 00051 // ---------------------------------------------------------------------------- 00052 // CLASS : sc_attr_base 00053 // 00054 // Attribute base class. 00055 // ---------------------------------------------------------------------------- 00056 00057 // constructors 00058 00059 sc_attr_base::sc_attr_base( const std::string& name_ ) 00060 : m_name( name_ ) 00061 {} 00062 00063 sc_attr_base::sc_attr_base( const sc_attr_base& a ) 00064 : m_name( a.m_name ) 00065 {} 00066 00067 00068 // destructor (does nothing) 00069 00070 sc_attr_base::~sc_attr_base() 00071 {} 00072 00073 00074 // get the name 00075 const std::string& 00076 sc_attr_base::name() const 00077 { 00078 return m_name; 00079 } 00080 00081 00082 // ---------------------------------------------------------------------------- 00083 // CLASS : sc_attr_cltn 00084 // 00085 // Attribute collection class. Stores pointers to attributes. 00086 // Note: iterate over the collection by using iterators. 00087 // ---------------------------------------------------------------------------- 00088 00089 // constructors 00090 00091 sc_attr_cltn::sc_attr_cltn() 00092 {} 00093 00094 sc_attr_cltn::sc_attr_cltn( const sc_attr_cltn& a ) 00095 : m_cltn( a.m_cltn ) 00096 {} 00097 00098 00099 // destructor 00100 sc_attr_cltn::~sc_attr_cltn() 00101 { 00102 remove_all(); 00103 } 00104 00105 00106 // add attribute to the collection. 00107 // returns 'true' if the name of the attribute is unique, 00108 // returns 'false' otherwise (attribute is not added). 00109 00110 bool 00111 sc_attr_cltn::push_back( sc_attr_base* attribute_ ) 00112 { 00113 if( attribute_ == 0 ) { 00114 return false; 00115 } 00116 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 00117 if( attribute_->name() == m_cltn[i]->name() ) { 00118 return false; 00119 } 00120 } 00121 m_cltn.push_back( attribute_ ); 00122 return true; 00123 } 00124 00125 00126 // get attribute by name. 00127 // returns pointer to attribute, or 0 if name does not exist. 00128 00129 sc_attr_base* 00130 sc_attr_cltn::operator [] ( const std::string& name_ ) 00131 { 00132 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 00133 if( name_ == m_cltn[i]->name() ) { 00134 return m_cltn[i]; 00135 } 00136 } 00137 return 0; 00138 } 00139 00140 const sc_attr_base* 00141 sc_attr_cltn::operator [] ( const std::string& name_ ) const 00142 { 00143 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 00144 if( name_ == m_cltn[i]->name() ) { 00145 return m_cltn[i]; 00146 } 00147 } 00148 return 0; 00149 } 00150 00151 00152 // remove attribute by name. 00153 // returns pointer to attribute, or 0 if name does not exist. 00154 00155 sc_attr_base* 00156 sc_attr_cltn::remove( const std::string& name_ ) 00157 { 00158 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 00159 if( name_ == m_cltn[i]->name() ) { 00160 sc_attr_base* attribute = m_cltn[i]; 00161 m_cltn[i] = m_cltn[m_cltn.size() - 1]; 00162 m_cltn.decr_count(); 00163 return attribute; 00164 } 00165 } 00166 return 0; 00167 } 00168 00169 00170 // remove all attributes 00171 00172 void 00173 sc_attr_cltn::remove_all() 00174 { 00175 m_cltn.erase_all(); 00176 } 00177 00178 } // namespace sc_core 00179 // Taf!