Changeset 97 for trunk/src/python


Ignore:
Timestamp:
Oct 10, 2005 9:00:37 PM (19 years ago)
Author:
dkearney
Message:

adding initial matlab bindings
few minor changes with other listed files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/python/PyRpUnits.cc

    r78 r97  
    3838    PyObject* rv = NULL;
    3939
    40     if (self->rp_unit){ 
     40    if (self->rp_unit){
    4141        rv = PyString_FromString(self->rp_unit->getUnitsName().c_str());
    4242    }
     
    5050    PyObject* rv = NULL;
    5151
    52     if (self->rp_unit){ 
     52    if (self->rp_unit){
    5353        rv = PyFloat_FromDouble(self->rp_unit->getExponent());
    5454    }
     
    102102    {"makeBasis", (PyCFunction)RpUnitsObject_makeBasis, METH_VARARGS,
    103103     "return the basis value of the value provided" },
    104    
     104
    105105    {NULL}  /* Sentinel */
    106106};
     
    183183        /*
    184184         * 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
    186186         * will be parsed in python when c++ calls the conv fxn.
    187187        PyArg_ParseTuple(args, "O!", &RpUnitsObjectType, &toUnits);
     
    204204
    205205    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,
    209209                                                    &result );
    210210        if (result) {
     
    266266{
    267267    PyObject* retVal = NULL;
    268    
     268
    269269    if ((PyObject*)fxnPtr != NULL) {
    270270        retVal = PyObject_CallObject((PyObject*)fxnPtr,(PyObject*)args);
     
    294294
    295295    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,
    298298                                          &PyFunction_Type, &forwConvFxnStr,
    299299                                          &PyFunction_Type, &backConvFxnStr);
     
    319319
    320320    // make sure we get callable functions and non-null RpUnit Objects
    321     if ( PyCallable_Check(forwConvFxnStr) && 
     321    if ( PyCallable_Check(forwConvFxnStr) &&
    322322         PyCallable_Check(backConvFxnStr) &&
    323323         fromUnit->rp_unit &&
     
    350350}
    351351
    352 PyDoc_STRVAR(RpUnits_find_doc, 
     352PyDoc_STRVAR(RpUnits_find_doc,
    353353"find(name) -> RpUnitsObject \n\
    354354\n\
     
    370370        return NULL;
    371371    }
    372    
     372
    373373    foundUnits = RpUnits::find(searchUnits);
    374374
     
    378378        if (returnUnits == NULL)
    379379            return NULL;
    380        
     380
    381381        returnUnits->rp_unit = foundUnits;
    382382    }
    383383
    384384    return (PyObject*) returnUnits;
    385    
     385
    386386}
    387387
     
    404404        return NULL;
    405405    }
    406    
     406
    407407    if (units->rp_unit) {
    408408        result = RpUnits::makeMetric(units->rp_unit);
     
    412412}
    413413
    414 PyDoc_STRVAR(RpUnits_convert_doc, 
     414PyDoc_STRVAR(RpUnits_convert_doc,
    415415"convert (fromVal, to, units) -> PyString \n\
    416416\n\
     
    439439
    440440    static char *kwlist[] = {"fromVal", "to", "units", NULL};
    441    
     441
    442442    if (PyTuple_Size(args) > 0) {
    443443        // PyArg_ParseTuple(args, "ss|s", &fromVal, &to, &units);
     
    467467    if ( (!retStr.empty()) && (result == 0) ) {
    468468        if (unitsVal) {
    469             retVal = PyString_FromString(retStr.c_str());   
     469            retVal = PyString_FromString(retStr.c_str());
    470470        }
    471471        else {
    472             // convert to a double and return that if 
     472            // convert to a double and return that if
    473473            // the units were turned off
    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             }
     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            }
    480480        }
    481481    }
     
    483483        //keeping this around in case you want string returned instead of None
    484484        //if (fromVal) {
    485         //    retVal = PyString_FromString(fromVal);   
     485        //    retVal = PyString_FromString(fromVal);
    486486        //}
    487487        //else {
     
    490490        //}
    491491    }
    492    
     492
    493493    return retVal;
    494494}
     
    506506    {"defineConv", RpUnits_defineConv, METH_VARARGS,
    507507        RpUnits_defineConv_doc},
    508    
     508
    509509    {"find", RpUnits_find, METH_VARARGS,
    510510        RpUnits_find_doc},
     
    512512    {"makeMetric", RpUnits_makeMetric, METH_VARARGS,
    513513        RpUnits_makeMetric_doc},
    514    
     514
    515515    {"convert", (PyCFunction)RpUnits_convert, METH_VARARGS|METH_KEYWORDS,
    516516        RpUnits_convert_doc},
    517    
     517
    518518    {NULL,        NULL}        /* sentinel */
    519519};
     
    529529
    530530    /* 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
    532532     * without requiring C++. */
    533533    if (PyType_Ready(&RpUnitsObjectType) < 0)
Note: See TracChangeset for help on using the changeset viewer.