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

_scv_ext_util.h

Go to the documentation of this file.
00001 //  -*- C++ -*- <this line is for emacs to recognize it as C++ code>
00002 /*****************************************************************************
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2002 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.3 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   _scv_ext_util -- The implementation for the extension component "util".
00021 
00022   Original Authors (Cadence Design Systems, Inc):
00023   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00024   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey
00025   2002-09-23
00026 
00027  *****************************************************************************/
00028 
00029 /*****************************************************************************
00030 
00031   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00032   changes you are making here.
00033 
00034       Name, Affiliation, Date:
00035   Description of Modification:
00036 
00037  *****************************************************************************/
00038 
00039 #include <stdio.h>
00040 
00041 // ----------------------------------------
00042 // a first class in the hierarchy that contains class variables.
00043 // ----------------------------------------
00044 class _scv_extension_util : public _SCV_INTROSPECTION_BASE {
00045 public:
00046   _scv_extension_util() 
00047     : _data(0), _name(""), _short_name(""), _parent(NULL) {}
00048   virtual ~_scv_extension_util() {
00049     if (_has_dynamic_data()) {
00050       delete _data;
00051     }
00052   }
00053 
00054   // scv_object_if
00055   virtual const char *get_name() const;
00056   virtual const char *kind() const;
00057   virtual void print(ostream& o= scv_out, int details=0, int indent=0) const;
00058   virtual void show(int details=0, int indent=0) const;
00059 
00060   // extension "util"
00061   virtual bool has_valid_extensions() const;
00062   virtual bool is_dynamic() const;
00063   virtual sc_string get_short_name() const;
00064   virtual void set_name(const char * s);
00065   virtual void _set_name(const string& s);
00066 
00067 public: // non-virtual for fast execution
00068   inline void trigger_value_change_cb() {
00069     if (_is_dynamic()) {
00070       this->updated();
00071       this->_get_dynamic_data()
00072   ->execute_callbacks(this, scv_extensions_if::VALUE_CHANGE);
00073     }
00074   }
00075 
00076 protected: // fast version of the introspection interface (non-virtual)
00077   bool _is_dynamic() const { return _data != 0; }
00078 
00079 public: // internal methods (non-virtual for efficiency)
00080   bool _has_dynamic_data() const {
00081     return _data != 0 && _data != (_scv_dynamic_data*) 1;
00082   }
00083   _scv_dynamic_data * _get_dynamic_data();
00084   _scv_dynamic_data * get_dynamic_data();
00085   const _scv_dynamic_data *_get_dynamic_data() const;
00086   void _set_parent(_scv_extension_util *p, const string& name);
00087   const scv_extensions_if *_get_parent() const { return _parent; }
00088 
00089 public: // internal methods (virtual to distinguish basic/record/array)
00090   virtual void _set_dynamic();
00091 
00092 public:
00093   // overloaded 
00094   //   0 : not dynamic
00095   //   1 : capable of dynamic
00096   //   valid-ptr: has dynamic
00097   mutable _scv_dynamic_data *_data; 
00098   string _name;
00099   string _short_name;
00100   scv_extensions_if *_parent;
00101 };
00102 
00103 // ----------------------------------------
00104 // specialization for record
00105 // ----------------------------------------
00106 class _scv_extension_util_record : public _scv_extension_util {
00107 public:
00108   virtual ~_scv_extension_util_record() {}
00109 
00110   // extension "util"
00111   virtual bool has_valid_extensions() const { return false; }
00112   virtual void set_name(const char * s) {
00113     _name = s;
00114     list<_scv_extension_util*>::iterator f;
00115     for (f = _fields.begin(); f != _fields.end(); ++f) {
00116       (*f)->_set_name(_name + "." + (*f)->get_short_name().c_str());
00117     }
00118   }
00119   virtual void _set_name(const string& s) {
00120     _name = s;
00121     list<_scv_extension_util*>::iterator f;
00122     for (f = _fields.begin(); f != _fields.end(); ++f) {
00123       (*f)->_set_name(_name + "." + (*f)->get_short_name().c_str());
00124     }
00125   }
00126 
00127 protected: // fast version of the introspection interface (non-virtual)
00128   int _get_num_fields() const { return _fields.size(); }
00129   _scv_extension_util * _get_field(unsigned i) {
00130   if (i>=_fields.size()) {
00131     _scv_message::message(_scv_message::INTROSPECTION_INVALID_INDEX,i,"composite object",get_name());
00132     return NULL;
00133   }
00134     list<_scv_extension_util*>::iterator f = _fields.begin(); 
00135     while (i--) { ++f; }
00136     return *f;  
00137   }
00138   const _scv_extension_util * _get_field(unsigned i) const { 
00139   if (i>=_fields.size()) {
00140     _scv_message::message(_scv_message::INTROSPECTION_INVALID_INDEX,i,"composite object",get_name());
00141     return NULL;
00142   }
00143     list<_scv_extension_util*>::const_iterator f = _fields.begin(); 
00144     while (i--) { ++f; }
00145     return *f;  
00146   }
00147 
00148 public: // internal methods (non-virtual for efficiency)
00149   void _add_field(_scv_extension_util * f) { _fields.push_back(f); }
00150 
00151 public: // internal methods (virtual to distinguish basic/record/array)
00152   virtual void _set_dynamic() { 
00153     _scv_extension_util::_set_dynamic();
00154     int size = _get_num_fields();
00155     for (int i=0; i<size; ++i) {
00156       _get_field(i)->_set_dynamic();
00157     }
00158   }
00159 
00160 protected:
00161   list<_scv_extension_util*> _fields;
00162 };
00163 
00164 template<typename T>
00165 class scv_extension_util
00166   : public _scv_extension_util_record {
00167 public:
00168   virtual ~scv_extension_util() {}
00169 };
00170 
00171 // ----------------------------------------
00172 // specialization for array
00173 // (added cast of N to "int" since some compilers automatically
00174 // regard it as unsigned even though I have declard it as int)
00175 // ----------------------------------------
00176 template<typename T, int N>
00177 class scv_extension_util<T[N]>
00178   : public _scv_extension_util {
00179 public:
00180   scv_extension_util() : _elts(0) {}
00181   virtual ~scv_extension_util() {
00182     if (_elts) delete[] _elts; 
00183   }
00184 
00185   // extension "util"
00186   virtual void set_name(const char * s) {
00187     _name = s;
00188     for (int i=0; i<(int)N; ++i) {
00189       _elts[i]->_set_name(_name + "[" + _scv_ext_util_get_string(i) + "]");
00190     }
00191   }
00192   virtual void _set_name(const string& s) {
00193     _name = s;
00194     for (int i=0; i<(int)N; ++i) {
00195       _elts[i]->_set_name(_name + "[" + _scv_ext_util_get_string(i) + "]");
00196     }
00197   }
00198 
00199 protected: // fast version of the introspection interface (non-virtual)
00200   inline int _get_array_size() { return N; }
00201   inline _scv_extension_util * _get_array_elt(unsigned i) {
00202     return _elts[i];
00203   }
00204   inline const _scv_extension_util * _get_array_elt(unsigned i) const {
00205     return _elts[i];
00206   }
00207 
00208 public: // internal methods (non-virtual for efficiency)
00209   inline void _set_up_array(_scv_extension_util** elts) { _elts = elts; }
00210 
00211 public: // internal methods (virtual to distinguish basic/record/array)
00212   virtual void _set_dynamic() {
00213     _scv_extension_util::_set_dynamic();
00214     for (int i=0; i<(int)N; ++i) {
00215       _elts[i]->_set_dynamic();
00216     }
00217   }
00218 
00219 protected:
00220   _scv_extension_util** _elts;
00221 };
00222 
00223 // ----------------------------------------
00224 // specialization for pointers
00225 // ----------------------------------------
00226 class _scv_extension_util_ptr : public _scv_extension_util {
00227 public:
00228   _scv_extension_util_ptr() : _ptr(0) {}
00229   virtual ~_scv_extension_util_ptr() {}
00230 
00231 protected: // fast version of the introspection interface (non-virtual)
00232   scv_extensions_if * _get_pointer() { return _ptr; }
00233   const scv_extensions_if * _get_pointer() const { return _ptr; }
00234 
00235 protected:
00236   mutable _scv_extension_util* _ptr;
00237 };
00238 
00239 template<typename T>
00240 class scv_extension_util<T*>
00241   : public _scv_extension_util_ptr {
00242 public:
00243   virtual ~scv_extension_util() {}
00244 };
00245 
00246 // ----------------------------------------
00247 // specialization for enums
00248 // ----------------------------------------
00249 class _scv_extension_util_enum : public _scv_extension_util {
00250 public:
00251   _scv_extension_util_enum() {}
00252   virtual ~_scv_extension_util_enum() {}
00253 
00254 protected: // fast version of the introspection interface (non-virtual)
00255   inline int _get_enum_size() const { return _get_names().size(); }
00256   void _get_enum_details(list<const char *>&, list<int>&) const;
00257   const char * _get_enum_string(int) const;
00258 
00259   virtual list<const char *>& _get_names() const = 0;
00260   virtual list<int>& _get_values() const = 0;
00261 };
00262 
00263 // ----------------------------------------
00264 // specialization for basic types
00265 // ----------------------------------------
00266 #define _SCV_COMPONENT(basic_type)                          \
00267 template<>                                                  \
00268 class scv_extension_util<basic_type>                        \
00269   : public _scv_extension_util {                            \
00270 public:                                                     \
00271   virtual ~scv_extension_util() {}                          \
00272 };                                                          \
00273 
00274 #define _SCV_COMPONENT_1(basic_type)                        \
00275 _SCV_COMPONENT(basic_type)                                  \
00276 
00277 #define _SCV_COMPONENT_N(basic_type)                        \
00278 template<int N>                                             \
00279 class scv_extension_util<basic_type<N> >                    \
00280   : public _scv_extension_util {                            \
00281 public:                                                     \
00282   virtual ~scv_extension_util() {}                          \
00283 };                                                          \
00284 
00285 _SCV_BASIC_TYPE_SPECIALIZATION();
00286 
00287 #undef _SCV_COMPONENT
00288 #undef _SCV_COMPONENT_1
00289 #undef _SCV_COMPONENT_N
00290 
00291 // ----------------------------------------
00292 // wrap up this component
00293 // ----------------------------------------
00294 #undef _SCV_INTROSPECTION_BASE
00295 #define _SCV_INTROSPECTION_BASE scv_extension_util<T>
00296 #undef _SCV_INTROSPECTION_BASE1
00297 #define _SCV_INTROSPECTION_BASE1 scv_extension_util<T*>
00298 #undef _SCV_INTROSPECTION_BASE2
00299 #define _SCV_INTROSPECTION_BASE2 scv_extension_util<T[N]>
00300 
00301 #define _SCV_INTROSPECTION_BASE_ENUM _scv_extension_util_enum

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