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

_scv_ext_callbacks.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_ext_callbacks.h -- The implementation for the extension "callbacks".
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, Samir Agrawal
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 inline static int s_add_callback(_scv_dynamic_data * data,
00041          _scv_dynamic_data::callback_base * c) {
00042   if (!data) { 
00043     _scv_message::message(_scv_message::INTROSPECTION_INVALID_DYNAMIC_EXTENSIONS,"callbacks");
00044     return -1;
00045   }
00046   c->set_id(data->_next_id++);
00047   data->_callbacks.push_back(c);
00048   return c->get_id();
00049 }
00050 
00051 inline static void s_remove_callback(_scv_dynamic_data * data,
00052          scv_extensions_if::callback_h id) {
00053   if(id !=-1) {
00054     if (!data) { 
00055       _scv_message::message(_scv_message::INTROSPECTION_INVALID_DYNAMIC_EXTENSIONS,"callbacks");
00056       return;
00057     }
00058 
00059     list<scv_extensions_if::callback_base*>::iterator i = data->_callbacks.begin();
00060     list<scv_extensions_if::callback_base*>::iterator e = data->_callbacks.end();
00061     while (i != e) {
00062       if ((*i)->get_id() == id) {
00063   data->_callbacks.erase(i);
00064   return;
00065       } else ++i;
00066     }
00067   }
00068   _scv_message::message(_scv_message::INTROSPECTION_BAD_CALLBACK_REMOVAL);
00069 }
00070 
00071 inline static   list<scv_extensions_if::callback_base*>::iterator 
00072 s_select_callback(_scv_dynamic_data * data,
00073          scv_extensions_if::callback_h id) {
00074   if (!data) { 
00075     _scv_message::message(_scv_message::INTROSPECTION_INVALID_DYNAMIC_EXTENSIONS,"callbacks");
00076     return list<scv_extensions_if::callback_base*>::iterator();
00077   }
00078  
00079   list<scv_extensions_if::callback_base*>::iterator i = data->_callbacks.begin();
00080   list<scv_extensions_if::callback_base*>::iterator e = data->_callbacks.end();
00081   while (i != e) {
00082     if ((*i)->get_id() == id) {
00083       return i;
00084     } else ++i;
00085   }
00086   return e;
00087 }
00088 
00089 // ----------------------------------------
00090 // specialization for records
00091 // ----------------------------------------
00092 template<typename T>
00093 class _scv_extension_callbacks_base
00094  : public _SCV_INTROSPECTION_BASE {
00095   // this class also for basic types
00096 public:
00097   _scv_extension_callbacks_base() {}
00098   virtual ~_scv_extension_callbacks_base() {
00099     if (this->_has_dynamic_data() && !this->get_parent())
00100   this->_get_dynamic_data()->execute_callbacks(this, scv_extensions_if::DELETE);
00101   }
00102 
00103   virtual scv_extensions_if::callback_h _register_cb(scv_extensions_if::callback_base * c) {
00104     return s_add_callback(this->_get_dynamic_data(),c); 
00105   }
00106   virtual void remove_cb(scv_extensions_if::callback_h id) { 
00107     s_remove_callback(this->_get_dynamic_data(),id); 
00108   }
00109 
00110   // void trigger_value_change_cb();
00111   // this is implemented as non-virtual in extension "util" for efficiency.
00112 };
00113 
00114 template<typename T>
00115 class scv_extension_callbacks
00116   : public _scv_extension_callbacks_base<T>
00117 {
00118 public:
00119   virtual scv_extensions_if::callback_h _register_cb(scv_extensions_if::callback_base * c) {
00120     int next_id = s_add_callback(this->_get_dynamic_data(),c); 
00121     if (next_id != -1) {
00122       int size = this->get_num_fields();
00123       int * children = new int[size];
00124       for (int i=0; i<size; ++i) {
00125   children[i] = this->get_field(i)->_register_cb(c->duplicate());
00126   c->set_children(children);
00127       }
00128     }
00129     return next_id;
00130   }
00131   virtual void remove_cb(scv_extensions_if::callback_h id) {
00132     if (id != -1) {
00133       list<scv_extensions_if::callback_base*>::iterator iter
00134   = s_select_callback(this->_get_dynamic_data(),id);
00135       int size = this->get_num_fields();
00136       int * children = (*iter)->get_children();
00137       for (int i=0; i<size; ++i) {
00138   this->get_field(i)->remove_cb(children[i]);
00139       }
00140       delete (*iter);
00141       this->_get_dynamic_data()->_callbacks.erase(iter);
00142     }
00143   }
00144 };
00145 
00146 // ----------------------------------------
00147 // specialization for arrays
00148 // (added cast of N to "int" since some compilers automatically
00149 // regard it as unsigned even though I have declard it as int)
00150 // ----------------------------------------
00151 template<typename T, int N>
00152 class scv_extension_callbacks<T[N]>
00153   : public _SCV_INTROSPECTION_BASE2 {
00154 public:
00155   scv_extension_callbacks() {}
00156   virtual ~scv_extension_callbacks() {
00157     if (this->_has_dynamic_data() && !this->get_parent())
00158   this->_get_dynamic_data()->execute_callbacks(this, scv_extensions_if::DELETE);
00159   }
00160 
00161   virtual scv_extensions_if::callback_h _register_cb(scv_extensions_if::callback_base * c) {
00162     int next_id = s_add_callback(this->_get_dynamic_data(),c);
00163     int * children = new int[N];
00164     for (int i=0; i<(int)N; ++i) {
00165       children[i] = this->_get_array_elt(i)->_register_cb(c->duplicate());
00166     }
00167     c->set_children(children);
00168     return next_id;
00169   }
00170   virtual void remove_cb(scv_extensions_if::callback_h id) {
00171     if (id != -1) {
00172       list<scv_extensions_if::callback_base*>::iterator iter
00173   = s_select_callback(this->_get_dynamic_data(),id);
00174       int * children = (*iter)->get_children();
00175       for (int i=0; i<(int)N; ++i) {
00176   this->_get_array_elt(i)->remove_cb(children[i]);
00177       }
00178       delete (*iter);
00179       this->_get_dynamic_data()->_callbacks.erase(iter);
00180     }
00181   }
00182 };
00183 
00184 // ----------------------------------------
00185 // specialization for pointers
00186 // ----------------------------------------
00187 template<typename T>
00188 class scv_extension_callbacks<T*>
00189  : public _SCV_INTROSPECTION_BASE1 {
00190 public:
00191   scv_extension_callbacks() {}
00192   virtual ~scv_extension_callbacks() {
00193     if (this->_has_dynamic_data() && !this->get_parent())
00194   this->_get_dynamic_data()->execute_callbacks(this, scv_extensions_if::DELETE);
00195   }
00196 
00197   virtual scv_extensions_if::callback_h _register_cb(scv_extensions_if::callback_base * c) {
00198     return s_add_callback(this->_get_dynamic_data(),c); 
00199   }
00200   virtual void remove_cb(scv_extensions_if::callback_h id) { 
00201     s_remove_callback(this->_get_dynamic_data(),id); 
00202   }
00203 };
00204 
00205 // ----------------------------------------
00206 // specialization for enums
00207 // ----------------------------------------
00208 class _scv_extension_callbacks_enum
00209   : public _SCV_INTROSPECTION_BASE_ENUM {
00210 public:
00211   _scv_extension_callbacks_enum() {}
00212   virtual ~_scv_extension_callbacks_enum() {
00213     if (this->_has_dynamic_data() && !this->get_parent())
00214   this->_get_dynamic_data()->execute_callbacks(this, scv_extensions_if::DELETE);
00215   }
00216 
00217 public:
00218   virtual scv_extensions_if::callback_h _register_cb(scv_extensions_if::callback_base * c);
00219   virtual void remove_cb(scv_extensions_if::callback_h id);
00220 };
00221 
00222 
00223 
00224 // ----------------------------------------
00225 // specialization for basis types
00226 // ----------------------------------------
00227 #define _SCV_EXT_CALLBACKS_FC_D(basic_type,type_id)                           \
00228 class _scv_extension_callbacks_ ## type_id  \
00229 : public scv_extension_rand<basic_type> {  \
00230 public:  \
00231   _scv_extension_callbacks_ ## type_id();  \
00232   virtual ~_scv_extension_callbacks_ ## type_id();  \
00233   \
00234   virtual scv_extensions_if::callback_h _register_cb(scv_extensions_if::callback_base * c);  \
00235   virtual void remove_cb(scv_extensions_if::callback_h id);  \
00236   \
00237   /* void trigger_value_change_cb(); */  \
00238   /* this is implemented as non-virtual in extension "util" for efficiency. */  \
00239 };  \
00240   \
00241 template<>                                                   \
00242 class scv_extension_callbacks<basic_type>                    \
00243   : public _scv_extension_callbacks_ ## type_id {};     \
00244 
00245 
00246 #define _SCV_EXT_CALLBACKS_FC_1_D(basic_type,type_id)                         \
00247   _SCV_EXT_CALLBACKS_FC_D(basic_type,type_id);
00248 
00249 
00250 #define _SCV_EXT_CALLBACKS_FC_N_D(basic_type)                         \
00251 template<int N>                                              \
00252 class scv_extension_callbacks<basic_type<N> >                \
00253   : public scv_extension_rand<basic_type<N> > {  \
00254 public:  \
00255   scv_extension_callbacks() {}  \
00256   virtual ~scv_extension_callbacks() {  \
00257     if (this->_has_dynamic_data() && !this->get_parent())  \
00258   this->_get_dynamic_data()->execute_callbacks(this, scv_extensions_if::DELETE);  \
00259   }  \
00260   \
00261   virtual scv_extensions_if::callback_h _register_cb(scv_extensions_if::callback_base * c) {  \
00262     return s_add_callback(this->_get_dynamic_data(),c);   \
00263   }  \
00264   virtual void remove_cb(scv_extensions_if::callback_h id) {   \
00265     s_remove_callback(this->_get_dynamic_data(),id);   \
00266   }  \
00267   \
00268   /* void trigger_value_change_cb(); */  \
00269   /* this is implemented as non-virtual in extension "util" for efficiency. */  \
00270 }; \
00271 
00272 
00273 _SCV_EXT_CALLBACKS_FC_D(bool,bool);                   
00274 _SCV_EXT_CALLBACKS_FC_D(char,char);                   
00275 _SCV_EXT_CALLBACKS_FC_D(unsigned char,unsigned_char);   
00276 _SCV_EXT_CALLBACKS_FC_D(short,short);     
00277 _SCV_EXT_CALLBACKS_FC_D(unsigned short,unsigned_short);   
00278 _SCV_EXT_CALLBACKS_FC_D(int,int);     
00279 _SCV_EXT_CALLBACKS_FC_D(unsigned int,unsigned_int);   
00280 _SCV_EXT_CALLBACKS_FC_D(long,long);     
00281 _SCV_EXT_CALLBACKS_FC_D(unsigned long,unsigned_long);   
00282 _SCV_EXT_CALLBACKS_FC_D(long long,long_long);   
00283 _SCV_EXT_CALLBACKS_FC_D(unsigned long long,unsigned_long_long); 
00284 _SCV_EXT_CALLBACKS_FC_D(float,float);     
00285 _SCV_EXT_CALLBACKS_FC_D(double,double);     
00286 _SCV_EXT_CALLBACKS_FC_D(string,string);     
00287 _SCV_EXT_CALLBACKS_FC_N_D(test_uint);   
00288 
00289 
00290 #ifdef SYSTEMC_H
00291 _SCV_EXT_CALLBACKS_FC_D(sc_string,sc_string);   
00292 _SCV_EXT_CALLBACKS_FC_1_D(sc_bit,sc_bit);   
00293 _SCV_EXT_CALLBACKS_FC_1_D(sc_logic,sc_logic);   
00294 _SCV_EXT_CALLBACKS_FC_N_D(sc_int);    
00295 _SCV_EXT_CALLBACKS_FC_N_D(sc_uint);   
00296 _SCV_EXT_CALLBACKS_FC_N_D(sc_bigint);   
00297 _SCV_EXT_CALLBACKS_FC_N_D(sc_biguint);    
00298 _SCV_EXT_CALLBACKS_FC_N_D(sc_bv);   
00299 _SCV_EXT_CALLBACKS_FC_N_D(sc_lv);   
00300 _SCV_EXT_CALLBACKS_FC_D(sc_signed,sc_signed);   
00301 _SCV_EXT_CALLBACKS_FC_D(sc_unsigned,sc_unsigned);   
00302 _SCV_EXT_CALLBACKS_FC_D(sc_int_base,sc_int_base);   
00303 _SCV_EXT_CALLBACKS_FC_D(sc_uint_base,sc_uint_base);   
00304 _SCV_EXT_CALLBACKS_FC_D(sc_lv_base,sc_lv_base);   
00305 _SCV_EXT_CALLBACKS_FC_D(sc_bv_base,sc_bv_base);   
00306 
00307 // SCV_EXT_CALLBACKS_FC_N_D(tag,sc_fixed);           
00308 // SCV_EXT_CALLBACKS_FC_N_D(tag,sc_ufixed);          
00309 #endif
00310 
00311 
00312 
00313 #undef _SCV_EXT_CALLBACKS_FC_D
00314 #undef _SCV_EXT_CALLBACKS_FC_1_D
00315 #undef _SCV_EXT_CALLBACKS_FC_N_D
00316 
00317 
00318 
00319 // ----------------------------------------
00320 // wrap up this component
00321 // ----------------------------------------
00322 #undef _SCV_INTROSPECTION_BASE
00323 #define _SCV_INTROSPECTION_BASE scv_extension_callbacks<T>
00324 #undef _SCV_INTROSPECTION_BASE1
00325 #define _SCV_INTROSPECTION_BASE1 scv_extension_callbacks<T*>
00326 #undef _SCV_INTROSPECTION_BASE2
00327 #define _SCV_INTROSPECTION_BASE2 scv_extension_callbacks<T[N]>
00328 
00329 #undef _SCV_INTROSPECTION_BASE_ENUM
00330 #define _SCV_INTROSPECTION_BASE_ENUM _scv_extension_callbacks_enum

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