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