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