Changeset 114 for trunk/include/core/RpUnits.h
- Timestamp:
- Oct 20, 2005, 8:47:25 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/core/RpUnits.h
r104 r114 53 53 double& exponent, 54 54 const RpUnits* basis, 55 unit* prev, 55 56 unit* next 56 57 ) … … 58 59 exponent (exponent), 59 60 basis (basis), 60 prev ( NULL),61 prev (prev), 61 62 next (next) 62 63 {}; … … 64 65 /* 65 66 // private copy constructor 66 unit ( unit& other )67 : units (other.units),68 exponent (other.exponent),69 basis (other.basis),70 prev (other.prev),71 next (other.next)67 unit ( const unit& other ) 68 : units other.units, 69 exponent other.exponent, 70 basis other.basis, 71 prev unit(other.prev), 72 next unit(other.next) 72 73 {}; 73 74 74 75 // copy assignment operator 75 unit& operator= (unit& other) { 76 units = other.units; 77 exponent = other.exponent; 78 basis = other.basis; 79 prev = other.prev; 80 next = other.next; 81 } 82 76 unit& operator= (unit& other) 77 : units other.units, 78 exponent other.exponent, 79 basis RpUnits(other.basis), 80 prev unit(other.prev), 81 next unit(other.next) 82 {} 83 */ 84 85 /* 83 86 // destructor (its not virtual yet, still testing) 84 87 ~unit () { … … 106 109 107 110 friend class RpUnits; 111 112 // copy constructor 113 conversion ( conversion& other) 114 : fromPtr (other.fromPtr), 115 toPtr (other.toPtr), 116 convForwFxnPtr (other.convForwFxnPtr), 117 convBackFxnPtr (other.convBackFxnPtr), 118 convForwFxnPtrDD (other.convForwFxnPtrDD), 119 convBackFxnPtrDD (other.convBackFxnPtrDD), 120 convForwFxnPtrVoid (other.convForwFxnPtrVoid), 121 convForwData (other.convForwData), 122 convBackFxnPtrVoid (other.convBackFxnPtrVoid), 123 convBackData (other.convBackData) 124 {}; 125 126 // copy assignment operator 127 conversion& operator= ( conversion& other ) 128 { 129 fromPtr = other.fromPtr; 130 toPtr = other.toPtr; 131 convForwFxnPtr = other.convForwFxnPtr; 132 convBackFxnPtr = other.convBackFxnPtr; 133 convForwFxnPtrDD = other.convForwFxnPtrDD; 134 convBackFxnPtrDD = other.convBackFxnPtrDD; 135 convForwFxnPtrVoid = other.convForwFxnPtrVoid; 136 convForwData = other.convForwData; 137 convBackFxnPtrVoid = other.convBackFxnPtrVoid; 138 convBackData = other.convBackData; 139 return *this; 140 } 141 142 // default destructor 143 virtual ~conversion () 144 {} 108 145 109 146 private: … … 120 157 void* convBackData; 121 158 122 conversion* prev;123 conversion* next;124 125 159 // constructor 126 160 // private because i only want RpUnits to be able to … … 130 164 const RpUnits* toPtr, 131 165 double (*convForwFxnPtr)(double), 132 double (*convBackFxnPtr)(double), 133 conversion* prev, 134 conversion* next 166 double (*convBackFxnPtr)(double) 135 167 ) 136 168 : fromPtr (fromPtr), … … 143 175 convForwData (NULL), 144 176 convBackFxnPtrVoid (NULL), 145 convBackData (NULL), 146 prev (prev), 147 next (next) 148 {}; 149 177 convBackData (NULL) 178 {}; 179 180 // constructor for 2 argument conversion functions 150 181 conversion ( 151 182 const RpUnits* fromPtr, 152 183 const RpUnits* toPtr, 153 184 double (*convForwFxnPtr)(double,double), 154 double (*convBackFxnPtr)(double,double), 155 conversion* prev, 156 conversion* next 185 double (*convBackFxnPtr)(double,double) 157 186 ) 158 187 : fromPtr (fromPtr), … … 165 194 convForwData (NULL), 166 195 convBackFxnPtrVoid (NULL), 167 convBackData (NULL) ,168 prev (prev),169 next (next) 170 {};171 196 convBackData (NULL) 197 {}; 198 199 // constructor for user defined void* returning 1 arg conversion fxns. 200 // the 1 arg is a user defined void* object 172 201 conversion ( 173 202 const RpUnits* fromPtr, … … 176 205 void* convForwData, 177 206 void* (*convBackFxnPtrVoid)(void*, void*), 178 void* convBackData, 179 conversion* prev, 180 conversion* next 207 void* convBackData 181 208 ) 182 209 : fromPtr (fromPtr), … … 189 216 convForwData (convForwData), 190 217 convBackFxnPtrVoid (convBackFxnPtrVoid), 191 convBackData (convBackData), 192 prev (prev), 193 next (next) 194 {}; 195 196 // copy constructor 197 198 // destructor 218 convBackData (convBackData) 219 {}; 220 199 221 }; 200 222 … … 212 234 friend class RpUnits; 213 235 236 virtual ~convEntry() 237 {} 238 214 239 private: 215 240 … … 228 253 {}; 229 254 230 /*231 ~convEntry()232 {233 234 }235 */236 255 }; 237 256 … … 293 312 static RpUnits * define(const std::string units, 294 313 const RpUnits* basis); 314 // unsigned int create=0); 295 315 static RpUnits * defineCmplx( const std::string units, 296 316 const RpUnits* basis); … … 318 338 // if group equals......................then load................ 319 339 // "all" load all available units 320 // "energy" load units related to length340 // "energy" load units related to energy 321 341 // "length" load units related to length 322 342 // "temp" load units related to temperature … … 325 345 // (no other groups have been created) 326 346 327 static int addPresets ( std::string group);347 static int addPresets (const std::string group); 328 348 329 349 // undefining a relation rule is probably not needed 330 350 // int undefine(); // delete a relation 331 332 // convert fxn will be taken care of in the RpUnitsConversion class333 // i think334 // int convert(const char* from, const char* to);335 351 336 352 // why are these functions friends... … … 341 357 342 358 // copy constructor 343 RpUnits ( const RpUnits& myRpUnit ) 359 RpUnits (RpUnits &other) 360 : head (NULL), 361 convList (NULL) 344 362 { 345 346 /* 347 from = myRpUnit.from; 348 to = myRpUnit.to; 349 convertForw = myRpUnit.convertForw; 350 convertBack = myRpUnit.convertBack; 351 */ 352 353 // copy constructor for unit 354 unit* tmp = NULL; 355 unit* newUnit = NULL; 356 unit* p = myRpUnit.head; 357 358 while (p != NULL) { 359 newUnit = new unit(p->units, p->exponent,p->basis,NULL); 360 361 newUnit->prev = tmp; 362 if (tmp) { 363 tmp->next = newUnit; 363 unit* p = NULL; 364 unit* current = NULL; 365 convEntry* q = NULL; 366 convEntry* curr2 = NULL; 367 368 dict = other.dict; 369 370 if (other.head) { 371 p = other.head; 372 head = new unit(p->units, p->exponent, p->basis, NULL, NULL); 373 current = head; 374 375 while (p->next) { 376 p = p->next; 377 current->next = new unit( p->units, 378 p->exponent, 379 p->basis, 380 current, 381 NULL ); 382 current = current->next; 364 383 } 365 366 tmp = newUnit; 367 p = p->next; 368 } 369 370 if (tmp) { 371 while (tmp->prev != NULL) { 372 tmp = tmp->prev; 384 } 385 if (other.convList) { 386 q = other.convList; 387 convList = new convEntry (q->conv,NULL,NULL); 388 curr2 = convList; 389 while (q->next) { 390 q = q->next; 391 curr2->next = new convEntry (q->conv,curr2,NULL); 392 curr2 = curr2->next; 373 393 } 374 394 } 375 376 head = tmp; 377 378 }; 379 380 /* 395 } 396 381 397 // copy assignment operator 382 RpUnits& operator= (const RpUnits& myRpUnit) { 383 384 if ( this != &myRpUnit ) { 398 RpUnits& operator= (const RpUnits& other) { 399 400 unit* p = NULL; 401 unit* current = NULL; 402 convEntry* q = NULL; 403 convEntry* curr2 = NULL; 404 405 if ( this != &other ) { 385 406 delete head; 386 407 delete convList; 387 delete conv; 388 } 408 } 409 410 dict = other.dict; 411 412 if (other.head) { 413 p = other.head; 414 head = new unit(p->units, p->exponent, p->basis, NULL, NULL); 415 current = head; 416 417 while (p->next) { 418 p = p->next; 419 current->next = new unit( p->units, 420 p->exponent, 421 p->basis, 422 current, 423 NULL ); 424 current = current->next; 425 } 426 } 427 if (other.convList) { 428 q = other.convList; 429 convList = new convEntry (q->conv,NULL,NULL); 430 curr2 = convList; 431 while (q->next) { 432 q = q->next; 433 curr2->next = new convEntry (q->conv,curr2,NULL); 434 curr2 = curr2->next; 435 } 436 } 437 438 return *this; 389 439 } 390 */ 440 441 // default destructor 442 // 443 ~RpUnits () 444 { 445 // clean up dynamic memory 446 447 unit* p = head; 448 unit* tmp = p; 449 convEntry* p2 = convList; 450 convEntry* tmp2 = p2; 451 452 while (p != NULL) { 453 tmp = p; 454 p = p->next; 455 delete tmp; 456 } 457 458 while (p2 != NULL) { 459 tmp2 = p2; 460 p2 = p2->next; 461 delete tmp2; 462 } 463 } 391 464 392 465 private: … … 415 488 mutable convEntry* convList; 416 489 417 // used by the RpUnits when defining conversion elements418 conversion* conv;419 490 420 491 // dictionary to store the units. … … 436 507 const RpUnits* basis 437 508 ) 438 : head ( new unit( units, exponent, basis, NULL) ), 439 convList (NULL), 440 conv (NULL) 509 : head ( new unit( units, exponent, basis, NULL, NULL) ), 510 convList (NULL) 441 511 {}; 442 512 443 // create a conversion element 444 445 446 447 448 RpUnits ( 449 const RpUnits* from, 450 const RpUnits* to, 451 double (*convForwFxnPtr)(double), 452 double (*convBackFxnPtr)(double), 453 conversion* prev, 454 conversion* next 455 ) 456 : head (NULL), 457 convList (NULL), 458 conv (new conversion 459 (from,to,convForwFxnPtr,convBackFxnPtr,prev,next)) 460 { 461 connectConversion(from); 462 connectConversion(to); 463 }; 464 465 466 RpUnits ( 467 const RpUnits* from, 468 const RpUnits* to, 469 double (*convForwFxnPtr)(double,double), 470 double (*convBackFxnPtr)(double,double), 471 conversion* prev, 472 conversion* next 473 ) 474 : head (NULL), 475 convList (NULL), 476 conv (new conversion 477 (from,to,convForwFxnPtr,convBackFxnPtr,prev,next)) 478 { 479 connectConversion(from); 480 connectConversion(to); 481 }; 482 483 484 485 RpUnits ( 486 const RpUnits* from, 487 const RpUnits* to, 488 void* (*convForwFxnPtr)(void*, void*), 489 void* convForwData, 490 void* (*convBackFxnPtr)(void*, void*), 491 void* convBackData, 492 conversion* prev, 493 conversion* next 494 ) 495 : head (NULL), 496 convList (NULL), 497 conv (new conversion ( from, to, 498 convForwFxnPtr, convForwData, 499 convBackFxnPtr, convBackData, 500 prev, next 501 ) 502 ) 503 { 504 connectConversion(from); 505 connectConversion(to); 506 }; 507 508 // default destructor 509 // 510 ~RpUnits () 511 { 512 // clean up dynamic memory 513 514 unit* p = head; 515 while (p != NULL) { 516 unit* tmp = p; 517 p = p->next; 518 delete tmp; 519 } 520 } 521 522 void RpUnits::connectConversion(const RpUnits* myRpUnit); 523 524 void RpUnits::fillMetricMap(); 525 526 // create the container keeping track of defined units 527 // returns 0 on success (table created or already exists) 528 // returns !0 on failure (table not created or cannot exist) 529 int RpUnits::createUnitsTable(); 513 void RpUnits::connectConversion(conversion* conv) const; 530 514 531 515 // insert new RpUnits object into RpUnitsTable … … 537 521 // returns 0 on success (linking within table was successful) 538 522 // returns !0 on failure (linking was not successful) 539 int RpUnits::link(RpUnits * unitA);523 // int RpUnits::link(RpUnits * unitA); 540 524 541 525 … … 561 545 /*--------------------------------------------------------------------------*/ 562 546 563 // #include "../src/RpUnits.cc"564 565 547 #endif
Note: See TracChangeset
for help on using the changeset viewer.