SystemC  Recoding Infrastructure for SystemC v0.6.3 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_attribute.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_attribute.h -- Attribute classes.
21 
22  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
23 
24  CHANGE LOG AT THE END OF THE FILE
25  *****************************************************************************/
26 
27 
28 #ifndef SC_ATTRIBUTE_H
29 #define SC_ATTRIBUTE_H
30 
31 #include <string>
32 #include <vector>
33 
34 namespace sc_core {
35 
36 // ----------------------------------------------------------------------------
37 // CLASS : sc_attr_base
38 //
39 // Attribute base class.
40 // ----------------------------------------------------------------------------
41 
43 {
44 public:
45 
46  // constructors
47  sc_attr_base( const std::string& name_ );
48  sc_attr_base( const sc_attr_base& );
49 
50  // destructor (does nothing)
51  virtual ~sc_attr_base();
52 
53  // get the name
54  const std::string& name() const;
55 
56 private:
57 
58  std::string m_name;
59 
60 private:
61 
62  // disabled
63  sc_attr_base();
64  sc_attr_base& operator = ( const sc_attr_base& );
65 };
66 
67 
68 // ----------------------------------------------------------------------------
69 // CLASS : sc_attr_cltn
70 //
71 // Attribute collection class. Stores pointers to attributes.
72 // Note: iterate over the collection by using iterators.
73 // ----------------------------------------------------------------------------
74 
76 {
77 public:
78 
79  // typedefs
81  typedef std::vector<elem_type>::iterator iterator;
82  typedef std::vector<elem_type>::const_iterator const_iterator;
83 
84  // constructors
85  sc_attr_cltn();
86  sc_attr_cltn( const sc_attr_cltn& );
87 
88  // destructor
89  ~sc_attr_cltn();
90 
91  // add attribute to the collection.
92  // returns 'true' if the name of the attribute is unique,
93  // returns 'false' otherwise (attribute is not added).
94  bool push_back( sc_attr_base* );
95 
96  // get attribute by name.
97  // returns pointer to attribute, or 0 if name does not exist.
98  sc_attr_base* operator [] ( const std::string& name_ );
99  const sc_attr_base* operator [] ( const std::string& name_ ) const;
100 
101  // remove attribute by name.
102  // returns pointer to attribute, or 0 if name does not exist.
103  sc_attr_base* remove( const std::string& name_ );
104 
105  // remove all attributes
106  void remove_all();
107 
108  // get the size of the collection
109  int size() const
110  { return m_cltn.size(); }
111 
112  // get the begin iterator
114  { return m_cltn.begin(); }
116  { return m_cltn.begin(); }
117 
118  // get the end iterator
120  { return m_cltn.end(); }
122  { return m_cltn.end(); }
123 
124 private:
125  std::vector<sc_attr_base*> m_cltn;
126 
127 private:
128 
129  // disabled
130  sc_attr_cltn& operator = ( const sc_attr_cltn& );
131 };
132 
133 
134 // ----------------------------------------------------------------------------
135 // CLASS : sc_attribute<T>
136 //
137 // Attribute class.
138 // Note: T must have a default constructor and copy constructor.
139 // ----------------------------------------------------------------------------
140 
141 template <class T>
143 : public sc_attr_base
144 {
145 public:
146 
147  // constructors
148 
149  sc_attribute( const std::string& name_ )
150  : sc_attr_base( name_ ), value()
151  {}
152 
153  sc_attribute( const std::string& name_, const T& value_ )
154  : sc_attr_base( name_ ), value( value_ )
155  {}
156 
158  : sc_attr_base( a.name() ), value( a.value )
159  {}
160 
161 
162  // destructor (does nothing)
163 
164  virtual ~sc_attribute()
165  {}
166 
167 public:
168 
169  // public data member; for easy access
170  T value;
171 
172 private:
173 
174  // disabled
175  sc_attribute();
176  sc_attribute<T>& operator = ( const sc_attribute<T>& );
177 };
178 
179 } // namespace sc_core
180 
181 // $Log: sc_attribute.h,v $
182 // Revision 1.6 2011/08/26 20:46:08 acg
183 // Andy Goodrich: moved the modification log to the end of the file to
184 // eliminate source line number skew when check-ins are done.
185 //
186 // Revision 1.5 2011/02/18 20:27:14 acg
187 // Andy Goodrich: Updated Copyrights.
188 //
189 // Revision 1.4 2011/02/13 21:47:37 acg
190 // Andy Goodrich: update copyright notice.
191 //
192 // Revision 1.3 2010/07/22 20:02:33 acg
193 // Andy Goodrich: bug fixes.
194 //
195 // Revision 1.2 2008/05/22 17:06:24 acg
196 // Andy Goodrich: updated copyright notice to include 2008.
197 //
198 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
199 // SystemC 2.3
200 //
201 // Revision 1.3 2006/01/13 18:44:29 acg
202 // Added $Log to record CVS changes into the source.
203 //
204 
205 #endif
206 
207 // Taf!
const_iterator end() const
Definition: sc_attribute.h:121
sc_attribute(const std::string &name_, const T &value_)
Definition: sc_attribute.h:153
sc_attr_base * operator[](const std::string &name_)
const std::string & name() const
std::vector< elem_type >::const_iterator const_iterator
Definition: sc_attribute.h:82
sc_attr_base * elem_type
Definition: sc_attribute.h:80
sc_attribute(const sc_attribute< T > &a)
Definition: sc_attribute.h:157
std::vector< elem_type >::iterator iterator
Definition: sc_attribute.h:81
sc_attribute(const std::string &name_)
Definition: sc_attribute.h:149
bool push_back(sc_attr_base *)
const_iterator begin() const
Definition: sc_attribute.h:115