Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sc_export.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-2004 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.3 (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_export.h -- Base classes of all export classes.
00021 
00022   Original Author: Andy Goodrich, Forte Design Systems
00023                    Bishnupriya Bhattacharya, Cadence Design Systems
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 #ifndef SC_EXPORT_H
00038 #define SC_EXPORT_H
00039 #include <typeinfo>
00040 
00041 #include "systemc/communication/sc_communication_ids.h"
00042 #include "systemc/communication/sc_interface.h"
00043 #include "systemc/kernel/sc_object.h"
00044 #include "systemc/kernel/sc_simcontext.h"
00045 
00046 //=============================================================================
00047 //  CLASS : sc_export_base
00048 //
00049 //  Abstract base class for class sc_export<IF>.
00050 //=============================================================================
00051 
00052 class sc_export_base : public sc_object
00053 {
00054     friend class sc_export_registry;
00055 public:
00056 
00057     // typedefs
00058     
00059     typedef sc_export_base this_type;
00060 
00061 public:
00062 
00063     virtual       sc_interface* get_interface() = 0;
00064     virtual       const sc_interface* get_interface() const = 0;
00065 
00066 protected:
00067     
00068     // constructors
00069 
00070     sc_export_base();
00071     sc_export_base(const char* name);
00072 
00073     // destructor
00074 
00075     virtual ~sc_export_base();
00076 
00077 protected:
00078 
00079     // called when construction is done 
00080     virtual void before_end_of_elaboration();
00081 
00082     // called by before_end_of_elaboration (does nothing by default)
00083     virtual void end_of_construction();
00084 
00085     // called when elaboration is done (does nothing by default)
00086     virtual void end_of_elaboration();
00087 
00088     // called before simulation starts (does nothing by default)
00089     virtual void start_of_simulation();
00090 
00091     // called after simulation ends (does nothing)
00092     virtual void end_of_simulation();
00093 
00094     virtual const char* if_typename() const = 0;
00095 
00096 private:
00097 
00098     // disabled
00099     sc_export_base(const this_type&);
00100     this_type& operator = (const this_type& );
00101 
00102 };
00103 
00104 //=============================================================================
00105 //  CLASS : sc_export
00106 //
00107 //  Generic export class for other export classes. This
00108 //  class provides a binding point for access to an interface.
00109 //=============================================================================
00110 template<class IF>
00111 class sc_export : public sc_export_base
00112 {
00113     typedef sc_export<IF> this_type;
00114 
00115 public: // constructors:
00116     sc_export() : sc_export_base()
00117     {
00118   m_interface_p = 0;
00119     }
00120 
00121     sc_export( const char* name_ ) : sc_export_base(name_)
00122     {
00123   m_interface_p = 0;
00124     }
00125 
00126     sc_export( IF& interface_ ) : sc_export_base()
00127     {
00128   m_interface_p = &interface_;
00129     }
00130 
00131     sc_export( const char* name_, IF& interface_ ) : sc_export_base(name_)
00132     {
00133   m_interface_p = &interface_;
00134     }
00135 
00136     explicit sc_export( this_type& child_ ) : sc_export_base()
00137     {
00138   m_interface_p = child_.m_interface_p;
00139     }
00140 
00141 public: // destructor:
00142     virtual ~sc_export() 
00143     {
00144     }
00145 
00146 public: // interface access:
00147 
00148     sc_interface* get_interface() 
00149     {
00150   return m_interface_p;
00151     }
00152 
00153     const sc_interface* get_interface() const
00154     {
00155         return m_interface_p;
00156     }
00157 
00158     IF* operator -> () {
00159         if ( m_interface_p == 0 )
00160         {
00161             SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_,name());
00162         }
00163         return m_interface_p;
00164     }
00165 
00166     operator IF& ()
00167     {
00168   if ( m_interface_p == 0 )
00169   {
00170       SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_,name());
00171   }
00172   return *m_interface_p;
00173     }
00174 
00175 public: // binding:
00176     void bind( IF& interface_ )
00177     {
00178   m_interface_p = &interface_;
00179     }
00180 
00181     void operator () ( IF& interface_ )
00182     {
00183   m_interface_p = &interface_;
00184     }
00185 
00186 public: // identification:
00187     virtual const char* kind() const { return "sc_export"; }
00188 
00189 protected:
00190   const char* if_typename() const {
00191     return typeid( IF ).name();
00192   }
00193 
00194 private: // disabled
00195     sc_export( const this_type& );
00196     this_type& operator = ( const this_type& );
00197 
00198 protected: // data fields:
00199     IF* m_interface_p;    // Interface this port provides.
00200 };
00201 
00202 // ----------------------------------------------------------------------------
00203 //  CLASS : sc_export_registry
00204 //
00205 //  Registry for all exports.
00206 //  FOR INTERNAL USE ONLY!
00207 // ----------------------------------------------------------------------------
00208 
00209 class sc_export_registry
00210 {
00211     friend class sc_simcontext;
00212 
00213 public:
00214 
00215     void insert( sc_export_base* );
00216     void remove( sc_export_base* );
00217 
00218     int size() const
00219         { return m_export_vec.size(); }
00220 
00221 private:
00222 
00223     // constructor
00224     explicit sc_export_registry( sc_simcontext& simc_ );
00225 
00226     // destructor
00227     ~sc_export_registry();
00228 
00229     // called when construction is done
00230     void construction_done();
00231 
00232     // called when elaboration is done
00233     void elaboration_done();
00234 
00235     // called before simulation starts
00236     void start_simulation();
00237 
00238     // called after simulation ends
00239     void simulation_done();
00240 
00241 private:
00242 
00243     sc_simcontext*              m_simc;
00244     sc_pvector<sc_export_base*>     m_export_vec;
00245 
00246 private:
00247 
00248     // disabled
00249     sc_export_registry();
00250     sc_export_registry( const sc_export_registry& );
00251     sc_export_registry& operator = ( const sc_export_registry& );
00252 };
00253 
00254 #endif
00255 
00256 // Taf!

Generated on Fri Jan 14 08:29:01 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18