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
36namespace sc_core {
37
38// ----------------------------------------------------------------------------
39//  CLASS : sc_attr_base
40//
41//  Attribute base class.
42// ----------------------------------------------------------------------------
43
44class sc_attr_base
45{
46public:
47
48    // constructors
49    sc_attr_base( const std::string& name_ );
50    sc_attr_base( const sc_attr_base& );
51
52    // destructor (does nothing)
53    virtual ~sc_attr_base();
54
55    // get the name
56    const std::string& name() const;
57
58private:
59
60    std::string m_name;
61
62private:
63
64    // disabled
65    sc_attr_base();
66    sc_attr_base& operator = ( const sc_attr_base& );
67};
68
69
70// ----------------------------------------------------------------------------
71//  CLASS : sc_attr_cltn
72//
73//  Attribute collection class. Stores pointers to attributes.
74//  Note: iterate over the collection by using iterators.
75// ----------------------------------------------------------------------------
76
77class sc_attr_cltn
78{
79public:
80
81    // typedefs
82    typedef sc_attr_base*                          elem_type;
83    typedef std::vector<elem_type>::iterator       iterator;
84    typedef std::vector<elem_type>::const_iterator const_iterator;
85
86    // constructors
87    sc_attr_cltn();
88    sc_attr_cltn( const sc_attr_cltn& );
89
90    // destructor
91    ~sc_attr_cltn();
92
93    // add attribute to the collection.
94    // returns 'true' if the name of the attribute is unique,
95    // returns 'false' otherwise (attribute is not added).
96    bool push_back( sc_attr_base* );
97
98    // get attribute by name.
99    // returns pointer to attribute, or 0 if name does not exist.
100          sc_attr_base* operator [] ( const std::string& name_ );
101    const sc_attr_base* operator [] ( const std::string& name_ ) const;
102
103    // remove attribute by name.
104    // returns pointer to attribute, or 0 if name does not exist.
105    sc_attr_base* remove( const std::string& name_ );
106
107    // remove all attributes
108    void remove_all();
109
110    // get the size of the collection
111    int size() const
112        { return m_cltn.size(); }
113
114    // get the begin iterator
115    iterator begin()
116        { return m_cltn.begin(); }
117    const_iterator begin() const
118        { return m_cltn.begin(); }
119
120    // get the end iterator
121    iterator end()
122        { return m_cltn.end(); }
123    const_iterator end() const
124        { return m_cltn.end(); }
125
126private:
127    std::vector<sc_attr_base*> m_cltn;
128
129private:
130
131    // disabled
132    sc_attr_cltn& operator = ( const sc_attr_cltn& );
133};
134
135
136// ----------------------------------------------------------------------------
137//  CLASS : sc_attribute<T>
138//
139//  Attribute class.
140//  Note: T must have a default constructor and copy constructor.
141// ----------------------------------------------------------------------------
142
143template <class T>
144class sc_attribute
145: public sc_attr_base
146{
147public:
148
149    // constructors
150
151    sc_attribute( const std::string& name_ )
152        : sc_attr_base( name_ ), value()
153        {}
154
155    sc_attribute( const std::string& name_, const T& value_ )
156        : sc_attr_base( name_ ), value( value_ )
157        {}
158
159    sc_attribute( const sc_attribute<T>& a )
160        : sc_attr_base( a.name() ), value( a.value )
161        {}
162
163
164    // destructor (does nothing)
165
166    virtual ~sc_attribute()
167        {}
168
169public:
170
171    // public data member; for easy access
172    T value;
173
174private:
175
176    // disabled
177    sc_attribute();
178    sc_attribute<T>& operator = ( const sc_attribute<T>& );
179};
180
181} // namespace sc_core
182
183// $Log: sc_attribute.h,v $
184// Revision 1.6  2011/08/26 20:46:08  acg
185//  Andy Goodrich: moved the modification log to the end of the file to
186//  eliminate source line number skew when check-ins are done.
187//
188// Revision 1.5  2011/02/18 20:27:14  acg
189//  Andy Goodrich: Updated Copyrights.
190//
191// Revision 1.4  2011/02/13 21:47:37  acg
192//  Andy Goodrich: update copyright notice.
193//
194// Revision 1.3  2010/07/22 20:02:33  acg
195//  Andy Goodrich: bug fixes.
196//
197// Revision 1.2  2008/05/22 17:06:24  acg
198//  Andy Goodrich: updated copyright notice to include 2008.
199//
200// Revision 1.1.1.1  2006/12/15 20:20:05  acg
201// SystemC 2.3
202//
203// Revision 1.3  2006/01/13 18:44:29  acg
204// Added $Log to record CVS changes into the source.
205//
206
207#endif
208
209// Taf!
210