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