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 | |
---|
15 | RpDict DICT_TEMPLATE_L ObjDict_Lib; |
---|
16 | RpDict 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 | |
---|
31 | int |
---|
32 | storeObject_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, &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 | |
---|
65 | RpLibrary* |
---|
66 | getObject_Lib(int objKey) { |
---|
67 | |
---|
68 | |
---|
69 | RpLibrary* retVal = NULL; |
---|
70 | |
---|
71 | retVal = *(ObjDict_Lib.find(objKey).getValue()); |
---|
72 | |
---|
73 | if (retVal == *(ObjDict_Lib.getNullEntry().getValue())) { |
---|
74 | retVal = NULL; |
---|
75 | } |
---|
76 | |
---|
77 | return retVal; |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | /**********************************************************************/ |
---|
82 | // FUNCTION: cleanLibDict() |
---|
83 | /// Clean the library dictionary, removing all entries in the dictionary |
---|
84 | /** |
---|
85 | * This function removes all entries from the library dictionary. |
---|
86 | * |
---|
87 | * \sa {storeObject_Lib,getObject_Lib} |
---|
88 | */ |
---|
89 | |
---|
90 | void |
---|
91 | cleanLibDict () { |
---|
92 | // clean up the dictionary |
---|
93 | |
---|
94 | RpDictEntry DICT_TEMPLATE_L *hPtr; |
---|
95 | // RpDictIterator DICT_TEMPLATE iter(fortObjDict_Lib); |
---|
96 | // should rp_quit clean up the dict or some function in RpBindingsCommon.h |
---|
97 | RpDictIterator DICT_TEMPLATE_L iter(ObjDict_Lib); |
---|
98 | |
---|
99 | hPtr = iter.first(); |
---|
100 | |
---|
101 | while (hPtr) { |
---|
102 | // Py_DECREF(*(hPtr->getValue())); |
---|
103 | hPtr->erase(); |
---|
104 | hPtr = iter.next(); |
---|
105 | } |
---|
106 | |
---|
107 | // if (fortObjDict_Lib.size()) { |
---|
108 | if (ObjDict_Lib.size()) { |
---|
109 | // probably want to change the warning sometime |
---|
110 | // printf("\nWARNING: internal dictionary is not empty..deleting\n"); |
---|
111 | } |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | /**********************************************************************/ |
---|
116 | // FUNCTION: storeObject_UnitsStr() |
---|
117 | /// Store an object into the UnitsStr dictionary. |
---|
118 | /** |
---|
119 | * This function stores the RpUnits names specified by 'objectName' |
---|
120 | * into the UnitsStr dictionary. This is helpful for writing bindings |
---|
121 | * for languages that can not accept pointers to provide back to the |
---|
122 | * function's caller. |
---|
123 | * |
---|
124 | * Returns the key of the object in the dictionary |
---|
125 | */ |
---|
126 | |
---|
127 | int |
---|
128 | storeObject_UnitsStr(std::string objectName) { |
---|
129 | |
---|
130 | int retVal = -1; |
---|
131 | int dictNextKey = ObjDictUnits.size() + 1; |
---|
132 | int newEntry = 0; |
---|
133 | |
---|
134 | if (objectName != "") { |
---|
135 | // dictionary returns a reference to the inserted value |
---|
136 | // no error checking to make sure it was successful in entering |
---|
137 | // the new entry. |
---|
138 | ObjDictUnits.set(dictNextKey,objectName, &newEntry); |
---|
139 | retVal = dictNextKey; |
---|
140 | } |
---|
141 | |
---|
142 | return retVal; |
---|
143 | } |
---|
144 | |
---|
145 | /**********************************************************************/ |
---|
146 | // FUNCTION: getObject_UnitsStr() |
---|
147 | /// Get an object from the UnitsStr dictionary. |
---|
148 | /** |
---|
149 | * This function retrieves the RpUnits name referenced to by 'objKey' |
---|
150 | * from the UnitsStr dictionary. This is helpful for writing bindings |
---|
151 | * for languages that can not accept pointers to provide back to the |
---|
152 | * function's caller. |
---|
153 | * |
---|
154 | * Returns the key of the object in the dictionary |
---|
155 | */ |
---|
156 | |
---|
157 | const RpUnits* |
---|
158 | getObject_UnitsStr(int objKey) { |
---|
159 | |
---|
160 | std::string basisName = *(ObjDictUnits.find(objKey).getValue()); |
---|
161 | |
---|
162 | if (basisName == *(ObjDictUnits.getNullEntry().getValue())) { |
---|
163 | // basisName = ""; |
---|
164 | return NULL; |
---|
165 | } |
---|
166 | |
---|
167 | return RpUnits::find(basisName); |
---|
168 | |
---|
169 | } |
---|
170 | |
---|
171 | /**********************************************************************/ |
---|
172 | // FUNCTION: cleanUnitsDict() |
---|
173 | /// Clean the UnitsStr dictionary, removing all entries. |
---|
174 | /** |
---|
175 | * This function removes all entries from the UnitsStr dictionary |
---|
176 | * |
---|
177 | * \sa {storeObject_UnitsStr,getObject_UnitsStr} |
---|
178 | */ |
---|
179 | |
---|
180 | void |
---|
181 | cleanUnitsDict () { |
---|
182 | // clean up the dictionary |
---|
183 | |
---|
184 | RpDictEntry DICT_TEMPLATE_U *hPtr; |
---|
185 | // RpDictIterator DICT_TEMPLATE iter(fortObjDict_Lib); |
---|
186 | // should rp_quit clean up the dict or some function in RpBindingsCommon.h |
---|
187 | RpDictIterator DICT_TEMPLATE_U iter(ObjDictUnits); |
---|
188 | |
---|
189 | hPtr = iter.first(); |
---|
190 | |
---|
191 | while (hPtr) { |
---|
192 | // Py_DECREF(*(hPtr->getValue())); |
---|
193 | hPtr->erase(); |
---|
194 | hPtr = iter.next(); |
---|
195 | } |
---|
196 | |
---|
197 | // if (fortObjDict_Lib.size()) { |
---|
198 | if (ObjDictUnits.size()) { |
---|
199 | // probably want to change the warning sometime |
---|
200 | // printf("\nWARNING: internal dictionary is not empty..deleting\n"); |
---|
201 | } |
---|
202 | |
---|
203 | } |
---|