SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_object.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_object.h -- Abstract base class of all SystemC `simulation' objects.
23 */
34 #ifndef SC_OBJECT_H
35 #define SC_OBJECT_H
36 
38 #include <iostream>
39 
40 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
41 #pragma warning(push)
42 #pragma warning(disable: 4251) // DLL import for std::string,vector
43 #endif
44 
45 namespace sc_core {
46 
47 class SC_API sc_event;
50 class sc_runnable;
54 
62 {
63  friend class sc_event;
64  friend class sc_module;
65  friend struct sc_invoke_method;
66  friend class sc_module_dynalloc_list;
67  friend class sc_object_manager;
69  friend class sc_process_b;
70  friend class sc_runnable;
71  friend class sc_simcontext;
72  friend class sc_trace_file_base;
73 
74 public:
75  typedef unsigned phase_cb_mask;
76 
77  const char* name() const
78  { return m_name.c_str(); }
79 
80  const char* basename() const;
81 
82  virtual void print(::std::ostream& os=::std::cout ) const;
83 
84  // dump() is more detailed than print()
85  virtual void dump(::std::ostream& os=::std::cout ) const;
86 
87  virtual void trace( sc_trace_file* tf ) const;
88 
89  virtual const char* kind() const { return "sc_object"; }
90 
92  { return m_simc; }
93 
94  // add attribute
95  bool add_attribute( sc_attr_base& );
96 
97  // get attribute by name
98  sc_attr_base* get_attribute( const std::string& name_ );
99  const sc_attr_base* get_attribute( const std::string& name_ ) const;
100 
101  // remove attribute by name
102  sc_attr_base* remove_attribute( const std::string& name_ );
103 
104  // remove all attributes
105  void remove_all_attributes();
106 
107  // get the number of attributes
108  int num_attributes() const;
109 
110  // get the attribute collection
111  sc_attr_cltn& attr_cltn();
112  const sc_attr_cltn& attr_cltn() const;
113 
114  virtual const std::vector<sc_event*>& get_child_events() const
115  { return m_child_events; }
116 
117  virtual const std::vector<sc_object*>& get_child_objects() const
118  { return m_child_objects; }
119 
120  sc_object* get_parent() const;
121  sc_object* get_parent_object() const { return m_parent; }
122 
123 protected:
124 
125  sc_object();
126  sc_object(const char* nm);
127 
128  sc_object( const sc_object& );
129  sc_object& operator=( const sc_object& );
130 
131 
132  virtual ~sc_object();
133 
134  virtual void add_child_event( sc_event* event_p );
135  virtual void add_child_object( sc_object* object_p );
136  virtual bool remove_child_event( sc_event* event_p );
137  virtual bool remove_child_object( sc_object* object_p );
138 
139  phase_cb_mask register_simulation_phase_callback( phase_cb_mask );
140  phase_cb_mask unregister_simulation_phase_callback( phase_cb_mask );
141 
142  class hierarchy_scope;
143 
144 private:
145  void do_simulation_phase_callback();
146  virtual void simulation_phase_callback();
147 
148  void detach();
149  virtual void orphan_child_events();
150  virtual void orphan_child_objects();
151  void sc_object_init(const char* nm);
152 
153 private:
154 
155  /* Each simulation object is associated with a simulation context */
156  mutable sc_attr_cltn* m_attr_cltn_p; // attributes for this object.
157  std::vector<sc_event*> m_child_events; // list of child events.
158  std::vector<sc_object*> m_child_objects; // list of child objects.
159  std::string m_name; // name of this object.
160  sc_object* m_parent; // parent for this object.
161  sc_simcontext* m_simc; // simcontext ptr / empty indicator
162 };
163 
164 inline
165 sc_object&
167 {
168  // deliberately do nothing
169  return *this;
170 }
171 
172 extern const char SC_HIERARCHY_CHAR;
173 extern bool sc_enable_name_checking;
174 
175 
176 inline
178 {
179  return obj_p->get_parent_object();
180 }
181 
182 } // namespace sc_core
183 
184 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
185 #pragma warning(pop)
186 #endif
187 
188 /*****************************************************************************
189 
190  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
191  changes you are making here.
192 
193  Name, Affiliation, Date: Andy Goodrich, Forte Design Systems
194  5 September 2003
195  Description of Modification: - Made creation of attributes structure
196  conditional on its being used. This eliminates
197  100 bytes of storage for each normal sc_object.
198 
199  *****************************************************************************/
200 
201 // $Log: sc_object.h,v $
202 // Revision 1.13 2011/08/29 18:04:32 acg
203 // Philipp A. Hartmann: miscellaneous clean ups.
204 //
205 // Revision 1.12 2011/08/26 20:46:10 acg
206 // Andy Goodrich: moved the modification log to the end of the file to
207 // eliminate source line number skew when check-ins are done.
208 //
209 // Revision 1.11 2011/03/06 15:55:11 acg
210 // Andy Goodrich: Changes for named events.
211 //
212 // Revision 1.10 2011/03/05 19:44:20 acg
213 // Andy Goodrich: changes for object and event naming and structures.
214 //
215 // Revision 1.9 2011/03/05 01:39:21 acg
216 // Andy Goodrich: changes for named events.
217 //
218 // Revision 1.8 2011/02/18 20:27:14 acg
219 // Andy Goodrich: Updated Copyrights.
220 //
221 // Revision 1.7 2011/02/13 21:47:37 acg
222 // Andy Goodrich: update copyright notice.
223 //
224 // Revision 1.6 2011/01/25 20:50:37 acg
225 // Andy Goodrich: changes for IEEE 1666 2011.
226 //
227 // Revision 1.5 2011/01/18 20:10:44 acg
228 // Andy Goodrich: changes for IEEE1666_2011 semantics.
229 //
230 // Revision 1.4 2010/07/22 20:02:33 acg
231 // Andy Goodrich: bug fixes.
232 //
233 // Revision 1.3 2009/02/28 00:26:58 acg
234 // Andy Goodrich: changed boost name space to sc_boost to allow use with
235 // full boost library applications.
236 //
237 // Revision 1.2 2008/05/22 17:06:26 acg
238 // Andy Goodrich: updated copyright notice to include 2008.
239 //
240 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
241 // SystemC 2.3
242 //
243 // Revision 1.5 2006/04/20 17:08:17 acg
244 // Andy Goodrich: 3.0 style process changes.
245 //
246 // Revision 1.4 2006/04/11 23:13:21 acg
247 // Andy Goodrich: Changes for reduced reset support that only includes
248 // sc_cthread, but has preliminary hooks for expanding to method and thread
249 // processes also.
250 //
251 // Revision 1.3 2006/01/13 18:44:30 acg
252 // Added $Log to record CVS changes into the source.
253 
254 #endif // SC_OBJECT_H
bool sc_enable_name_checking
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:61
Attribute collection class.
Definition: sc_attribute.h:89
sc_object & operator=(const sc_object &)
Definition: sc_object.h:166
The event class.
Definition: sc_event.h:256
Attribute classes.
virtual const std::vector< sc_object * > & get_child_objects() const
Definition: sc_object.h:117
unsigned phase_cb_mask
Definition: sc_object.h:75
virtual const char * kind() const
Definition: sc_object.h:89
Manager of objects.
Attribute base class.
Definition: sc_attribute.h:55
Base class for all structural entities.
Definition: sc_module.h:83
class SC_API sc_event
Definition: sc_interface.h:40
sc_object * sc_get_parent(const sc_object *obj_p)
Definition: sc_object.h:177
The simulation context.
const char * name() const
Definition: sc_object.h:77
sc_object * get_parent_object() const
Definition: sc_object.h:121
const char SC_HIERARCHY_CHAR
virtual const std::vector< sc_event * > & get_child_events() const
Definition: sc_object.h:114
sc_simcontext * simcontext() const
Definition: sc_object.h:91
#define SC_API
Definition: sc_cmnhdr.h:168