00001
00015 #include "OSGeneral.h"
00016 #include "OSParameters.h"
00017 #include "OSErrorClass.h"
00018 #include "OSMathUtil.h"
00019 #include "OSBase64.h"
00020 #include "OSOutput.h"
00021
00022 #include <iostream>
00023 #include <sstream>
00024
00025
00026 using namespace std;
00027 using std::endl;
00028
00029 GeneralFileHeader::GeneralFileHeader():
00030 name(""),
00031 source(""),
00032 description(""),
00033 fileCreator(""),
00034 licence("")
00035 {
00036 }
00037
00038 GeneralFileHeader::~GeneralFileHeader()
00039 {
00040 #ifndef NDEBUG
00041 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside file header destructor");
00042 #endif
00043 }
00044
00045 bool GeneralFileHeader::IsEqual(GeneralFileHeader *that)
00046 {
00047 std::ostringstream outStr;
00048
00049 #ifndef NDEBUG
00050 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in GeneralFileHeader");
00051 #endif
00052 if (this == NULL)
00053 {
00054 if (that == NULL)
00055 return true;
00056 else
00057 {
00058 #ifndef NDEBUG
00059 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "First object is NULL, second is not");
00060 #endif
00061 return false;
00062 }
00063 }
00064 else
00065 {
00066 if (that == NULL)
00067 {
00068 #ifndef NDEBUG
00069 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Second object is NULL, first is not");
00070 #endif
00071 return false;
00072 }
00073 else
00074 {
00075 if ((this->name != that->name) ||
00076 (this->source != that->source) ||
00077 (this->description != that->description) ||
00078 (this->fileCreator != that->fileCreator) ||
00079 (this->licence != that->licence))
00080 {
00081 #ifndef NDEBUG
00082 outStr.str("");
00083 outStr.clear();
00084 outStr << "name: " << this->name << " vs. " << that->name << endl;
00085 outStr << "source: " << this->source << " vs. " << that->source << endl;
00086 outStr << "description: " << this->description << " vs. " << that->description << endl;
00087 outStr << "fileCreator: " << this->fileCreator << " vs. " << that->fileCreator << endl;
00088 outStr << "licence: " << this->licence << " vs. " << that->licence << endl;
00089 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00090
00091 #endif
00092 return false;
00093 }
00094 return true;
00095 }
00096 }
00097 }
00098
00099 bool GeneralFileHeader::setRandom(double density, bool conformant)
00100 {
00101 if (OSRand() <= density) this->name = "random string";
00102 if (OSRand() <= density) this->source = "random string";
00103 if (OSRand() <= density) this->description = "random string";
00104 if (OSRand() <= density) this->fileCreator = "random string";
00105 if (OSRand() <= density) this->licence = "random string";
00106 return true;
00107 }
00108
00109 bool GeneralFileHeader::deepCopyFrom(GeneralFileHeader *that)
00110 {
00111 #ifndef NDEBUG
00112 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of GeneralFileHeader");
00113 #endif
00114 this->name = that->name;
00115 this->source = that->source;
00116 this->description = that->description;
00117 this->fileCreator = that->fileCreator;
00118 this->licence = that->licence;
00119 return true;
00120 }
00121
00122 std::string GeneralFileHeader::getHeaderItem(std::string item)
00123 {
00124 if (item == "name") return name;
00125 if (item == "source") return source;
00126 if (item == "description") return description;
00127 if (item == "fileCreator") return fileCreator;
00128 if (item == "licence") return licence;
00129 throw ErrorClass("Attempting to access undefined header item in getHeaderItem");
00130 }
00131
00132 bool GeneralFileHeader::setHeader(std::string name, std::string source,
00133 std::string description, std::string fileCreator, std::string licence)
00134 {
00135 this->name = name;
00136 this->source = source;
00137 this->description = description;
00138 this->fileCreator = fileCreator;
00139 this->licence = licence;
00140 return true;
00141 }
00142
00143 SparseVector::SparseVector( int number_):
00144 number( number_)
00145 {
00146 indexes = new int[ number];
00147 values = new double[ number];
00148 bDeleteArrays = true;
00149 }
00150
00151
00152 SparseVector::SparseVector( ):
00153 bDeleteArrays(true),
00154 indexes( NULL),
00155 values( NULL)
00156 {
00157 }
00158
00159 SparseVector::~SparseVector()
00160 {
00161 #ifndef NDEBUG
00162 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside sparseVector destructor");
00163 #endif
00164 if( bDeleteArrays == true)
00165 {
00166 #ifndef NDEBUG
00167 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "delete[] indexes and arrays");
00168 #endif
00169 delete[] indexes;
00170 delete[] values;
00171 }
00172 values = NULL;
00173 indexes = NULL;
00174 }
00175
00176 SparseMatrix::SparseMatrix():
00177 bDeleteArrays( true),
00178 isColumnMajor(true),
00179 startSize(0),
00180 valueSize(0),
00181 starts(NULL),
00182 indexes(NULL),
00183 values(NULL)
00184 {
00185 }
00186
00187
00188
00189 SparseMatrix::SparseMatrix(bool isColumnMajor_, int startSize_, int valueSize_):
00190 isColumnMajor(isColumnMajor_),
00191 startSize(startSize_),
00192 valueSize(valueSize_)
00193 {
00194 bDeleteArrays = true;
00195 starts = new int[startSize];
00196 indexes = new int[valueSize];
00197 values = new double[valueSize];
00198
00199 }
00200
00201
00202 SparseMatrix::~SparseMatrix()
00203 {
00204 #ifndef NDEBUG
00205 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside SparseMatrix destructor");
00206 #endif
00207 if( bDeleteArrays == true)
00208 {
00209 delete[] starts;
00210 delete[] indexes;
00211 delete[] values;
00212 }
00213 starts = NULL;
00214 indexes = NULL;
00215 values = NULL;
00216 }
00217
00218
00219 bool SparseMatrix::display(int secondaryDim)
00220 {
00221 int i, j, k;
00222 for ( i = 0; i < startSize - 1; i++)
00223 {
00224 if (starts[i] == starts[i + 1])
00225 {
00226 for ( k = 0; k < secondaryDim; k++)
00227 {
00228
00229 }
00230 }
00231 else
00232 {
00233 for ( j = 0; j < indexes[starts[i]]; j ++)
00234 {
00235
00236 }
00237
00238 for ( j = starts[ i ]; j < starts[i + 1]; j++)
00239 {
00240
00241
00242 if ( j < starts[i + 1] - 1)
00243 {
00244 for ( k = indexes [j] + 1; k < indexes[j + 1]; k++)
00245 {
00246
00247 }
00248 }
00249 else
00250 {
00251 for ( k = indexes [j] + 1; k < secondaryDim; k++)
00252 {
00253
00254 }
00255 }
00256 }
00257 }
00258
00259 }
00260
00261 return true;
00262
00263 }
00264
00265 SparseJacobianMatrix::SparseJacobianMatrix():
00266 bDeleteArrays( true),
00267 startSize(0),
00268 valueSize(0),
00269 starts(NULL),
00270 conVals(NULL),
00271 indexes(NULL),
00272 values(NULL)
00273 {
00274 }
00275
00276
00277 SparseJacobianMatrix::SparseJacobianMatrix(int startSize_, int valueSize_):
00278 bDeleteArrays( true),
00279 startSize(startSize_),
00280 valueSize(valueSize_)
00281 {
00282 starts = new int[startSize];
00283 conVals = new int[startSize];
00284 indexes = new int[valueSize];
00285 values = new double[valueSize];
00286 }
00287
00288
00289 SparseJacobianMatrix::~SparseJacobianMatrix()
00290 {
00291 #ifndef NDEBUG
00292 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside SparseJacobianMatrix destructor");
00293 #endif
00294 if(bDeleteArrays == true)
00295 {
00296 #ifndef NDEBUG
00297 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "delete SparseJacobianArrays");
00298 #endif
00299 delete[] starts;
00300 delete[] conVals;
00301 delete[] indexes;
00302 delete[] values;
00303 }
00304 starts = NULL;
00305 conVals = NULL;
00306 indexes = NULL;
00307 values = NULL;
00308 }
00309
00310
00311 SparseHessianMatrix::SparseHessianMatrix():
00312 bDeleteArrays( true),
00313 hessDimension(0),
00314 hessRowIdx( NULL),
00315 hessColIdx( NULL),
00316 hessValues( NULL)
00317 {
00318 }
00319
00320
00321
00322 SparseHessianMatrix::~SparseHessianMatrix()
00323 {
00324 #ifndef NDEBUG
00325 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside SparseHessianMatrix destructor");
00326 #endif
00327 if(bDeleteArrays == true)
00328 {
00329 delete[] hessRowIdx;
00330 delete[] hessColIdx;
00331 delete[] hessValues;
00332 }
00333 hessRowIdx = NULL;
00334 hessColIdx = NULL;
00335 hessValues = NULL;
00336 }
00337
00338
00339
00340 QuadraticTerms::QuadraticTerms():
00341 rowIndexes(NULL),
00342 varOneIndexes(NULL),
00343 varTwoIndexes(NULL),
00344 coefficients(NULL)
00345 {
00346 }
00347
00348 QuadraticTerms::~QuadraticTerms()
00349 {
00350 #ifndef NDEBUG
00351 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside QuadraticTerms destructor");
00352 #endif
00353 delete[] rowIndexes;
00354 rowIndexes = NULL;
00355 delete[] varOneIndexes;
00356 varOneIndexes = NULL;
00357 delete[] varTwoIndexes;
00358 varTwoIndexes = NULL;
00359 delete[] coefficients;
00360 coefficients = NULL;
00361 }
00362
00363
00364 IntVector::IntVector():
00365 bDeleteArrays(true),
00366 numberOfEl(0),
00367 el(NULL)
00368 {
00369 #ifndef NDEBUG
00370 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside IntVector Constructor");
00371 #endif
00372 }
00373
00374
00375 IntVector::IntVector(int n):
00376 bDeleteArrays(true)
00377 {
00378 #ifndef NDEBUG
00379 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside alternate IntVector Constructor");
00380 #endif
00381
00382 numberOfEl = n;
00383 el = new int[n];
00384 }
00385
00386 IntVector::~IntVector()
00387 {
00388 #ifndef NDEBUG
00389 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside IntVector destructor");
00390 #endif
00391 if( bDeleteArrays == true)
00392 {
00393 delete[] el;
00394 el = NULL;
00395 }
00396 }
00397
00398 bool IntVector::setIntVector(int *i, int ni)
00399 {
00400 if (this->numberOfEl != 0)
00401 delete[] this->el;
00402
00403 this->numberOfEl = ni;
00404
00405 this->el = new int[ni];
00406 for (int j=0; j<ni; j++)
00407 this->el[j] = i[j];
00408
00409 return true;
00410 }
00411
00412 bool IntVector::extendIntVector(int i)
00413 {
00414 int ni;
00415
00416
00417
00418 if (this->el == NULL)
00419 ni = 0;
00420 else
00421 ni = this->numberOfEl;
00422
00423 int* temp = new int[ni+1];
00424 for (int j = 0; j < ni; ++j)
00425 temp[j] = this->el[j];
00426
00427 delete[] this->el;
00428
00429 temp[ni] = i;
00430
00431 this->el = temp;
00432 this->numberOfEl = ++ni;
00433
00434 return true;
00435 }
00436
00437 int IntVector::getNumberOfEl()
00438 {
00439 return this->numberOfEl;
00440 }
00441
00442 int IntVector::getEl(int j)
00443 {
00444 if (j < 0 || j >= this->numberOfEl)
00445 throw ErrorClass("Attempting to access undefined memory in IntVector::getEl(j)");
00446 return this->el[j];
00447 }
00448
00449 bool IntVector::getEl(int* i)
00450 {
00451 for (int j=0; j < this->numberOfEl; ++j)
00452 i[j] = this->el[j];
00453 return true;
00454 }
00455
00456 bool IntVector::IsEqual(IntVector *that)
00457 {
00458 std::ostringstream outStr;
00459
00460 #ifndef NDEBUG
00461 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in IntVector");
00462 #endif
00463 if (this == NULL)
00464 {
00465 if (that == NULL)
00466 return true;
00467 else
00468 {
00469 #ifndef NDEBUG
00470 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "First object is NULL, second is not");
00471 #endif
00472 return false;
00473 }
00474 }
00475 else
00476 {
00477 if (that == NULL)
00478 {
00479 #ifndef NDEBUG
00480 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Second object is NULL, first is not");
00481 #endif
00482 return false;
00483 }
00484 else
00485 {
00486 if (this->numberOfEl != that->numberOfEl)
00487 {
00488 #ifndef NDEBUG
00489 outStr.str("");
00490 outStr.clear();
00491 outStr << "numberOfEl: " << this->numberOfEl << " vs. " << that->numberOfEl << endl;
00492 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00493 #endif
00494 return false;
00495 }
00496 for (int i=0; i<this->numberOfEl; i++)
00497 {
00498 if (this->el[i] != that->el[i])
00499 {
00500
00501 #ifndef NDEBUG
00502 outStr.str("");
00503 outStr.clear();
00504 outStr << "El[" << i << "]: " << this->el[i] << " vs. " << that->el[i] << endl;
00505 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00506 #endif
00507 return false;
00508 }
00509 }
00510 return true;
00511 }
00512 }
00513 }
00514
00515 bool IntVector::setRandom(double density, bool conformant, int iMin, int iMax)
00516 {
00517 #ifndef NDEBUG
00518 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Set random IntVector");
00519 #endif
00520 this->numberOfEl = (int)(4*OSRand());
00521
00522 int n;
00523
00524 if (conformant) n = this->numberOfEl;
00525 else n = (int)(4*OSRand());
00526
00527 el = new int[n];
00528 for (int i = 0; i < n; i++)
00529 el[i] = (int)OSiRand(iMin, iMax);
00530
00531 return true;
00532 }
00533
00534 bool IntVector::deepCopyFrom(IntVector *that)
00535 {
00536 #ifndef NDEBUG
00537 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of IntVector");
00538 #endif
00539 this->numberOfEl = that->numberOfEl;
00540 int n = this->numberOfEl;
00541
00542 if (n < 0) return false;
00543 if (n == 0) return true;
00544
00545 this->el = new int[n];
00546 for (int i = 0; i < n; i++)
00547 this->el[i] = that->el[i];
00548
00549 return true;
00550 }
00551
00552 OtherOptionEnumeration::OtherOptionEnumeration():
00553 IntVector(),
00554 value(""),
00555 description("")
00556 {
00557 #ifndef NDEBUG
00558 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace,
00559 "Inside the OtherOptionEnumeration Constructor");
00560 #endif
00561 }
00562
00563 OtherOptionEnumeration::OtherOptionEnumeration(int n):
00564 IntVector(n),
00565 value(""),
00566 description("")
00567 {
00568 #ifndef NDEBUG
00569 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace,
00570 "Inside the alternate OtherOptionEnumeration Constructor");
00571 #endif
00572 }
00573
00574 OtherOptionEnumeration::~OtherOptionEnumeration()
00575 {
00576 #ifndef NDEBUG
00577 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace,
00578 "Inside the OtherOptionEnumeration Destructor");
00579 #endif
00580 }
00581
00582 bool OtherOptionEnumeration::setOtherOptionEnumeration(std::string value, std::string description, int *i, int ni)
00583 {
00584 this->value = value;
00585 this->description = description;
00586 return this->IntVector::setIntVector(i, ni);
00587 }
00588
00589 std::string OtherOptionEnumeration::getValue()
00590 {
00591 return this->value;
00592 }
00593
00594 std::string OtherOptionEnumeration::getDescription()
00595 {
00596 return this->description;
00597 }
00598
00599
00600 bool OtherOptionEnumeration::IsEqual(OtherOptionEnumeration *that)
00601 {
00602 std::ostringstream outStr;
00603
00604 #ifndef NDEBUG
00605 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in OtherOptionEnumeration");
00606 #endif
00607 if (this == NULL)
00608 {
00609 if (that == NULL)
00610 return true;
00611 else
00612 {
00613 #ifndef NDEBUG
00614 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "First object is NULL, second is not");
00615 #endif
00616 return false;
00617 }
00618 }
00619 else
00620 {
00621 if (that == NULL)
00622 {
00623 #ifndef NDEBUG
00624 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Second object is NULL, first is not");
00625 #endif
00626 return false;
00627 }
00628 else
00629 {
00630 if (this->value != that->value || this->description != that->description)
00631 {
00632 #ifndef NDEBUG
00633 outStr.str("");
00634 outStr.clear();
00635 outStr << "value: " << this->value << " vs. " << that->value << endl;
00636 outStr << "description: " << this->description << " vs. " << that->description << endl;
00637 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00638 #endif
00639 return false;
00640 }
00641
00642 return this->IntVector::IsEqual(that);
00643 }
00644 }
00645 }
00646
00647 bool OtherOptionEnumeration::setRandom(double density, bool conformant, int iMin, int iMax)
00648 {
00649 #ifndef NDEBUG
00650 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Set random OtherOptionEnumeration");
00651 #endif
00652 if (OSRand() <= density) this->value = "random string";
00653 if (OSRand() <= density) this->description = "random string";
00654
00655 if (OSRand() <= density) this->IntVector::setRandom(density,conformant,iMin,iMax);
00656 return true;
00657 }
00658
00659 bool OtherOptionEnumeration::deepCopyFrom(OtherOptionEnumeration *that)
00660 {
00661 #ifndef NDEBUG
00662 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of OtherOptionEnumeration");
00663 #endif
00664 this->value = that->value;
00665 this->description = that->description;
00666
00667 if (!this->IntVector::deepCopyFrom(that))
00668 return false;
00669
00670 return true;
00671 }
00672
00673
00674 DoubleVector::DoubleVector():
00675 bDeleteArrays(true),
00676 el(NULL)
00677 {
00678 #ifndef NDEBUG
00679 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Inside the DoubleVector Constructor");
00680 #endif
00681
00682 }
00683
00684
00685 DoubleVector::~DoubleVector()
00686 {
00687 #ifndef NDEBUG
00688 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Inside the DoubleVector Destructor");
00689 #endif
00690 if( bDeleteArrays == true)
00691 {
00692 delete[] el;
00693 el = NULL;
00694 }
00695 }
00696
00697
00698 bool DoubleVector::IsEqual(DoubleVector *that)
00699 {
00700 std::ostringstream outStr;
00701
00702 #ifndef NDEBUG
00703 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in DoubleVector");
00704 #endif
00705 if (this == NULL)
00706 {
00707 if (that == NULL)
00708 return true;
00709 else
00710 {
00711 #ifndef NDEBUG
00712 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "First object is NULL, second is not");
00713 #endif
00714 return false;
00715 }
00716 }
00717 else
00718 {
00719 if (that == NULL)
00720 {
00721 #ifndef NDEBUG
00722 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Second object is NULL, first is not");
00723 #endif
00724 return false;
00725 }
00726 else
00727 {
00728 if (this->numberOfEl != that->numberOfEl)
00729 {
00730 #ifndef NDEBUG
00731 outStr.str("");
00732 outStr.clear();
00733 outStr << "numberOfEl: " << this->numberOfEl << " vs. " << that->numberOfEl << endl;
00734 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00735 #endif
00736 return false;
00737 }
00738 for (int i=0; i<this->numberOfEl; i++)
00739 {
00740 if (!isEqual(this->el[i], that->el[i]))
00741 {
00742
00743 #ifndef NDEBUG
00744 outStr.str("");
00745 outStr.clear();
00746 outStr << "El[" << i << "]: " << this->el[i] << " vs. " << that->el[i] << endl;
00747 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00748 #endif
00749 return false;
00750 }
00751 }
00752 return true;
00753 }
00754 }
00755 }
00756
00757
00758 BasisStatus::BasisStatus():
00759 basic(NULL),
00760 atLower(NULL),
00761 atUpper(NULL),
00762 atEquality(NULL),
00763 isFree(NULL),
00764 superbasic(NULL),
00765 unknown(NULL)
00766 {
00767 #ifndef NDEBUG
00768 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Inside the BasisStatus Constructor");
00769 #endif
00770 }
00771
00772
00773 BasisStatus::~BasisStatus()
00774 {
00775 #ifndef NDEBUG
00776 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Inside the BasisStatus Destructor");
00777 #endif
00778 if (basic != NULL)
00779 {
00780 delete basic;
00781 basic = NULL;
00782 }
00783 if (atLower != NULL)
00784 {
00785 delete atLower;
00786 atLower = NULL;
00787 }
00788 if (atUpper != NULL)
00789 {
00790 delete atUpper;
00791 atUpper = NULL;
00792 }
00793 if (atEquality != NULL)
00794 {
00795 delete atEquality;
00796 atEquality = NULL;
00797 }
00798 if (isFree != NULL)
00799 {
00800 delete isFree;
00801 isFree = NULL;
00802 }
00803 if (superbasic != NULL)
00804 {
00805 delete superbasic;
00806 superbasic = NULL;
00807 }
00808 if (unknown != NULL)
00809 {
00810 delete unknown;
00811 unknown = NULL;
00812 }
00813 }
00814
00815
00816 bool BasisStatus::setIntVector(int status, int *i, int ni)
00817 {
00818 switch (status)
00819 {
00820 case ENUM_BASIS_STATUS_basic:
00821 {
00822 if (this->basic == NULL) this->basic = new IntVector();
00823
00824 return this->basic->setIntVector(i, ni);
00825 }
00826 case ENUM_BASIS_STATUS_atLower:
00827 {
00828 if (this->atLower == NULL) this->atLower = new IntVector(ni);
00829
00830 return this->atLower->setIntVector(i, ni);
00831 }
00832 case ENUM_BASIS_STATUS_atUpper:
00833 {
00834 if (this->atUpper == NULL) this->atUpper = new IntVector(ni);
00835
00836 return this->atUpper->setIntVector(i, ni);
00837 }
00838 case ENUM_BASIS_STATUS_atEquality:
00839 {
00840 if (this->atEquality == NULL) this->atEquality = new IntVector(ni);
00841
00842 return this->atEquality->setIntVector(i, ni);
00843 }
00844 case ENUM_BASIS_STATUS_isFree:
00845 {
00846 if (this->isFree == NULL) this->isFree = new IntVector(ni);
00847
00848 return this->isFree->setIntVector(i, ni);
00849 }
00850 case ENUM_BASIS_STATUS_superbasic:
00851 {
00852 if (this->superbasic == NULL) this->superbasic = new IntVector(ni);
00853
00854 return this->superbasic->setIntVector(i, ni);
00855 }
00856 case ENUM_BASIS_STATUS_unknown:
00857 {
00858 if (this->unknown == NULL) this->unknown = new IntVector(ni);
00859
00860 return this->unknown->setIntVector(i, ni);
00861 }
00862 default:
00863 throw ErrorClass("Unknown basis status encountered in BasisStatus::setIntVector");
00864 }
00865 }
00866
00867 bool BasisStatus::addIdx(int status, int idx)
00868 {
00869 switch (status)
00870 {
00871 case ENUM_BASIS_STATUS_basic:
00872 {
00873 if (this->basic == NULL) this->basic = new IntVector();
00874 return this->basic->extendIntVector(idx);
00875 }
00876 case ENUM_BASIS_STATUS_atLower:
00877 {
00878 if (this->atLower == NULL) this->atLower = new IntVector();
00879 return this->atLower->extendIntVector(idx);
00880 }
00881 case ENUM_BASIS_STATUS_atUpper:
00882 {
00883 if (this->atUpper == NULL) this->atUpper = new IntVector();
00884 return this->atUpper->extendIntVector(idx);
00885 }
00886 case ENUM_BASIS_STATUS_atEquality:
00887 {
00888 if (this->atEquality == NULL) this->atEquality = new IntVector();
00889 return this->atEquality->extendIntVector(idx);
00890 }
00891 case ENUM_BASIS_STATUS_isFree:
00892 {
00893 if (this->isFree == NULL) this->isFree = new IntVector();
00894 return this->isFree->extendIntVector(idx);
00895 }
00896 case ENUM_BASIS_STATUS_superbasic:
00897 {
00898 if (this->superbasic == NULL) this->superbasic = new IntVector();
00899 return this->superbasic->extendIntVector(idx);
00900 }
00901 case ENUM_BASIS_STATUS_unknown:
00902 {
00903 if (this->unknown == NULL) this->unknown = new IntVector();
00904 return this->unknown->extendIntVector(idx);
00905 }
00906 default:
00907 throw ErrorClass("Unknown basis status encountered in BasisStatus::addIdx");
00908 }
00909 }
00910
00911
00912 bool BasisStatus::getIntVector(int status, int *i)
00913 {
00914 switch (status)
00915 {
00916 case ENUM_BASIS_STATUS_basic:
00917 {
00918 if (this->basic == NULL) return false;
00919 return this->basic->getEl(i);
00920 }
00921 case ENUM_BASIS_STATUS_atLower:
00922 {
00923 if (this->atLower == NULL) return false;
00924 return this->atLower->getEl(i);
00925 }
00926 case ENUM_BASIS_STATUS_atUpper:
00927 {
00928 if (this->atUpper == NULL) return false;
00929 return this->atUpper->getEl(i);
00930 }
00931 case ENUM_BASIS_STATUS_atEquality:
00932 {
00933 if (this->atEquality == NULL) return false;
00934 return this->atEquality->getEl(i);
00935 }
00936 case ENUM_BASIS_STATUS_isFree:
00937 {
00938 if (this->isFree == NULL) return false;
00939 return this->isFree->getEl(i);
00940 }
00941 case ENUM_BASIS_STATUS_superbasic:
00942 {
00943 if (this->superbasic == NULL) return false;
00944 return this->superbasic->getEl(i);
00945 }
00946 case ENUM_BASIS_STATUS_unknown:
00947 {
00948 if (this->unknown == NULL) return false;
00949 return this->unknown->getEl(i);
00950 }
00951 default:
00952 throw ErrorClass("Unknown basis status encountered in setIntVector");
00953 }
00954 }
00955
00956
00957 int BasisStatus::getNumberOfEl(int status)
00958 {
00959 switch (status)
00960 {
00961 case ENUM_BASIS_STATUS_basic:
00962 {
00963 if (this->basic == NULL) return -1;
00964 else return this->basic->numberOfEl;
00965 }
00966 case ENUM_BASIS_STATUS_atLower:
00967 {
00968 if (this->atLower == NULL) return -1;
00969 else return this->atLower->numberOfEl;
00970 }
00971 case ENUM_BASIS_STATUS_atUpper:
00972 {
00973 if (this->atUpper == NULL) return -1;
00974 else return this->atUpper->numberOfEl;
00975 }
00976 case ENUM_BASIS_STATUS_atEquality:
00977 {
00978 if (this->atEquality == NULL) return -1;
00979 else return this->atEquality->numberOfEl;
00980 }
00981 case ENUM_BASIS_STATUS_isFree:
00982 {
00983 if (this->isFree == NULL) return -1;
00984 else return this->isFree->numberOfEl;
00985 }
00986 case ENUM_BASIS_STATUS_superbasic:
00987 {
00988 if (this->superbasic == NULL) return -1;
00989 else return this->superbasic->numberOfEl;
00990 }
00991 case ENUM_BASIS_STATUS_unknown:
00992 {
00993 if (this->unknown == NULL) return -1;
00994 else return this->unknown->numberOfEl;
00995 }
00996 default:
00997 throw ErrorClass("Unknown basis status encountered in getBasisStatusNumberOfEl");
00998 }
00999 }
01000
01001
01002 int BasisStatus::getEl(int status, int j)
01003 {
01004 switch (status)
01005 {
01006 case ENUM_BASIS_STATUS_basic:
01007 {
01008 if (this->basic == NULL)
01009 throw ErrorClass("\"basic\" index array never defined in routine BasisStatus::getEl()");
01010 else return this->basic->el[j];
01011 }
01012 case ENUM_BASIS_STATUS_atLower:
01013 {
01014 if (this->atLower == NULL)
01015 throw ErrorClass("\"atLower\" index array never defined in routine BasisStatus::getEl()");
01016 else return this->atLower->el[j];
01017 }
01018 case ENUM_BASIS_STATUS_atUpper:
01019 {
01020 if (this->atUpper == NULL)
01021 throw ErrorClass("\"atUpper\" index array never defined in routine BasisStatus::getEl()");
01022 else return this->atUpper->el[j];
01023 }
01024 case ENUM_BASIS_STATUS_atEquality:
01025 {
01026 if (this->atEquality == NULL)
01027 throw ErrorClass("\"atEquality\" index array never defined in routine BasisStatus::getEl()");
01028 else return this->atEquality->el[j];
01029 }
01030 case ENUM_BASIS_STATUS_isFree:
01031 {
01032 if (this->isFree == NULL)
01033 throw ErrorClass("\"isFree\" index array never defined in routine BasisStatus::getEl()");
01034 else return this->isFree->el[j];
01035 }
01036 case ENUM_BASIS_STATUS_superbasic:
01037 {
01038 if (this->superbasic == NULL)
01039 throw ErrorClass("\"superbasic\" index array never defined in routine BasisStatus::getEl()");
01040 else return this->superbasic->el[j];
01041 }
01042 case ENUM_BASIS_STATUS_unknown:
01043 {
01044 if (this->unknown == NULL)
01045 throw ErrorClass("\"unknown\" index array never defined in routine BasisStatus::getEl()");
01046 else return this->unknown->el[j];
01047 }
01048 default:
01049 throw ErrorClass("Unknown basis status encountered in getBasisStatusNumberOfEl");
01050 }
01051 }
01052
01053 int BasisStatus::getBasisDense(int *resultArray, int dim, bool flipIdx)
01054 {
01055 int i, n, nCopied;
01056 int* statusArray = NULL;
01057
01058 nCopied = 0;
01059
01060 if (this->basic != NULL)
01061 {
01062 n = this->basic->getNumberOfEl();
01063 statusArray = new int[n];
01064 this->basic->getEl(statusArray);
01065 for (i=0; i < n; i++)
01066 {
01067 if (!flipIdx)
01068 resultArray[statusArray[i]] = ENUM_BASIS_STATUS_basic;
01069 else
01070 resultArray[-1 - statusArray[i]] = ENUM_BASIS_STATUS_basic;
01071 }
01072 delete [] statusArray;
01073 statusArray = NULL;
01074 nCopied += n;
01075 }
01076
01077 if (this->atLower != NULL)
01078 {
01079 n = this->atLower->getNumberOfEl();
01080 statusArray = new int[n];
01081 this->atLower->getEl(statusArray);
01082 for (i=0; i < n; i++)
01083 {
01084 if (!flipIdx)
01085 resultArray[statusArray[i]] = ENUM_BASIS_STATUS_atLower;
01086 else
01087 resultArray[-1 - statusArray[i]] = ENUM_BASIS_STATUS_atLower;
01088 }
01089 delete [] statusArray;
01090 nCopied += n;
01091 }
01092
01093 if (this->atUpper != NULL)
01094 {
01095 n = this->atUpper->getNumberOfEl();
01096 statusArray = new int[n];
01097 this->atUpper->getEl(statusArray);
01098 for (i=0; i < n; i++)
01099 {
01100 if (!flipIdx)
01101 resultArray[statusArray[i]] = ENUM_BASIS_STATUS_atUpper;
01102 else
01103 resultArray[-1 - statusArray[i]] = ENUM_BASIS_STATUS_atUpper;
01104 }
01105 delete [] statusArray;
01106 nCopied += n;
01107 }
01108
01109 if (this->atEquality != NULL)
01110 {
01111 n = this->atEquality->getNumberOfEl();
01112 statusArray = new int[n];
01113 this->atEquality->getEl(statusArray);
01114 for (i=0; i < n; i++)
01115 {
01116 if (!flipIdx)
01117 resultArray[statusArray[i]] = ENUM_BASIS_STATUS_atEquality;
01118 else
01119 resultArray[-1 - statusArray[i]] = ENUM_BASIS_STATUS_atEquality;
01120 }
01121 delete [] statusArray;
01122 nCopied += n;
01123 }
01124
01125 if (this->isFree != NULL)
01126 {
01127 n = this->isFree->getNumberOfEl();
01128 statusArray = new int[n];
01129 this->isFree->getEl(statusArray);
01130 for (i=0; i < n; i++)
01131 {
01132 if (!flipIdx)
01133 resultArray[statusArray[i]] = ENUM_BASIS_STATUS_isFree;
01134 else
01135 resultArray[-1 - statusArray[i]] = ENUM_BASIS_STATUS_isFree;
01136 }
01137 delete [] statusArray;
01138 nCopied += n;
01139 }
01140
01141 if (this->superbasic != NULL)
01142 {
01143 n = this->superbasic->getNumberOfEl();
01144 statusArray = new int[n];
01145 this->superbasic->getEl(statusArray);
01146 for (i=0; i < n; i++)
01147 {
01148 if (!flipIdx)
01149 resultArray[statusArray[i]] = ENUM_BASIS_STATUS_superbasic;
01150 else
01151 resultArray[-1 - statusArray[i]] = ENUM_BASIS_STATUS_superbasic;
01152 }
01153 delete [] statusArray;
01154 nCopied += n;
01155 }
01156
01157 if (this->unknown != NULL)
01158 {
01159 n = this->unknown->getNumberOfEl();
01160 statusArray = new int[n];
01161 this->unknown->getEl(statusArray);
01162 for (i=0; i < n; i++)
01163 {
01164 if (!flipIdx)
01165 resultArray[statusArray[i]] = ENUM_BASIS_STATUS_unknown;
01166 else
01167 resultArray[-1 - statusArray[i]] = ENUM_BASIS_STATUS_unknown;
01168 }
01169 delete [] statusArray;
01170 nCopied += n;
01171 }
01172 return nCopied;
01173 }
01174
01175 bool BasisStatus::IsEqual(BasisStatus *that)
01176 {
01177 std::ostringstream outStr;
01178
01179 #ifndef NDEBUG
01180 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in BasisStatus");
01181 #endif
01182 if (this == NULL)
01183 {
01184 if (that == NULL)
01185 return true;
01186 else
01187 {
01188 #ifndef NDEBUG
01189 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "First object is NULL, second is not");
01190 #endif
01191 return false;
01192 }
01193 }
01194 else
01195 {
01196 if (that == NULL)
01197 {
01198
01199 #ifndef NDEBUG
01200 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Second object is NULL, first is not");
01201 #endif
01202 return false;
01203 }
01204 else
01205 {
01206 if ( !this->basic->IsEqual(that->basic) ) return false;
01207 if ( !this->atLower->IsEqual(that->atLower) ) return false;
01208 if ( !this->atUpper->IsEqual(that->atUpper) ) return false;
01209 if ( !this->atEquality->IsEqual(that->atEquality) ) return false;
01210 if ( !this->isFree->IsEqual(that->isFree) ) return false;
01211 if ( !this->superbasic->IsEqual(that->superbasic) ) return false;
01212 if ( !this->unknown->IsEqual(that->unknown) ) return false;
01213
01214 return true;
01215 }
01216 }
01217 }
01218
01219 bool BasisStatus::setRandom(double density, bool conformant, int iMin, int iMax)
01220 {
01221 #ifndef NDEBUG
01222 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Set random BasisStatus");
01223 #endif
01224 if (OSRand() <= density)
01225 {
01226 this->basic = new IntVector();
01227 this->basic->setRandom(density, conformant, iMin, iMax);
01228 }
01229 if (OSRand() <= density)
01230 {
01231 this->atLower = new IntVector();
01232 this->atLower->setRandom(density, conformant, iMin, iMax);
01233 }
01234 if (OSRand() <= density)
01235 {
01236 this->atUpper = new IntVector();
01237 this->atUpper->setRandom(density, conformant, iMin, iMax);
01238 }
01239 if (OSRand() <= density)
01240 {
01241 this->atEquality = new IntVector();
01242 this->atEquality->setRandom(density, conformant, iMin, iMax);
01243 }
01244 if (OSRand() <= density)
01245 {
01246 this->isFree = new IntVector();
01247 this->isFree->setRandom(density, conformant, iMin, iMax);
01248 }
01249 if (OSRand() <= density)
01250 {
01251 this->superbasic = new IntVector();
01252 this->superbasic->setRandom(density, conformant, iMin, iMax);
01253 }
01254 if (OSRand() <= density)
01255 {
01256 this->unknown = new IntVector();
01257 this->unknown->setRandom(density, conformant, iMin, iMax);
01258 }
01259
01260 return true;
01261 }
01262
01263 bool BasisStatus::deepCopyFrom(BasisStatus *that)
01264 {
01265 #ifndef NDEBUG
01266 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of BasisStatus");
01267 #endif
01268 if (that->basic != NULL)
01269 {
01270 this->basic = new IntVector();
01271 if (!this->basic->deepCopyFrom(that->basic))
01272 return false;
01273 }
01274 if (that->atLower != NULL)
01275 {
01276 this->atLower = new IntVector();
01277 if (!this->atLower->deepCopyFrom(that->atLower))
01278 return false;
01279 }
01280 if (that->atUpper != NULL)
01281 {
01282 this->atUpper = new IntVector();
01283 if (!this->atUpper->deepCopyFrom(that->atUpper))
01284 return false;
01285 }
01286 if (that->atEquality != NULL)
01287 {
01288 this->atEquality = new IntVector();
01289 if (!this->atEquality->deepCopyFrom(that->atEquality))
01290 return false;
01291 }
01292 if (that->isFree != NULL)
01293 {
01294 this->isFree = new IntVector();
01295 if (!this->isFree->deepCopyFrom(that->isFree))
01296 return false;
01297 }
01298 if (that->superbasic != NULL)
01299 {
01300 this->superbasic = new IntVector();
01301 if (!this->superbasic->deepCopyFrom(that->superbasic))
01302 return false;
01303 }
01304 if (that->unknown != NULL)
01305 {
01306 this->unknown = new IntVector();
01307 if (!this->unknown->deepCopyFrom(that->unknown))
01308 return false;
01309 }
01310
01311 return true;
01312 }
01313
01314 StorageCapacity::StorageCapacity():
01315 unit("byte"),
01316 description(""),
01317 value(0.0)
01318 {
01319 }
01320
01321 StorageCapacity::~StorageCapacity()
01322 {
01323 #ifndef NDEBUG
01324 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside StorageCapacity destructor");
01325 #endif
01326 }
01327
01328 bool StorageCapacity::IsEqual(StorageCapacity *that)
01329 {
01330 std::ostringstream outStr;
01331
01332 #ifndef NDEBUG
01333 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in StorageCapacity");
01334 #endif
01335 if (this == NULL)
01336 {
01337 if (that == NULL)
01338 return true;
01339 else
01340 {
01341 #ifndef NDEBUG
01342 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "First object is NULL, second is not");
01343 #endif
01344 return false;
01345 }
01346 }
01347 else
01348 {
01349 if (that == NULL)
01350 {
01351 #ifndef NDEBUG
01352 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Second object is NULL, first is not");
01353 #endif
01354 return false;
01355 }
01356 else
01357 {
01358 if ( (this->unit != that->unit) ||
01359 (this->description != that->description) ||
01360 !isEqual(this->value, that->value))
01361 {
01362 #ifndef NDEBUG
01363 outStr.str("");
01364 outStr.clear();
01365 outStr << "unit: " << this->unit << " vs. " << that->unit << endl;
01366 outStr << "description: " << this->description << " vs. " << that->description << endl;
01367 outStr << "value: " << this->value << " vs. " << that->value << endl;
01368 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
01369 #endif
01370 return false;
01371 }
01372 return true;
01373 }
01374 }
01375 }
01376
01377 bool StorageCapacity::setRandom(double density, bool conformant)
01378 {
01379 if (OSRand() <= density)
01380 {
01381 double temp = OSRand();
01382 if (conformant) temp = 0.5*temp;
01383
01384 if (temp <= 0.25) this->unit = "byte";
01385 else if (temp <= 0.50) this->unit = "megabyte";
01386 else if (temp <= 0.75) this->unit = "";
01387 else this->unit = "overbyte";
01388 }
01389 if (OSRand() <= density) this->description = "random string";
01390 if (OSRand() <= density)
01391 {
01392 if (OSRand() <= 0.5) this->value = 3.14156;
01393 else this->value = 2.71828;
01394 }
01395 return true;
01396 }
01397
01398 bool StorageCapacity::deepCopyFrom(StorageCapacity *that)
01399 {
01400 #ifndef NDEBUG
01401 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of StorageCapacity");
01402 #endif
01403 this->unit = that->unit;
01404 this->description = that->description;
01405 this->value = that->value;
01406 return true;
01407 }
01408
01409 CPUSpeed::CPUSpeed():
01410 unit("hertz"),
01411 description(""),
01412 value(0.0)
01413 {
01414 }
01415
01416 CPUSpeed::~CPUSpeed()
01417 {
01418 #ifndef NDEBUG
01419 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside CPUSpeed destructor");
01420 #endif
01421 }
01422
01423 bool CPUSpeed::IsEqual(CPUSpeed *that)
01424 {
01425 std::ostringstream outStr;
01426
01427 #ifndef NDEBUG
01428 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in CPUSpeed");
01429 #endif
01430 if (this == NULL)
01431 {
01432 if (that == NULL)
01433 return true;
01434 else
01435 {
01436 #ifndef NDEBUG
01437 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "First object is NULL, second is not");
01438 #endif
01439 return false;
01440 }
01441 }
01442 else
01443 {
01444 if (that == NULL)
01445 {
01446 #ifndef NDEBUG
01447 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Second object is NULL, first is not");
01448 #endif
01449 return false;
01450 }
01451 else
01452 {
01453 if ((this->unit != that->unit) ||
01454 (this->description != that->description) ||
01455 !isEqual(this->value, that->value))
01456 {
01457 #ifndef NDEBUG
01458 outStr.str("");
01459 outStr.clear();
01460 outStr << "unit: " << this->unit << " vs. " << that->unit << endl;
01461 outStr << "description: " << this->description << " vs. " << that->description << endl;
01462 outStr << "value: " << this->value << " vs. " << that->value << endl;
01463 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
01464 #endif
01465 return false;
01466 }
01467 return true;
01468 }
01469 }
01470 }
01471
01472 bool CPUSpeed::setRandom(double density, bool conformant)
01473 {
01474 if (OSRand() <= density)
01475 {
01476 double temp = OSRand();
01477 if (conformant) temp = 0.5*temp;
01478
01479 if (temp <= 0.25) this->unit = "hertz";
01480 else if (temp <= 0.50) this->unit = "gigaflops";
01481 else if (temp <= 0.75) this->unit = "";
01482 else this->unit = "bellyflops";
01483 }
01484 if (OSRand() <= density) this->description = "random string";
01485 if (OSRand() <= density)
01486 {
01487 if (OSRand() <= 0.5) this->value = 3.14156;
01488 else this->value = 2.71828;
01489 }
01490 return true;
01491 }
01492
01493 bool CPUSpeed::deepCopyFrom(CPUSpeed *that)
01494 {
01495 #ifndef NDEBUG
01496 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of CPUSpeed");
01497 #endif
01498 this->unit = that->unit;
01499 this->description = that->description;
01500 this->value = that->value;
01501 return true;
01502 }
01503
01504 CPUNumber::CPUNumber():
01505 description(""),
01506 value(0)
01507 {
01508 }
01509
01510 CPUNumber::~CPUNumber()
01511 {
01512 #ifndef NDEBUG
01513 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside CPUNumber destructor");
01514 #endif
01515 }
01516
01517 bool CPUNumber::IsEqual(CPUNumber *that)
01518 {
01519 std::ostringstream outStr;
01520
01521 #ifndef NDEBUG
01522 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in CPUNumber");
01523 #endif
01524 if (this == NULL)
01525 {
01526 if (that == NULL)
01527 return true;
01528 else
01529 {
01530 #ifndef NDEBUG
01531 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "First object is NULL, second is not");
01532 #endif
01533 return false;
01534 }
01535 }
01536 else
01537 {
01538 if (that == NULL)
01539 {
01540 #ifndef NDEBUG
01541 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Second object is NULL, first is not");
01542 #endif
01543 return false;
01544 }
01545 else
01546
01547 {
01548 if ((this->description != that->description) ||
01549 (this->value != that->value))
01550 {
01551 #ifndef NDEBUG
01552 outStr.str("");
01553 outStr.clear();
01554 outStr << "description: " << this->description << " vs. " << that->description << endl;
01555 outStr << "value: " << this->value << " vs. " << that->value << endl;
01556 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
01557 #endif
01558 return false;
01559 }
01560 return true;
01561 }
01562 }
01563 }
01564
01565 bool CPUNumber::setRandom(double density, bool conformant)
01566 {
01567 if (OSRand() <= density) this->description = "random string";
01568 if (OSRand() <= density) this->value = (int)(4*OSRand());
01569 return true;
01570 }
01571
01572 bool CPUNumber::deepCopyFrom(CPUNumber *that)
01573 {
01574 #ifndef NDEBUG
01575 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of CPUNumber");
01576 #endif
01577 this->description = that->description;
01578 this->value = that->value;
01579 return true;
01580 }
01581
01582
01583 TimeSpan::TimeSpan():
01584 unit("second"),
01585 value(0.0)
01586 {
01587 }
01588
01589 TimeSpan::~TimeSpan()
01590 {
01591 #ifndef NDEBUG
01592 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "inside TimeSpan destructor");
01593 #endif
01594 }
01595
01596 bool TimeSpan::IsEqual(TimeSpan *that)
01597 {
01598 std::ostringstream outStr;
01599
01600 #ifndef NDEBUG
01601 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, "Start comparing in TimeSpan");
01602 #endif
01603 if (this == NULL)
01604 {
01605 if (that == NULL)
01606 return true;
01607 else
01608 {
01609 #ifndef NDEBUG
01610 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "First object is NULL, second is not");
01611 #endif
01612 return false;
01613 }
01614 }
01615 else
01616 {
01617 if (that == NULL)
01618 {
01619 #ifndef NDEBUG
01620 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Second object is NULL, first is not");
01621 #endif
01622 return false;
01623 }
01624 else
01625 {
01626 if (!isEqual(this->value, that->value) ||
01627 this->unit != that->unit )
01628
01629 {
01630 #ifndef NDEBUG
01631 outStr.str("");
01632 outStr.clear();
01633 outStr << "unit: " << this->unit << " vs. " << that->unit << endl;
01634 outStr << "value: " << this->value << " vs. " << that->value << endl;
01635 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_debug, outStr.str());
01636 #endif
01637 return false;
01638 }
01639 return true;
01640 }
01641 }
01642 }
01643
01644 bool TimeSpan::setRandom(double density, bool conformant)
01645 {
01646 if (OSRand() <= density)
01647 {
01648 double temp = OSRand();
01649 if (conformant) temp = 0.5*temp;
01650
01651 if (temp <= 0.25) this->unit = "second";
01652 else if (temp <= 0.50) this->unit = "tick";
01653 else if (temp <= 0.75) this->unit = "";
01654 else this->unit = "flea";
01655 }
01656 if (OSRand() <= density)
01657 {
01658 if (OSRand() <= 0.5) this->value = 3.14156;
01659 else this->value = 2.71828;
01660 }
01661 return true;
01662 }
01663
01664 bool TimeSpan::deepCopyFrom(TimeSpan *that)
01665 {
01666 #ifndef NDEBUG
01667 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of TimeSpan");
01668 #endif
01669 this->unit = that->unit;
01670 this->value = that->value;
01671 return true;
01672 }
01673