sc_process_handle.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_process_handle.h -- Process access support.
00021 
00022   Original Author: Andy Goodrich, Forte Design Systems, 17 June 2003
00023 
00024 
00025  *****************************************************************************/
00026 
00027 /*****************************************************************************
00028 
00029   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00030   changes you are making here.
00031 
00032       Name, Affiliation, Date:
00033   Description of Modification:
00034 
00035  *****************************************************************************/
00036 
00037 // $Log: sc_process_handle.h,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:37  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.5  2006/04/11 23:13:21  acg
00042 //   Andy Goodrich: Changes for reduced reset support that only includes
00043 //   sc_cthread, but has preliminary hooks for expanding to method and thread
00044 //   processes also.
00045 //
00046 // Revision 1.4  2006/01/24 20:49:05  acg
00047 // Andy Goodrich: changes to remove the use of deprecated features within the
00048 // simulator, and to issue warning messages when deprecated features are used.
00049 //
00050 // Revision 1.3  2006/01/13 18:44:30  acg
00051 // Added $Log to record CVS changes into the source.
00052 //
00053 
00054 #if !defined(sc_process_handle_h_INCLUDED)
00055 #define sc_process_handle_h_INCLUDED
00056 
00057 #include "sysc/kernel/sc_module.h"
00058 
00059 namespace sc_core {
00060 
00061 class sc_process_handle;
00062 // friend operator declarations
00063     bool operator == ( const sc_process_handle& left, const sc_process_handle& right );
00064     bool operator != ( const sc_process_handle& left, const sc_process_handle& right );
00065 
00066 
00067 //=============================================================================
00068 // CLASS sc_process_handle
00069 //
00070 // This class provides access to an sc_process_b object instance in a
00071 // manner which allows some persistence after the deletion of the actual
00072 // process.
00073 //=============================================================================
00074 class sc_simcontext;
00075 class sc_process_handle {
00076     typedef sc_process_handle this_type;
00077 
00078     friend bool operator == ( const this_type& left, const this_type& right );
00079     friend bool operator != ( const this_type& left, const this_type& right );
00080     friend class sc_object;
00081     friend class sc_join;
00082     friend class sc_module;
00083     friend class sc_reset;
00084     friend class sc_sensitive;
00085     friend class sc_sensitive_pos;
00086     friend class sc_sensitive_neg;
00087     friend class sc_thread_process;
00088 
00089   public:
00090     inline sc_process_handle();
00091     inline explicit sc_process_handle( sc_object* object_p );
00092     inline sc_process_handle( const sc_process_handle& orig );
00093     inline ~sc_process_handle();
00094     inline sc_process_handle& operator = ( const sc_process_handle& src );
00095 
00096   public:
00097     inline bool dynamic() const;
00098     inline const std::vector<sc_object*>& get_child_objects() const;
00099     inline sc_object* get_parent_object() const;
00100     inline sc_object* get_process_object() const;
00101     inline const char* name() const;
00102     inline sc_curr_proc_kind proc_kind() const;
00103     inline sc_event& terminated_event();
00104     inline bool terminated() const;
00105     inline bool valid() const;
00106 
00107   protected:
00108     inline bool dont_initialize() const
00109         { return m_target_p ? m_target_p->dont_initialize() : false; }
00110     inline void dont_initialize( bool dont );
00111 
00112   public:
00113     operator sc_process_b* ()
00114         { return m_target_p; }
00115     operator sc_cthread_handle ();
00116     operator sc_method_handle ();
00117     operator sc_thread_handle ();
00118 
00119   protected:
00120     sc_process_b* m_target_p;   // Target for this object instance.
00121 
00122   protected:
00123     static std::vector<sc_object*> empty_vector; // Returned if m_target_p == 0.
00124     static sc_event                non_event;    // Returned if m_target_p == 0.
00125 };
00126 
00127 inline bool operator == (
00128     const sc_process_handle& left, const sc_process_handle& right )
00129 {
00130     return (left.m_target_p != 0) && (right.m_target_p != 0) &&
00131         (left.m_target_p == right.m_target_p);
00132 }
00133 
00134 inline bool operator != (
00135     const sc_process_handle& left, const sc_process_handle& right )
00136 {
00137     return (left.m_target_p == 0) || (right.m_target_p == 0) ||
00138         (left.m_target_p != right.m_target_p);
00139 }
00140 
00141 //------------------------------------------------------------------------------
00142 //"sc_process_handle::sc_process_handle - non-pointer constructor"
00143 //
00144 // This version of the object instance constructor for this class creates
00145 // an object instance whose target needs to be supplied via an assignment.
00146 //------------------------------------------------------------------------------
00147 inline sc_process_handle::sc_process_handle()
00148 {
00149     m_target_p = (sc_process_b*)0;
00150 }
00151 
00152 
00153 //------------------------------------------------------------------------------
00154 //"sc_process_handle::sc_process_handle - pointer constructor"
00155 //
00156 // This version of the object instance constructor for this class creates
00157 // an object instance whose target is the supplied sc_object instance.
00158 // The supplied sc_object must in fact be an sc_process_b instance.
00159 //     object_p -> sc_object instance this is handle for.
00160 //------------------------------------------------------------------------------
00161 inline sc_process_handle::sc_process_handle( sc_object* object_p )
00162 {
00163     m_target_p = object_p ? DCAST<sc_process_b*>(object_p) : (sc_process_b*)0;
00164     if ( m_target_p ) m_target_p->reference_increment();
00165 }
00166 
00167 
00168 //------------------------------------------------------------------------------
00169 //"sc_process_handle::sc_process_handle - copy constructor"
00170 //
00171 // This version of the object instance constructor for this class provides
00172 // the copy constructor for the class. It clones the supplied original
00173 // handle and increments the references to its target.
00174 //     orig = sc_process_handle object instance to be copied from.
00175 //------------------------------------------------------------------------------
00176 inline sc_process_handle::sc_process_handle( const sc_process_handle& orig )
00177 {
00178     m_target_p = orig.m_target_p;
00179     if ( m_target_p ) m_target_p->reference_increment();
00180 }
00181 
00182 //------------------------------------------------------------------------------
00183 //"sc_process_handle::operator = - copy constructor"
00184 //
00185 // This version of the object instance constructor for this class provides
00186 // the copy constructor for the class. It clones the supplied original
00187 // handle and increments the references to its target.
00188 //     orig = sc_process_handle object instance to be copied from.
00189 //------------------------------------------------------------------------------
00190 inline sc_process_handle&
00191 sc_process_handle::operator = ( const sc_process_handle& orig )
00192 {
00193     if ( m_target_p ) m_target_p->reference_decrement();
00194     m_target_p = orig.m_target_p;
00195     if ( m_target_p ) m_target_p->reference_increment();
00196     return *this;
00197 }
00198 
00199 
00200 //------------------------------------------------------------------------------
00201 //"sc_process_handle::~sc_process_handle"
00202 //
00203 // This is the object instance destructor for this class. It decrements
00204 // the reference count for its target.
00205 //------------------------------------------------------------------------------
00206 inline sc_process_handle::~sc_process_handle()
00207 {
00208     if ( m_target_p ) m_target_p->reference_decrement();
00209 }
00210 
00211 //------------------------------------------------------------------------------
00212 //"sc_process_handle::inline methods"
00213 //
00214 // These are short inline methods.
00215 //------------------------------------------------------------------------------
00216 inline void sc_process_handle::dont_initialize( bool dont )
00217 {
00218     if ( m_target_p ) m_target_p->dont_initialize( dont );
00219 }
00220 
00221 inline bool sc_process_handle::dynamic() const
00222 {
00223     return m_target_p ? m_target_p->dynamic() : false;
00224 }
00225 
00226 inline
00227 const std::vector<sc_object*>& sc_process_handle::get_child_objects() const
00228 {
00229     return m_target_p ? m_target_p->get_child_objects() :
00230         sc_process_handle::empty_vector;
00231 }
00232 
00233 inline sc_object* sc_process_handle::get_parent_object() const
00234 {
00235     return m_target_p ? m_target_p->get_parent_object() : (sc_object*)0;
00236 }
00237 
00238 inline sc_object* sc_process_handle::get_process_object() const
00239 {
00240     return m_target_p;
00241 }
00242 
00243 inline const char* sc_process_handle::name() const
00244 {
00245     return m_target_p ? m_target_p->name() : "";
00246 }
00247 
00248 inline sc_curr_proc_kind sc_process_handle::proc_kind() const
00249 {
00250     return m_target_p ? m_target_p->proc_kind() : SC_NO_PROC_;
00251 }
00252 
00253 inline bool sc_process_handle::terminated() const
00254 {
00255     return m_target_p ? m_target_p->terminated() : false;
00256 }
00257 
00258 inline sc_event& sc_process_handle::terminated_event()
00259 {
00260     return m_target_p ? m_target_p->terminated_event() :
00261         sc_process_handle::non_event;
00262 }
00263 
00264 inline bool sc_process_handle::valid() const
00265 {
00266     return m_target_p ? true : false;
00267 }
00268 
00269 
00270 //------------------------------------------------------------------------------
00271 //"sc_process_b::last_created_process_handle"
00272 //
00273 // This method returns the kind of this process.
00274 //------------------------------------------------------------------------------
00275 inline sc_process_handle sc_process_b::last_created_process_handle()
00276 {
00277     return sc_process_handle(m_last_created_process_p);
00278 }
00279 
00280 inline sc_process_handle sc_get_last_created_process_handle()
00281 {
00282     return sc_process_b::last_created_process_handle();
00283 }
00284 
00285 } // namespace sc_core
00286 
00287 
00288 #endif // !defined(sc_spawn_h_INCLUDED)

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5