00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 const string& _scv_get_name(scv_constraint_base*);
00041
00042 #ifndef _SCV_INTROSPECTION_ONLY
00043 #include "scv/_scv_randomization.h"
00044 #else
00045 #define GET_RANDOM()
00046 class _scv_constraint_data {
00047 public:
00048 void set_random(scv_shared_ptr<scv_random>) {}
00049 scv_shared_ptr<scv_random> get_random() const { return scv_shared_ptr<scv_random>(); }
00050 };
00051 template<typename T> class _scv_distribution {};
00052 #endif
00053
00054 void _scv_constraint_wrapup(scv_extensions_if* e);
00055
00056
00057
00058
00059 class _scv_extension_rand_enum
00060 : public _SCV_INTROSPECTION_BASE_ENUM {
00061 public:
00062 _scv_extension_rand_enum() {}
00063 virtual ~_scv_extension_rand_enum() {
00064 if (this->_has_dynamic_data() && this->_get_dynamic_data()->cdata_) {
00065 if (this->_get_dynamic_data()->cdata_->get_constraint()) {
00066 _scv_constraint_wrapup(this);
00067 }
00068 delete this->_get_dynamic_data()->cdata_;
00069 }
00070 }
00071 virtual void next();
00072 virtual void disable_randomization();
00073 virtual void enable_randomization();
00074 virtual bool is_randomization_enabled();
00075 virtual void set_random(scv_shared_ptr<scv_random> gen);
00076 virtual scv_shared_ptr<scv_random> get_random(void);
00077 virtual scv_expression form_expression() const;
00078 virtual void use_constraint(scv_smart_ptr_if& s);
00079 virtual void use_constraint(scv_extensions_if* e);
00080 void reset_distribution();
00081 public:
00082 virtual void uninitialize();
00083 virtual void initialize() const;
00084 virtual void updated();
00085 virtual void set_constraint(scv_constraint_base* c);
00086 virtual void set_constraint(bool mode);
00087 virtual void set_extension(scv_extensions_if * e = NULL);
00088 virtual bool is_initialized() const;
00089 virtual void generate_value_() = 0;
00090 virtual void _reset_bag_distribution() = 0;
00091 virtual _scv_constraint_data* get_constraint_data();
00092 virtual void get_generator(void);
00093 #ifndef _SCV_INTROSPECTION_ONLY
00094 void set_value_mode(_scv_constraint_data::gen_mode m);
00095 #endif
00096 protected:
00097 void _reset_keep_only_distribution();
00098 };
00099
00100 #ifndef _SCV_INTROSPECTION_ONLY
00101 inline _scv_constraint_data* _get_constraint_data_enum(_scv_extension_rand_enum* data)
00102 {
00103 return data->get_constraint_data();
00104 }
00105
00106 inline void _set_mode_enum(_scv_extension_rand_enum* data, _scv_constraint_data::gen_mode m)
00107 {
00108 data->set_value_mode(m);
00109 }
00110
00111 inline scv_shared_ptr<scv_random> _get_random_enum(_scv_extension_rand_enum* data)
00112 {
00113 return data->get_constraint_data()->get_random(data);
00114 }
00115
00116 bool _scv_has_complex_constraint(scv_extensions_if*);
00117 void _scv_set_constraint(scv_extensions_if* s, bool mode);
00118 #endif
00119
00120 #ifndef _SCV_INTROSPECTION_ONLY
00121 void _scv_use_constraint(scv_extensions_if* to, scv_extensions_if* e);
00122 scv_extensions_if* _scv_get_extension(scv_smart_ptr_if& s);
00123 #else
00124 inline void _scv_use_constraint(scv_extensions_if* to, scv_extensions_if* e) {}
00125 inline scv_extensions_if* _scv_get_extension(scv_smart_ptr_if& s) { return 0; }
00126 #endif
00127
00128
00129
00130
00131 template<typename T>
00132 class scv_extension_rand
00133 : public _SCV_INTROSPECTION_BASE {
00134 public:
00135 virtual ~scv_extension_rand() {
00136 #ifndef _SCV_INTROSPECTION_ONLY
00137 if (this->_has_dynamic_data() &&
00138 this->_get_dynamic_data()->cdata_) {
00139 delete this->_get_dynamic_data()->cdata_;
00140 }
00141 #endif
00142 }
00143 virtual void set_distribution_from(scv_extensions_if* e) {
00144 int size = this->_get_num_fields();
00145 for (int i=0; i<size; ++i) {
00146 this->_get_field(i)->set_distribution_from(e);
00147 }
00148 }
00149 virtual void next() { GET_RANDOM(); uninitialize(); initialize(); }
00150 virtual void uninitialize() {
00151 if (this->_get_dynamic_data()->disable_randomization_ == true) return ;
00152 int size = this->_get_num_fields();
00153 for (int i=0; i<size; ++i) {
00154 this->_get_field(i)->uninitialize();
00155 }
00156 #ifndef _SCV_INTROSPECTION_ONLY
00157 if (get_constraint_data()->get_mode() == _scv_constraint_data::EXTENSION) {
00158 get_constraint_data()->get_extension()->uninitialize();
00159 }
00160 #endif
00161 }
00162 virtual void initialize() const {
00163 if (this->_is_dynamic()) {
00164 int size = this->_get_num_fields();
00165 for (int i=0; i<size; ++i) {
00166 this->_get_field(i)->initialize();
00167 }
00168 }
00169 };
00170 virtual void disable_randomization() {
00171 _SCV_CHECK_DYNAMIC(enable_randomization,return);
00172 this->_get_dynamic_data()->disable_randomization_ = true;
00173 int size = this->_get_num_fields();
00174 for (int i=0; i<size; ++i) {
00175 this->_get_field(i)->disable_randomization();
00176 }
00177 }
00178 virtual void enable_randomization() {
00179 _SCV_CHECK_DYNAMIC(enable_randomization,return);
00180 this->_get_dynamic_data()->disable_randomization_ = false;
00181 int size = this->_get_num_fields();
00182 for (int i=0; i<size; ++i) {
00183 this->_get_field(i)->enable_randomization();
00184 }
00185 uninitialize();
00186 }
00187 virtual bool is_randomization_enabled() {
00188 if (!this->_is_dynamic()) return false;
00189 int size = this->_get_num_fields();
00190 for (int i=0; i<size; ++i) {
00191 if (this->_get_field(i)->is_randomization_enabled())
00192 return true;
00193 }
00194 if (this->_has_dynamic_data()) {
00195 return !this->_get_dynamic_data()->disable_randomization_;
00196 }
00197 return false;
00198 }
00199 virtual void updated() {
00200 int size = this->_get_num_fields();
00201 for (int i=0; i<size; ++i) {
00202 this->_get_field(i)->updated();
00203 }
00204 }
00205 virtual void set_constraint(scv_constraint_base* c) {
00206 int size = this->_get_num_fields();
00207 for (int i=0; i<size; ++i) {
00208 this->_get_field(i)->set_constraint(c);
00209 }
00210 #ifndef _SCV_INTROSPECTION_ONLY
00211 get_constraint_data()->set_constraint(c);
00212 #endif
00213 }
00214 virtual void set_constraint(bool mode) {
00215 #ifndef _SCV_INTROSPECTION_ONLY
00216 _scv_set_constraint(this, mode);
00217 #endif
00218 }
00219 virtual void set_extension(scv_extensions_if * e = NULL) {
00220 #ifndef _SCV_INTROSPECTION_ONLY
00221 get_constraint_data()->set_extension(e);
00222 get_constraint_data()->set_mode(_scv_constraint_data::EXTENSION);
00223 int size = this->_get_num_fields();
00224 for (int i=0; i<size; ++i) {
00225 this->_get_field(i)->set_extension(e->get_field(i));
00226 }
00227 #endif
00228 }
00229 virtual void set_random(scv_shared_ptr<scv_random> gen) {
00230 get_constraint_data()->set_random(gen);
00231
00232 int size = this->_get_num_fields();
00233 for (int i=0; i<size; ++i) {
00234 this->_get_field(i)->set_random(gen);
00235 }
00236 }
00237 virtual scv_shared_ptr<scv_random> get_random(void) {
00238 #ifndef _SCV_INTROSPECTION_ONLY
00239 return get_constraint_data()->get_random(this);
00240 #else
00241 return scv_shared_ptr<scv_random>();
00242 #endif
00243 }
00244 virtual bool is_initialized() const {
00245 if (this->_has_dynamic_data()) return !this->_get_dynamic_data()->undefined_;
00246 return !this->_is_dynamic();
00247 }
00248 virtual scv_expression form_expression() const {
00249 _scv_message::message(_scv_message::INTROSPECTION_INVALID_EXPRESSION,"composite object",this->get_name());
00250 return scv_expression();
00251 }
00252 void use_constraint(scv_smart_ptr_if& s) {
00253 use_constraint(_scv_get_extension(s));
00254 }
00255 virtual void use_constraint(scv_extensions_if* e) {
00256 _scv_use_constraint(this, e);
00257 return;
00258 }
00259 virtual _scv_constraint_data * get_constraint_data() {
00260 if (!this->_get_dynamic_data()->cdata_)
00261 this->_get_dynamic_data()->cdata_ = new _scv_constraint_data;
00262 return this->_get_dynamic_data()->cdata_;
00263 }
00264 virtual void get_generator(void) {
00265 _scv_message::message(_scv_message::INTERNAL_ERROR,"cannot call get_generator for composite object");
00266 return;
00267 }
00268 };
00269
00270
00271
00272
00273
00274
00275 template<typename T, int N>
00276 class scv_extension_rand<T[N]>
00277 : public _SCV_INTROSPECTION_BASE2 {
00278 public:
00279 scv_extension_rand() {}
00280 virtual ~scv_extension_rand() {
00281 if (this->_has_dynamic_data() && this->_get_dynamic_data()->cdata_)
00282 delete this->_get_dynamic_data()->cdata_;
00283 }
00284
00285 public:
00286 virtual void next() { GET_RANDOM(); uninitialize(); initialize(); }
00287 virtual void set_distribution_from(scv_extensions_if* e) {
00288 for (int i=0; i<(int)N; ++i) {
00289 this->_get_array_elt(i)->set_distribution_from(e);
00290 }
00291 }
00292 virtual void disable_randomization() {
00293 for (int i=0; i<(int)N; ++i) {
00294 this->_get_array_elt(i)->disable_randomization();
00295 }
00296 }
00297 virtual void enable_randomization() {
00298 for (int i=0; i<(int)N; ++i) {
00299 this->_get_array_elt(i)->enable_randomization();
00300 }
00301 }
00302 virtual bool is_randomization_enabled() {
00303 for (int i=0; i<(int)N; ++i) {
00304 if (this->_get_array_elt(i)->is_randomization_enabled())
00305 return true;
00306 }
00307 return false;
00308 }
00309 virtual void set_random(scv_shared_ptr<scv_random> r) {
00310 _SCV_CHECK_DYNAMIC(set_random,return);
00311 get_constraint_data()->set_random(r);
00312 for (int i=0; i<(int)N; ++i) {
00313 this->_get_array_elt(i)->set_random(r);
00314 }
00315 }
00316 virtual scv_shared_ptr<scv_random> get_random(void){
00317 _SCV_CHECK_DYNAMIC(set_random,return scv_shared_ptr<scv_random>());
00318 return get_constraint_data()->get_random(this);
00319 }
00320 virtual void get_generator(void) {
00321 _scv_message::message(_scv_message::INTERNAL_ERROR,"Cannot do get_generator for array type.");
00322 return;
00323 }
00324 virtual _scv_constraint_data * get_constraint_data() {
00325 if (!this->_get_dynamic_data()->cdata_)
00326 this->_get_dynamic_data()->cdata_ = new _scv_constraint_data;
00327 return this->_get_dynamic_data()->cdata_;
00328 }
00329 virtual scv_expression form_expression() const {
00330 _scv_message::message(_scv_message::INTROSPECTION_INVALID_EXPRESSION,"array",this->get_name());
00331 return scv_expression();
00332 }
00333 virtual void use_constraint(scv_smart_ptr_if& s) {
00334 _scv_message::message(_scv_message::INTERNAL_ERROR,"Cannot set constraint to array type.");
00335 }
00336 virtual void use_constraint(scv_extensions_if*) {
00337 _scv_message::message(_scv_message::INTERNAL_ERROR,"Cannot set constraint to array type.");
00338 }
00339
00340 public:
00341 virtual void uninitialize() {
00342 for (int i=0; i<(int)N; ++i) {
00343 this->_get_array_elt(i)->uninitialize();
00344 }
00345 }
00346 virtual void initialize() const {
00347 for (int i=0; i<(int)N; ++i) {
00348 this->_get_array_elt(i)->initialize();
00349 }
00350 }
00351 virtual bool is_initialized() const {
00352 for (int i=0; i<(int)N; ++i) {
00353 if (!this->_get_array_elt(i)->is_initialized()) return false;
00354 }
00355 return true;
00356 }
00357 virtual void updated() {
00358 for (int i=0; i<(int)N; ++i) {
00359 this->_get_array_elt(i)->updated();
00360 }
00361 }
00362 virtual void set_constraint(scv_constraint_base* c) {
00363 for (int i=0; i<(int)N; ++i) {
00364 this->_get_array_elt(i)->set_constraint(c);
00365 }
00366 get_constraint_data()->set_constraint(c);
00367 }
00368 virtual void set_constraint(bool mode) {
00369 #ifndef _SCV_INTROSPECTION_ONLY
00370 _scv_set_constraint(this, mode);
00371 #endif
00372 }
00373 virtual void set_extension(scv_extensions_if* e) {
00374 get_constraint_data()->set_extension(e);
00375 get_constraint_data()->set_mode(_scv_constraint_data::EXTENSION);
00376 for (int i=0; i<(int)N; ++i) {
00377 this->_get_array_elt(i)->set_extension(e->get_array_elt(i));
00378 }
00379 }
00380 };
00381
00382
00383
00384
00385 template<typename T>
00386 class scv_extension_rand<T*>
00387 : public _SCV_INTROSPECTION_BASE1 {
00388 public:
00389 virtual scv_shared_ptr<scv_random> get_random(void){
00390 #ifndef _SCV_INTROSPECTION_ONLY
00391 _SCV_CHECK_DYNAMIC(get_random,return scv_shared_ptr<scv_random>());
00392 return get_constraint_data()->get_random(this);
00393 #endif
00394 }
00395 virtual bool is_randomization_enabled() {
00396 return false;
00397 }
00398 virtual scv_expression form_expression() const {
00399 _scv_message::message(_scv_message::INTROSPECTION_INVALID_EXPRESSION,"pointer",this->get_name());
00400 return scv_expression();
00401 }
00402 virtual void set_constraint(scv_constraint_base*) {
00403
00404 }
00405 virtual void set_constraint(bool mode) {
00406 }
00407 virtual void set_extension(scv_extensions_if*) {
00408 _scv_message::message(_scv_message::INTERNAL_ERROR,"Cannot set constraint to pointer type.");
00409 }
00410 void use_constraint(scv_smart_ptr_if& s) {
00411 _scv_message::message(_scv_message::INTERNAL_ERROR,"Cannot use constraint from pointer type.");
00412 }
00413 virtual void use_constraint(scv_extensions_if*) {
00414 _scv_message::message(_scv_message::INTERNAL_ERROR,"Cannot use constraint from pointer type.");
00415 }
00416 virtual void set_random(scv_shared_ptr<scv_random>r) {
00417 _SCV_CHECK_DYNAMIC(set_random,return);
00418 get_constraint_data()->set_random(r);
00419 }
00420
00421 virtual _scv_constraint_data * get_constraint_data() {
00422 if (!this->_get_dynamic_data()->cdata_)
00423 this->_get_dynamic_data()->cdata_ = new _scv_constraint_data;
00424 return this->_get_dynamic_data()->cdata_;
00425 }
00426
00427 virtual void get_generator(void) {
00428 _scv_message::message(_scv_message::INTERNAL_ERROR, "cannot call get_generator for pointer types");
00429 return;
00430 }
00431 virtual void set_distribution_from(scv_extensions_if* e) {}
00432 public:
00433 virtual void disable_randomization() {}
00434 virtual void enable_randomization() {}
00435 virtual void next() { uninitialize(); initialize(); }
00436 virtual void uninitialize() {}
00437 virtual void initialize() const {}
00438 virtual bool is_initialized() const { return true; }
00439 virtual void updated() {}
00440 };
00441
00442
00443
00444
00445
00446
00447
00448 #ifndef _SCV_INTROSPECTION_ONLY
00449 #define _SCV_EXT_RAND_FC_EXTRA_D(T, type_id) \
00450 void set_value_mode(_scv_constraint_data::gen_mode m); \
00451 void keep_only(const T& value); \
00452 void keep_only(const T& lb, const T& ub); \
00453 void keep_only(const list<T>& vlist); \
00454 \
00455 void keep_out(const T& value); \
00456 void keep_out(const T& lb, const T& ub); \
00457 void keep_out(const list<T>& vlist); \
00458 _scv_distribution<T> * _get_distribution(); \
00459 void _set_distribution(_scv_distribution<T>*); \
00460 virtual ~_scv_extension_rand_ ## type_id(); \
00461 void set_mode(scv_extensions_if::mode_t t); \
00462 void set_mode(scv_bag<pair<T, T> >& d); \
00463 void set_mode(scv_bag<T>& d); \
00464 void reset_distribution(); \
00465 scv_extensions_if::mode_t get_mode(void); \
00466 protected: \
00467 void _reset_bag_distribution(); \
00468 void _reset_keep_only_distribution(); \
00469
00470 #else
00471 #define _SCV_EXT_RAND_FC_EXTRA_D(T, type_id)
00472 #endif
00473
00474
00475 #define _SCV_EXT_RAND_FC_D(T, type_id) \
00476 class _scv_extension_rand_ ## type_id \
00477 : public scv_extension_rw<T> { \
00478 public: \
00479 virtual void next(); \
00480 virtual void uninitialize(); \
00481 virtual void initialize() const; \
00482 public: \
00483 virtual void disable_randomization(); \
00484 virtual void enable_randomization(); \
00485 virtual bool is_randomization_enabled(); \
00486 virtual scv_expression form_expression() const; \
00487 virtual void updated(); \
00488 virtual bool is_initialized() const; \
00489 virtual void set_random(scv_shared_ptr<scv_random> gen); \
00490 virtual scv_shared_ptr<scv_random> get_random(void); \
00491 void use_constraint(scv_smart_ptr_if& s); \
00492 virtual void use_constraint(scv_extensions_if* e); \
00493 virtual void set_constraint(scv_constraint_base* c); \
00494 virtual void set_constraint(bool mode); \
00495 virtual void set_extension(scv_extensions_if * e = NULL); \
00496 \
00497 virtual _scv_constraint_data * get_constraint_data(); \
00498 virtual void set_distribution_from(scv_extensions_if* e); \
00499 virtual void get_generator(void); \
00500 _scv_extension_rand_ ## type_id(); \
00501 virtual void generate_value_(); \
00502 _SCV_EXT_RAND_FC_EXTRA_D(T, type_id) \
00503 }; \
00504 \
00505 template<> \
00506 class scv_extension_rand<T> \
00507 : public _scv_extension_rand_ ## type_id {}; \
00508
00509
00510 #define _SCV_EXT_RAND_FC_1_D(basic_type,type_id) \
00511 _SCV_EXT_RAND_FC_D(basic_type,type_id) \
00512
00513
00514 #define _SCV_EXT_RAND_FC_D_D(T, type_id) \
00515 class _scv_extension_rand_ ## type_id \
00516 : public scv_extension_rw<T> { \
00517 public: \
00518 virtual void next(); \
00519 virtual void uninitialize(); \
00520 virtual void initialize() const; \
00521 public: \
00522 virtual void disable_randomization(); \
00523 virtual void enable_randomization(); \
00524 virtual bool is_randomization_enabled(); \
00525 virtual scv_expression form_expression() const; \
00526 virtual void updated(); \
00527 virtual bool is_initialized() const; \
00528 virtual void set_random(scv_shared_ptr<scv_random> gen); \
00529 virtual scv_shared_ptr<scv_random> get_random(void); \
00530 void use_constraint(scv_smart_ptr_if& s); \
00531 virtual void use_constraint(scv_extensions_if* e); \
00532 virtual void set_constraint(scv_constraint_base* c); \
00533 virtual void set_constraint(bool mode); \
00534 virtual void set_extension(scv_extensions_if * e = NULL); \
00535 \
00536 virtual _scv_constraint_data * get_constraint_data(); \
00537 virtual void get_generator(void); \
00538 _scv_extension_rand_ ## type_id(); \
00539 virtual void generate_value_(); \
00540 virtual void set_distribution_from(scv_extensions_if* e); \
00541 _SCV_EXT_RAND_FC_EXTRA_D(T, type_id) \
00542 }; \
00543 \
00544 template<> \
00545 class scv_extension_rand<T> \
00546 : public _scv_extension_rand_ ## type_id {}; \
00547
00548
00549
00550
00551
00552 template<typename T>
00553 class _scv_extension_rand_N
00554 : public scv_extension_rw<T> {
00555 public:
00556 virtual void next() { uninitialize(); initialize(); }
00557 virtual void uninitialize() {
00558 assert(this->_is_dynamic());
00559 if (this->_get_dynamic_data()->disable_randomization_ == true) return ;
00560 this->_get_dynamic_data()->undefined_ = true;
00561 #ifndef _SCV_INTROSPECTION_ONLY
00562 if (get_constraint_data()->get_mode() == _scv_constraint_data::EXTENSION) {
00563 get_constraint_data()->get_extension()->uninitialize();
00564 }
00565 #endif
00566 }
00567 virtual void initialize() const {
00568 if (this->_is_dynamic() && this->_get_dynamic_data()->undefined_) {
00569 const_cast<_scv_extension_rand_N*>(this)->generate_value_();
00570 const_cast<_scv_extension_rand_N*>(this)->_get_dynamic_data()->undefined_ = false;
00571 }
00572 };
00573 public:
00574 virtual void disable_randomization() {
00575 assert(this->_is_dynamic());
00576 this->_get_dynamic_data()->disable_randomization_ = true;
00577 }
00578 virtual void enable_randomization() {
00579 assert(this->_is_dynamic());
00580 this->_get_dynamic_data()->disable_randomization_ = false;
00581 uninitialize();
00582 }
00583 virtual bool is_randomization_enabled() {
00584 if (!this->_is_dynamic()) return false;
00585 if (this->_has_dynamic_data()) return !this->_get_dynamic_data()->disable_randomization_;
00586 return true;
00587 }
00588 virtual scv_expression form_expression() const {
00589 return scv_expression(new scv_expression_core((scv_extensions_if*)(this)));
00590 }
00591 virtual void updated() {
00592 this->_get_dynamic_data()->undefined_ = false;
00593 }
00594 virtual bool is_initialized() const {
00595 return !this->_get_dynamic_data()->undefined_;
00596 }
00597 virtual void set_random(scv_shared_ptr<scv_random> gen) {
00598 get_constraint_data()->set_random(gen);
00599 }
00600 virtual scv_shared_ptr<scv_random> get_random(void) {
00601 #ifndef _SCV_INTROSPECTION_ONLY
00602 return get_constraint_data()->get_random(this);
00603 #endif
00604 }
00605 void use_constraint(scv_smart_ptr_if& s) {
00606 use_constraint(_scv_get_extension(s));
00607 }
00608 virtual void use_constraint(scv_extensions_if* e) {
00609 _scv_use_constraint(this, e);
00610 return;
00611 }
00612 virtual void set_constraint(scv_constraint_base* c) {
00613 #ifndef _SCV_INTROSPECTION_ONLY
00614 get_constraint_data()->set_constraint(c);
00615 #endif
00616 }
00617 virtual void set_constraint(bool mode) {
00618 #ifndef _SCV_INTROSPECTION_ONLY
00619 _scv_set_constraint(this, mode);
00620 #endif
00621 }
00622 virtual void set_extension(scv_extensions_if * e = NULL) {
00623 #ifndef _SCV_INTROSPECTION_ONLY
00624 get_constraint_data()->set_extension(e);
00625 get_constraint_data()->set_mode(_scv_constraint_data::EXTENSION);
00626 #endif
00627 }
00628
00629 #ifndef _SCV_INTROSPECTION_ONLY
00630 void set_value_mode(_scv_constraint_data::gen_mode m) {
00631 get_constraint_data()->set_mode(m);
00632 if (m == _scv_constraint_data::DISTRIBUTION ||
00633 m == _scv_constraint_data::DISTRIBUTION_RANGE) {
00634 get_constraint_data()->set_ext_mode(scv_extensions_if::DISTRIBUTION);
00635 }
00636 }
00637 #endif
00638 virtual _scv_constraint_data * get_constraint_data() {
00639 #ifndef _SCV_INTROSPECTION_ONLY
00640 assert(this->_is_dynamic());
00641 if (!this->_get_dynamic_data()->cdata_) {
00642 this->_get_dynamic_data()->cdata_ = new _scv_constraint_data;
00643 }
00644 return this->_get_dynamic_data()->cdata_;
00645 #endif
00646 }
00647 virtual void get_generator(void) {
00648 #ifndef _SCV_INTROSPECTION_ONLY
00649 if (get_constraint_data()->get_gen_type() == _scv_constraint_data::EMPTY) {
00650 T* dummy_value = new T;
00651 _scv_keep_range(this, *dummy_value, *dummy_value, false, true);
00652 get_constraint_data()->set_mode(_scv_constraint_data::NO_CONSTRAINT);
00653 delete dummy_value;
00654 }
00655 return;
00656 #endif
00657 }
00658 #ifndef _SCV_INTROSPECTION_ONLY
00659 void keep_only(const T& value) {
00660 _reset_bag_distribution();
00661 _scv_keep_range(this, value, value, false);
00662 }
00663 void keep_only(const T& lb, const T& ub) {
00664 _reset_bag_distribution();
00665 _scv_keep_range(this, lb, ub, false);
00666 }
00667 void keep_only(const list<T>& vlist) {
00668 _reset_bag_distribution();
00669 _scv_keep_range(this, vlist);
00670 }
00671
00672 void keep_out(const T& value) {
00673 _reset_bag_distribution();
00674 _scv_keep_range(this, value, value, true);
00675 }
00676 void keep_out(const T& lb, const T& ub) {
00677 _reset_bag_distribution();
00678 _scv_keep_range(this, lb, ub, true);
00679 }
00680 void keep_out(const list<T>& vlist) {
00681 _reset_bag_distribution();
00682 typename list<T>::const_iterator i;
00683 for (i = vlist.begin(); i != vlist.end(); i++) {
00684 _scv_keep_range(this, *i, *i, true);
00685 }
00686 }
00687 #endif
00688 public:
00689 _scv_extension_rand_N() {}
00690
00691 #ifndef _SCV_INTROSPECTION_ONLY
00692 _scv_distribution<T> * _get_distribution() {
00693 return (_scv_distribution<T> *) this->_get_dynamic_data()->dist_;
00694 }
00695 void _set_distribution(_scv_distribution<T>* d) {
00696 _scv_distribution<T> * dist = _get_distribution();
00697 _scv_constraint_data * cdata = get_constraint_data();
00698 if (!dist) {
00699 this->_get_dynamic_data()->dist_ = new _scv_distribution<T>;
00700 dist = _get_distribution();
00701 } else {
00702 dist->reset_distribution();
00703 }
00704 if (d->dist_) {
00705 dist->set_mode(*d->dist_, cdata, this);
00706 } else if (d->dist_r_) {
00707 dist->set_mode(*d->dist_r_, cdata, this);
00708 } else {
00709 _scv_message::message(_scv_message::INTERNAL_ERROR, "_set_distribution(basis_types)");
00710 }
00711 }
00712 virtual ~_scv_extension_rand_N() {
00713 if (this->_has_dynamic_data() && this->_get_dynamic_data()->dist_)
00714 delete _get_distribution();
00715 if (this->_has_dynamic_data() && this->_get_dynamic_data()->cdata_) {
00716 if (this->_get_dynamic_data()->cdata_->get_constraint()) {
00717 _scv_constraint_wrapup(this);
00718 }
00719 delete this->_get_dynamic_data()->cdata_;
00720 }
00721 }
00722 #endif
00723 virtual void generate_value_() {
00724 #ifndef _SCV_INTROSPECTION_ONLY
00725 if (!_get_distribution()) { this->_get_dynamic_data()->dist_ = new _scv_distribution<T>; }
00726 _get_distribution()->generate_value_(this,this->get_constraint_data());
00727 return;
00728 #endif
00729 }
00730 #ifndef _SCV_INTROSPECTION_ONLY
00731 void set_mode(scv_extensions_if::mode_t t) {
00732 int lb, ub; lb =0; ub =0;
00733 if (!_get_distribution()) {
00734 this->_get_dynamic_data()->dist_ = new _scv_distribution<T>;
00735 }
00736 if (!check_mode(t, this, this->get_name(), _get_distribution()))
00737 return;
00738 else
00739 this->get_constraint_data()->set_ext_mode(t, lb, ub);
00740 }
00741 void set_mode(scv_bag<pair<T, T> >& d) {
00742 _reset_keep_only_distribution();
00743 if (!_get_distribution()) { this->_get_dynamic_data()->dist_ = new _scv_distribution<T>; }
00744 _get_distribution()->set_mode(d,this->get_constraint_data(),this);
00745 }
00746 void set_mode(scv_bag<T>& d) {
00747 _reset_keep_only_distribution();
00748 if (!_get_distribution()) { this->_get_dynamic_data()->dist_ = new _scv_distribution<T>; }
00749 _get_distribution()->set_mode(d,this->get_constraint_data(),this);
00750 }
00751 void reset_distribution() {
00752 _reset_bag_distribution();
00753 _reset_keep_only_distribution();
00754 }
00755 scv_extensions_if::mode_t get_mode(void) {
00756 return this->get_constraint_data()->get_ext_mode();
00757 }
00758 virtual void set_distribution_from(scv_extensions_if* e) {
00759 _scv_distribution<T> *dist = (_scv_distribution<T>*)
00760 e->get_dynamic_data()->dist_;
00761 _set_distribution(dist);
00762 }
00763 protected:
00764 void _reset_bag_distribution() {
00765 if (_get_distribution()) {
00766 _get_distribution()->reset_distribution();
00767 }
00768 }
00769 void _reset_keep_only_distribution() {
00770 this->get_constraint_data()->reset_distribution(this);
00771 }
00772 #endif
00773 };
00774
00775
00776 #define _SCV_EXT_RAND_FC_N_D(basic_type) \
00777 template<int N> \
00778 class scv_extension_rand<basic_type > \
00779 : public _scv_extension_rand_N<basic_type > {}; \
00780
00781
00782 _SCV_EXT_RAND_FC_D(bool,bool);
00783 _SCV_EXT_RAND_FC_D(char,char);
00784 _SCV_EXT_RAND_FC_D(unsigned char,unsigned_char);
00785 _SCV_EXT_RAND_FC_D(short,short);
00786 _SCV_EXT_RAND_FC_D(unsigned short,unsigned_short);
00787 _SCV_EXT_RAND_FC_D(int,int);
00788 _SCV_EXT_RAND_FC_D(unsigned int,unsigned_int);
00789 _SCV_EXT_RAND_FC_D(long,long);
00790 _SCV_EXT_RAND_FC_D(unsigned long,unsigned_long);
00791 _SCV_EXT_RAND_FC_D(long long,long_long);
00792 _SCV_EXT_RAND_FC_D(unsigned long long,unsigned_long_long);
00793 _SCV_EXT_RAND_FC_D(float,float);
00794 _SCV_EXT_RAND_FC_D(double,double);
00795 _SCV_EXT_RAND_FC_D(string,string);
00796 _SCV_EXT_RAND_FC_N_D(test_uint<N>);
00797
00798
00799 #ifdef SYSTEMC_H
00800 _SCV_EXT_RAND_FC_D(sc_string,sc_string);
00801 _SCV_EXT_RAND_FC_1_D(sc_bit,sc_bit);
00802 _SCV_EXT_RAND_FC_1_D(sc_logic,sc_logic);
00803 _SCV_EXT_RAND_FC_N_D(sc_int<N>);
00804 _SCV_EXT_RAND_FC_N_D(sc_uint<N>);
00805 _SCV_EXT_RAND_FC_N_D(sc_bigint<N>);
00806 _SCV_EXT_RAND_FC_N_D(sc_biguint<N>);
00807 _SCV_EXT_RAND_FC_N_D(sc_bv<N>);
00808 _SCV_EXT_RAND_FC_N_D(sc_lv<N>);
00809
00810
00811 _SCV_EXT_RAND_FC_D_D(sc_signed,sc_signed);
00812 _SCV_EXT_RAND_FC_D_D(sc_unsigned,sc_unsigned);
00813 _SCV_EXT_RAND_FC_D_D(sc_int_base,sc_int_base);
00814 _SCV_EXT_RAND_FC_D_D(sc_uint_base,sc_uint_base);
00815 _SCV_EXT_RAND_FC_D_D(sc_lv_base,sc_lv_base);
00816 _SCV_EXT_RAND_FC_D_D(sc_bv_base,sc_bv_base);
00817 #endif
00818
00819
00820 #undef _SCV_EXT_RAND_FC_D
00821 #undef _SCV_EXT_RAND_FC_1_D
00822 #undef _SCV_EXT_RAND_FC_N_D
00823
00824
00825
00826
00827
00828
00829 #undef _SCV_INTROSPECTION_BASE
00830 #define _SCV_INTROSPECTION_BASE scv_extension_rand<T>
00831 #undef _SCV_INTROSPECTION_BASE1
00832 #define _SCV_INTROSPECTION_BASE1 scv_extension_rand<T*>
00833 #undef _SCV_INTROSPECTION_BASE2
00834 #define _SCV_INTROSPECTION_BASE2 scv_extension_rand<T[N]>
00835
00836 #undef _SCV_INTROSPECTION_BASE_ENUM
00837 #define _SCV_INTROSPECTION_BASE_ENUM _scv_extension_rand_enum