diff options
| author | Bob Jamison <ishmalius@gmail.com> | 2008-03-11 16:51:24 +0000 |
|---|---|---|
| committer | ishmal <ishmal@users.sourceforge.net> | 2008-03-11 16:51:24 +0000 |
| commit | 3e6941a753bde5c180c5960720825a3729384c4e (patch) | |
| tree | 2b0e981b8de5fc840deac4fd140cd9d4f4f2180d /src/bind/dobinding.cpp | |
| parent | Report JVM version (diff) | |
| download | inkscape-3e6941a753bde5c180c5960720825a3729384c4e.tar.gz inkscape-3e6941a753bde5c180c5960720825a3729384c4e.zip | |
Improve native method table structure
(bzr r5054)
Diffstat (limited to 'src/bind/dobinding.cpp')
| -rw-r--r-- | src/bind/dobinding.cpp | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/bind/dobinding.cpp b/src/bind/dobinding.cpp index ec0518d8b..29d61b722 100644 --- a/src/bind/dobinding.cpp +++ b/src/bind/dobinding.cpp @@ -54,6 +54,18 @@ using namespace org::w3c::dom; * This file can get quite large! */ +/** + * This struct associates a class name with its native + * bindings. Since C++ does not allow "flexible" arrays, + * we will separate each of the tables into a JNINativeMethod + * array, and a class with a name and a pointer to that array. + */ +typedef struct +{ + const char *className; + JNINativeMethod *methods; +} NativeClass; + //######################################################################## //# BASE OBJECT @@ -90,13 +102,18 @@ static void JNICALL DOMBase_destruct } -static JNINativeMethod DOMBaseMethods[] = +static JNINativeMethod nm_DOMBase[] = { { (char *)"construct", (char *)"()V", (void *)DOMBase_construct }, { (char *)"destruct", (char *)"()V", (void *)DOMBase_destruct }, { NULL, NULL, NULL } }; +static NativeClass nc_DOMBase = +{ + "org/inkscape/dom/DOMBase", + nm_DOMBase +}; //######################################################################## //# DOMImplementation //######################################################################## @@ -114,38 +131,44 @@ void JNICALL DOMImplementation_nCreateDocument -static JNINativeMethod DOMImplementationMethods[] = +static JNINativeMethod nm_DOMImplementation[] = { { (char *)"construct", (char *)"()V", (void *)DOMImplementation_nCreateDocument }, { NULL, NULL, NULL } }; +static NativeClass nc_DOMImplementation = +{ + "org/inkscape/dom/DOMImplementation", + nm_DOMImplementation +}; + //######################################################################## //# MAIN //######################################################################## -typedef struct -{ - const char *className; - JNINativeMethod *methods; -} NativeEntry; -static NativeEntry nativeEntries[] = +/** + * This is a table-of-tables, matching a class name to its + * table of native methods. We can probably think of a cleaner way + * of doing this + */ +static NativeClass *allClasses[] = { - { "org/inkscape/dom/DOMBase", DOMBaseMethods }, - { "org/inkscape/dom/DOMImplementation", DOMImplementationMethods }, - { NULL, NULL } + &nc_DOMBase, + &nc_DOMImplementation, + NULL }; bool JavaBinderyImpl::doBinding() { - for (NativeEntry *ne = nativeEntries ; ne->className ; ne++) + for (NativeClass **nc = allClasses ; *nc ; nc++) { - bool ret = registerNatives(ne->className, ne->methods); + bool ret = registerNatives((*nc)->className, (*nc)->methods); if (!ret) { err("Could not bind native methods"); |
