- Timestamp:
- Oct 20, 2005, 8:47:25 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cee/RpLibraryCInterface.h
r97 r114 15 15 #endif 16 16 17 17 typedef struct RpLibrary RpLibrary; 18 18 19 // lib definition functions 20 RpLibrary* rpLibrary (const char* path); 21 void rpFreeLibrary (RpLibrary* lib); 19 // lib definition functions 20 // 21 RpLibrary* rpLibrary (const char* path); 22 void rpFreeLibrary (RpLibrary* lib); 22 23 23 24 25 26 27 28 24 // RpLibrary member functions 25 RpLibrary* rpElement (RpLibrary* lib, const char* path); 26 RpLibrary* rpElementAsObject (RpLibrary* lib, const char* path); 27 const char* rpElementAsType (RpLibrary* lib, const char* path); 28 const char* rpElementAsComp (RpLibrary* lib, const char* path); 29 const char* rpElementAsId (RpLibrary* lib, const char* path); 29 30 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 31 RpLibrary* rpChildren (RpLibrary* lib, 32 const char* path, 33 RpLibrary* childEle); 34 RpLibrary* rpChildrenByType (RpLibrary* lib, 35 const char* path, 36 RpLibrary* childEle, 37 const char* type ); 38 /* 39 RpLibrary* rpChildrenAsObject (RpLibrary* lib, 40 const char* path, 41 const char* type ); 42 const char* rpChildrenAsType (RpLibrary* lib, 43 const char* path, 44 const char* type ); 45 const char* rpChildrenAsComp (RpLibrary* lib, 46 const char* path, 47 const char* type ); 48 const char* rpChildrenAsId (RpLibrary* lib, 49 const char* path, 50 const char* type ); 51 */ 51 52 52 53 54 53 RpLibrary* rpGet (RpLibrary* lib, const char* path); 54 const char* rpGetString (RpLibrary* lib, const char* path); 55 double rpGetDouble (RpLibrary* lib, const char* path); 55 56 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 57 void rpPut (RpLibrary* lib, 58 const char* path, 59 const char* value, 60 const char* id, 61 int append ); 62 void rpPutStringId (RpLibrary* lib, 63 const char* path, 64 const char* value, 65 const char* id, 66 int append ); 67 void rpPutString (RpLibrary* lib, 68 const char* path, 69 const char* value, 70 int append ); 71 void rpPutDoubleId (RpLibrary* lib, 72 const char* path, 73 double value, 74 const char* id, 75 int append ); 76 void rpPutDouble (RpLibrary* lib, 77 const char* path, 78 double value, 79 int append ); 79 80 80 81 const char* rpXml (RpLibrary* lib); 81 82 82 83 84 83 const char* rpNodeComp (RpLibrary* node); 84 const char* rpNodeType (RpLibrary* node); 85 const char* rpNodeId (RpLibrary* node); 85 86 86 87 void rpResult (RpLibrary* lib); 87 88 88 89 #ifdef __cplusplus -
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 -
trunk/src/core/RpUnits.cc
r104 r114 433 433 const RpUnits* to, 434 434 double (*convForwFxnPtr)(double), 435 double (*convBackFxnPtr)(double)) { 436 437 RpUnits* conv = new RpUnits( from, 438 to, 439 convForwFxnPtr, 440 convBackFxnPtr, 441 NULL, 442 NULL); 443 444 return conv; 435 double (*convBackFxnPtr)(double) ) { 436 437 // this is kinda the wrong way to get the job done... 438 // how do we only create 1 conversion object and share it between atleast two RpUnits 439 // objs so that when the RpUnits objs are deleted, we are not trying to delete already 440 // deleted memory. 441 // so for the sake of safety we get the following few lines of code. 442 443 conversion* conv1 = NULL; 444 conversion* conv2 = NULL; 445 446 conv1 = new conversion (from,to,convForwFxnPtr,convBackFxnPtr); 447 conv2 = new conversion (from,to,convForwFxnPtr,convBackFxnPtr); 448 449 from->connectConversion(conv1); 450 to->connectConversion(conv2); 451 452 return NULL; 445 453 } 446 454 … … 451 459 double (*convBackFxnPtr)(double,double)) { 452 460 453 RpUnits* conv = new RpUnits( from, 454 to, 455 convForwFxnPtr, 456 convBackFxnPtr, 457 NULL, 458 NULL); 459 460 return conv; 461 // this is kinda the wrong way to get the job done... 462 // how do we only create 1 conversion object and share it between atleast two RpUnits 463 // objs so that when the RpUnits objs are deleted, we are not trying to delete already 464 // deleted memory. 465 // so for the sake of safety we get the following few lines of code. 466 467 conversion* conv1 = NULL; 468 conversion* conv2 = NULL; 469 470 conv1 = new conversion (from,to,convForwFxnPtr,convBackFxnPtr); 471 conv2 = new conversion (from,to,convForwFxnPtr,convBackFxnPtr); 472 473 from->connectConversion(conv1); 474 to->connectConversion(conv2); 475 476 return NULL; 461 477 } 462 478 … … 469 485 void* convBackData) { 470 486 471 RpUnits* conv = new RpUnits( from, 472 to, 473 convForwFxnPtr, 474 convForwData, 475 convBackFxnPtr, 476 convBackData, 477 NULL, 478 NULL); 479 480 return conv; 487 // this is kinda the wrong way to get the job done... 488 // how do we only create 1 conversion object and share it between atleast two RpUnits 489 // objs so that when the RpUnits objs are deleted, we are not trying to delete already 490 // deleted memory. 491 // so for the sake of safety we get the following few lines of code. 492 493 conversion* conv1 = NULL; 494 conversion* conv2 = NULL; 495 496 conv1 = new conversion (from,to,convForwFxnPtr,convForwData,convBackFxnPtr,convBackData); 497 conv2 = new conversion (from,to,convForwFxnPtr,convForwData,convBackFxnPtr,convBackData); 498 499 from->connectConversion(conv1); 500 to->connectConversion(conv2); 501 502 return NULL; 481 503 } 482 504 … … 630 652 const RpUnits* basis = getBasis(); 631 653 double retVal = *value; 632 int convResult = 0;654 int convResult = 1; 633 655 634 656 if (basis == NULL) { … … 644 666 } 645 667 646 if ( (convResult == 1) ) {668 if ( (convResult == 0) ) { 647 669 *value = retVal; 648 670 } … … 1206 1228 // check if the list was created previously. if not, start the list 1207 1229 if (head == 0) { 1208 head = new unit(units,exponent,basis,NULL );1230 head = new unit(units,exponent,basis,NULL,NULL); 1209 1231 return; 1210 1232 } 1211 1233 1212 1234 // now add a new node at the beginning of the list: 1213 p = new unit(units,exponent,basis, head);1235 p = new unit(units,exponent,basis,NULL,head); 1214 1236 head->prev = p; 1215 1237 head = p; … … 1343 1365 1344 1366 1345 void 1346 RpUnits::connectConversion(con st RpUnits* myRpUnit){1347 1348 convEntry* p = myRpUnit->convList;1367 void 1368 RpUnits::connectConversion(conversion* conv) const { 1369 1370 convEntry* p = convList; 1349 1371 1350 1372 if (p == NULL) { 1351 myRpUnit->convList = new convEntry (this->conv,NULL,NULL);1373 convList = new convEntry (conv,NULL,NULL); 1352 1374 } 1353 1375 else { … … 1356 1378 } 1357 1379 1358 p->next = new convEntry ( this->conv,p,NULL);1380 p->next = new convEntry (conv,p,NULL); 1359 1381 } 1360 1382 … … 1363 1385 // return codes: 0 success, anything else is error 1364 1386 int 1365 RpUnits::addPresets ( std::string group) {1387 RpUnits::addPresets (const std::string group) { 1366 1388 int retVal = -1; 1367 1389 if (group.compare("all") == 0) { -
trunk/test/src/RpUnits_test.cc
r104 r114 258 258 const RpUnits* eV = RpUnits::define("eV", NULL); 259 259 const RpUnits* joules = RpUnits::define("J", NULL); 260 260 261 261 RpUnits::define(eV, joules, electronVolt2joule, joule2electronVolt); 262 262 263 263 value = joules->convert(eV,1,&result); 264 264 std::cout << "1 joule = " << value << " electronVolts" << std::endl; 265 265 266 266 value = eV->convert(joules,1,&result); 267 267 std::cout << "1 electronVolt = " << value << " joules" << std::endl; 268 268 269 269 strValue = RpUnits::convert("10eV","J",1); 270 270 std::cout << "strValue convert(10eV,J,1) = " << strValue << std::endl; … … 272 272 strValue = RpUnits::convert("1eV","J",0); 273 273 std::cout << "strValue convert(1eV,J,0) = " << strValue << std::endl; 274 274 275 275 strValue = RpUnits::convert("10J","eV",1); 276 276 std::cout << "strValue convert(10J,eV,1) = " << strValue << std::endl; … … 278 278 strValue = RpUnits::convert("1J","eV",0); 279 279 std::cout << "strValue convert(1J,eV,0) = " << strValue << std::endl; 280 280 281 282 283 284 285 286 std::cout << "TESTING COPY CONSTRUCTOR" << std::endl; 287 288 RpUnits *origRpUnits = RpUnits::define("obj2", NULL); 289 RpUnits copyRpUnits = *origRpUnits; 290 291 std::cout << "origRpUnits = " << origRpUnits->getUnitsName() << std::endl; 292 std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; 293 std::cout << "modifying origRpUnits" << std::endl; 294 delete origRpUnits; 295 origRpUnits = RpUnits::define("obj3",NULL); 296 std::cout << "origRpUnits = " << origRpUnits->getUnitsName() << std::endl; 297 std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; 298 std::cout << "deleting origRpUnits" << std::endl; 299 delete origRpUnits; 300 std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; 301 302 std::cout << "TESTING COPY ASSIGNMENT OPERATOR" << std::endl; 303 304 RpUnits *testRpUnits = RpUnits::define("test2", NULL); 305 copyRpUnits = *testRpUnits; 306 307 std::cout << "testRpUnits = " << testRpUnits->getUnitsName() << std::endl; 308 std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; 309 std::cout << "modifying testRpUnits" << std::endl; 310 delete testRpUnits; 311 testRpUnits = RpUnits::define("test3",NULL); 312 std::cout << "testRpUnits = " << testRpUnits->getUnitsName() << std::endl; 313 std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; 314 std::cout << "deleting testRpUnits" << std::endl; 315 delete testRpUnits; 316 std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl; 281 317 return 0; 282 318 }
Note: See TracChangeset
for help on using the changeset viewer.