SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_attribute.h
Go to the documentation of this file.
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_attribute.h -- Attribute classes.
23
24 Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
25
26 CHANGE LOG AT THE END OF THE FILE
27 *****************************************************************************/
28
29
30#ifndef SC_ATTRIBUTE_H
31#define SC_ATTRIBUTE_H
32
33#include <string>
34#include <vector>
35
37
38#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
39#pragma warning(push)
40#pragma warning(disable: 4251) // DLL import for std::string,vector
41#endif
42
43namespace sc_core {
44
45// ----------------------------------------------------------------------------
46// CLASS : sc_attr_base
47//
48// Attribute base class.
49// ----------------------------------------------------------------------------
50
52{
53public:
54
55 // constructors
56 sc_attr_base( const std::string& name_ );
58
59 // destructor (does nothing)
60 virtual ~sc_attr_base();
61
62 // get the name
63 const std::string& name() const;
64
65private:
66
67 std::string m_name;
68
69private:
70
71 // disabled
73 sc_attr_base& operator = ( const sc_attr_base& );
74};
75
76
77// ----------------------------------------------------------------------------
78// CLASS : sc_attr_cltn
79//
80// Attribute collection class. Stores pointers to attributes.
81// Note: iterate over the collection by using iterators.
82// ----------------------------------------------------------------------------
83
85{
86public:
87
88 // typedefs
90 typedef std::vector<elem_type>::iterator iterator;
91 typedef std::vector<elem_type>::const_iterator const_iterator;
92
93 // constructors
96
97 // destructor
99
100 // add attribute to the collection.
101 // returns 'true' if the name of the attribute is unique,
102 // returns 'false' otherwise (attribute is not added).
104
105 // get attribute by name.
106 // returns pointer to attribute, or 0 if name does not exist.
107 sc_attr_base* operator [] ( const std::string& name_ );
108 const sc_attr_base* operator [] ( const std::string& name_ ) const;
109
110 // remove attribute by name.
111 // returns pointer to attribute, or 0 if name does not exist.
112 sc_attr_base* remove( const std::string& name_ );
113
114 // remove all attributes
116
117 // get the size of the collection
118 int size() const
119 { return static_cast<int>(m_cltn.size()); }
120
121 // get the begin iterator
123 { return m_cltn.begin(); }
125 { return m_cltn.begin(); }
126
127 // get the end iterator
129 { return m_cltn.end(); }
131 { return m_cltn.end(); }
132
133private:
134 std::vector<sc_attr_base*> m_cltn;
135
136private:
137
138 // disabled
139 sc_attr_cltn& operator = ( const sc_attr_cltn& );
140};
141
142
143// ----------------------------------------------------------------------------
144// CLASS : sc_attribute<T>
145//
146// Attribute class.
147// Note: T must have a default constructor and copy constructor.
148// ----------------------------------------------------------------------------
149
150template <class T>
152: public sc_attr_base
153{
154public:
155
156 // constructors
157
158 sc_attribute( const std::string& name_ )
159 : sc_attr_base( name_ ), value()
160 {}
161
162 sc_attribute( const std::string& name_, const T& value_ )
163 : sc_attr_base( name_ ), value( value_ )
164 {}
165
167 : sc_attr_base( a.name() ), value( a.value )
168 {}
169
170
171 // destructor (does nothing)
172
174 {}
175
176public:
177
178 // public data member; for easy access
180
181private:
182
183 // disabled
184 sc_attribute();
185 sc_attribute<T>& operator = ( const sc_attribute<T>& );
186};
187
188} // namespace sc_core
189
190#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
191#pragma warning(pop)
192#endif
193
194// $Log: sc_attribute.h,v $
195// Revision 1.6 2011/08/26 20:46:08 acg
196// Andy Goodrich: moved the modification log to the end of the file to
197// eliminate source line number skew when check-ins are done.
198//
199// Revision 1.5 2011/02/18 20:27:14 acg
200// Andy Goodrich: Updated Copyrights.
201//
202// Revision 1.4 2011/02/13 21:47:37 acg
203// Andy Goodrich: update copyright notice.
204//
205// Revision 1.3 2010/07/22 20:02:33 acg
206// Andy Goodrich: bug fixes.
207//
208// Revision 1.2 2008/05/22 17:06:24 acg
209// Andy Goodrich: updated copyright notice to include 2008.
210//
211// Revision 1.1.1.1 2006/12/15 20:20:05 acg
212// SystemC 2.3
213//
214// Revision 1.3 2006/01/13 18:44:29 acg
215// Added $Log to record CVS changes into the source.
216//
217
218#endif
219
220// Taf!
#define SC_API
Definition: sc_cmnhdr.h:148
sc_attr_base(const std::string &name_)
sc_attr_base(const sc_attr_base &)
const std::string & name() const
std::vector< elem_type >::iterator iterator
Definition: sc_attribute.h:90
sc_attr_base * elem_type
Definition: sc_attribute.h:89
const_iterator begin() const
Definition: sc_attribute.h:124
std::vector< elem_type >::const_iterator const_iterator
Definition: sc_attribute.h:91
const_iterator end() const
Definition: sc_attribute.h:130
sc_attr_base * remove(const std::string &name_)
sc_attr_cltn(const sc_attr_cltn &)
bool push_back(sc_attr_base *)
sc_attribute(const std::string &name_, const T &value_)
Definition: sc_attribute.h:162
sc_attribute(const std::string &name_)
Definition: sc_attribute.h:158
sc_attribute(const sc_attribute< T > &a)
Definition: sc_attribute.h:166