Changeset 97 for trunk/src/python
- Timestamp:
- Oct 10, 2005 9:00:37 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/python/PyRpUnits.cc
r78 r97 38 38 PyObject* rv = NULL; 39 39 40 if (self->rp_unit){ 40 if (self->rp_unit){ 41 41 rv = PyString_FromString(self->rp_unit->getUnitsName().c_str()); 42 42 } … … 50 50 PyObject* rv = NULL; 51 51 52 if (self->rp_unit){ 52 if (self->rp_unit){ 53 53 rv = PyFloat_FromDouble(self->rp_unit->getExponent()); 54 54 } … … 102 102 {"makeBasis", (PyCFunction)RpUnitsObject_makeBasis, METH_VARARGS, 103 103 "return the basis value of the value provided" }, 104 104 105 105 {NULL} /* Sentinel */ 106 106 }; … … 183 183 /* 184 184 * need to make it so user can give any number of variables in arglist 185 * because the new argList is sent to the python conversion fxn where it 185 * because the new argList is sent to the python conversion fxn where it 186 186 * will be parsed in python when c++ calls the conv fxn. 187 187 PyArg_ParseTuple(args, "O!", &RpUnitsObjectType, &toUnits); … … 204 204 205 205 if (self->rp_unit){ 206 outVal = (PyObject*) self->rp_unit->convert(toUnits->rp_unit, 207 // (void*)&inVal, 208 (void*)argList, 206 outVal = (PyObject*) self->rp_unit->convert(toUnits->rp_unit, 207 // (void*)&inVal, 208 (void*)argList, 209 209 &result ); 210 210 if (result) { … … 266 266 { 267 267 PyObject* retVal = NULL; 268 268 269 269 if ((PyObject*)fxnPtr != NULL) { 270 270 retVal = PyObject_CallObject((PyObject*)fxnPtr,(PyObject*)args); … … 294 294 295 295 if (PyTuple_Size(args) > 0) { 296 PyArg_ParseTuple(args, "O!O!O!O!",&RpUnitsObjectType, &fromUnit, 297 &RpUnitsObjectType, &toUnit, 296 PyArg_ParseTuple(args, "O!O!O!O!",&RpUnitsObjectType, &fromUnit, 297 &RpUnitsObjectType, &toUnit, 298 298 &PyFunction_Type, &forwConvFxnStr, 299 299 &PyFunction_Type, &backConvFxnStr); … … 319 319 320 320 // make sure we get callable functions and non-null RpUnit Objects 321 if ( PyCallable_Check(forwConvFxnStr) && 321 if ( PyCallable_Check(forwConvFxnStr) && 322 322 PyCallable_Check(backConvFxnStr) && 323 323 fromUnit->rp_unit && … … 350 350 } 351 351 352 PyDoc_STRVAR(RpUnits_find_doc, 352 PyDoc_STRVAR(RpUnits_find_doc, 353 353 "find(name) -> RpUnitsObject \n\ 354 354 \n\ … … 370 370 return NULL; 371 371 } 372 372 373 373 foundUnits = RpUnits::find(searchUnits); 374 374 … … 378 378 if (returnUnits == NULL) 379 379 return NULL; 380 380 381 381 returnUnits->rp_unit = foundUnits; 382 382 } 383 383 384 384 return (PyObject*) returnUnits; 385 385 386 386 } 387 387 … … 404 404 return NULL; 405 405 } 406 406 407 407 if (units->rp_unit) { 408 408 result = RpUnits::makeMetric(units->rp_unit); … … 412 412 } 413 413 414 PyDoc_STRVAR(RpUnits_convert_doc, 414 PyDoc_STRVAR(RpUnits_convert_doc, 415 415 "convert (fromVal, to, units) -> PyString \n\ 416 416 \n\ … … 439 439 440 440 static char *kwlist[] = {"fromVal", "to", "units", NULL}; 441 441 442 442 if (PyTuple_Size(args) > 0) { 443 443 // PyArg_ParseTuple(args, "ss|s", &fromVal, &to, &units); … … 467 467 if ( (!retStr.empty()) && (result == 0) ) { 468 468 if (unitsVal) { 469 retVal = PyString_FromString(retStr.c_str()); 469 retVal = PyString_FromString(retStr.c_str()); 470 470 } 471 471 else { 472 // convert to a double and return that if 472 // convert to a double and return that if 473 473 // the units were turned off 474 475 476 Py_INCREF(tmpPyStr);477 retVal = PyFloat_FromString(tmpPyStr,NULL);478 Py_DECREF(tmpPyStr);479 474 tmpPyStr = PyString_FromString(retStr.c_str()); 475 if (tmpPyStr) { 476 Py_INCREF(tmpPyStr); 477 retVal = PyFloat_FromString(tmpPyStr,NULL); 478 Py_DECREF(tmpPyStr); 479 } 480 480 } 481 481 } … … 483 483 //keeping this around in case you want string returned instead of None 484 484 //if (fromVal) { 485 // retVal = PyString_FromString(fromVal); 485 // retVal = PyString_FromString(fromVal); 486 486 //} 487 487 //else { … … 490 490 //} 491 491 } 492 492 493 493 return retVal; 494 494 } … … 506 506 {"defineConv", RpUnits_defineConv, METH_VARARGS, 507 507 RpUnits_defineConv_doc}, 508 508 509 509 {"find", RpUnits_find, METH_VARARGS, 510 510 RpUnits_find_doc}, … … 512 512 {"makeMetric", RpUnits_makeMetric, METH_VARARGS, 513 513 RpUnits_makeMetric_doc}, 514 514 515 515 {"convert", (PyCFunction)RpUnits_convert, METH_VARARGS|METH_KEYWORDS, 516 516 RpUnits_convert_doc}, 517 517 518 518 {NULL, NULL} /* sentinel */ 519 519 }; … … 529 529 530 530 /* Finalize the type object including setting type of the new type 531 * object; doing it here is required for portability to Windows 531 * object; doing it here is required for portability to Windows 532 532 * without requiring C++. */ 533 533 if (PyType_Ready(&RpUnitsObjectType) < 0)
Note: See TracChangeset
for help on using the changeset viewer.