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

Generated on Wed Apr 25 13:53:25 2007 for SystemC by  doxygen 1.5.1