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