rc_port_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_PORT_HANDLE_H_
00040 #define RC_PORT_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 port_handle {
00051 
00056 class port_ref
00057 {
00058 public:
00059     virtual sc_interface* get_interface() const = 0;
00060 
00061     virtual sc_port_base& get_port_base() const = 0;
00062 
00063 protected:
00064     virtual ~port_ref() { }
00065 };
00066 
00070 template<class PORT>
00071 class port_ref_t
00072     : virtual public port_ref
00073 {
00074 public:
00075     port_ref_t(PORT& port_)
00076         : p_port(port_)
00077         { }
00078     virtual sc_interface* get_interface() const
00079         { return p_port.get_interface(); }
00080     virtual sc_port_base& get_port_base() const
00081         { return p_port; }
00082 
00083 private:
00085     mutable PORT& p_port;
00086 };
00087 
00088 } // namespace port_handle
00089 } // namespace internals
00090 
00099 class rc_port_handle // (copyable)
00100 {
00101 private:
00104     typedef internals::port_handle::port_ref      port_ref;
00108     typedef rc_hash_map<sc_port_base*, port_ref*> portmap;
00109 
00110 public:
00112     rc_port_handle()
00113         : p_port_base(NULL), p_port_ref(NULL)
00114         { }
00115 
00117     template<class IF, int N, sc_port_policy POL>
00118     rc_port_handle(sc_port<IF, N, POL>& port_);
00119 
00125     bool valid() const
00126         { return (p_port_base != NULL); }
00127 
00130     void reset()
00131         { p_port_base = NULL; p_port_ref = NULL; }
00132 
00136     sc_interface* get_interface() const
00137         { return p_port_ref->get_interface(); }
00138 
00142     sc_object* get_object() const
00143         { return p_port_base; }
00144 
00148     sc_port_base* operator->() const
00149         { return p_port_base; }
00150 
00154     sc_port_base* operator*() const
00155         { return p_port_base; }
00156 
00157     operator sc_port_base*() const
00158         { return p_port_base; }
00159 
00160     operator sc_object*() const
00161         { return p_port_base; }
00162 
00166     bool operator==(const rc_port_handle& other) const
00167         { return p_port_base == other.p_port_base; }
00168 
00173     bool operator<(const rc_port_handle& other) const
00174         { return p_port_base < other.p_port_base; }
00175 
00176 private:
00181     sc_port_base* p_port_base;
00186     port_ref*     p_port_ref;
00187 
00188 private:
00191     static portmap p_portmap;
00192 };
00193 
00194 /* template code */
00195 
00196 template<class IF, int N, sc_port_policy POL>
00197 rc_port_handle::rc_port_handle(sc_port<IF, N, POL>& port_)
00198     : p_port_base(&port_)
00199 {
00200     typedef sc_port<IF, N, POL> port_type;
00201     // find the map element for the port (create it if not exists)
00202     port_ref*& pref = p_portmap[&port_];
00203     // is port_ not contained in the map?
00204     if (pref == NULL) {
00205         // create the port's storage element and write it to the map
00206         pref = new internals::port_handle::port_ref_t<port_type>(port_);
00207     }
00208     // let p_port_ref point to the current port
00209     p_port_ref = pref;
00210 }
00211 
00212 } // namespace ReChannel
00213 
00214 #endif // RC_PORT_HANDLE_H_
00215 
00216 //
00217 // $Id: rc_port_handle.h,v 1.5 2007/10/09 00:22:26 felke Exp $
00218 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/util/rc_port_handle.h,v $
00219 //

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