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