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.h -- 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 #ifndef SC_ATTRIBUTE_H 00037 #define SC_ATTRIBUTE_H 00038 00039 #include "systemc/utils/sc_string.h" 00040 #include "systemc/utils/sc_vector.h" 00041 00042 00043 // ---------------------------------------------------------------------------- 00044 // CLASS : sc_attr_base 00045 // 00046 // Attribute base class. 00047 // ---------------------------------------------------------------------------- 00048 00049 class sc_attr_base 00050 { 00051 public: 00052 00053 // constructors 00054 sc_attr_base( const sc_string& name_ ); 00055 sc_attr_base( const sc_attr_base& ); 00056 00057 // destructor (does nothing) 00058 virtual ~sc_attr_base(); 00059 00060 // get the name 00061 const sc_string& name() const; 00062 00063 private: 00064 00065 sc_string m_name; 00066 00067 private: 00068 00069 // disabled 00070 sc_attr_base(); 00071 sc_attr_base& operator = ( const sc_attr_base& ); 00072 }; 00073 00074 00075 // ---------------------------------------------------------------------------- 00076 // CLASS : sc_attr_cltn 00077 // 00078 // Attribute collection class. Stores pointers to attributes. 00079 // Note: iterate over the collection by using iterators. 00080 // ---------------------------------------------------------------------------- 00081 00082 class sc_attr_cltn 00083 { 00084 public: 00085 00086 // typedefs 00087 typedef sc_attr_base* elem_type; 00088 typedef elem_type* iterator; 00089 typedef const elem_type* const_iterator; 00090 00091 // constructors 00092 sc_attr_cltn(); 00093 sc_attr_cltn( const sc_attr_cltn& ); 00094 00095 // destructor 00096 ~sc_attr_cltn(); 00097 00098 // add attribute to the collection. 00099 // returns 'true' if the name of the attribute is unique, 00100 // returns 'false' otherwise (attribute is not added). 00101 bool push_back( sc_attr_base* ); 00102 00103 // get attribute by name. 00104 // returns pointer to attribute, or 0 if name does not exist. 00105 sc_attr_base* operator [] ( const sc_string& name_ ); 00106 const sc_attr_base* operator [] ( const sc_string& name_ ) const; 00107 00108 // remove attribute by name. 00109 // returns pointer to attribute, or 0 if name does not exist. 00110 sc_attr_base* remove( const sc_string& name_ ); 00111 00112 // remove all attributes 00113 void remove_all(); 00114 00115 // get the size of the collection 00116 int size() const 00117 { return m_cltn.size(); } 00118 00119 // get the begin iterator 00120 iterator begin() 00121 { return m_cltn.begin(); } 00122 const_iterator begin() const 00123 { return m_cltn.begin(); } 00124 00125 // get the end iterator 00126 iterator end() 00127 { return m_cltn.end(); } 00128 const_iterator end() const 00129 { return m_cltn.end(); } 00130 00131 private: 00132 00133 sc_pvector<sc_attr_base*> m_cltn; 00134 00135 private: 00136 00137 // disabled 00138 sc_attr_cltn& operator = ( const sc_attr_cltn& ); 00139 }; 00140 00141 00142 // ---------------------------------------------------------------------------- 00143 // CLASS : sc_attribute<T> 00144 // 00145 // Attribute class. 00146 // Note: T must have a default constructor and copy constructor. 00147 // ---------------------------------------------------------------------------- 00148 00149 template <class T> 00150 class sc_attribute 00151 : public sc_attr_base 00152 { 00153 public: 00154 00155 // constructors 00156 00157 sc_attribute( const sc_string& name_ ) 00158 : sc_attr_base( name_ ), value() 00159 {} 00160 00161 sc_attribute( const sc_string& name_, const T& value_ ) 00162 : sc_attr_base( name_ ), value( value_ ) 00163 {} 00164 00165 sc_attribute( const sc_attribute<T>& a ) 00166 : sc_attr_base( a.name() ), value( a.value ) 00167 {} 00168 00169 00170 // destructor (does nothing) 00171 00172 virtual ~sc_attribute() 00173 {} 00174 00175 public: 00176 00177 // public data member; for easy access 00178 T value; 00179 00180 private: 00181 00182 // disabled 00183 sc_attribute(); 00184 sc_attribute<T>& operator = ( const sc_attribute<T>& ); 00185 }; 00186 00187 00188 #endif 00189 00190 // Taf!
1.2.18