1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 sc_attribute.cpp -- Attribute classes. 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 25 26 CHANGE LOG APPEARS AT THE END OF THE FILE 27 *****************************************************************************/ 28 29#include "sysc/kernel/sc_attribute.h" 30 31namespace sc_core { 32 33// ---------------------------------------------------------------------------- 34// CLASS : sc_attr_base 35// 36// Attribute base class. 37// ---------------------------------------------------------------------------- 38 39// constructors 40 41sc_attr_base::sc_attr_base( const std::string& name_ ) 42: m_name( name_ ) 43{} 44 45sc_attr_base::sc_attr_base( const sc_attr_base& a ) 46: m_name( a.m_name ) 47{} 48 49 50// destructor (does nothing) 51 52sc_attr_base::~sc_attr_base() 53{} 54 55 56// get the name 57const std::string& 58sc_attr_base::name() const 59{ 60 return m_name; 61} 62 63 64// ---------------------------------------------------------------------------- 65// CLASS : sc_attr_cltn 66// 67// Attribute collection class. Stores pointers to attributes. 68// Note: iterate over the collection by using iterators. 69// ---------------------------------------------------------------------------- 70 71// constructors 72 73sc_attr_cltn::sc_attr_cltn() : m_cltn() 74{} 75 76sc_attr_cltn::sc_attr_cltn( const sc_attr_cltn& a ) 77: m_cltn( a.m_cltn ) 78{} 79 80 81// destructor 82sc_attr_cltn::~sc_attr_cltn() 83{ 84 remove_all(); 85} 86 87 88// add attribute to the collection. 89// returns 'true' if the name of the attribute is unique, 90// returns 'false' otherwise (attribute is not added). 91 92bool 93sc_attr_cltn::push_back( sc_attr_base* attribute_ ) 94{ 95 if( attribute_ == 0 ) { 96 return false; 97 } 98 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 99 if( attribute_->name() == m_cltn[i]->name() ) { 100 return false; 101 } 102 } 103 m_cltn.push_back( attribute_ ); 104 return true; 105} 106 107 108// get attribute by name. 109// returns pointer to attribute, or 0 if name does not exist. 110 111sc_attr_base* 112sc_attr_cltn::operator [] ( const std::string& name_ ) 113{ 114 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 115 if( name_ == m_cltn[i]->name() ) { 116 return m_cltn[i]; 117 } 118 } 119 return 0; 120} 121 122const sc_attr_base* 123sc_attr_cltn::operator [] ( const std::string& name_ ) const 124{ 125 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 126 if( name_ == m_cltn[i]->name() ) { 127 return m_cltn[i]; 128 } 129 } 130 return 0; 131} 132 133 134// remove attribute by name. 135// returns pointer to attribute, or 0 if name does not exist. 136 137sc_attr_base* 138sc_attr_cltn::remove( const std::string& name_ ) 139{ 140 for( int i = m_cltn.size() - 1; i >= 0; -- i ) { 141 if( name_ == m_cltn[i]->name() ) { 142 sc_attr_base* attribute = m_cltn[i]; 143 std::swap( m_cltn[i], m_cltn.back() ); 144 m_cltn.pop_back(); 145 return attribute; 146 } 147 } 148 return 0; 149} 150 151 152// remove all attributes 153 154void 155sc_attr_cltn::remove_all() 156{ 157 m_cltn.clear(); 158} 159 160} // namespace sc_core 161 162// $Log: sc_attribute.cpp,v $ 163// Revision 1.7 2011/08/26 20:46:08 acg 164// Andy Goodrich: moved the modification log to the end of the file to 165// eliminate source line number skew when check-ins are done. 166// 167// Revision 1.6 2011/08/24 22:05:50 acg 168// Torsten Maehne: initialization changes to remove warnings. 169// 170// Revision 1.5 2011/02/18 20:27:14 acg 171// Andy Goodrich: Updated Copyrights. 172// 173// Revision 1.4 2011/02/13 21:47:37 acg 174// Andy Goodrich: update copyright notice. 175// 176// Revision 1.3 2010/07/22 20:02:33 acg 177// Andy Goodrich: bug fixes. 178// 179// Revision 1.2 2008/05/22 17:06:24 acg 180// Andy Goodrich: updated copyright notice to include 2008. 181// 182// Revision 1.1.1.1 2006/12/15 20:20:05 acg 183// SystemC 2.3 184// 185// Revision 1.4 2006/01/16 22:27:08 acg 186// Test of $Log comment. 187// 188// Revision 1.3 2006/01/13 18:44:29 acg 189// Added $Log to record CVS changes into the source. 190 191// Taf! 192