rc_export_handle.h

Go to the documentation of this file.
00001 // vim:set et sts=4 ts=4 tw=75 sw=4 ai ci cin cino=g0,t0:
00002 /*
00003  * Copyright (C) 2007, Technical Computer Science Group,
00004  *                     University of Bonn
00005  *
00006  * This file is part of the ReChannel library.
00007  *
00008  * The ReChannel library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be
00014  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this library; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022  *
00023  * Authors: Andreas Raabe and Armin Felke. Implementation by Armin Felke.
00024  *          {raabe, felke}@cs.uni-bonn.de
00025  */
00039 #ifndef RC_EXPORT_HANDLE_H_
00040 #define RC_EXPORT_HANDLE_H_
00041 
00042 #include <systemc.h>
00043 
00044 #include "ReChannel/util/rc_hash_map.h"
00045 #include "ReChannel/util/rc_report.h"
00046 
00047 namespace ReChannel {
00048 
00049 namespace internals {
00050 namespace export_handle {
00051 
00056 class export_ref
00057 {
00058 public:
00059     virtual sc_interface* get_interface() const = 0;
00060 
00061     virtual sc_export_base& get_export_base() const = 0;
00062 
00063 protected:
00064     virtual ~export_ref() { }
00065 };
00066 
00070 template<class IF>
00071 class export_ref_t
00072     : virtual public export_ref
00073 {
00074 public:
00075     export_ref_t(sc_export<IF>& export_)
00076         : p_export(export_)
00077         { }
00078     virtual sc_interface* get_interface() const
00079         { return p_export.get_interface(); }
00080     virtual sc_export_base& get_export_base() const
00081         { return p_export; }
00082 
00083 private:
00085     mutable sc_export<IF>& p_export;
00086 };
00087 
00088 } // namespace export_handle
00089 } // namespace internals
00090 
00099 class rc_export_handle // (copyable)
00100 {
00101 private:
00104     typedef internals::export_handle::export_ref      export_ref;
00108     typedef rc_hash_map<sc_export_base*, export_ref*> exportmap;
00109 
00110 public:
00112     rc_export_handle()
00113         : p_export_base(NULL), p_export_ref(NULL)
00114         { }
00115 
00117     template<class IF> rc_export_handle(sc_export<IF>& export_);
00118 
00124     bool valid() const
00125         { return (p_export_base != NULL); }
00126 
00129     void reset()
00130         { p_export_base = NULL; p_export_ref = NULL; }
00131 
00135     sc_interface* get_interface() const
00136         { return p_export_ref->get_interface(); }
00137 
00141     sc_object* get_object() const
00142         { return p_export_base; }
00143 
00147     sc_export_base* operator->() const
00148         { return p_export_base; }
00149 
00150     sc_export_base* operator*() const
00151         { return p_export_base; }
00152 
00153     operator sc_export_base*() const
00154         { return p_export_base; }
00155 
00156     operator sc_object*() const
00157         { return p_export_base; }
00158 
00162     bool operator==(const rc_export_handle& other) const
00163         { return p_export_base == other.p_export_base; }
00164 
00169     bool operator<(const rc_export_handle& other) const
00170         { return p_export_base < other.p_export_base; }
00171 
00172 private:
00177     sc_export_base* p_export_base;
00182     export_ref*     p_export_ref;
00183 
00184 private:
00187     static exportmap p_exportmap;
00188 };
00189 
00190 /* template code */
00191 
00192 template<class IF>
00193 rc_export_handle::rc_export_handle(sc_export<IF>& export_)
00194     : p_export_base(&export_)
00195 {
00196     // find the map element for the export (create it if not exists)
00197     export_ref*& expref = p_exportmap[&export_];
00198     // was export_ not contained in the map?
00199     if (expref == NULL) {
00200         // store new export_ref_ in the map
00201         expref =
00202             new internals::export_handle::export_ref_t<IF>(export_);
00203     }
00204     // let p_export_ref point to the current export
00205     p_export_ref = expref;
00206 }
00207 
00208 } // namespace ReChannel
00209 
00210 #endif // RC_EXPORT_HANDLE_H_
00211 
00212 //
00213 // $Id: rc_export_handle.h,v 1.7 2007/12/20 20:33:00 felke Exp $
00214 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/util/rc_export_handle.h,v $
00215 //

Generated on Tue Jan 1 23:13:33 2008 for ReChannel by  doxygen 1.5.3