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

Last change on this file since 125 was 122, checked in by dkearney, 18 years ago

added initial version of octave language bindings.
1) no claiming language bindings work, but will happily take credit if they do.
2) bindings are untested
3) bindings happen to work with mystery example that happens to be located in examples/app-fermi/matlab/fermi_rp.m and happens to be invokable with examples/app-fermi/matlab/tool_rp.xml
4) bindings need octave2.1-headers installed (in debian: apt-get install octave2.1-headers) to get the mkoctfile program
5) binding function names might be changing to be more discriptive and more tightly bound to either the lib or units module.
6) adjusted Makefile to add octave bindings compilation.

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