source: trunk/src/core/RpBindingsDict.cc @ 1006

Last change on this file since 1006 was 569, checked in by dkearney, 18 years ago

removed make metric functions from matlab and octave, fixed up the rappture dictionary set() function call in the bindings dict code.

File size: 6.3 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Common Rappture Dictionary Source
4 *
5 * ======================================================================
6 *  AUTHOR:  Derrick S. Kearney, Purdue University
7 *  Copyright (c) 2004-2005  Purdue Research Foundation
8 *
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13#include "RpBindingsDict.h"
14
15RpDict DICT_TEMPLATE_L ObjDict_Lib;
16RpDict DICT_TEMPLATE_U ObjDictUnits;
17
18/**********************************************************************/
19// FUNCTION: storeObject_Lib()
20/// Store an object into the library dictionary.
21/**
22 * This function stores the RpLibrary object pointed to by 'objectName'
23 * into the library dictionary. This is helpful for writing bindings
24 * for languages that can not accept pointers to provide back to the
25 * function's caller.
26 *
27 * Returns the key of the object in the dictionary
28 * On Error, returns 0 (which also means nothing can be stored at 0)
29 */
30
31int
32storeObject_Lib(RpLibrary* objectName, int key) {
33
34    int retVal = 0;
35    int dictKey = key;
36    int newEntry = 0;
37
38    if (objectName) {
39        // dictionary returns a reference to the inserted value
40        // no error checking to make sure it was successful in entering
41        // the new entry.
42
43        if (dictKey == 0) {
44            dictKey = ObjDict_Lib.size() + 1;
45        }
46        ObjDict_Lib.set(dictKey,objectName, NULL,&newEntry);
47        retVal = dictKey;
48    }
49
50    return retVal;
51}
52
53/**********************************************************************/
54// FUNCTION: getObject_Lib()
55/// Get an object from the library dictionary.
56/**
57 * This function retrieves the RpLibrary object associated with the key
58 * 'objKey' from the library dictionary and returns its address to the
59 * caller. This is helpful for writing bindings for languages that can
60 * not accept pointers to provide back to the function's caller.
61 *
62 * Returns the address of the RpLibrary object in the dictionary
63 */
64
65RpLibrary*
66getObject_Lib(int objKey) {
67
68
69    RpDictEntry DICT_TEMPLATE_L* libEntry = &(ObjDict_Lib.getNullEntry());
70    RpDictEntry DICT_TEMPLATE_L* nullEntry = &(ObjDict_Lib.getNullEntry());
71
72    libEntry = &(ObjDict_Lib.find(objKey));
73
74
75    if ( (!libEntry->isValid()) || (libEntry == nullEntry) ) {
76        return NULL;
77    }
78
79   return *(libEntry->getValue());
80
81}
82
83/**********************************************************************/
84// FUNCTION: cleanLibDict()
85/// Clean the library dictionary, removing all entries in the dictionary
86/**
87 * This function removes all entries from the library dictionary.
88 *
89 * \sa {storeObject_Lib,getObject_Lib}
90 */
91
92void
93cleanLibDict () {
94    // clean up the dictionary
95
96    RpDictEntry DICT_TEMPLATE_L *hPtr;
97    // RpDictIterator DICT_TEMPLATE iter(fortObjDict_Lib);
98    // should rp_quit clean up the dict or some function in RpBindingsCommon.h
99    RpDictIterator DICT_TEMPLATE_L iter(ObjDict_Lib);
100
101    hPtr = iter.first();
102
103    while (hPtr) {
104        // Py_DECREF(*(hPtr->getValue()));
105        hPtr->erase();
106        hPtr = iter.next();
107    }
108
109    // if (fortObjDict_Lib.size()) {
110    if (ObjDict_Lib.size()) {
111        // probably want to change the warning sometime
112        // printf("\nWARNING: internal dictionary is not empty..deleting\n");
113    }
114
115}
116
117/**********************************************************************/
118// FUNCTION: storeObject_UnitsStr()
119/// Store an object into the UnitsStr dictionary.
120/**
121 * This function stores the RpUnits names specified by 'objectName'
122 * into the UnitsStr dictionary. This is helpful for writing bindings
123 * for languages that can not accept pointers to provide back to the
124 * function's caller.
125 *
126 * Returns the key of the object in the dictionary
127 */
128
129int
130storeObject_UnitsStr(std::string objectName) {
131
132    int retVal = -1;
133    int dictNextKey = ObjDictUnits.size() + 1;
134    int newEntry = 0;
135
136    if (objectName != "") {
137        // dictionary returns a reference to the inserted value
138        // no error checking to make sure it was successful in entering
139        // the new entry.
140        ObjDictUnits.set(dictNextKey,objectName, NULL, &newEntry);
141        retVal = dictNextKey;
142    }
143
144    return retVal;
145}
146
147/**********************************************************************/
148// FUNCTION: getObject_UnitsStr()
149/// Get an object from the UnitsStr dictionary.
150/**
151 * This function retrieves the RpUnits name referenced to by 'objKey'
152 * from the UnitsStr dictionary. This is helpful for writing bindings
153 * for languages that can not accept pointers to provide back to the
154 * function's caller.
155 *
156 * Returns the key of the object in the dictionary
157 */
158
159const RpUnits*
160getObject_UnitsStr(int objKey) {
161
162    /*
163    std::string basisName = *(ObjDictUnits.find(objKey).getValue());
164
165    if (basisName == *(ObjDictUnits.getNullEntry().getValue())) {
166        // basisName = "";
167        return NULL;
168    }
169
170    return RpUnits::find(basisName);
171    */
172
173    RpDictEntry DICT_TEMPLATE_U* unitEntry = &(ObjDictUnits.getNullEntry());
174    RpDictEntry DICT_TEMPLATE_U* nullEntry = &(ObjDictUnits.getNullEntry());
175
176    unitEntry = &(ObjDictUnits.find(objKey));
177
178
179    if ( (!unitEntry->isValid()) || (unitEntry == nullEntry) ) {
180        return NULL;
181    }
182
183    return RpUnits::find(*(unitEntry->getValue()));
184
185}
186
187/**********************************************************************/
188// FUNCTION: cleanUnitsDict()
189/// Clean the UnitsStr dictionary, removing all entries.
190/**
191 * This function removes all entries from the UnitsStr dictionary
192 *
193 * \sa {storeObject_UnitsStr,getObject_UnitsStr}
194 */
195
196void
197cleanUnitsDict () {
198    // clean up the dictionary
199
200    RpDictEntry DICT_TEMPLATE_U *hPtr;
201    // RpDictIterator DICT_TEMPLATE iter(fortObjDict_Lib);
202    // should rp_quit clean up the dict or some function in RpBindingsCommon.h
203    RpDictIterator DICT_TEMPLATE_U iter(ObjDictUnits);
204
205    hPtr = iter.first();
206
207    while (hPtr) {
208        // Py_DECREF(*(hPtr->getValue()));
209        hPtr->erase();
210        hPtr = iter.next();
211    }
212
213    // if (fortObjDict_Lib.size()) {
214    if (ObjDictUnits.size()) {
215        // probably want to change the warning sometime
216        // printf("\nWARNING: internal dictionary is not empty..deleting\n");
217    }
218
219}
Note: See TracBrowser for help on using the repository browser.