Changeset 73 for trunk/src/python
- Timestamp:
- Sep 28, 2005 12:09:43 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/python/PyRpUnits.cc
r71 r73 428 428 char* to = NULL; 429 429 char* units = NULL; 430 char* tmpRetStr = NULL; 430 431 std::string fromVal_S = ""; 431 432 std::string to_S = ""; … … 434 435 int result = 0; 435 436 std::string retStr = ""; 437 PyObject* retVal = NULL; 436 438 437 439 static char *kwlist[] = {"fromVal", "to", "units", NULL}; … … 462 464 retStr = RpUnits::convert(fromVal_S,to_S,unitsVal,&result); 463 465 464 if (!retStr.empty()) { 465 466 } 467 468 return PyString_FromString(retStr.c_str()); 466 if ( (!retStr.empty()) && (result == 1) ) { 467 if (unitsVal) { 468 retVal = PyString_FromString(retStr.c_str()); 469 } 470 else { 471 // convert to an integer and return that if 472 // the units were turned off 473 tmpRetStr = (char*) calloc(retStr.length(), sizeof(char)); 474 if (tmpRetStr) { 475 strncpy(tmpRetStr,retStr.c_str(),retStr.length()); 476 retVal = PyInt_FromString(tmpRetStr, NULL, 0); 477 free(tmpRetStr); 478 tmpRetStr = NULL; 479 } 480 } 481 } 482 else { 483 //keeping this around in case you want string returned instead of None 484 //if (fromVal) { 485 // retVal = PyString_FromString(fromVal); 486 //} 487 //else { 488 retVal = Py_None; 489 Py_INCREF(retVal); 490 //} 491 } 492 493 return retVal; 469 494 } 470 495
Note: See TracChangeset
for help on using the changeset viewer.