sc_attribute.h revision 12027
13170Sstever@eecs.umich.edu/***************************************************************************** 25254Sksewell@umich.edu 35254Sksewell@umich.edu Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 43170Sstever@eecs.umich.edu more contributor license agreements. See the NOTICE file distributed 55254Sksewell@umich.edu with this work for additional information regarding copyright ownership. 65254Sksewell@umich.edu Accellera licenses this file to you under the Apache License, Version 2.0 75254Sksewell@umich.edu (the "License"); you may not use this file except in compliance with the 85254Sksewell@umich.edu License. You may obtain a copy of the License at 95254Sksewell@umich.edu 105254Sksewell@umich.edu http://www.apache.org/licenses/LICENSE-2.0 115254Sksewell@umich.edu 125254Sksewell@umich.edu Unless required by applicable law or agreed to in writing, software 135254Sksewell@umich.edu distributed under the License is distributed on an "AS IS" BASIS, 145254Sksewell@umich.edu WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 153170Sstever@eecs.umich.edu implied. See the License for the specific language governing 165254Sksewell@umich.edu permissions and limitations under the License. 175254Sksewell@umich.edu 185254Sksewell@umich.edu *****************************************************************************/ 195254Sksewell@umich.edu 205254Sksewell@umich.edu/***************************************************************************** 215254Sksewell@umich.edu 225254Sksewell@umich.edu sc_attribute.h -- Attribute classes. 235254Sksewell@umich.edu 245254Sksewell@umich.edu Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 255254Sksewell@umich.edu 265254Sksewell@umich.edu CHANGE LOG AT THE END OF THE FILE 273170Sstever@eecs.umich.edu *****************************************************************************/ 285254Sksewell@umich.edu 293170Sstever@eecs.umich.edu 303170Sstever@eecs.umich.edu#ifndef SC_ATTRIBUTE_H 313170Sstever@eecs.umich.edu#define SC_ATTRIBUTE_H 323170Sstever@eecs.umich.edu 333170Sstever@eecs.umich.edu#include <string> 343170Sstever@eecs.umich.edu#include <vector> 353170Sstever@eecs.umich.edu 363170Sstever@eecs.umich.edunamespace sc_core { 373170Sstever@eecs.umich.edu 383170Sstever@eecs.umich.edu// ---------------------------------------------------------------------------- 393170Sstever@eecs.umich.edu// CLASS : sc_attr_base 404661Sksewell@umich.edu// 414661Sksewell@umich.edu// Attribute base class. 424661Sksewell@umich.edu// ---------------------------------------------------------------------------- 433170Sstever@eecs.umich.edu 443170Sstever@eecs.umich.educlass sc_attr_base 453170Sstever@eecs.umich.edu{ 463170Sstever@eecs.umich.edupublic: 473170Sstever@eecs.umich.edu 483170Sstever@eecs.umich.edu // constructors 493170Sstever@eecs.umich.edu sc_attr_base( const std::string& name_ ); 503170Sstever@eecs.umich.edu sc_attr_base( const sc_attr_base& ); 513170Sstever@eecs.umich.edu 524661Sksewell@umich.edu // destructor (does nothing) 535222Sksewell@umich.edu virtual ~sc_attr_base(); 545222Sksewell@umich.edu 554661Sksewell@umich.edu // get the name 564661Sksewell@umich.edu const std::string& name() const; 573170Sstever@eecs.umich.edu 583170Sstever@eecs.umich.eduprivate: 593170Sstever@eecs.umich.edu 603170Sstever@eecs.umich.edu std::string m_name; 613170Sstever@eecs.umich.edu 623170Sstever@eecs.umich.eduprivate: 633170Sstever@eecs.umich.edu 644661Sksewell@umich.edu // disabled 654661Sksewell@umich.edu sc_attr_base(); 664661Sksewell@umich.edu sc_attr_base& operator = ( const sc_attr_base& ); 674661Sksewell@umich.edu}; 684661Sksewell@umich.edu 694661Sksewell@umich.edu 704661Sksewell@umich.edu// ---------------------------------------------------------------------------- 714661Sksewell@umich.edu// CLASS : sc_attr_cltn 725222Sksewell@umich.edu// 735222Sksewell@umich.edu// Attribute collection class. Stores pointers to attributes. 744661Sksewell@umich.edu// Note: iterate over the collection by using iterators. 754661Sksewell@umich.edu// ---------------------------------------------------------------------------- 764661Sksewell@umich.edu 774661Sksewell@umich.educlass sc_attr_cltn 784661Sksewell@umich.edu{ 795222Sksewell@umich.edupublic: 804661Sksewell@umich.edu 814661Sksewell@umich.edu // typedefs 824661Sksewell@umich.edu typedef sc_attr_base* elem_type; 834661Sksewell@umich.edu typedef std::vector<elem_type>::iterator iterator; 844661Sksewell@umich.edu typedef std::vector<elem_type>::const_iterator const_iterator; 854661Sksewell@umich.edu 864661Sksewell@umich.edu // constructors 874661Sksewell@umich.edu sc_attr_cltn(); 884661Sksewell@umich.edu sc_attr_cltn( const sc_attr_cltn& ); 894661Sksewell@umich.edu 904661Sksewell@umich.edu // destructor 914661Sksewell@umich.edu ~sc_attr_cltn(); 924661Sksewell@umich.edu 934661Sksewell@umich.edu // add attribute to the collection. 944661Sksewell@umich.edu // returns 'true' if the name of the attribute is unique, 954661Sksewell@umich.edu // returns 'false' otherwise (attribute is not added). 964661Sksewell@umich.edu bool push_back( sc_attr_base* ); 974661Sksewell@umich.edu 984661Sksewell@umich.edu // get attribute by name. 994661Sksewell@umich.edu // returns pointer to attribute, or 0 if name does not exist. 1004661Sksewell@umich.edu sc_attr_base* operator [] ( const std::string& name_ ); 1014661Sksewell@umich.edu const sc_attr_base* operator [] ( const std::string& name_ ) const; 1024661Sksewell@umich.edu 1034661Sksewell@umich.edu // remove attribute by name. 1044661Sksewell@umich.edu // returns pointer to attribute, or 0 if name does not exist. 1054661Sksewell@umich.edu sc_attr_base* remove( const std::string& name_ ); 1064661Sksewell@umich.edu 1074661Sksewell@umich.edu // remove all attributes 1084661Sksewell@umich.edu void remove_all(); 1094661Sksewell@umich.edu 1103170Sstever@eecs.umich.edu // get the size of the collection 1113170Sstever@eecs.umich.edu int size() const 1123170Sstever@eecs.umich.edu { return m_cltn.size(); } 1133170Sstever@eecs.umich.edu 1143170Sstever@eecs.umich.edu // get the begin iterator 1153170Sstever@eecs.umich.edu iterator begin() 1163170Sstever@eecs.umich.edu { return m_cltn.begin(); } 117 const_iterator begin() const 118 { return m_cltn.begin(); } 119 120 // get the end iterator 121 iterator end() 122 { return m_cltn.end(); } 123 const_iterator end() const 124 { return m_cltn.end(); } 125 126private: 127 std::vector<sc_attr_base*> m_cltn; 128 129private: 130 131 // disabled 132 sc_attr_cltn& operator = ( const sc_attr_cltn& ); 133}; 134 135 136// ---------------------------------------------------------------------------- 137// CLASS : sc_attribute<T> 138// 139// Attribute class. 140// Note: T must have a default constructor and copy constructor. 141// ---------------------------------------------------------------------------- 142 143template <class T> 144class sc_attribute 145: public sc_attr_base 146{ 147public: 148 149 // constructors 150 151 sc_attribute( const std::string& name_ ) 152 : sc_attr_base( name_ ), value() 153 {} 154 155 sc_attribute( const std::string& name_, const T& value_ ) 156 : sc_attr_base( name_ ), value( value_ ) 157 {} 158 159 sc_attribute( const sc_attribute<T>& a ) 160 : sc_attr_base( a.name() ), value( a.value ) 161 {} 162 163 164 // destructor (does nothing) 165 166 virtual ~sc_attribute() 167 {} 168 169public: 170 171 // public data member; for easy access 172 T value; 173 174private: 175 176 // disabled 177 sc_attribute(); 178 sc_attribute<T>& operator = ( const sc_attribute<T>& ); 179}; 180 181} // namespace sc_core 182 183// $Log: sc_attribute.h,v $ 184// Revision 1.6 2011/08/26 20:46:08 acg 185// Andy Goodrich: moved the modification log to the end of the file to 186// eliminate source line number skew when check-ins are done. 187// 188// Revision 1.5 2011/02/18 20:27:14 acg 189// Andy Goodrich: Updated Copyrights. 190// 191// Revision 1.4 2011/02/13 21:47:37 acg 192// Andy Goodrich: update copyright notice. 193// 194// Revision 1.3 2010/07/22 20:02:33 acg 195// Andy Goodrich: bug fixes. 196// 197// Revision 1.2 2008/05/22 17:06:24 acg 198// Andy Goodrich: updated copyright notice to include 2008. 199// 200// Revision 1.1.1.1 2006/12/15 20:20:05 acg 201// SystemC 2.3 202// 203// Revision 1.3 2006/01/13 18:44:29 acg 204// Added $Log to record CVS changes into the source. 205// 206 207#endif 208 209// Taf! 210