Changeset 1084 for trunk/src


Ignore:
Timestamp:
Aug 3, 2008, 11:04:29 PM (16 years ago)
Author:
dkearney
Message:

adding new general purpose dictionary to store void*'s instead of specific objects like RpLibrary?*'s or RpDXWriter*'s
we'll try this out in fortran, matlab and octave bindings

Location:
trunk/src/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpBindingsDict.cc

    r1011 r1084  
    1515RpDict DICT_TEMPLATE_L ObjDict_Lib;
    1616RpDict DICT_TEMPLATE_U ObjDictUnits;
     17RpDict DICT_TEMPLATE_V ObjDict_Void;
    1718
    1819/**********************************************************************/
     
    3536    int dictKey = key;
    3637    int newEntry = 0;
     38    bool ci = false;
    3739
    3840    if (objectName) {
     
    4547        }
    4648        long int dictKey_long = dictKey;
    47         ObjDict_Lib.set(dictKey_long,objectName,NULL,&newEntry);
     49        ObjDict_Lib.set(dictKey_long,objectName,NULL,&newEntry,ci);
    4850        retVal = dictKey;
    4951    }
     
    9496void
    9597cleanLibDict () {
    96     // clean up the dictionary
    97 
    9898    RpDictEntry DICT_TEMPLATE_L *hPtr;
    99     // RpDictIterator DICT_TEMPLATE iter(fortObjDict_Lib);
    10099    // should rp_quit clean up the dict or some function in RpBindingsCommon.h
    101100    RpDictIterator DICT_TEMPLATE_L iter(ObjDict_Lib);
     
    104103
    105104    while (hPtr) {
    106         // Py_DECREF(*(hPtr->getValue()));
    107105        hPtr->erase();
    108106        hPtr = iter.next();
    109107    }
    110108
    111     // if (fortObjDict_Lib.size()) {
    112109    if (ObjDict_Lib.size()) {
    113110        // probably want to change the warning sometime
     
    135132    int dictNextKey = ObjDictUnits.size() + 1;
    136133    int newEntry = 0;
     134    bool ci = false;
    137135
    138136    if (objectName != "") {
     
    141139        // the new entry.
    142140        long int dictNextKey_long = dictNextKey;
    143         ObjDictUnits.set(dictNextKey_long,objectName, NULL, &newEntry);
     141        ObjDictUnits.set(dictNextKey_long,objectName,NULL,&newEntry,ci);
    144142        retVal = dictNextKey;
    145143    }
     
    189187void
    190188cleanUnitsDict () {
    191     // clean up the dictionary
    192 
    193189    RpDictEntry DICT_TEMPLATE_U *hPtr;
    194190    // should rp_quit clean up the dict or some function in RpBindingsCommon.h
     
    207203    }
    208204}
     205
     206/**********************************************************************/
     207// FUNCTION: storeObject_Void()
     208/// Store an object into the general dictionary.
     209/**
     210 * This function stores a void* object pointed to by 'objectName'
     211 * into the general dictionary. This is helpful for writing bindings
     212 * for languages that can not accept pointers to provide back to the
     213 * function's caller.
     214 *
     215 * Returns the key of the object in the dictionary
     216 * On Error, returns 0 (which also means nothing can be stored at 0)
     217 */
     218
     219size_t
     220storeObject_Void(void* objectName, size_t key) {
     221
     222    size_t retVal = 0;
     223    size_t dictKey = key;
     224    int newEntry = 0;
     225    bool ci = false;
     226
     227    if (objectName) {
     228        // dictionary returns a reference to the inserted value
     229        // no error checking to make sure it was successful in entering
     230        // the new entry.
     231
     232        if (dictKey == 0) {
     233            dictKey = ObjDict_Void.size() + 1;
     234        }
     235        ObjDict_Void.set(dictKey,objectName,NULL,&newEntry,ci);
     236        retVal = dictKey;
     237    }
     238
     239    return retVal;
     240}
     241
     242/**********************************************************************/
     243// FUNCTION: getObject_Void()
     244/// Get an object from the general dictionary.
     245/**
     246 * This function retrieves the void* object associated with the key
     247 * 'objKey' from the general dictionary and returns its address to the
     248 * caller. This is helpful for writing bindings for languages that can
     249 * not accept pointers to provide back to the function's caller.
     250 *
     251 * Returns the address of the void* object in the dictionary
     252 */
     253
     254void*
     255getObject_Void(size_t objKey) {
     256
     257    RpDictEntry DICT_TEMPLATE_V* voidEntry = &(ObjDict_Void.getNullEntry());
     258    RpDictEntry DICT_TEMPLATE_V* nullEntry = &(ObjDict_Void.getNullEntry());
     259
     260    voidEntry = &(ObjDict_Void.find(objKey));
     261
     262    if ( (!voidEntry->isValid()) || (voidEntry == nullEntry) ) {
     263        return NULL;
     264    }
     265
     266   return *(voidEntry->getValue());
     267
     268}
     269
     270/**********************************************************************/
     271// FUNCTION: cleanVoidDict()
     272/// Clean the library dictionary, removing all entries in the dictionary
     273/**
     274 * This function removes all entries from the library dictionary.
     275 *
     276 * \sa {storeObject_Lib,getObject_Lib}
     277 */
     278
     279void
     280cleanVoidDict () {
     281    RpDictEntry DICT_TEMPLATE_V *hPtr;
     282    // should rp_quit clean up the dict or some function in RpBindingsCommon.h
     283    RpDictIterator DICT_TEMPLATE_V iter(ObjDict_Void);
     284
     285    hPtr = iter.first();
     286
     287    while (hPtr) {
     288        hPtr->erase();
     289        hPtr = iter.next();
     290    }
     291
     292    if (ObjDict_Lib.size()) {
     293        // probably want to change the warning sometime
     294        // printf("\nWARNING: internal dictionary is not empty..deleting\n");
     295    }
     296
     297}
     298
  • trunk/src/core/RpBindingsDict.h

    r1011 r1084  
    3030#define DICT_TEMPLATE_L <long,RpLibrary*>
    3131#define DICT_TEMPLATE_U <long,std::string>
     32#define DICT_TEMPLATE_V <size_t,void*>
    3233
    3334// global declaration of library and units dictionaries
     
    3738extern RpDict DICT_TEMPLATE_L ObjDict_Lib;
    3839extern RpDict DICT_TEMPLATE_U ObjDictUnits;
     40extern RpDict DICT_TEMPLATE_V ObjDict_Void;
    3941
    4042
    4143int storeObject_Lib(RpLibrary* objectName, int key=0);
    4244int storeObject_UnitsStr(std::string objectName);
     45size_t storeObject_Void(void* objectName, size_t key=0);
    4346
    4447RpLibrary* getObject_Lib(int objKey);
    4548const RpUnits* getObject_UnitsStr(int objKey);
     49void* getObject_Void(size_t objKey);
    4650
    4751void cleanLibDict();
    4852void cleanUnitsDict();
     53void cleanVoidDict();
    4954
    5055#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.