00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 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 (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.accellera.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 CHANGE LOG AT THE END OF THE FILE 00025 *****************************************************************************/ 00026 00027 00028 #ifndef SC_ATTRIBUTE_H 00029 #define SC_ATTRIBUTE_H 00030 00031 #include <string> 00032 #include <vector> 00033 00034 namespace sc_core { 00035 00036 // ---------------------------------------------------------------------------- 00037 // CLASS : sc_attr_base 00038 // 00039 // Attribute base class. 00040 // ---------------------------------------------------------------------------- 00041 00042 class sc_attr_base 00043 { 00044 public: 00045 00046 // constructors 00047 sc_attr_base( const std::string& name_ ); 00048 sc_attr_base( const sc_attr_base& ); 00049 00050 // destructor (does nothing) 00051 virtual ~sc_attr_base(); 00052 00053 // get the name 00054 const std::string& name() const; 00055 00056 private: 00057 00058 std::string m_name; 00059 00060 private: 00061 00062 // disabled 00063 sc_attr_base(); 00064 sc_attr_base& operator = ( const sc_attr_base& ); 00065 }; 00066 00067 00068 // ---------------------------------------------------------------------------- 00069 // CLASS : sc_attr_cltn 00070 // 00071 // Attribute collection class. Stores pointers to attributes. 00072 // Note: iterate over the collection by using iterators. 00073 // ---------------------------------------------------------------------------- 00074 00075 class sc_attr_cltn 00076 { 00077 public: 00078 00079 // typedefs 00080 typedef sc_attr_base* elem_type; 00081 typedef std::vector<elem_type>::iterator iterator; 00082 typedef std::vector<elem_type>::const_iterator const_iterator; 00083 00084 // constructors 00085 sc_attr_cltn(); 00086 sc_attr_cltn( const sc_attr_cltn& ); 00087 00088 // destructor 00089 ~sc_attr_cltn(); 00090 00091 // add attribute to the collection. 00092 // returns 'true' if the name of the attribute is unique, 00093 // returns 'false' otherwise (attribute is not added). 00094 bool push_back( sc_attr_base* ); 00095 00096 // get attribute by name. 00097 // returns pointer to attribute, or 0 if name does not exist. 00098 sc_attr_base* operator [] ( const std::string& name_ ); 00099 const sc_attr_base* operator [] ( const std::string& name_ ) const; 00100 00101 // remove attribute by name. 00102 // returns pointer to attribute, or 0 if name does not exist. 00103 sc_attr_base* remove( const std::string& name_ ); 00104 00105 // remove all attributes 00106 void remove_all(); 00107 00108 // get the size of the collection 00109 int size() const 00110 { return m_cltn.size(); } 00111 00112 // get the begin iterator 00113 iterator begin() 00114 { return m_cltn.begin(); } 00115 const_iterator begin() const 00116 { return m_cltn.begin(); } 00117 00118 // get the end iterator 00119 iterator end() 00120 { return m_cltn.end(); } 00121 const_iterator end() const 00122 { return m_cltn.end(); } 00123 00124 private: 00125 std::vector<sc_attr_base*> m_cltn; 00126 00127 private: 00128 00129 // disabled 00130 sc_attr_cltn& operator = ( const sc_attr_cltn& ); 00131 }; 00132 00133 00134 // ---------------------------------------------------------------------------- 00135 // CLASS : sc_attribute<T> 00136 // 00137 // Attribute class. 00138 // Note: T must have a default constructor and copy constructor. 00139 // ---------------------------------------------------------------------------- 00140 00141 template <class T> 00142 class sc_attribute 00143 : public sc_attr_base 00144 { 00145 public: 00146 00147 // constructors 00148 00149 sc_attribute( const std::string& name_ ) 00150 : sc_attr_base( name_ ), value() 00151 {} 00152 00153 sc_attribute( const std::string& name_, const T& value_ ) 00154 : sc_attr_base( name_ ), value( value_ ) 00155 {} 00156 00157 sc_attribute( const sc_attribute<T>& a ) 00158 : sc_attr_base( a.name() ), value( a.value ) 00159 {} 00160 00161 00162 // destructor (does nothing) 00163 00164 virtual ~sc_attribute() 00165 {} 00166 00167 public: 00168 00169 // public data member; for easy access 00170 T value; 00171 00172 private: 00173 00174 // disabled 00175 sc_attribute(); 00176 sc_attribute<T>& operator = ( const sc_attribute<T>& ); 00177 }; 00178 00179 } // namespace sc_core 00180 00181 // $Log: sc_attribute.h,v $ 00182 // Revision 1.6 2011/08/26 20:46:08 acg 00183 // Andy Goodrich: moved the modification log to the end of the file to 00184 // eliminate source line number skew when check-ins are done. 00185 // 00186 // Revision 1.5 2011/02/18 20:27:14 acg 00187 // Andy Goodrich: Updated Copyrights. 00188 // 00189 // Revision 1.4 2011/02/13 21:47:37 acg 00190 // Andy Goodrich: update copyright notice. 00191 // 00192 // Revision 1.3 2010/07/22 20:02:33 acg 00193 // Andy Goodrich: bug fixes. 00194 // 00195 // Revision 1.2 2008/05/22 17:06:24 acg 00196 // Andy Goodrich: updated copyright notice to include 2008. 00197 // 00198 // Revision 1.1.1.1 2006/12/15 20:20:05 acg 00199 // SystemC 2.3 00200 // 00201 // Revision 1.3 2006/01/13 18:44:29 acg 00202 // Added $Log to record CVS changes into the source. 00203 // 00204 00205 #endif 00206 00207 // Taf!