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

scv_introspection.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_introspection.h -- 
00021   The public interface for the introspection facility.
00022  
00023   You can use this facility without the other SCV facilities
00024   by using #include "scv/scv_introspection.h" and
00025   -D_SCV_INTROSPECTION_ONLY on your compilation line.
00026  
00027 
00028   Original Authors (Cadence Design Systems, Inc):
00029   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00030   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey, Samir Agrawal
00031   2002-09-23
00032 
00033  *****************************************************************************/
00034 
00035 /*****************************************************************************
00036 
00037   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00038   changes you are making here.
00039 
00040       Name, Affiliation, Date:
00041   Description of Modification:
00042 
00043  *****************************************************************************/
00044 
00045 #ifndef SCV_INTROSPECTION_H
00046 #define SCV_INTROSPECTION_H
00047 
00048 #include "scv/scv_object_if.h"
00049 
00050 // ----------------------------------------
00051 // configuration
00052 //
00053 // some of these to be moved to scv_config.h
00054 // ----------------------------------------
00055 
00056 // compiler configuration
00057 #if defined( __HP_aCC )
00058 #ifndef _INCLUDE_LONGLONG
00059 #define _INCLUDE_LONGLONG
00060 #endif
00061 #endif
00062 
00063 // utilities
00064 #include <assert.h>
00065 #include <list>
00066 #include <string>
00067 
00068 
00069 #if defined(__SUNPRO_CC)
00070 using std::list;
00071 using std::pair;
00072 #include <string>
00073 using std::string;
00074 #endif
00075 
00076 // specific stuff for randomization extensions
00077 template<typename T> class scv_extensions ;
00078 class scv_constraint_base;
00079 class scv_extensions_if;
00080 class scv_smart_ptr_if;
00081 class _scv_constraint_data;
00082 class scv_expression;
00083 
00084 #ifndef _SCV_INTROSPECTION_ONLY
00085 #include "scv/scv_report.h"
00086 #include "scv/scv_bag.h"
00087 #include "scv/scv_random.h"
00088 #else
00089 template<typename T> class scv_bag {};
00090 class scv_random {};
00091 enum scv_severity {
00092   SCV_INFO = 0, // informative only
00093   SCV_WARNING,  // indicates potentially incorrect condition
00094   SCV_ERROR,  // indicates a definite problem
00095   SCV_FATAL // indicates a problem from which we cannot recover
00096 };
00097 class _scv_message_desc {
00098 friend class _scv_message;
00099 private:
00100   _scv_message_desc(string tag, string format, scv_severity severity, unsigned actions)
00101     : _tag(tag), _format(format), _severity(severity), _actions(actions) {}
00102   const char *get_tag() const { return _tag.c_str(); }
00103   const char *get_format() const { return _format.c_str(); }
00104   scv_severity get_severity() const { return _severity; }
00105   unsigned get_actions() const { return _actions; }
00106   string _tag;
00107   string _format;
00108   scv_severity _severity;
00109   unsigned _actions;
00110 };
00111 class _scv_message {
00112 public:
00113   enum severity_level { INFO, WARNING, ERROR, FATAL };
00114 
00115   enum response_level {
00116     NONE_SPECIFIED, ENABLE_MESSAGE, SUPPRESS_MESSAGE
00117   };
00118 
00119   enum stack_print {
00120     NO_STACK, SHORT_STACK, LONG_STACK
00121   };
00122 
00123 // Message types are actually pointers to descriptors
00124 #define _SCV_DEFERR(code, number, string, severity, printStack) \
00125   static _scv_message_desc *code##_base; \
00126   static _scv_message_desc **code;
00127 #include "scv_messages.h"
00128 #undef _SCV_DEFERR
00129 
00130   // Used internally by SystemC Verification Standard to report exceptions
00131   static void message(_scv_message_desc **desc_pp, ... ) { scv_out << "exception received" << endl; }
00132 };
00133 #endif
00134 
00135 // specific stuff for scv_smart_ptr 
00136 #include "scv/scv_shared_ptr.h"
00137 
00138 // ----------------------------------------
00139 // test sc_uint<N> without SystemC
00140 // ----------------------------------------
00141 #define TEST_NEST_TEMPLATE
00142 template<int N>
00143 class test_uint {
00144   int i;
00145 public:
00146   test_uint(int i = 0) : i(i) {}
00147   test_uint(const test_uint& j) : i(j) {}
00148   test_uint& operator=(const test_uint& j) { i = j.i; return *this; }
00149   test_uint& operator=(int j) { i = j; return *this; }
00150   operator int() const { return i; } 
00151   int to_int64() const { return i; }
00152   int to_uint64() const { return i; }
00153 };
00154 
00155 // ----------------------------------------
00156 // core introspection infrastructure
00157 // ----------------------------------------
00158 
00159 // overall interface for the extensions 
00160 class scv_extensions_if;
00161 
00162 #define _SCV_INTROSPECTION_BASE scv_object_if
00163 
00164 // ----------------------------------------
00165 // utilities supporting all extensions
00166 // ----------------------------------------
00167 class scv_extension_util_if : public _SCV_INTROSPECTION_BASE {
00168 public:
00169   // scv_object_if's interface is also available 
00170   //
00171   // const char *get_name() const;
00172   // const char *kind() const;
00173   // void print();
00174   // void show();
00175   //
00176   virtual bool has_valid_extensions() const = 0;
00177   virtual bool is_dynamic() const = 0;
00178   virtual sc_string get_short_name() const = 0;
00179   virtual void set_name(const char *) = 0; // error if performed on fields/array-elts 
00180 };
00181 
00182 #undef _SCV_INTROSPECTION_BASE
00183 #define _SCV_INTROSPECTION_BASE scv_extension_util_if
00184 
00185 // ----------------------------------------
00186 // static extension to extract type information
00187 // ----------------------------------------
00188 class scv_extension_type_if : public _SCV_INTROSPECTION_BASE {
00189 public:
00190   virtual const char *get_type_name() const = 0;
00191 
00192   enum data_type {
00193     BOOLEAN,                       // bool
00194     ENUMERATION,                   // enum
00195     INTEGER,                       // char, short, int, long, long long, sc_int, sc_bigint  
00196     UNSIGNED,                      // unsigned { char, short, int, long, long long }, sc_uint, sc_biguint  
00197     FLOATING_POINT_NUMBER,         // float, double 
00198     BIT_VECTOR,                    // sc_bit, sc_bv
00199     LOGIC_VECTOR,                  // sc_logic, sc_lv
00200     FIXED_POINT_INTEGER,           // sc_fixed
00201     UNSIGNED_FIXED_POINT_INTEGER,  // sc_ufixed
00202     RECORD,                        // struct/class
00203     POINTER,                       // T*
00204     ARRAY,                         // T[N]
00205     STRING                         // string, sc_string
00206   };
00207   virtual data_type get_type() const = 0;
00208 
00209   bool is_bool() const { return get_type() == BOOLEAN; }
00210 
00211   bool is_enum() const { return get_type() == ENUMERATION; }
00212   virtual int get_enum_size() const = 0;
00213   virtual void get_enum_details(list<const char *>&, list<int>&) const = 0;
00214   virtual const char *get_enum_string(int) const = 0;
00215 
00216   bool is_integer() const { return get_type() == INTEGER; }
00217   bool is_unsigned() const { return get_type() == UNSIGNED; }
00218   bool is_bit_vector() const { return get_type() == BIT_VECTOR; }
00219   bool is_logic_vector() const { return get_type() == LOGIC_VECTOR; }
00220   bool is_fixed() const { return get_type() == FIXED_POINT_INTEGER; }
00221   bool is_unsigned_fixed() const { return get_type() == UNSIGNED_FIXED_POINT_INTEGER; }
00222   bool is_floating_point_number() const { return get_type() == FLOATING_POINT_NUMBER; } 
00223 
00224   bool is_record() const { return get_type() == RECORD; }
00225   virtual int get_num_fields() const = 0;
00226   virtual scv_extensions_if *get_field(unsigned) = 0; 
00227   virtual const scv_extensions_if *get_field(unsigned) const = 0; 
00228 
00229   bool is_pointer() const { return get_type() == POINTER; }
00230   virtual scv_extensions_if *get_pointer() = 0;
00231   virtual const scv_extensions_if *get_pointer() const = 0;
00232 
00233   bool is_array() const { return get_type() == ARRAY; }
00234   virtual int get_array_size() const = 0; 
00235   virtual scv_extensions_if *get_array_elt(int) = 0; 
00236   virtual const scv_extensions_if *get_array_elt(int) const = 0;
00237 
00238   bool is_string() const { return get_type() == STRING; }
00239 
00240   virtual int get_bitwidth() const = 0;
00241 
00242   // return non-null if this is a field in a record
00243   // or an element in an array. 
00244   virtual scv_extensions_if *get_parent() = 0;
00245   virtual const scv_extensions_if *get_parent() const = 0;
00246 
00247   // ... more to be added.
00248 };
00249 
00250 #undef _SCV_INTROSPECTION_BASE
00251 #define _SCV_INTROSPECTION_BASE scv_extension_type_if
00252 
00253 // ----------------------------------------
00254 // static extension to read and write to an object, its field, and its array element
00255 // ----------------------------------------
00256 class scv_extension_rw_if : public _SCV_INTROSPECTION_BASE {
00257 public:
00258   virtual void assign(bool) = 0;
00259   virtual void assign(char) = 0;
00260   virtual void assign(unsigned char) = 0;
00261   virtual void assign(short) = 0;
00262   virtual void assign(unsigned short) = 0;
00263   virtual void assign(int) = 0;
00264   virtual void assign(unsigned) = 0;
00265   virtual void assign(long) = 0;
00266   virtual void assign(unsigned long) = 0;
00267   virtual void assign(long long) = 0;
00268   virtual void assign(unsigned long long) = 0;
00269   virtual void assign(float) = 0;
00270   virtual void assign(double) = 0;
00271   virtual void assign(const string&) = 0;
00272   virtual void assign(const sc_string&) = 0;
00273   virtual void assign(const char *) = 0;
00274 
00275   virtual bool get_bool() const = 0;
00276   virtual long long get_integer() const = 0;
00277   virtual unsigned long long get_unsigned() const = 0;
00278   virtual double get_double() const = 0;
00279   virtual sc_string get_string() const = 0;
00280 
00281 #ifdef SYSTEMC_H
00282   virtual void assign(const sc_bv_base& v) = 0;
00283   virtual void get_value(sc_bv_base& v) const = 0;
00284   virtual void assign(const sc_lv_base& v) = 0;
00285   virtual void get_value(sc_lv_base& v) const = 0;
00286 #endif
00287 };
00288 
00289 #undef _SCV_INTROSPECTION_BASE
00290 #define _SCV_INTROSPECTION_BASE scv_extension_rw_if
00291 
00292 class _scv_dynamic_data;
00293 
00294 // ----------------------------------------
00295 // dynamic extension to perform randomization
00296 // ----------------------------------------
00297 class scv_extension_rand_if : public _SCV_INTROSPECTION_BASE {
00298 public:
00299   enum mode_t {
00300     RANDOM,
00301     SCAN,
00302     RANDOM_AVOID_DUPLICATE,
00303     DISTRIBUTION
00304   };
00305 public: 
00306   virtual void next() = 0; 
00307   virtual void disable_randomization() = 0;
00308   virtual void enable_randomization() = 0;
00309   virtual bool is_randomization_enabled() = 0;
00310   virtual void use_constraint(scv_extensions_if*) = 0;
00311   virtual void set_random(scv_shared_ptr<scv_random> gen) = 0;
00312   virtual scv_shared_ptr<scv_random> get_random(void) = 0;
00313   virtual scv_expression form_expression() const = 0;
00314 
00315 public: // implementation (private)
00316   virtual _scv_constraint_data *get_constraint_data() =0;
00317   virtual void get_generator() =0;
00318   virtual void set_constraint(scv_constraint_base*) = 0;
00319   virtual void set_constraint(bool mode=true) = 0;
00320   virtual void set_extension(scv_extensions_if *e = NULL) = 0;
00321   virtual void set_distribution_from(scv_extensions_if*) = 0;
00322   virtual _scv_dynamic_data *get_dynamic_data() = 0;
00323   virtual void updated() = 0;
00324   virtual void uninitialize() = 0;
00325   virtual void initialize() const = 0;
00326   virtual bool is_initialized() const = 0;
00327 };
00328 
00329 #undef _SCV_INTROSPECTION_BASE
00330 #define _SCV_INTROSPECTION_BASE scv_extension_rand_if
00331 
00332 // ----------------------------------------
00333 // dynamic extension to perform value change callback
00334 // ----------------------------------------
00335 class scv_extension_callbacks_if : public _SCV_INTROSPECTION_BASE {
00336 public:
00337   enum callback_reason { VALUE_CHANGE, DELETE };
00338   typedef int callback_h;
00339 
00340 public:
00341   callback_h register_cb(void (*f)(scv_extensions_if&, callback_reason)) {
00342     return _register_cb(new callback_t(f));
00343   }
00344   template<typename arg_t>
00345   callback_h register_cb(void (*f)(scv_extensions_if&, callback_reason, arg_t), arg_t arg) {
00346     return _register_cb(new callback_arg_t<arg_t>(f,arg));
00347   }
00348   virtual void remove_cb(callback_h) = 0;
00349 
00350 public: // internal
00351   class callback_base {
00352     int *_children;
00353     int _id;
00354   public:  
00355     virtual void execute(scv_extensions_if*,callback_reason) = 0;
00356     virtual callback_base *duplicate() const = 0;
00357     callback_base() : _id(0) {} 
00358     virtual ~callback_base() { if (_children) delete[] _children; }
00359     int get_id() { return _id; }
00360     void set_id(int i) { _id = i; }
00361     int *get_children() { return _children; }
00362     void set_children(int *p) { _children = p; }
00363   };
00364   class callback_t : public callback_base {
00365   public:
00366     typedef void (*fcn_t)(scv_extensions_if&, callback_reason);
00367     fcn_t _fcn;
00368     callback_t(fcn_t f) : _fcn(f) {}
00369     virtual void execute(scv_extensions_if*d, callback_reason r) { (*_fcn)(*d,r); }
00370     virtual callback_base *duplicate() const { return new callback_t(_fcn); }
00371   };
00372   template<typename arg_t>
00373   class callback_arg_t : public callback_base {
00374   public:
00375     typedef void (*fcn_t)(scv_extensions_if&, callback_reason, arg_t);
00376     fcn_t _fcn;
00377     arg_t _arg;
00378     callback_arg_t(fcn_t f, arg_t arg) : _fcn(f), _arg(arg) {}
00379     virtual void execute(scv_extensions_if*d, callback_reason r) { (*_fcn)(*d,r,_arg); }
00380     virtual callback_base *duplicate() const { return new callback_arg_t(_fcn, _arg); }
00381   };
00382   virtual callback_h _register_cb(callback_base *) = 0;
00383 };
00384 
00385 #undef _SCV_INTROSPECTION_BASE
00386 #define _SCV_INTROSPECTION_BASE scv_extension_callbacks_if
00387 
00388 // ----------------------------------------
00389 // a thin coordination layer to collect all the extensions
00390 // -- to be updated when a new extension is made available
00391 // ----------------------------------------
00392 
00393 // interface for the overall extensions
00394 class scv_extensions_if : public _SCV_INTROSPECTION_BASE {
00395 public:
00396   static int get_debug();
00397   static void set_debug(int);
00398 };
00399 
00400 #undef _SCV_INTROSPECTION_BASE
00401 #define _SCV_INTROSPECTION_BASE scv_extensions_if
00402 
00403 
00404 #ifndef _SCV_INTROSPECTION_ONLY
00405 #include "scv/scv_expression.h"
00406 #else
00407 class scv_expression_core_base {};
00408 template<typename T>
00409 class scv_expression_core : public scv_expression_core_base { 
00410 public:
00411   scv_expression_core(scv_extensions_if*) {}
00412 };
00413 class scv_expression {
00414 public:
00415   scv_expression() {}
00416   scv_expression(scv_expression_core_base*) {}
00417 };
00418 #endif
00419 
00420 
00421 // implementation details
00422 #include "scv/_scv_ext_comp.h"
00423 
00424 // to be used as base class of your composite type
00425 template<typename T>
00426 class scv_extensions_base : public _SCV_INTROSPECTION_BASE {
00427 public:
00428   virtual ~scv_extensions_base() {}
00429 };
00430 
00431 // to be used as base class of your enum type
00432 template<typename T>
00433 class scv_enum_base : public _SCV_INTROSPECTION_BASE_ENUM {
00434 public:
00435   scv_enum_base() {}
00436   virtual ~scv_enum_base() {
00437     if (this->_has_dynamic_data() && this->_get_dynamic_data()->dist_)
00438       delete _get_distribution();
00439   }
00440   virtual list<const char *>& _get_names() const { static list<const char *> _names; return _names; }
00441   virtual list<int>& _get_values() const { static list<int> _values; return _values; }
00442   virtual int get_bitwidth() const { return 8*sizeof(T); }
00443   T read() const { return (T) _SCV_INTROSPECTION_BASE_ENUM::read(); }
00444   void write(const T rhs) { _SCV_INTROSPECTION_BASE_ENUM::write((int) rhs); }
00445   void _set_instance(T *p) { _SCV_INTROSPECTION_BASE_ENUM::_set_instance((int*)p); }
00446   void _set_as_field(_scv_extension_util_record *parent,
00447          T *p, const string& name) {
00448     _SCV_INTROSPECTION_BASE_ENUM::_set_as_field(parent,(int*)p,name);
00449   }
00450   T *_get_instance() const { return (T*)_instance; }
00451   T *get_instance() {
00452     _scv_message::message(_scv_message::INTROSPECTION_GET_INSTANCE_USAGE);
00453     return (T *) _instance;
00454   }
00455   const T *get_instance() const { return (T*)_instance; }
00456   virtual _scv_distribution<T> *_get_distribution() {         
00457     return (_scv_distribution<T> *) _get_dynamic_data()->dist_;
00458   }                                                                    
00459   void _set_distribution(_scv_distribution<T>* d) {
00460     _scv_distribution<T> * dist = _get_distribution();
00461     _scv_constraint_data * cdata = get_constraint_data();
00462     if (!dist) { 
00463       this->_get_dynamic_data()->dist_ = new _scv_distribution<T>; 
00464       dist = _get_distribution();
00465     } else {
00466       dist->reset_distribution();
00467     }
00468     if (d->dist_) {
00469       dist->set_mode(*d->dist_, cdata, this);
00470     } else if (d->dist_r_) {
00471       dist->set_mode(*d->dist_r_, cdata, this);
00472     } else {
00473       _scv_message::message(_scv_message::INTERNAL_ERROR, "_set_distribution(enum)");
00474     }
00475   }
00476   void set_distribution_from(scv_extensions_if* e) {
00477     _scv_distribution<T> *dist = (_scv_distribution<T>*)
00478       e->get_dynamic_data()->dist_;
00479     _set_distribution(dist);
00480   }
00481   void set_mode(scv_bag<pair<T, T> >& d){               
00482     _reset_keep_only_distribution();                                   
00483     if (!_get_distribution())                                          
00484       _get_dynamic_data()->dist_ = new _scv_distribution<T>;   
00485     _get_distribution()->set_mode(d,this);                             
00486   }                                                                    
00487   void set_mode(scv_bag<T>& d) { 
00488     _reset_keep_only_distribution(); 
00489     if (!_get_distribution())       
00490       _get_dynamic_data()->dist_ = new _scv_distribution<T>;   
00491     _get_distribution()->set_mode(d,this);                             
00492   }                                                                    
00493   void set_mode(scv_extensions_if::mode_t t) {                          
00494     if (!_get_distribution()) 
00495       _get_dynamic_data()->dist_ = new _scv_distribution<T>;  
00496     if (!check_mode(t, this, get_name(), _get_distribution()))   
00497       return;
00498     else 
00499       get_constraint_data()->set_ext_mode(t, 0, 0); 
00500   }
00501   virtual void _reset_bag_distribution() {                             
00502     if (_get_distribution()) 
00503       _get_distribution()->reset_distribution();  
00504   }
00505   virtual void generate_value_() {                                     
00506     if (!_get_distribution()) 
00507       _get_dynamic_data()->dist_ = new _scv_distribution<T>; 
00508     _get_distribution()->generate_value_(this,get_constraint_data()); 
00509     return;                                                            
00510   }                                                                    
00511   void keep_only(const T& value)  {                            
00512     keep_only(value, value);  
00513   }                                                                    
00514   void keep_only(const T& lb, const T& ub) {           
00515     _reset_bag_distribution(); 
00516     _scv_keep_range(this, lb, ub, false); 
00517   }                                                                    
00518   void keep_only(const list<T>& vlist) {                       
00519     _reset_bag_distribution(); 
00520     _scv_keep_range_list_enum(this, vlist, false);
00521   }                                                                    
00522   void keep_out(const T& value){                               
00523     _reset_bag_distribution();
00524     keep_out(value, value); 
00525   }                                                                    
00526   void keep_out(const T& lb, const T& ub) {            
00527     _reset_bag_distribution();  
00528     _scv_keep_range(this, lb, ub, true); 
00529   }                                                                    
00530   void keep_out(const list<T>& vlist) {                        
00531     _reset_bag_distribution(); 
00532     _scv_keep_range_list_enum(this, vlist, true);  
00533   }                                                                    
00534 };
00535 
00536 // to be specialized for user-specified datatype
00537 template<typename T>
00538 class scv_extensions : public scv_extensions_base<T> {
00539 public:
00540   scv_extensions() {
00541     // this class should never be instantiated because
00542     // only specializations of this template is instantiated
00543     _scv_message::message(_scv_message::INTROSPECTION_INVALID_EXTENSIONS);
00544   }
00545 };
00546 
00547 
00548 
00549 #define _SCV_PAREN_OPERATOR(typename)  \
00550   scv_expression operator()() {                                     \
00551     return scv_expression(new scv_expression_core(this));\
00552   }                                                                \
00553 
00554 
00555 
00556 // supporting macros
00557 #define SCV_EXTENSIONS(type_name)                                        \
00558   template<>                                                             \
00559   class scv_extensions<type_name> : public scv_extensions_base<type_name>\
00560 
00561 #define SCV_EXTENSIONS_CTOR(type_name)                                   \
00562   virtual const char *get_type_name() const {                            \
00563     static const char *s = strdup(#type_name);                           \
00564     return s;                                                            \
00565   }                                                                      \
00566   scv_extensions() { _set_instance(NULL); }                              \
00567   scv_extensions(const scv_extensions& rhs) {                            \
00568     _set_instance(NULL);                                                 \
00569     _set_instance((type_name*)rhs._get_instance());                      \
00570   }                                                                      \
00571   virtual ~scv_extensions() {}                                           \
00572   scv_extensions& operator=(const scv_extensions& rhs) {                 \
00573     write(*rhs._get_instance()); return *this;                           \
00574   }                                                                      \
00575   scv_extensions& operator=(const type_name& rhs) {                      \
00576     write(rhs); return *this;                                            \
00577   }                                                                      \
00578   operator const type_name&() const { return *(type_name*)_get_instance(); } \
00579   _SCV_PAREN_OPERATOR(typename);                                         \
00580   virtual void _set_instance_core_wrap(void *p) { _set_instance_core((type_name*)p); } \
00581   void _set_instance_core(type_name *_scv_object_with_introspection) \
00582 
00583 #define SCV_FIELD(field_name)                                            \
00584   string field_name ## _name = #field_name;                       \
00585   field_name._set_as_field(this,_scv_object_with_introspection?(&_scv_object_with_introspection->field_name):0,field_name ## _name);   \
00586 
00587 #define SCV_EXTENSIONS_BASE_CLASS(class_name) \
00588   scv_extensions<class_name>::_set_instance_core(_scv_object_with_introspection); \
00589 
00590 #define SCV_ENUM_EXTENSIONS(type_name)                                   \
00591   template<>                                                             \
00592   class scv_extensions<type_name> : public scv_enum_base<type_name>      \
00593 
00594 #define SCV_ENUM_CTOR(type_name)                                         \
00595   virtual const char *get_type_name() const {                           \
00596     static const char *s = strdup(#type_name);                           \
00597     return s;                                                            \
00598   }                                                                      \
00599   scv_extensions() { static bool dummy = _init(); if (0) cout << dummy;} \
00600   scv_extensions(const scv_extensions& rhs) {                            \
00601     _set_instance(rhs._get_instance());                                  \
00602   }                                                                      \
00603   virtual ~scv_extensions() {}                                           \
00604   scv_extensions& operator=(const scv_extensions& rhs) {                 \
00605     write(*rhs._get_instance()); return *this;                           \
00606   }                                                                      \
00607   scv_extensions& operator=(type_name rhs) {                             \
00608     write(rhs); return *this;                                            \
00609   }                                                                      \
00610   operator type_name() const { return *(type_name*)_get_instance(); }    \
00611   _SCV_PAREN_OPERATOR(typename);                                         \
00612   bool _init() { __init(); return true; }                                \
00613   void __init()                                                          \
00614 
00615 #define SCV_ENUM(element_name)                                           \
00616   _set_enum((int)element_name,#element_name);                            \
00617 
00618 
00619 // convenient functions for extensions 
00620 #if !defined( __HP_aCC )
00621 template<typename T>
00622 ostream& operator<<(ostream& os, const scv_extensions<T>& data) {
00623   os << *data._get_instance(); return os;
00624 }
00625 #endif
00626 
00627 // implementation details
00628 #include "scv/_scv_introspection.h"
00629 
00630 // ----------------------------------------
00631 // various access interface to access an extension object
00632 //
00633 // scv_get_const_extensions is there to get around HP ambituous
00634 // overloaded function call problem.
00635 // ----------------------------------------
00636 template <typename T>
00637 scv_extensions<T> scv_get_extensions(T& d);
00638 
00639 template <typename T>
00640 const scv_extensions<T> scv_get_const_extensions(const T& d);
00641 
00642 // ----------------------------------------
00643 // the scv_smart_ptr template
00644 // ----------------------------------------
00645 class scv_smart_ptr_if : public scv_object_if {
00646 public:
00647   virtual scv_extensions_if *get_extensions_ptr() = 0;
00648   virtual const scv_extensions_if *get_extensions_ptr() const = 0;
00649 };
00650 
00651 template <typename T>
00652 class scv_smart_ptr : public scv_smart_ptr_if {
00653 public:
00654   scv_extensions<T>& operator*() { return *tmp_; }
00655   const scv_extensions<T>& operator*() const { return *tmp_; }
00656   scv_extensions<T> *operator->() { return tmp_; }
00657   const scv_extensions<T> *operator->() const { return tmp_; }
00658   scv_expression operator()() { return (*tmp_)(); }
00659   const T& read() const { tmp_->initialize(); return *data_; }
00660   void write(const T& rhs) { *tmp_ = rhs; }
00661 
00662 public:
00663   scv_smart_ptr();
00664   scv_smart_ptr(const string& name);
00665   scv_smart_ptr(const sc_string& name);
00666   scv_smart_ptr(const char *name);
00667   scv_smart_ptr(T *data);
00668   scv_smart_ptr(T *data, const string& name);
00669   scv_smart_ptr(T *data, const sc_string& name);
00670   scv_smart_ptr(T *data, const char *name);
00671   scv_smart_ptr(const scv_smart_ptr<T>& rhs); 
00672   scv_smart_ptr(
00673     scv_shared_ptr<T> data,
00674     scv_shared_ptr< scv_extensions<T> > ext,
00675     scv_extensions<T> *tmp
00676   );
00677   virtual ~scv_smart_ptr();
00678 
00679 public:
00680   template<typename T2>
00681   operator scv_smart_ptr<T2> () { return scv_smart_ptr<T2>(data_,ext_,tmp_); }
00682 
00683 public:
00684   virtual scv_extensions_if *get_extensions_ptr() { return tmp_; }
00685   virtual const scv_extensions_if *get_extensions_ptr() const { return tmp_; }
00686 
00687 public:
00688   scv_smart_ptr& operator=(const scv_smart_ptr& rhs);
00689 
00690 public:
00691   virtual const char *get_name() const { return tmp_->get_name(); }
00692   virtual const char *kind() const { return tmp_->kind(); }
00693 
00694   virtual void print(ostream& o=scv_out, int details=0, int indent=0) const {
00695     tmp_->print(o,details,indent);
00696   }
00697   virtual void show(int details=0, int indent=0) const {
00698     tmp_->show(details,indent);
00699   }
00700 
00701 public: // private
00702   const T *get_value() const { return &*data_; }
00703   T *get_value() { return &*data_; }
00704 
00705 private:
00706   scv_smart_ptr(scv_shared_ptr<T> data);
00707   scv_shared_ptr<T> data_;
00708   scv_shared_ptr< scv_extensions<T> > ext_;
00709   scv_extensions<T> *tmp_;
00710 
00711   friend class scv_constraint_base;
00712   void init();
00713 };
00714 
00715 // implementation details
00716 #include "scv/_scv_smart_ptr.h"
00717 
00718 #endif

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