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

_scv_smart_ptr.h

Go to the documentation of this file.
00001 //  -*- C++ -*- <this line is for emacs to recognize it as C++ code>
00002 /*****************************************************************************
00003 
00004   The following code is derived, directly or indirectly, from the SystemC
00005   source code Copyright (c) 1996-2002 by all Contributors.
00006   All Rights reserved.
00007 
00008   The contents of this file are subject to the restrictions and limitations
00009   set forth in the SystemC Open Source License Version 2.3 (the "License");
00010   You may not use this file except in compliance with such restrictions and
00011   limitations. You may obtain instructions on how to receive a copy of the
00012   License at http://www.systemc.org/. Software distributed by Contributors
00013   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00014   ANY KIND, either express or implied. See the License for the specific
00015   language governing rights and limitations under the License.
00016 
00017  *****************************************************************************/
00018 
00019 /*****************************************************************************
00020 
00021   _scv_smart_ptr -- The main implementation for the scv_smart_ptr class.
00022 
00023   Original Authors (Cadence Design Systems, Inc):
00024   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00025   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey
00026   2002-09-23
00027 
00028  *****************************************************************************/
00029 
00030 /*****************************************************************************
00031 
00032   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00033   changes you are making here.
00034 
00035       Name, Affiliation, Date:
00036   Description of Modification:
00037 
00038  *****************************************************************************/
00039 
00040 // ----------------------------------------
00041 // implementation of the access methods to static extensions
00042 // ----------------------------------------
00043 template <typename T>
00044 scv_extensions<T> scv_get_extensions(T& d) {
00045   scv_extensions<T> e;
00046   e._set_instance(&d);
00047   return e;
00048 };
00049 
00050 template <typename T>
00051 const scv_extensions<T> scv_get_const_extensions(const T& d) {
00052   scv_extensions<T> e;
00053   e._set_instance((T*)&d);
00054   return e;
00055 };
00056 
00057 // ----------------------------------------
00058 // implementation of scv_smart_ptr
00059 // ----------------------------------------
00060 extern void _scv_insert_smart_ptr(scv_smart_ptr_if *);
00061 
00062 template <typename T> scv_smart_ptr<T>::scv_smart_ptr()
00063   : data_(new T()),
00064     ext_(new scv_extensions<T>()),
00065     tmp_(&*ext_) {
00066   ext_->_set_instance(&*data_);
00067   init();  
00068 }
00069 
00070 template <typename T>
00071 scv_smart_ptr<T>::scv_smart_ptr(const string& name)
00072   : data_(new T()),
00073     ext_(new scv_extensions<T>()),
00074     tmp_(&*ext_) {
00075   ext_->_set_instance(&*data_);
00076   ext_->set_name(name.c_str());
00077   init();  
00078 }
00079 
00080 template <typename T>
00081 scv_smart_ptr<T>::scv_smart_ptr(const sc_string& name)
00082   : data_(new T()),
00083     ext_(new scv_extensions<T>()),
00084     tmp_(&*ext_) {
00085   ext_->_set_instance(&*data_);
00086   ext_->set_name(name.c_str());
00087   init();  
00088 }
00089 
00090 template <typename T>
00091 scv_smart_ptr<T>::scv_smart_ptr(const char * name)
00092   : data_(new T()),
00093     ext_(new scv_extensions<T>()),
00094     tmp_(&*ext_) {
00095   ext_->_set_instance(&*data_);
00096   ext_->set_name(name);
00097   init();  
00098 }
00099 
00100 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(T * data)
00101   : data_(data),
00102     ext_(new scv_extensions<T>()),
00103     tmp_(&*ext_) {
00104   ext_->_set_instance(data);
00105   init();  
00106 }
00107 
00108 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(T * data, const string& name)
00109   : data_(data),
00110     ext_(new scv_extensions<T>()),
00111     tmp_(&*ext_) {
00112   ext_->_set_instance(data);
00113   ext_->set_name(name.c_str());
00114   init();  
00115 }
00116 
00117 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(T * data, const sc_string& name)
00118   : data_(data),
00119     ext_(new scv_extensions<T>()),
00120     tmp_(&*ext_) {
00121   ext_->_set_instance(data);
00122   ext_->set_name(name.c_str());
00123   init();  
00124 }
00125 
00126 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(T * data, const char * name)
00127   : data_(data),
00128     ext_(new scv_extensions<T>()),
00129     tmp_(&*ext_) {
00130   ext_->_set_instance(data);
00131   ext_->set_name(name);
00132   init();  
00133 }
00134 
00135 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(const scv_smart_ptr<T>& rhs) 
00136   : data_(rhs.data_), ext_(rhs.ext_), tmp_(&*ext_) {
00137 }
00138 
00139 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(
00140   scv_shared_ptr<T> data, 
00141   scv_shared_ptr< scv_extensions<T> > ext,
00142   scv_extensions<T> *tmp
00143 ) : data_(data), ext_(ext), tmp_(tmp)
00144 { init(); }
00145 
00146 void _scv_constraint_wrapup(scv_extensions_if* e);
00147 
00148 template <typename T> scv_smart_ptr<T>::~scv_smart_ptr() {
00149 #ifndef _SCV_INTROSPECTION_ONLY
00150   //_scv_constraint_wrapup(&*ext_);
00151 #endif
00152 }
00153 
00154 template <typename T> void scv_smart_ptr<T>::init() {
00155   ext_->_set_dynamic();
00156 #ifndef _SCV_INTROSPECTION_ONLY
00157   ::_scv_insert_smart_ptr(this);
00158 #endif
00159 }
00160 
00161 template <typename T> scv_smart_ptr<T>& 
00162 scv_smart_ptr<T>::operator=(const scv_smart_ptr<T>& rhs) {
00163   data_ = rhs.data_; // shared object
00164   ext_ = rhs.ext_;   // shared extension
00165   tmp_ = rhs.tmp_;
00166   return *this;
00167 }
00168 
00169 template<typename T> scv_extensions<T*>& 
00170 scv_extensions<T*>::operator=(const scv_smart_ptr<T>& rhs) {
00171   *this->_get_instance() = (T*) rhs->_get_instance();
00172   if (rhs->is_dynamic()) {
00173     // share the same extension until the object disapear
00174     // (in practise (but slow), probably need to register
00175     // a deletion callback.
00176     this->_own_typed_ptr = false;
00177     this->_ptr = (scv_extensions<T>*) &*rhs;
00178     this->_typed_ptr = (scv_extensions<T>*) &*rhs;
00179   }
00180   _set_ptr();
00181   this->trigger_value_change_cb();
00182   return *this;
00183 }
00184 
00185 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(scv_shared_ptr<T> data) 
00186   : data_(data), ext_(new scv_extensions<T>()), tmp_(&*ext_) {
00187   _scv_message::message(_scv_message::INTERNAL_ERROR,"scv_smart_ptr(scv_shared_ptr) should not be called.");
00188   ext_->_set_instance(&*data_);
00189   init();
00190 }
00191 
00192 // ----------------------------------------
00193 // special extension class to handle getting an extension from a smart pointer
00194 // ----------------------------------------
00195 template<typename T>
00196 class scv_extensions< scv_smart_ptr<T> > : public scv_extensions<T*> {
00197 public:
00198   scv_extensions() {}
00199   scv_extensions(const scv_extensions<T*>& rhs) : scv_extensions<T*>(rhs) {}
00200   virtual ~scv_extensions() {}
00201   scv_extensions& operator=(const scv_extensions<T*>& rhs) {
00202     return scv_extensions<T*>::operator=(rhs);
00203   }
00204   scv_extensions& operator=(const T * rhs) {
00205     return scv_extensions<T*>::operator=(rhs);
00206   }
00207   operator const T *() const { return *scv_extensions<T*>::_get_instance(); }
00208   scv_expression operator()() { return scv_extensions<T*>::form_expression(); }
00209 
00210   virtual void _set_instance(T ** i) {
00211     scv_extensions<T*>::_set_instance(i);
00212   }  
00213   virtual void _set_instance(scv_smart_ptr<T> * i) {
00214     scv_extensions<T*>::_set_instance(i->get_extension_ptr()->_get_instance());
00215   }  
00216 };

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