rc_object_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  */
00042 #ifndef RC_OBJECT_HANDLE_H_
00043 #define RC_OBJECT_HANDLE_H_
00044 
00045 #include "ReChannel/util/rc_port_handle.h"
00046 #include "ReChannel/util/rc_export_handle.h"
00047 
00048 namespace ReChannel {
00049 
00060 class rc_object_handle // (copyable)
00061 {
00062 public:
00064     rc_object_handle();
00065 
00067     rc_object_handle(sc_object& obj_);
00068 
00070     rc_object_handle(const rc_port_handle& port_);
00071 
00073     template<class IF, int N, sc_port_policy POL>
00074     rc_object_handle(sc_port<IF, N, POL>& port_);
00075 
00077     rc_object_handle(const rc_export_handle& export_);
00078 
00080     template<class IF>
00081     rc_object_handle(sc_export<IF>& export_);
00082 
00083 public:
00084     rc_object_handle& operator=(sc_object& obj_);
00085 
00086     template<class IF, int N, sc_port_policy POL>
00087     rc_object_handle& operator=(sc_port<IF, N, POL>& port_);
00088 
00089     rc_object_handle& operator=(const rc_port_handle& port_);
00090 
00091     template<class IF>
00092     rc_object_handle& operator=(sc_export<IF>& export_);
00093 
00094     rc_object_handle& operator=(const rc_export_handle& export_);
00095 
00097     inline bool valid() const
00098         { return (p_object != NULL); }
00099 
00101     inline bool is_port() const
00102         { return p_port.valid(); }
00103 
00105     inline bool is_export() const
00106         { return p_export.valid(); }
00107 
00109     inline bool is_channel() const
00110         { return p_channel_if != NULL; }
00111 
00113     inline bool is_comm_object() const
00114         { return (is_channel() || is_port() || is_export()); }
00115 
00117     inline rc_port_handle get_port() const
00118         { return p_port; }
00119 
00121     inline rc_export_handle get_export() const
00122         { return p_export; }
00123 
00125     sc_interface* get_interface() const;
00126 
00128     inline sc_object* get_object() const
00129         { return p_object; }
00130 
00132     sc_object* operator->() const
00133         { return p_object; }
00134 
00136     sc_object* operator*() const
00137         { return p_object; }
00138 
00139     inline operator sc_object*() const
00140         { return p_object; }
00141 
00145     bool operator==(const rc_object_handle& other) const
00146         { return p_object == other.p_object; }
00147 
00152     bool operator<(const rc_object_handle& other) const
00153         { return p_object < other.p_object; }
00154 
00155 private:
00157     sc_object*       p_object;
00159     sc_interface*    p_channel_if;
00161     rc_port_handle   p_port;
00163     rc_export_handle p_export;
00164 };
00165 
00166 /* template code */
00167 
00168 template<class IF, int N, sc_port_policy POL>
00169 rc_object_handle::rc_object_handle(sc_port<IF, N, POL>& port_)
00170     : p_object(static_cast<sc_object*>(&port_)), p_channel_if(NULL),
00171       p_port(port_)
00172 { }
00173 
00174 template<class IF>
00175 rc_object_handle::rc_object_handle(sc_export<IF>& export_)
00176     : p_object(static_cast<sc_object*>(&export_)), p_channel_if(NULL),
00177       p_export(export_)
00178 { }
00179 
00180 template<class IF, int N, sc_port_policy POL>
00181 rc_object_handle& rc_object_handle::operator=(sc_port<IF, N, POL>& port_)
00182 {
00183     p_object = static_cast<sc_object*>(&port_);
00184     p_channel_if = NULL;
00185     p_port = port_;
00186     p_export.reset();
00187     return *this;
00188 }
00189 
00190 template<class IF>
00191 rc_object_handle& rc_object_handle::operator=(sc_export<IF>& export_)
00192 {
00193     p_object = static_cast<sc_object*>(&export_);
00194     p_channel_if = NULL;
00195     p_port.reset();
00196     p_export = export_;
00197     return *this;
00198 }
00199 
00200 } // namespace ReChannel
00201 
00202 #endif // RC_PORT_HANDLE_H_
00203 
00204 //
00205 // $Id: rc_object_handle.h,v 1.3 2007/10/09 00:22:26 felke Exp $
00206 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/util/rc_object_handle.h,v $
00207 //

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