summaryrefslogtreecommitdiff
path: root/swigweb/Doc1.1/HTML
diff options
context:
space:
mode:
Diffstat (limited to 'swigweb/Doc1.1/HTML')
-rw-r--r--swigweb/Doc1.1/HTML/About.html51
-rw-r--r--swigweb/Doc1.1/HTML/Advanced.html305
-rw-r--r--swigweb/Doc1.1/HTML/Contents.html184
-rw-r--r--swigweb/Doc1.1/HTML/Copyright.html70
-rw-r--r--swigweb/Doc1.1/HTML/Documentation.html652
-rw-r--r--swigweb/Doc1.1/HTML/Exceptions.html295
-rw-r--r--swigweb/Doc1.1/HTML/Extending.html1848
-rw-r--r--swigweb/Doc1.1/HTML/Index.html559
-rw-r--r--swigweb/Doc1.1/HTML/Introduction.html323
-rw-r--r--swigweb/Doc1.1/HTML/Library.html225
-rw-r--r--swigweb/Doc1.1/HTML/Perl5.html1919
-rw-r--r--swigweb/Doc1.1/HTML/Preface.html83
-rw-r--r--swigweb/Doc1.1/HTML/Python.html2334
-rw-r--r--swigweb/Doc1.1/HTML/SWIG.html1586
-rw-r--r--swigweb/Doc1.1/HTML/Scripting.html255
-rw-r--r--swigweb/Doc1.1/HTML/Tcl.html2048
-rw-r--r--swigweb/Doc1.1/HTML/Typemaps.html733
-rw-r--r--swigweb/Doc1.1/HTML/ch1.1.pngbin6148 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch1.2.pngbin8416 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.1.pngbin12692 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.1.pngbin6985 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.10.pngbin8876 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.11.pngbin6250 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.12.pngbin9528 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.2.pngbin13907 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.3.pngbin5086 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.4.pngbin5852 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.5.pngbin8878 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.6.pngbin21025 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.7.pngbin4933 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.8.pngbin7908 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch10.table.9.pngbin6387 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch11.1.pngbin2492 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch11.2.pngbin2624 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch11.3.pngbin2942 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch12.1.pngbin3605 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch2.1.pngbin3146 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch2.2.pngbin3374 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch3.1.pngbin3444 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch5.1.pngbin5549 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch5.2.pngbin22200 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch5.3.pngbin19818 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch6.1.pngbin10389 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch6.2.pngbin8490 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch6.table.1.pngbin18471 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch6.table.2.pngbin6812 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch6.table.3.pngbin11610 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.1.pngbin3321 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.2.pngbin8749 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.3.pngbin24103 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.table.1.pngbin5535 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.table.2.pngbin5824 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.table.3.pngbin9355 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.table.4.pngbin5413 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.table.5.pngbin5007 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.table.6.pngbin7582 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch8.table.7.pngbin7699 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.1.pngbin7926 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.2.pngbin27079 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.3.pngbin3152 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.1.pngbin18189 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.10.pngbin8616 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.2.pngbin3821 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.3.pngbin3916 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.4.pngbin6779 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.5.pngbin10807 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.6.pngbin6055 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.7.pngbin4106 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.8.pngbin13424 -> 0 bytes
-rw-r--r--swigweb/Doc1.1/HTML/ch9.table.9.pngbin6940 -> 0 bytes
70 files changed, 0 insertions, 13470 deletions
diff --git a/swigweb/Doc1.1/HTML/About.html b/swigweb/Doc1.1/HTML/About.html
deleted file mode 100644
index 56f9c6011..000000000
--- a/swigweb/Doc1.1/HTML/About.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<html>
-<head>
-<title>About this manual</title>
-</head>
-
-<body bgcolor="#ffffff">
-<h1>About This Manual</h1><p>
-
-The HTML version of the SWIG Users Manual is a direct translation
-of the printed version which is produced using Framemaker 5. The
-conversion process was roughly as follows :
-
-<ul>
-<li> Raw HTML was produced using Framemaker 5 and Quadralay WebWorks Lite.
-<li> Tables and figures were converted into GIF images.
-<li> All of this output was fed into a magic Python script that cleaned
-up the HTML source and merged the GIF figures into the text.
-<li> A table of contents and alphabetized topic index were produced from
-HTML heading tags by the same script.
-</ul>
-
-While the conversion process is mostly complete, there are a few things
-to keep in mind :
-
-<ul>
-<li> Some sections of preformatted text may have weird formatting
-problems.
-<li> Framemaker tables were converted into GIF images instead
-of HTML tables--this is a little weird, but the easiest
-approach for now.
-<li> There may be a few minor formatting problems throughout
-due to minor "glitches" that slipped through the conversion process
-(although I've tried to correct as many as these as possible).
-<li> The printed version of the SWIG manual is more than
-300 pages long--resulting in about 670 Kbytes of HTML. The HTML version
-is broken up into chapters. Each chapter is fairly well-contained, but
-some may contain as many as 50 pages of printed text.
-</ul>
-
-Please report any problems with the documentation to beazley@cs.utah.edu.
-
-<hr>
-<address>
-Last Modified : August 3, 1997</address>
-</body>
-</html>
-
-
-
-
-
diff --git a/swigweb/Doc1.1/HTML/Advanced.html b/swigweb/Doc1.1/HTML/Advanced.html
deleted file mode 100644
index c95599089..000000000
--- a/swigweb/Doc1.1/HTML/Advanced.html
+++ /dev/null
@@ -1,305 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Advanced Topics</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>11 Advanced Topics</h1><p><ul>
-<li> <a href="#n1">Creating multi-module packages</a>
-<li> <a href="#n2">Dynamic Loading of C++ modules</a>
-<li> <a href="#n3">Inside the SWIG type-checker</a>
-</ul>
-
-<a name="n1"></a><h2> Creating multi-module packages</h2>
-SWIG can be used to create packages consisting of many different modules. However, there are some technical aspects of doing this and techniques for managing the problem.<p>
-<a name="n4"></a><h3> Runtime support (and potential problems)</h3>
-All SWIG generated modules rely upon a small collection of functions that are used during run-time. These functions are primarily used for pointer type-checking, exception handling, and so on. When you run SWIG, these functions are included in the wrapper file (and declared as static). If you create a system consisting of many modules, each one will have an identical copy of these runtime libraries :<p>
-<center><img src="ch11.1.png"></center><p>
-<p>
-This duplication of runtime libraries is usually harmless since there are no namespace conflicts and memory overhead is minimal. However, there is serious problem related to the fact that modules do not share type-information. This is particularly a problem when working with C++ (as described next).<p>
-<a name="n5"></a><h3> Why doesn't C++ inheritance work between modules?</h3>
-Consider for a moment the following two interface files :<p>
-<p>
-<blockquote><pre>// File : a.i
-%module a
-
-// Here is a base class
-class a {
-public:
- a();
- ~a();
- void foo(double);
-};
-
-
-// File : b.i
-%module b
-
-// Here is a derived class
-%extern a.i // Gets definition of base class
-
-class b : public a {
-public:
- bar();
-};
-
-</pre></blockquote>
-When compiled into two separate modules, the code does not work properly. In fact, you get a type error such as the following :<p>
-<p>
-<blockquote><pre>[beazley@guinness shadow]$ python
-Python 1.4 (Jan 16 1997) [GCC 2.7.2]
-Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
-&gt;&gt;&gt; from a import *
-&gt;&gt;&gt; from b import *
-&gt;&gt;&gt; # Create a new "b"
-&gt;&gt;&gt; b = new_b()
-&gt;&gt;&gt; # Call a function in the base class
-...
-&gt;&gt;&gt; a_foo(b,3)
-Traceback (innermost last):
- File "&lt;stdin&gt;", line 1, in ?
-TypeError: Type error in argument 1 of a_foo. Expected _a_p.
-&gt;&gt;&gt;
-</pre></blockquote>
-<p>
-However, from our class definitions we know that "b" is an "a" by inheritance and there should be no type-error. This problem is directly due to the lack of type-sharing between modules. If we look closely at the module modules created here, they look like this :<p>
-<center><img src="ch11.2.png"></center><p>
-<p>
-The type information listed shows the acceptable values for various C datatypes. In the "a" module, we see that "a" can only accept instances of itself. In the "b" module, we see that "a" can accept both "a" and "b" instances--which is correct given that a "b" is an "a" by inheritance.<p>
-<p>
-Unfortunately, this problem is inherent in the method by which SWIG makes modules. When we made the "a" module, we had no idea what derived classes might be used at a later time. However, it's impossible to produce the proper type information until after we know all of the derived classes. A nice problem to be sure, but one that can be fixed by making all modules share a single copy of the SWIG run-time library.<p>
-<a name="n6"></a><h3> The SWIG runtime library</h3>
-To reduce overhead and to fix type-handling problems, it is possible to share the SWIG run-time functions between multiple modules. This requires the use of the SWIG runtime library which is optionally built during SWIG installation. To use the runtime libraries, follow these steps :<p>
-<p>
-1. Build the SWIG run-time libraries. The <tt>SWIG1.1/Runtime</tt> directory contains a makefile for doing this. If successfully built, you will end up with 6 files that are usually installed in <tt>/usr/local/lib</tt>.<p>
-<p>
-<blockquote><pre>libswigtcl.a # Tcl library (static)
-libswigtcl.so # Tcl library (shared)
-libswigpl.a # Perl library (static)
-libswigpl.so # Perl library (shared)
-libswigpy.a # Python library (static)
-libswigpy.so # Python library (shared)
-</pre></blockquote>
-<p>
-Note that certain libraries may be missing due to missing packages or unsupported features (like dynamic loading) on your machine.<p>
-<p>
-2. Compile all SWIG modules using the <tt>-c</tt> option. For example :<p>
-<p>
-<blockquote><pre>% swig -c -python a.i
-% swig -c -python b.i
-
-</pre></blockquote>
-The <tt>-c</tt> option tells SWIG to omit runtime support. It's now up to you to provide it separately--which we will do using our libraries.<p>
-<p>
-3. Build SWIG modules by linking against the appropriate runtime libraries.<p>
-<p>
-<blockquote><pre>% swig -c -python a.i
-% swig -c -python b.i
-% gcc -c a_wrap.c b_wrap.c -I/usr/local/include
-% ld -shared a_wrap.o b_wrap.o -lswigpy -o a.so
-
-</pre></blockquote>
-or if building a new executable (static linking)<p>
-<p>
-<blockquote><pre>% swig -c -tcl -ltclsh.i a.i
-% gcc a_wrap.c -I/usr/local/include -L/usr/local/lib -ltcl -lswigtcl -lm -o mytclsh
-
-</pre></blockquote>
-<p>
-When completed you should now end up with a collection of modules like this :<p>
-<center><img src="ch11.3.png"></center><p>
-<p>
-<p>
-In this configuration, the runtime library manages all datatypes and other information between modules. This management process is dynamic in nature--when new modules are loaded, they contribute information to the run-time system. In the C++ world, one could incrementally load classes as needed. As this process occurs, type information is updated and base-classes learn about derived classes as needed.<p>
-<a name="n7"></a><h3> A few dynamic loading gotchas</h3>
-When working with dynamic loading, it is critical to check that only one copy of the run-time library is being loaded into the system. When working with <tt>.a</tt> library files, problems can sometimes occur so there are a few approaches to the problem.<p>
-<p>
-1. Rebuild the scripting language executable with the SWIG runtime library attached to it. This is actually, fairly easy to do using SWIG. For example :<p>
-<p>
-<blockquote><pre>%module mytclsh
-%{
-
-static void *__embedfunc(void *a) { return a};
-%}
-
-void *__embedfunc(void *);
-%include tclsh.i
-
-</pre></blockquote>
-<p>
-Now, run SWIG and compile as follows :<p>
-<p>
-<blockquote><pre>% swig -c -tcl mytclsh.i
-% gcc mytclsh_wrap.c -I/usr/local/include -L/usr/local/lib -ltcl -lswigtcl -ldl -lm \
- -o tclsh
-
-</pre></blockquote>
-This produces a new executable "<tt>tclsh</tt>" that contains a copy of the SWIG runtime library. The weird <tt>__embedfunc()</tt> function is needed to force the functions in the runtime library to be included in the final executable. <p>
-<p>
-To make new dynamically loadable SWIG modules, simply compile as follows :<p>
-<p>
-<blockquote><pre>% swig -c -tcl example.i
-% gcc -c example_wrap.c -I/usr/local/include
-% ld -shared example_wrap.o -o example.so
-
-</pre></blockquote>
-Linking against the <tt>swigtcl</tt> library is no longer necessary as all of the functions are now included in the <tt>tclsh</tt> executable and will be resolved when your module is loaded.<p>
-<p>
-2. Using shared library versions of the runtime library<p>
-<p>
-If supported on your machine, the runtime libraries will be built as shared libraries (indicated by a <tt>.so</tt>, <tt>.sl</tt>, or .<tt>dll</tt> suffix). To compile using the runtime libraries, you link process should look something like this :<p>
-<blockquote><pre>
-% ld -shared swigtcl_wrap.o -o libswigtcl.so # Irix
-% gcc -shared swigtcl_wrap.o -o libswigtcl.so # Linux
-% ld -G swigtcl_wrap.o -o libswigtcl.so # Solaris
-</pre></blockquote>
-In order for the <tt>libswigtcl.so</tt> library to work, it needs to be placed in a location where the dynamic loader can find it. Typically this is a system library directory (ie. <tt>/usr/local/lib</tt> or <tt>/usr/lib</tt>). <p>
-<p>
-When running with the shared libary version, you may get error messages such as the following <p>
-<p>
-<blockquote><pre>Unable to locate libswigtcl.so
-
-</pre></blockquote>
-This indicates that the loader was unable to find the shared libary at run-time. To find shared libaries, the loader looks through a collection of predetermined paths. If the <tt>libswigtcl.so</tt> file is not in any of these directories, it results in an error. On most machines, you can change the loader search path by changing the Unix environment variable <tt>LD_LIBRARY_PATH</tt>. For example :<p>
-<p>
-<blockquote><pre>% setenv LD_LIBRARY_PATH .:/home/beazley/packages/lib
-
-</pre></blockquote>
-A somewhat better approach is to link your module with the proper path encoded. This is typically done using the `-rpath' or `-R' option to your linker (see the man page). For example :<p>
-<p>
-<blockquote><pre>% ld -shared example_wrap.o example.o -rpath /home/beazley/packages/lib \
- -L/home/beazley/packages/lib -lswigtcl.so -o example.so
-
-</pre></blockquote>
-The <tt>-rpath</tt> option encodes the location of shared libraries into your modules and gets around having to set the <tt>LD_LIBRARY_PATH</tt> variable. <p>
-<p>
-If all else fails, pull up the man pages for your linker and start playing around. <p>
-<a name="n2"></a><h2> Dynamic Loading of C++ modules</h2>
-Dynamic loading of C++ modules presents a special problem for many systems. This is because C++ modules often need additional supporting code for proper initialization and operation. Static constructors are also a bit of a problem.<p>
-<p>
-While the process of building C++ modules is, by no means, and exact science, here are a few rules of thumb to follow :<p>
-<p>
-<ul>
-<li>Don't use static constructors if at all possible (not always avoidable).
-<li>Try linking your module with the C++ compiler using a command like `c++ -shared'. This often solves alot of problems.
-<li>Sometimes it is necessary to link against special libraries. For example, modules compiled with g++ often need to be linked against the <tt>libgcc.a</tt>, <tt>libg++.a</tt>, and <tt>libstdc++.a</tt> libraries.
-<li>Read the compiler and linker man pages over and over until you have them memorized (this may not help in some cases however).
-<li>Search articles on Usenet, particularly in <tt>comp.lang.tcl</tt>, <tt>comp.lang.perl</tt>, and <tt>comp.lang.python</tt>. Building C++ modules is a common problem.
-</ul>
-<p>
-The SWIG distribution contains some additional documentation about C++ modules in the Doc directory as well.<p>
-<a name="n3"></a><h2> Inside the SWIG type-checker</h2>
-The SWIG runtime type-checker plays a critical role in the correct operation of SWIG modules. It not only checks the validity of pointer types, but also manages C++ inheritance, and performs proper type-casting of pointers when necessary. This section provides some insight into what it does, how it works, and why it is the way it is.<p>
-<a name="n8"></a><h3> Type equivalence</h3>
-SWIG uses a name-based approach to managing pointer datatypes. For example, if you are using a pointer like "<tt>double *</tt>", the type-checker will look for a particular string representation of that datatype such as "<tt>_double_p</tt>". If no match is found, a type-error is reported.<p>
-<p>
-However, the matching process is complicated by the fact that datatypes may use a variety of different names. For example, the following declarations<p>
-<p>
-<blockquote><pre>typedef double Real;
-typedef Real * RealPtr;
-typedef double Float;
-
-</pre></blockquote>
-define two sets of equivalent types :<p>
-<p>
-<blockquote><pre>{double, Real, Float}
-{RealPtr, Real *}
-
-</pre></blockquote>
-All of the types in each set are freely interchangable and the type-checker knows about the relationships by managing a table of equivalences such as the following :<p>
-<blockquote><pre>
-double =&gt; { Real, Float }
-Real =&gt; { double, Float }
-Float =&gt; { double, Real }
-RealPtr =&gt; { Real * }
-Real * =&gt; { RealPtr }
-
-</pre></blockquote>
-<p>
-When you declare a function such as the following :<p>
-<p>
-<blockquote><pre>void foo(Real *a);
-
-</pre></blockquote>
-SWIG first checks to see if the argument passed is a "<tt>Real *</tt>". If not, it checks to see if it is any of the other equivalent types (<tt>double *</tt>, <tt>RealPtr</tt>, <tt>Float *</tt>). If so, the value is accepted and no error occurs.<p>
-<p>
-Derived versions of the various datatypes are also legal. For example, if you had a function like this,<p>
-<p>
-<blockquote><pre>void bar(Float ***a);
-
-</pre></blockquote>
-The type-checker will accept pointers of type <tt>double ***</tt> and <tt>Real ***.</tt> However, the type-checker does not always capture the full-range of possibilities. For example, a datatype of `<tt>RealPtr **</tt>' is equivalent to a `<tt>Float ***</tt>' but would be flagged as a type error. If you encounter this kind of problem, you can manually force SWIG to make an equivalence as follows:<p>
-<p>
-<blockquote><pre>// Tell the type checker that `Float_ppp' and `RealPtr_pp' are equivalent.
-%init %{
- SWIG_RegisterMapping("Float_ppp","RealPtr_pp",0);
-%}
-
-</pre></blockquote>
-Doing this should hardly ever be necessary (I have never encountered a case where this was necessary), but if all else fails, you can force the run-time type checker into doing what you want.<p>
-<p>
-Type-equivalence of C++ classes is handled in a similar manner, but is encoded in a manner to support inheritance. For example, consider the following classes hierarchy :<p>
-<p>
-<blockquote><pre>class A { };
-class B : public A { };
-class C : public B { };
-class D {};
-class E : public C, public D {};
-
-</pre></blockquote>
-The type-checker encodes this into the following sets :<p>
-<p>
-<blockquote><pre>A =&gt; { B, C, E } "B isa A, C isa A, E isa A"
-B =&gt; { C, E } "C isa B, E isa B"
-C =&gt; { E } "E isa C"
-D =&gt; { E } "E isa D"
-E =&gt; { }
-
-</pre></blockquote>
-The encoding reflects the class hierarchy. For example, any object of type "A" will also accept objects of type B,C, and E because these are all derived from A. However, it is not legal to go the other way. For example, a function operating on a object from class E will not accept an object from class A.<p>
-<a name="n9"></a><h3> Type casting</h3>
-When working with C++ classes, SWIG needs to perform proper typecasting between derived and base classes. This is particularly important when working with multiple inheritance. To do this, conversion functions are created such as the following :<p>
-<p>
-<blockquote><pre>void *EtoA(void *ptr) {
- E *in = (E *) ptr;
- A *out = (A *) in; // Cast using C++
- return (void *) out;
-}
-
-</pre></blockquote>
-All pointers are internally represented as void *, but conversion functions are always invoked when pointer values are converted between base and derived classes in a C++ class hierarchy.<p>
-<a name="n10"></a><h3> Why a name based approach?</h3>
-SWIG uses a name-based approach to type-checking for a number of reasons :<p>
-<p>
-<ul>
-<li>One of SWIG's main uses is code development and debugging. In this environment, the type name of an object turns out to be a useful piece of information in tracking down problems.
-<li>In languages like Perl, the name of a datatype is used to determine things like packages and classes. By using datatype names we get a natural mapping between C and Perl.
-<li>I believe using the original names of datatypes is more intuitive than munging them into something completely different.
-</ul>
-<p>
-An alternative to a name based scheme would be to generate type-signatures based on the structure of a datatype. Such a scheme would result in perfect type-checking, but I think it would also result in a very confusing scripting language module. For this reason, I see SWIG sticking with the name-based approach--at least for the foreseeable future. <p>
-<a name="n11"></a><h3> Performance of the type-checker</h3>
-The type-checker performs the following steps when matching a datatype :<p>
-<p>
-
-<dl>
-<dt>1. Check a pointer against the type supplied in the original C declaration. If there is a perfect match, we're done.
-<dt>2. Check the supplied pointer against a cache of recently used datatypes.
-<dt>3. Search for a match against the full list of equivalent datatypes.
-<dt>4. If not found, report an error.
-
-</dl>
-<p>
-Most well-structured C codes will find an exact match on the first attempt, providing the best possible performance. For C++ codes, it is quite common to be passing various objects of a common base-class around between functions. When base-class functions are invoked, it almost always results in a miscompare (because the type-checker is looking for the base-type). In this case, we drop down to a small cache of recently used datatypes. If we've used a pointer of the same type recently, it will be in the cache and we can match against it. For tight loops, this results in about 10-15% overhead over finding a match on the first try. Finally, as a last resort, we need to search the internal pointer tables for a match. This involves a combination of hash table lookup and linear search. If a match is found, it is placed into the cache and the result returned. If not, we finally report a type-mismatch.<p>
-<p>
-As a rule of thumb, C++ programs require somewhat more processing than C programs, but this seems to be avoidable. Also, keep in mind that performance penalties in the type-checker don't necessarily translate into big penalties in the overall application. Performance is most greatly affected by the efficiency of the target scripting language and the types of operations your C code is performing.<p>
-<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:47:13 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Contents.html b/swigweb/Doc1.1/HTML/Contents.html
deleted file mode 100644
index d7e5e5b0f..000000000
--- a/swigweb/Doc1.1/HTML/Contents.html
+++ /dev/null
@@ -1,184 +0,0 @@
-
-<html>
-<head>
-<title> SWIG 1.1 Users Manual - Table of Contents </title>
-</head>
-<body bgcolor="#ffffff">
-
-<h1> SWIG 1.1 Users Manual </h1>
-
-<ul>
-<li> <a href="Copyright.html">Copyright</a>
-<li> <a href="About.html">About this manual</a>
-<li> <a href="Index.html">Alphabetical Topic Index</a>
-</ul>
-<h2><a href="Preface.html">Preface</a></h2><p><ul>
-<li> <a href="Preface.html#n1">Introduction</a>
-<li> <a href="Preface.html#n2">SWIG resources</a>
-<li> <a href="Preface.html#n3">About this manual</a>
-<li> <a href="Preface.html#n4">Credits</a>
-<li> <a href="Preface.html#n5">What's new?</a>
-<li> <a href="Preface.html#n6">Bug reports</a>
-<li> <a href="Preface.html#n7">SWIG is free</a>
-</ul>
-<h2><a href="Introduction.html">1 Introduction</a></h2><p><ul>
-<li> <a href="Introduction.html#n1">What is SWIG?</a>
-<li> <a href="Introduction.html#n2">Life before SWIG</a>
-<li> <a href="Introduction.html#n3">Life after SWIG</a>
-<li> <a href="Introduction.html#n4">The SWIG package</a>
-<li> <a href="Introduction.html#n5">A SWIG example</a>
-<li> <a href="Introduction.html#n6">C syntax, but not a C compiler</a>
-<li> <a href="Introduction.html#n7">Non-intrusive interface building</a>
-<li> <a href="Introduction.html#n8">Hands off code generation</a>
-<li> <a href="Introduction.html#n9">Event driven C programming</a>
-<li> <a href="Introduction.html#n10">Automatic documentation generation</a>
-<li> <a href="Introduction.html#n11">Summary</a>
-<li> <a href="Introduction.html#n12">SWIG for Windows and Macintosh</a>
-</ul>
-<h2><a href="Scripting.html">2 Scripting Languages</a></h2><p><ul>
-<li> <a href="Scripting.html#n1">The two language view of the world</a>
-<li> <a href="Scripting.html#n2">How does a scripting language talk to C?</a>
-<li> <a href="Scripting.html#n3">Building scripting language extensions</a>
-<li> <a href="Scripting.html#n4">Shared libraries and dynamic loading</a>
-</ul>
-<h2><a href="SWIG.html">3 SWIG Basics</a></h2><p><ul>
-<li> <a href="SWIG.html#n1">Running SWIG</a>
-<li> <a href="SWIG.html#n2">Simple C functions, variables, and constants</a>
-<li> <a href="SWIG.html#n3">Pointers and complex objects</a>
-<li> <a href="SWIG.html#n4">Getting down to business</a>
-<li> <a href="SWIG.html#n5">Structures, unions, and object oriented C programming</a>
-<li> <a href="SWIG.html#n6">C++ support</a>
-<li> <a href="SWIG.html#n7">Objective-C</a>
-<li> <a href="SWIG.html#n8">Conditional compilation</a>
-<li> <a href="SWIG.html#n9">Code Insertion</a>
-<li> <a href="SWIG.html#n10">A general interface building strategy</a>
-</ul>
-<h2><a href="Library.html">4 Multiple files and the SWIG library</a></h2><p><ul>
-<li> <a href="Library.html#n1">The %include directive</a>
-<li> <a href="Library.html#n2">The %extern directive</a>
-<li> <a href="Library.html#n3">The %import directive</a>
-<li> <a href="Library.html#n4">Including files on the command line</a>
-<li> <a href="Library.html#n5">The SWIG library</a>
-<li> <a href="Library.html#n6">Library example</a>
-<li> <a href="Library.html#n7">Creating Library Files</a>
-<li> <a href="Library.html#n8">Working with library files</a>
-<li> <a href="Library.html#n9">Static initialization of multiple modules</a>
-<li> <a href="Library.html#n10">More about the SWIG library</a>
-</ul>
-<h2><a href="Documentation.html">5 Documentation System</a></h2><p><ul>
-<li> <a href="Documentation.html#n1">Introduction</a>
-<li> <a href="Documentation.html#n2">How it works</a>
-<li> <a href="Documentation.html#n3">Choosing a documentation format</a>
-<li> <a href="Documentation.html#n4">Function usage and argument names</a>
-<li> <a href="Documentation.html#n5">Titles, sections, and subsections</a>
-<li> <a href="Documentation.html#n6">Formatting</a>
-<li> <a href="Documentation.html#n7">Adding Additional Text</a>
-<li> <a href="Documentation.html#n8">Disabling all documentation</a>
-<li> <a href="Documentation.html#n9">An Example</a>
-<li> <a href="Documentation.html#n10">ASCII Documentation</a>
-<li> <a href="Documentation.html#n11">HTML Documentation</a>
-<li> <a href="Documentation.html#n12">LaTeX Documentation</a>
-<li> <a href="Documentation.html#n13">C++ Support</a>
-<li> <a href="Documentation.html#n14">The Final Word?</a>
-</ul>
-<h2><a href="Typemaps.html">6 Pointers, Constraints, and Typemaps</a></h2><p><ul>
-<li> <a href="Typemaps.html#n1">Introduction</a>
-<li> <a href="Typemaps.html#n2">The SWIG Pointer Library</a>
-<li> <a href="Typemaps.html#n3">Introduction to typemaps</a>
-<li> <a href="Typemaps.html#n4">Managing input and output parameters</a>
-<li> <a href="Typemaps.html#n5">Applying constraints to input values</a>
-<li> <a href="Typemaps.html#n6">Writing new typemaps</a>
-<li> <a href="Typemaps.html#n7">Common typemap methods</a>
-<li> <a href="Typemaps.html#n8">Writing typemap code</a>
-<li> <a href="Typemaps.html#n9">Typemaps for handling arrays</a>
-<li> <a href="Typemaps.html#n10">Typemaps and the SWIG Library</a>
-<li> <a href="Typemaps.html#n11">Implementing constraints with typemaps</a>
-<li> <a href="Typemaps.html#n12">Typemap examples</a>
-<li> <a href="Typemaps.html#n13">How to break everything with a typemap</a>
-<li> <a href="Typemaps.html#n14">Typemaps and the future</a>
-</ul>
-<h2><a href="Exceptions.html">7 Exception Handling</a></h2><p><ul>
-<li> <a href="Exceptions.html#n1">The %except directive</a>
-<li> <a href="Exceptions.html#n2">Handling exceptions in C code</a>
-<li> <a href="Exceptions.html#n3">Exception handling with longjmp()</a>
-<li> <a href="Exceptions.html#n4">Handling C++ exceptions</a>
-<li> <a href="Exceptions.html#n5">Defining different exception handlers</a>
-<li> <a href="Exceptions.html#n6">Using The SWIG exception library</a>
-<li> <a href="Exceptions.html#n7">Debugging and other interesting uses for %except</a>
-<li> <a href="Exceptions.html#n8">More Examples</a>
-</ul>
-<h2><a href="Perl5.html">8 SWIG and Perl5</a></h2><p><ul>
-<li> <a href="Perl5.html#n1">Preliminaries</a>
-<li> <a href="Perl5.html#n2">Building Perl Extensions under Windows 95/NT</a>
-<li> <a href="Perl5.html#n3">Modules, packages, and classes</a>
-<li> <a href="Perl5.html#n4">Basic Perl interface</a>
-<li> <a href="Perl5.html#n5">A simple Perl example</a>
-<li> <a href="Perl5.html#n6">Accessing arrays and other strange objects</a>
-<li> <a href="Perl5.html#n7">Implementing methods in Perl</a>
-<li> <a href="Perl5.html#n8">Shadow classes</a>
-<li> <a href="Perl5.html#n9">Getting serious</a>
-<li> <a href="Perl5.html#n10">Wrapping C libraries and other packages</a>
-<li> <a href="Perl5.html#n11">Building a Perl5 interface to MATLAB</a>
-<li> <a href="Perl5.html#n12">Handling output values (the easy way)</a>
-<li> <a href="Perl5.html#n13">Exception handling</a>
-<li> <a href="Perl5.html#n14">Remapping datatypes with typemaps</a>
-<li> <a href="Perl5.html#n15">The gory details on shadow classes</a>
-<li> <a href="Perl5.html#n16">Where to go from here?</a>
-</ul>
-<h2><a href="Python.html">9 SWIG and Python</a></h2><p><ul>
-<li> <a href="Python.html#n1">Preliminaries</a>
-<li> <a href="Python.html#n2">Building Python Extensions under Windows 95/NT</a>
-<li> <a href="Python.html#n3">The low-level Python/C interface</a>
-<li> <a href="Python.html#n4">Python shadow classes</a>
-<li> <a href="Python.html#n5">About the Examples</a>
-<li> <a href="Python.html#n6">Solving a simple heat-equation</a>
-<li> <a href="Python.html#n7">Wrapping a C library</a>
-<li> <a href="Python.html#n8">Putting it all together</a>
-<li> <a href="Python.html#n9">Exception handling</a>
-<li> <a href="Python.html#n10">Remapping C datatypes with typemaps</a>
-<li> <a href="Python.html#n11">Implementing C callback functions in Python</a>
-<li> <a href="Python.html#n12">Other odds and ends</a>
-<li> <a href="Python.html#n13">The gory details of shadow classes</a>
-</ul>
-<h2><a href="Tcl.html">10 SWIG and Tcl</a></h2><p><ul>
-<li> <a href="Tcl.html#n1">Preliminaries</a>
-<li> <a href="Tcl.html#n2">Building Tcl/Tk Extensions under Windows 95/NT</a>
-<li> <a href="Tcl.html#n3">Basic Tcl Interface</a>
-<li> <a href="Tcl.html#n4">The object oriented interface</a>
-<li> <a href="Tcl.html#n5">About the examples</a>
-<li> <a href="Tcl.html#n6">Binary trees in Tcl</a>
-<li> <a href="Tcl.html#n7">Building C/C++ data structures with Tk</a>
-<li> <a href="Tcl.html#n8">Accessing arrays</a>
-<li> <a href="Tcl.html#n9">Building a simple OpenGL module</a>
-<li> <a href="Tcl.html#n10">Exception handling</a>
-<li> <a href="Tcl.html#n11">Typemaps</a>
-<li> <a href="Tcl.html#n12">Configuration management with SWIG</a>
-<li> <a href="Tcl.html#n13">Building new kinds of Tcl interfaces (in Tcl)</a>
-<li> <a href="Tcl.html#n14">Extending the Tcl Netscape Plugin</a>
-<li> <a href="Tcl.html#n15">Tcl8.0 features</a>
-</ul>
-<h2><a href="Advanced.html">11 Advanced Topics</a></h2><p><ul>
-<li> <a href="Advanced.html#n1">Creating multi-module packages</a>
-<li> <a href="Advanced.html#n2">Dynamic Loading of C++ modules</a>
-<li> <a href="Advanced.html#n3">Inside the SWIG type-checker</a>
-</ul>
-<h2><a href="Extending.html">12 Extending SWIG</a></h2><p><ul>
-<li> <a href="Extending.html#n1">Introduction</a>
-<li> <a href="Extending.html#n2">Compiling a SWIG extension</a>
-<li> <a href="Extending.html#n3">SWIG output</a>
-<li> <a href="Extending.html#n4">The Language class (simple version)</a>
-<li> <a href="Extending.html#n5">A tour of SWIG datatypes</a>
-<li> <a href="Extending.html#n6">Typemaps (from C)</a>
-<li> <a href="Extending.html#n7">File management</a>
-<li> <a href="Extending.html#n8">Naming Services</a>
-<li> <a href="Extending.html#n9">Code Generation Functions</a>
-<li> <a href="Extending.html#n10">Writing a Real Language Module</a>
-<li> <a href="Extending.html#n11">C++ Processing</a>
-<li> <a href="Extending.html#n12">Documentation Processing</a>
-<li> <a href="Extending.html#n13">The Future of SWIG</a>
-</ul>
-
-<p><hr>
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:47:18 1997 </address>
-</body>
-</html> \ No newline at end of file
diff --git a/swigweb/Doc1.1/HTML/Copyright.html b/swigweb/Doc1.1/HTML/Copyright.html
deleted file mode 100644
index 94d882892..000000000
--- a/swigweb/Doc1.1/HTML/Copyright.html
+++ /dev/null
@@ -1,70 +0,0 @@
-<HTML>
-<HEAD>
-<title> SWIG Documentation Copyright</title>
-</head>
-
-<body BGCOLOR="#FFFFFF">
-<h2> SWIG Users Manual </h2>
-<b>
-Version 1.1<br>
-June, 1997 <br>
-</b>
-<p>
-Copyright(C) 1996, 1997<br>
-All Rights Reserved<br>
-<br>
-David M. Beazley<br>
-Department of Computer Science <br>
-University of Utah <br>
-Salt Lake City, Utah 84112 </br>
-<tt>beazley@cs.utah.edu</tt>
-
-<p>
-This document may be freely distributed in whole or part provided this
-copyright notice is retained. Commercial distribution of this document
-is prohibited without the express written consent of the author.
-
-<hr>
-SWIG 1.1 is Copyright (C) 1995-1997 by the University of Utah and the
-Univerity of California and distributed under the following license.
-
-<p>
-This software is copyrighted by the University of Utah and the Regents
-of the University of California. The following terms apply to all
-files associated with the software unless explicitly disclaimed
-in individual files.
-
-<p>
-Permission is hereby granted, without written agreement and without
-license or royalty fees, to use, copy, modify, and distribute this
-software and its documentation for any purpose, provided that
-(1) The above copyright notice and the following two paragraphs
-appear in all copies of the source code and (2) redistributions
-including binaries reproduces these notices in the supporting
-documentation. Substantial modifications to this software may be
-copyrighted by their authors and need not follow the licensing terms
-described here, provided that the new terms are clearly indicated in
-all files where they apply.
-<p>
-IN NO EVENT SHALL THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, THE
-UNIVERSITY OF UTAH OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
-PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
-EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
-THE POSSIBILITY OF SUCH DAMAGE.
-
-<p>
-THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, AND THE UNIVERSITY OF UTAH
-SPECIFICALLY DISCLAIM ANY WARRANTIES,INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
-THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
-SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-
-<hr>
-<address><a href="http://www.cs.utah.edu/~beazley"> beazley@cs.utah.edu </a> <br>
-Last Modified, August 3, 1997</address>
-</body>
-</html>
-
-
diff --git a/swigweb/Doc1.1/HTML/Documentation.html b/swigweb/Doc1.1/HTML/Documentation.html
deleted file mode 100644
index d7e836f8f..000000000
--- a/swigweb/Doc1.1/HTML/Documentation.html
+++ /dev/null
@@ -1,652 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Documentation System</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>5 Documentation System</h1><p><ul>
-<li> <a href="#n1">Introduction</a>
-<li> <a href="#n2">How it works</a>
-<li> <a href="#n3">Choosing a documentation format</a>
-<li> <a href="#n4">Function usage and argument names</a>
-<li> <a href="#n5">Titles, sections, and subsections</a>
-<li> <a href="#n6">Formatting</a>
-<li> <a href="#n7">Adding Additional Text</a>
-<li> <a href="#n8">Disabling all documentation</a>
-<li> <a href="#n9">An Example</a>
-<li> <a href="#n10">ASCII Documentation</a>
-<li> <a href="#n11">HTML Documentation</a>
-<li> <a href="#n12">LaTeX Documentation</a>
-<li> <a href="#n13">C++ Support</a>
-<li> <a href="#n14">The Final Word?</a>
-</ul>
-
-<a name="n1"></a><h2> Introduction</h2>
-While SWIG makes it easy to build interfaces, it is often difficult to keep track of all of the different functions, variables, constants, and other objects that have been wrapped. This especially becomes a problem when your interface starts to grow in size from a handful to several hundred functions. To address these concerns, SWIG can automatically generate documentation in a number of formats including ASCII, HTML, and LaTeX. The goal is that you could look at the documentation file to see what functions were wrapped and how they are used in the target scripting language.<p>
-<p>
-Usage documentation is generated for each declaration found in an interface file. This documentation is generated by the target language module so the Tcl module will follow Tcl syntax, the Perl module will use Perl syntax, and so on. In addition, C/C++ comments can be used to add descriptive text to each function. Comments can be processed in a number of different styles to suit personal preferences or to match the style used in a particular input file.<p>
-<p>
-Automatic documentation generation for C/C++ programs is a fairly formidable problem and SWIG was never intended to be a substitute for a full-blown documentation generator. However, I feel that is does a reasonable job of documenting scripting language interfaces. It seems to do just fine for many of SWIG's primary applications--rapid prototyping, debugging, and development.<p>
-<a name="n2"></a><h2> How it works</h2>
-For each declaration in an interface file, SWIG creates a "Documentation Entry." This entry contains three components; (1) a usage string, (2) a C information string, and (3) descriptive text. For example, suppose you have this declaration in an interface file :<p>
-<p>
-<blockquote><pre>int fact(int n);
-/* This function computes a factorial */
-
-</pre></blockquote>
-The documentation entry produced by the SWIG ASCII module will look like this for Tcl:<p>
-<p>
-<blockquote><pre>fact n
- [ returns int ]
- This function computes a factorial
-
-</pre></blockquote>
-The first line shows how to call the function, the second line shows some additional information about the function (related to its C implementation), while the third line contains the comment text. The first two lines are automatically generated by SWIG and may be different for each language module. For example, the Perl5 module would generate the following output :<p>
-<p>
-<blockquote><pre>fact($n)
- [ returns int ]
- This function computes a factorial
-
-</pre></blockquote>
-<p>
-Of course, this is only a simple example, more sophisticated things are possible.<p>
-<a name="n3"></a><h2> Choosing a documentation format</h2>
-The type of documentation is selected using the following command line options :<p>
-<blockquote><pre>
--dascii Produce ASCII documentation
--dhtml Produce HTML documentation
--dlatex Produce LaTeX documentation
--dnone Produce no documentation
-
-</pre></blockquote>
-The various documentation modules are implemented in a manner similar to language modules so the exact choice may change in the future. With a little C++ hacking, it is also possible for you to add your own modules to SWIG. For example, with a bit of work you could turn all of the documentation into an online help command in your scripting language. <p>
-<a name="n4"></a><h2> Function usage and argument names</h2>
-The function usage string is produced to match the declaration given in the SWIG interface file. The names of arguments can be specified by using argument names. For example, the declarations<p>
-<p>
-<blockquote><pre>void insert_item(List *, char *);
-char *lookup_item(char *name);
-</pre></blockquote>
-<p>
-will produce the following documentation (for Python) :<p>
-<p>
-<blockquote><pre>insert_item(List *, char *)
- [ returns void ]
-
-lookup_item(name)
- [ returns char * ]
-
-</pre></blockquote>
-When argument names are omitted, SWIG will use the C datatypes of the arguments in the documentation. If an argument name is specified, SWIG will use that in the documentation instead. Of course, it is up to each language module to create an appropriate usage string so your results may vary depending on how things have been implemented in each module.<p>
-<a name="n5"></a><h2> Titles, sections, and subsections</h2>
-The SWIG documentation system is hierarchical in nature and is organized into a collection of sections, subsections, subsubsections, and so on. The following SWIG directives can be used to organize an interface file :<p>
-<p>
-<ul>
-<li><tt>%title "Title Text"</tt>. Set the documentation title (may only be used once)
-<li><tt>%section "Section title"</tt>. Start a new section.
-<li><tt>%subsection "Subsection title"</tt>. Create a new subsection.
-<li><tt>%subsubsection "Subsubsection title"</tt>. Create a new subsubsection.
-</ul>
-<p>
-The <tt>%title</tt> directive should be placed prior to the first declaration in an interface file and may only be used once (subsequent occurrences will simply be ignored). The section directives may be placed anywhere. However, <tt>%subsection</tt> can only be used after a <tt>%section</tt> directive and <tt>%subsubsection</tt> can only be used after a <tt>%subsection</tt> directive.<p>
-<p>
-With the organization directives, a SWIG interface file looks something like this :<p>
-<p>
-<blockquote><pre>%title "Example Interface File"
-%module example
-%{
-#include "my_header.h"
-%}
-
-%section "Mathematical Functions"
-
-... declarations ...
-
-%section "Graphics"
-%subsection "2D Plotting"
-... Declarations ...
-%subsection "3D Plotting"
-%subsubsection "Viewing transformations"
-... Declarations ...
-%subsubsection "Lighting"
-... Declarations ...
-%subsubsection "Primitives"
-... Declarations ...
-
-%section "File I/O"
-
-... Declarations ...
-</pre></blockquote>
-<a name="n6"></a><h2> Formatting</h2>
-Documentation text can be sorted, chopped, sliced, and diced in a variety of ways. Formatting information is specified using a comma separated list of parameters after the <tt>%title</tt>, <tt>%section</tt>, <tt>%subsection</tt>, or <tt>%subsubsection</tt> directives. For example :<p>
-<p>
-<blockquote><pre>%title "My Documentation", sort, before, pre
-
-</pre></blockquote>
-This tells SWIG to sort all of the documentation, use comments that are before each declaration, and assume that text is preformatted. These formatting directives are applied to all children in the documentation tree--in this case, everything in an interface file.<p>
-<p>
-If formatting information is specified for a section like this<p>
-<p>
-<blockquote><pre>%subsection "3D Graphics", nosort, after
-</pre></blockquote>
-<p>
-then the effect will only apply to that particular section (and all of its subsections). In this case, the formatting of the subsection would override any previous formatting, but these changes would only apply to this subsection. The next subsection could use its own formatting or that of its parent.<p>
-<p>
-Style parameters can also be specified using the <tt>%style</tt> and <tt>%localstyle</tt> parameters. The <tt>%style</tt> directive applies a new format to the current section and all of its parents. The <tt>%localstyle</tt> directive applies a new format to the current section. For example :<p>
-<p>
-<blockquote><pre>%style sort,before, skip=1 # Apply these formats everywhere
-%localstyle sort # Apply this format to the current section
-
-</pre></blockquote>
-Use of these directives usually isn't required since it's easy enough to simply specify the information after each section.<p>
-<a name="n15"></a><h3> Default Formatting</h3>
-By default, SWIG will reformat comment text, produce documentation in the order encountered in an interface file (nosort), and annotate descriptions with a C information string. This behavior most closely matches that used in SWIG 1.0, although it is not an exact match due to differences in the old documentation system.<p>
-<p>
-When used in the default mode, comment text may contain documentation specific formatting markup. For example, you could embed LaTeX or HTML markup in comments to have precise control over the look of the final document.<p>
-<a name="n16"></a><h3> Comment Formatting variables</h3>
-The default formatting can be changed by changing one or more of the following formatting variables :<p>
-<blockquote><pre>
-after Use comments after a declaration (default)
-before Use comments before a declaration
-chop_top=nlines Comment chopping (preformatted)
-chop_bottom=nlines Comment chopping (preformatted)
-chop_left=nchar Comment chopping (preformatted)
-chop_right=nchar Comment chopping (preformatted)
-format Allow SWIG to reformat text (the default)
-ignore Ignore comments
-info Print C information text (default)
-keep Keep comments (opposite of ignore)
-noinfo Don't print C information text
-nosort Don't sort documentation (default)
-pre Assume text is preformatted
-skip=nlines Number of blank lines between comment and declaration
-sort Sort documentation
-tabify Leave tabs intact
-untabify Convert tabs to spaces (default)
-</pre></blockquote>
-<p>
-More variables may be available depending on particular documentation modules. The use of these variables is described in the next few sections.<p>
-<a name="n17"></a><h3> Sorting </h3>
-Documentation can be sorted using the `<tt>sort</tt>' parameter. For example :<p>
-<p>
-<blockquote><pre>%title "My interface",sort
-</pre></blockquote>
-<p>
-When used, all documentation entries, including sections will be alphabetically sorted. Sorting can be disabled in particular sections and subsection by specifying the `<tt>nosort</tt>' parameter in a section declaration. By default, SWIG does not sort documentation. As a general rule, it really only comes in handy if you have a really messy interface file.<p>
-<p>
-For backwards compatibility with earlier versions of SWIG, the following directives can be used to specify sorting. <p>
-<p>
-<blockquote><pre>%alpha Sort documentation alphabetically (obsolete)
-%raw Keep documentation in order (obsolete)
-
-</pre></blockquote>
-These directives only apply globally and should near the beginning of file. Future support of these directives is not guaranteed and generally discouraged.<p>
-<a name="n18"></a><h3> Comment placement and formatting</h3>
-Comments may be placed before or after a declaration. This is specified using the `<tt>before</tt>' and `<tt>after</tt>' parameters. The space between a comment and a declaration can be set by changing the `<tt>skip</tt>' parameter. By default, <tt>skip=1</tt>, indicating that a comment and declaration must be on adjacent lines. Use of the <tt>skip</tt> parameter makes it possible for the documentation generator to ignore comments that are too far away and possibly unrelated to a declaration.<p>
-<p>
-By default, SWIG reformats the text found in a comment. However, in many cases, your file may have preformatted comments or comment blocks. To handle such comments correctly, you can use preformatted mode. This is specified using the `pre' parameter as follows :<p>
-<p>
-<blockquote><pre>%section "Preformatted Section",pre
-%section "Reformatted Section", format
-
-</pre></blockquote>
-All declarations in this section will now be assumed to have preformatted comments. When using the preformat mode, a variety of other parameters are available as shown in the following diagram :<p>
-<center><img src="ch5.1.png"></center>
-
-.<p>
-<p>
-The chopping parameters can be used to strip out the text of block comments. For example, using <tt>chop_left=3</tt>, <tt>chop_top=1</tt>, <tt>chop_bottom=1</tt> on the above comment produces the following output :<p>
-<blockquote><pre>
-Plot2D_line x1 y1 x2 y2 color
- [ returns void ]
- void Plot2D_line(int x1, int y1, int x2, int y2, Pixel color)
-
- Draws a line between the points (x1,y1) and (x2,y2) using the
- the given color. The line is cropped to fit in the current
- bounding box.
-
- Uses the Bresenham line drawing algorithm.
-</pre></blockquote>
-<p>
-The chopping parameters only apply if a comment is sufficiently large (i.e.. if the number of lines exceed <tt>chop_top</tt>+<tt>chop_bottom</tt>). Thus, in our example, a one line comment will be unaltered even though chopping has been set. By default, SWIG sets chop_left=3 and all others to zero. This setting removes the `<tt>/* </tt>` or `<tt>// </tt>` preceeding a comment.<p>
-<a name="n19"></a><h3> Tabs and other annoyances</h3>
-When using the preformatted mode, SWIG will automatically convert tabs to white space. This is done assuming that tabs are placed every 8 characters. The tabification mode can be selected using the `tabify' and `untabify' parameters :<p>
-<p>
-<blockquote><pre>%section "Untabified Section",untabify
-%section "Leave those tabs alone", tabify
-
-</pre></blockquote>
-Tabs are simply ignored when comments are reformatted (well, actually, they're just copied into the output, but the target documentation method will ignore them).<p>
-<a name="n20"></a><h3> Ignoring comments</h3>
-To ignore the comments in a particular section, you can use the `ignore' parameter. For example :<p>
-<blockquote><pre>
-%section "No Comments", ignore
-%section "Keep Comments", keep
-
-</pre></blockquote>
-The `<tt>keep</tt>' parameter is used to disable the effect of an ignore parameter (if set by a section's parent).<p>
-<a name="n21"></a><h3> C Information</h3>
-Normally, each declaration in a file will have a C information tag attached to it. This is usually enclosed in [ ] and contains the return type of a function along with other information. This text can disabled using the `noinfo' parameters and reenabled using the `info' parameter.<p>
-<p>
-<blockquote><pre>%section "No C Information", noinfo
-%section "Print C Information", info
-
-</pre></blockquote>
-<a name="n7"></a><h2> Adding Additional Text</h2>
-Additional documentation text can be added using the <tt>%text</tt> directive as shown :<p>
-<p>
-<blockquote><pre><tt>%text %{
-</tt>
-This is some additional documentation text.
-
-%}
-
-</pre></blockquote>
-The <tt>%text</tt> directive is primarily used to add text that is not associated with any particular declaration. For example, you may want to provide a general description of a module before defining all of the functions. Any text can be placed inside the <tt>%{,%}</tt> block except for a `<tt>%}</tt>' that ends the block. For the purposes of sorting, text segments will always appear immediately after the previous declaration.<p>
-<a name="n8"></a><h2> Disabling all documentation</h2>
-All documentation can be suppressed for a portion of an interface file by using the <tt>%disabledoc</tt> and <tt>%enabledoc </tt>directives. These would be used as follows:<p>
-<p>
-<blockquote><pre>%disabledoc
-... A a bunch of declarations with no documentation ...
-%enabledoc
-... Now declarations are documented again ...
-
-</pre></blockquote>
-These directives can be safely nested. Thus, the occurrence of these directives inside a <tt>%disabledoc </tt>section has no effect (only the outer-most occurrence is important).<p>
-<p>
-The primary use of these directives is for disabling the documentation on commonly used modules that you might use repeatedly (but don't want any documentation for). For example :<p>
-<blockquote><pre>
-%disabledoc
-%include wish.i
-%include array.i
-%include timer.i
-%enabledoc
-
-</pre></blockquote>
-<p>
-<a name="n9"></a><h2> An Example</h2>
-To illustrate the documentation system in action, here is some code from the SWIG library file `array.i'.<p>
-<p>
-<blockquote><pre>//
-// array.i
-// This SWIG library file provides access to C arrays.
-
-%module carray
-
-%section "SWIG C Array Module",info,after,pre,nosort,skip=1,chop_left=3,
-chop_right=0,chop_top=0,chop_bottom=0
-
-%text %{
-%include array.i
-
-This module provides scripting language access to various kinds of C/C++
-arrays. For each datatype, a collection of four functions are created :
-
- &lt;type&gt;_array(size) : Create a new array of given size
- &lt;type&gt;_get(array, index) : Get an element from the array
- &lt;type&gt;_set(array, index, value) : Set an element in the array
- &lt;type&gt;_destroy(array) : Destroy an array
-
-The functions in this library are only low-level accessor functions
-designed to directly access C arrays. Like C, no bounds checking is
-performed so use at your own peril.
-%}
-
-// -----------------------------------------------------------------------
-// Integer array support
-// -----------------------------------------------------------------------
-
-%subsection "Integer Arrays"
-/* The following functions provide access to integer arrays (mapped
- onto the C 'int' datatype. */
-
-%{
- ... Supporting C code ...
-%}
-int *int_array(int nitems);
-/* Creates a new array of integers. nitems specifies the number of elements.
- The array is created using malloc() in C and new() in C++. */
-
-void int_destroy(int *array);
-/* Destroys the given array. */
-
-int int_get(int *array, int index);
-/* Returns the value of array[index]. */
-
-int int_set(int *array, int index, int value);
-/* Sets array[index] = value. Returns value. */
-
-// -----------------------------------------------------------------------
-// Floating point
-// -----------------------------------------------------------------------
-
-%subsection "Floating Point Arrays"
-/* The following functions provide access to arrays of floats and doubles. */
-
-%{
- .. Supporting C code ...
-%}
-double *double_array(int nitems);
-/* Creates a new array of doubles. nitems specifies the number of elements.
- The array is created using malloc() in C and new() in C++. */
-
-void double_destroy(double *array);
-/* Destroys the given array. */
-
-double double_get(double *array, int index);
-/* Returns the value of array[index]. */
-
-double double_set(double *array, int index, double value);
-/* Sets array[index] = value. Returns value. */
-
-float *float_array(int nitems);
-/* Creates a new array of floats. nitems specifies the number of elements.
- The array is created using malloc() in C and new() in C++. */
-
-void float_destroy(float *array);
-/* Destroys the given array. */
-
-float float_get(float *array, int index);
-/* Returns the value of array[index]. */
-
-float float_set(float *array, int index, float value);
-/* Sets array[index] = value. Returns value. */
-
-// -----------------------------------------------------------------------
-// Character strings
-// -----------------------------------------------------------------------
-
-%subsection "String Arrays"
-
-%text %{
-The following functions provide support for the 'char **' datatype. This
-is primarily used to handle argument lists and other similar structures that
-need to be passed to a C/C++ function.
-%}
-
-#if defined(SWIGTCL)
-%text %{
-To convert from a Tcl list into a 'char **', the following code can be used :
-
- # $list is a list
- set args [string_array expr {[llength $list] + 1}]
- set i 0
- foreach a $list {
- string_set $args $i $a
- incr i 1
- }
- string_set $i ""
- # $args is now a char ** type
-%}
-#elif defined(SWIGPERL)
-
-%text %{
-To convert from a Perl list into a 'char **', code similar to the following
-can be used :
-
- # @list is a list
- my $l = scalar(@list);
- my $args = string_array($l+1);
- my $i = 0;
- foreach $arg (@list) {
- string_set($args,$i,$arg);
- $i++;
- }
- string_set($args,$i,"");
-
-(of course, there is always more than one way to do it)
-%}
-#elif defined(SWIGPYTHON)
-
-%text %{
-To convert from a Python list to a 'char **', code similar to the following
-can be used :
-
- # 'list' is a list
- args = string_array(len(list)+1)
- for i in range(0,len(list)):
- string_set(args,i,list[i])
- string_set(args,len(list),"")
-%}
-
-#endif
-
-%{
- ... Supporting C code ...
-%}
-char **string_array(int nitems);
-/* Creates a new array of strings. nitems specifies the number of elements.
- The array is created using malloc() in C and new() in C++. Each element
- of the array is set to NULL upon initialization. */
-
-void string_destroy(char *array);
-/* Destroys the given array. Each element of the array is assumed to be
- a NULL-terminated string allocated with malloc() or new(). All of
- these strings will be destroyed as well. (It is probably only safe to
- use this function on an array created by string_array) */
-
-char *string_get(char **array, int index);
-/* Returns the value of array[index]. Returns a string of zero length
- if the corresponding element is NULL. */
-
-char *string_set(char **array, int index, char *value);
-/* Sets array[index] = value. value is assumed to be a NULL-terminated
- string. A string of zero length is mapped into a NULL value. When
- setting the value, the value will be copied into a new string allocated
- with malloc() or new(). Any previous value in the array will be
- destroyed. */
-</pre></blockquote>
-<p>
-In this file, all of the declarations are placed into a new section. We specify formatting information for our section. Since this is a general purpose library file, we have no idea what formatting our parent might be using so an explicit declaration makes sure we get it right. Each comment contains preformatted text describing each function. Finally, in the case of the string functions, we are using a combination of conditional compilation and documentation system directives to produce language-specific documentation. In this case, the documentation contains a usage example in the target scripting language.<p>
-<p>
-When processed through the ASCII module, this file will produce documentation similar to the following :<p>
-<p>
-<blockquote><pre>7. SWIG C Array Module
-=======================
-
-%include array.i
-
-This module provides scripting language access to various kinds of C/C++
-arrays. For each datatype, a collection of four functions are created :
-
- &lt;type&gt;_array(size) : Create a new array of given size
- &lt;type&gt;_get(array, index) : Get an element from the array
- &lt;type&gt;_set(array, index, value) : Set an element in the array
- &lt;type&gt;_destroy(array) : Destroy an array
-
-The functions in this library are only low-level accessor functions
-designed to directly access C arrays. Like C, no bounds checking is
-performed so use at your own peril.
-
-7.1. Integer Arrays
---------------------
-The following functions provide access to integer arrays (mapped
-onto the C 'int' datatype.
-
-
-int_array(nitems)
- [ returns int * ]
- Creates a new array of integers. nitems specifies the number of elements.
- The array is created using malloc() in C and new() in C++.
-
-int_destroy(array)
- [ returns void ]
- Destroys the given array.
-
-int_get(array,index)
- [ returns int ]
- Returns the value of array[index].
-
-int_set(array,index,value)
- [ returns int ]
- Sets array[index] = value. Returns value.
-
-7.2. Floating Point Arrays
----------------------------
-The following functions provide access to arrays of floats and doubles.
-
-
-double_array(nitems)
- [ returns double * ]
- Creates a new array of doubles. nitems specifies the number of elements.
- The array is created using malloc() in C and new() in C++.
-
-double_destroy(array)
- [ returns void ]
- Destroys the given array.
-
-double_get(array,index)
- [ returns double ]
- Returns the value of array[index].
-
-double_set(array,index,value)
- [ returns double ]
- Sets array[index] = value. Returns value.
-
-float_array(nitems)
- [ returns float * ]
- Creates a new array of floats. nitems specifies the number of elements.
- The array is created using malloc() in C and new() in C++.
-
-float_destroy(array)
- [ returns void ]
- Destroys the given array.
-
-float_get(array,index)
- [ returns float ]
- Returns the value of array[index].
-
-float_set(array,index,value)
- [ returns float ]
- Sets array[index] = value. Returns value.
-
-7.3. String Arrays
--------------------
-
-The following functions provide support for the 'char **' datatype. This
-is primarily used to handle argument lists and other similar structures that
-need to be passed to a C/C++ function.
-
-To convert from a Python list to a 'char **', code similar to the following
-can be used :
-
- # 'list' is a list
- args = string_array(len(list)+1)
- for i in range(0,len(list)):
- string_set(args,i,list[i])
- string_set(args,len(list),"")
-
-string_array(nitems)
- [ returns char ** ]
- Creates a new array of strings. nitems specifies the number of elements.
- The array is created using malloc() in C and new() in C++. Each element
- of the array is set to NULL upon initialization.
-
-string_destroy(array)
- [ returns void ]
- Destroys the given array. Each element of the array is assumed to be
- a NULL-terminated string allocated with malloc() or new(). All of
- these strings will be destroyed as well. (It is probably only safe to
- use this function on an array created by string_array)
-
-string_get(array,index)
- [ returns char * ]
- Returns the value of array[index]. Returns a string of zero length
- if the corresponding element is NULL.
-
-string_set(array,index,value)
- [ returns char * ]
- Sets array[index] = value. value is assumed to be a NULL-terminated
- string. A string of zero length is mapped into a NULL value. When
- setting the value, the value will be copied into a new string allocated
- with malloc() or new(). Any previous value in the array will be
- destroyed.
-
-</pre></blockquote>
-<a name="n10"></a><h2> ASCII Documentation</h2>
-The ASCII module produces documentation in plaintext as shown in the previous example. Two formatting options are available (default values shown) :<p>
-<p>
-<blockquote><pre>ascii_indent = 8
-ascii_columns = 70
-
-</pre></blockquote>
-`<tt>ascii_indent</tt>' specifies the number of characters to indent each function description. `<tt>ascii_columns</tt>' specifies the width of the output when reformatting text.<p>
-<p>
-When reformatting text, all extraneous white-space is stripped and text is filled to fit in the specified number of columns. The output text will be left-justified. A single newline is ignored, but multiple newlines can be used to start a new paragraph. The character sequence `\\' can be used to force a newline.<p>
-<p>
-Preformatted text is printed into the resulting output unmodified although it may be indented when used as part of a function description.<p>
-<a name="n11"></a><h2> HTML Documentation</h2>
-The HTML module produces documentation in HTML format (who would have guessed?). However, a number of style parameters are available (shown with default values)<p>
-<blockquote><pre>
-html_title = "&lt;H1&gt;:&lt;/H1&gt;"
-html_contents = "&lt;H1&gt;:&lt;/H1&gt;"
-html_section = "&lt;HR&gt;&lt;H2&gt;:&lt;/H2&gt;"
-html_subsection = "&lt;H3&gt;:&lt;/H3&gt;"
-html_subsubsection = "&lt;H4&gt;:&lt;/H4&gt;"
-html_usage = "&lt;B&gt;&lt;TT&gt;:&lt;/TT&gt;&lt;/B&gt;"
-html_descrip = "&lt;BLOCKQUOTE&gt;:&lt;/BLOCKQUOTE&gt;"
-html_text = "&lt;P&gt;"
-html_cinfo = ""
-html_preformat = "&lt;PRE&gt;:&lt;/PRE&gt;"
-html_body = "&lt;BODY bg_color=\"#ffffff\"&gt;:&lt;/BODY&gt;"
-</pre></blockquote>
-<p>
-Any of these parameters can be changed, by simply specifying them after a <tt>%title</tt> or <tt>%section</tt> directive. However, the effects are applied globally so it probably makes sense to use the <tt>%style</tt> directive instead. For example :<p>
-<p>
-<blockquote><pre>%style html_contents="&lt;HR&gt;&lt;H1&gt;:&lt;/H1&gt;"
-... Rest of declarations ...
-
-</pre></blockquote>
-Each tag uses a ":" to separate the start and end tags. Any text will be inserted in place of the ":". Since strings are specified in SWIG using quotes, any quotes that need to be inserted into a tag should be escaped using the "\" character.<p>
-<p>
-Sample HTML output is shown below :<p>
-<p><a href="ch5.2.png">Sample Screenshot 1 </a><p>
-<p>
-<p>
-Since our example used preformatted text, the output is very similar to the ASCII module. However, if you use the default mode, it is possible to insert HTML markup directly into your C comments for a more personalized document.<p>
-<p>
-For navigation within the document, SWIG also produces a table of contents with links to each section within the document. With a large interface, the contents may look something like this :<p>
-<p><a href="ch5.3.png">Sample Screenshot 2 </a><p>
-<p>
-<p>
-<a name="n12"></a><h2> LaTeX Documentation</h2>
-The LaTeX module operates in a manner similar to the HTML module. The following style parameters are available (some knowledge of LaTeX is assumed).<p>
-<blockquote><pre>
-latex_parindent = "0.0in"
-latex_textwidth = "6.5in"
-latex_documentstyle = "[11pt]{article}"
-latex_oddsidemargin = "0.0in"
-latex_pagestyle = "\\pagestyle{headings}"
-latex_title = "{\\Large \\bf :} \\\\\n"
-latex_preformat = "{\\small \\begin{verbatim}:\\end{verbatim}}"
-latex_usage = "{\\tt \\bf : }"
-latex_descrip = "{\\\\\n \\makebox[0.5in]{} \begin{minipage}[t]{6in} : \n
-\\end{minipage} \\\\";
-latex_text = ":\\\\"
-latex_cinfo = "{\\tt : }"
-latex_section = "\\section{:}"
-latex_subsection = "\\subsection{:}"
-latex_subsubsection = "\\subsubsection{:}"
-
-</pre></blockquote>
-The style parameters, well, look downright ugly. Keep in mind that the strings used by SWIG have escape codes in them so it's necessary to represent the `\' character as `\\'. Thus, within SWIG your code will look something like this :<p>
-<p>
-<blockquote><pre>%style latex_section="\\newpage \n \\section{:}"
-</pre></blockquote>
-<p>
-The default values should be sufficient for creating a readable LaTeX document in any case you don't want to worry changing the default style parameters.<p>
-<a name="n13"></a><h2> C++ Support</h2>
-C++ classes are encapsulated in a new subsection of the current section. This subsection contains descriptions of all of the member functions and variables. Since language modules are responsible for creating the documentation, the use of shadow classes will result in documentation describing the resulting shadow classes, not the lower level interface to the code.<p>
-<p>
-While it's not entirely clear that this is the best way to document C++ code, it is a start (and it's better than no documentation).<p>
-<a name="n14"></a><h2> The Final Word?</h2>
-Early versions of SWIG used a fairly primitive documentation system, that could best be described as "barely usable." The system described here represents an almost total rewrite of the documentation system. While it is, by no means, a perfect solution, I think it is a step in the right direction. The SWIG library is now entirely self-documenting and is a good source of documentation examples. As always suggestions and improvements are welcome.<p>
-<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:46:55 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Exceptions.html b/swigweb/Doc1.1/HTML/Exceptions.html
deleted file mode 100644
index 7ee575b31..000000000
--- a/swigweb/Doc1.1/HTML/Exceptions.html
+++ /dev/null
@@ -1,295 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Exception Handling</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>7 Exception Handling</h1><p><ul>
-<li> <a href="#n1">The %except directive</a>
-<li> <a href="#n2">Handling exceptions in C code</a>
-<li> <a href="#n3">Exception handling with longjmp()</a>
-<li> <a href="#n4">Handling C++ exceptions</a>
-<li> <a href="#n5">Defining different exception handlers</a>
-<li> <a href="#n6">Using The SWIG exception library</a>
-<li> <a href="#n7">Debugging and other interesting uses for %except</a>
-<li> <a href="#n8">More Examples</a>
-</ul>
-
-In some cases, it is desirable to catch errors that occur in C functions and propagate them up to the scripting language interface (ie. raise an exception). By default, SWIG does nothing, but you can create a user-definable exception handler using the <tt>%except</tt> directive.<p>
-<a name="n1"></a><h2> The %except directive</h2>
-The <tt>%except</tt> directive allows you to define an exception handler. It works something like this :<p>
-<p>
-<blockquote><pre>%except(python) {
- try {
- $function
- }
- catch (RangeError) {
- PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
- return NULL;
- }
-}
-</pre></blockquote>
-<p>
-As an argument, you need to specify the target language. The exception handling C/C++ code is then enclosed in braces. The symbol <tt>$function </tt>is replaced with the real C/C++ function call that SWIG would be ordinarily make in the wrapper code. The C code you specify inside the <tt>%except</tt> directive can be anything you like including custom C code and C++ exceptions.<p>
-<p>
-To delete an exception handler, simply use the <tt>%except</tt> directive with no code. For example :<p>
-<p>
-<blockquote><pre>%except(python); // Deletes any previously defined handler
-
-</pre></blockquote>
-Exceptions can be redefined as necessary. The scope of an exception handler is from the point of definition to the end of the file, the definition of a new exception handler, or until the handler is deleted.<p>
-<a name="n2"></a><h2> Handling exceptions in C code</h2>
-C has no formal mechanism for handling exceptions so there are many possibilities. The first approach is to simply provide some functions for setting and checking an error code. For example :<p>
-<p>
-<blockquote><pre>
-
-/* File : except.c */
-
-static char error_message[256];
-static int error_status = 0;
-
-void throw_exception(char *msg) {
- strncpy(error_message,msg,256);
- error_status = 1;
-}
-
-void clear_exception() {
- error_status = 0;
-}
-char *check_exception() {
- if (error_status) return error_message;
- else return NULL;
-}
-
-</pre></blockquote>
-To work, functions will need to explicitly call <tt>throw_exception()</tt> to indicate an error occurred. For example :<p>
-<p>
-<blockquote><pre>double inv(double x) {
- if (x != 0) return 1.0/x;
- else {
- throw_exception("Division by zero");
- return 0;
- }
-}
-
-</pre></blockquote>
-To catch the exception, you can write a simple exception handler such as the following (shown for Perl5) :<p>
-<p>
-<blockquote><pre>%except(perl5) {
- char *err;
- clear_exception();
- $function
- if ((err = check_exception())) {
- croak(err);
- }
-}
-</pre></blockquote>
-<p>
-Now, when an error occurs, it will be translated into a Perl error. The downside to this approach is that it isn't particularly clean and it assumes that your C code is a willing participant in generating error messages. (This isn't going to magically add exceptions to a code that doesn't have them).<p>
-<a name="n3"></a><h2> Exception handling with longjmp()</h2>
-Exception handling can also be added to C code using the <tt>&lt;setjmp.h&gt;</tt> library. This usually isn't documented very well (at least not in any of my C books). In any case, here's one implementation that uses the C preprocessor :<p>
-<blockquote><pre>
-/* File : except.c
- Just the declaration of a few global variables we're going to use */
-
-#include &lt;setjmp.h&gt;
-jmp_buf exception_buffer;
-int exception_status;
-
-/* File : except.h */
-#include &lt;setjmp.h&gt;
-extern jmp_buf exception_buffer;
-extern int exception_status;
-
-#define try if ((exception_status = setjmp(exception_buffer)) == 0)
-#define catch(val) else if (exception_status == val)
-#define throw(val) longjmp(exception_buffer,val)
-#define finally else
-
-/* Exception codes */
-
-#define RangeError 1
-#define DivisionByZero 2
-#define OutOfMemory 3
-
-</pre></blockquote>
-Now, within a C program, you can do the following :<p>
-<p>
-<blockquote><pre>double inv(double x) {
- if (x) return 1.0/x;
- else {throw(DivisionByZero);
-}
-
-</pre></blockquote>
-Finally, to create a SWIG exception handler, write the following :<p>
-<p>
-<blockquote><pre>%{
-#include "except.h"
-%}
-
-%except(perl5) {
- try {
- $function
- } catch(RangeError) {
- croak("Range Error");
- } catch(DivisionByZero) {
- croak("Division by zero");
- } catch(OutOfMemory) {
- croak("Out of memory");
- } finally {
- croak("Unknown exception");
- }
-}
-
-</pre></blockquote>
-<p>
-At this point, you're saying this sure looks alot like C++ and you'd be right (C++ exceptions are often implemented in a similar manner). As always, the usual disclaimers apply--your mileage may vary. <p>
-<a name="n4"></a><h2> Handling C++ exceptions</h2>
-Handling C++ exceptions is almost completely trivial (well, all except for the actual C++ part). A typical SWIG exception handler will look like this :<p>
-<p>
-<blockquote><pre>%except(perl5) {
- try {
- $function
- } catch(RangeError) {
- croak("Range Error");
- } catch(DivisionByZero) {
- croak("Division by zero");
- } catch(OutOfMemory) {
- croak("Out of memory");
- } catch(...) {
- croak("Unknown exception");
- }
-}
-
-</pre></blockquote>
-The exception types need to be declared as classes elsewhere, possibly in a header file :<p>
-<p>
-<blockquote><pre>class RangeError {};
-class DivisionByZero {};
-class OutOfMemory {};
-
-</pre></blockquote>
-Newer versions of the SWIG parser should ignore exceptions specified in function declarations. For example :<p>
-<p>
-<blockquote><pre>double inv(double) throw(DivisionByZero);
-
-</pre></blockquote>
-<a name="n5"></a><h2> Defining different exception handlers</h2>
-By default, the <tt>%except</tt> directive creates an exception handler that is used for all wrapper functions that follow it. Creating one universal exception handler for all functions may be unwieldy and promote excessive code bloat since the handler will be inlined into each wrapper function created. For this reason, the exception handler can be redefined at any point in an interface file. Thus, a more efficient use of exception handling may work like this :<p>
-<p>
-<blockquote><pre>%except(python) {
- ... your exception handler ...
-}
-/* Define critical operations that can throw exceptions here */
-
-%except(python); // Clear the exception handler
-
-/* Define non-critical operations that don't throw exceptions */
-
-</pre></blockquote>
-<a name="n9"></a><h3> Applying exception handlers to specific datatypes.</h3>
-An alternative approach to using the <tt>%except</tt> directive is to use the "except" typemap. This allows you to attach an error handler to specific datatypes and function name. The typemap is applied to the return value of a function. For example :<p>
-<p>
-<blockquote><pre>%typemap(python,except) void * {
- $function
- if (!$source) {
- PyExc_SetString(PyExc_MemoryError,"Out of memory in $name");
- return NULL;
- }
-}
-
-void *malloc(int size);
-
-</pre></blockquote>
-When applied, this will automatically check the return value of <tt>malloc()</tt> and raise an exception if it's invalid. For example :<p>
-<p>
-<blockquote><pre>Python 1.4 (Jan 16 1997) [GCC 2.7.2]
-Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
-&gt;&gt;&gt; from example import *
-&gt;&gt;&gt; a = malloc(2048)
-&gt;&gt;&gt; b = malloc(1500000000)
-Traceback (innermost last):
- File "&lt;stdin&gt;", line 1, in ?
-MemoryError: Out of memory in malloc
-&gt;&gt;&gt;
-</pre></blockquote>
-<p>
-Since typemaps can be named, you can define an exception handler for a specific function as follows :<p>
-<p>
-<blockquote><pre>%typemap(python,except) void *malloc {
- ...
-}
-
-</pre></blockquote>
-This will only be applied to the <tt>malloc()</tt> function returning <tt>void *</tt>. While you probably wouldn't want to write a different exception handler for every function, it is possible to have a high degree of control if you need it. When typemaps are used, they override any exception handler defined with <tt>%except</tt>.<p>
-<a name="n6"></a><h2> Using The SWIG exception library</h2>
-The <tt>exception.i</tt> library file provides support for creating language independent exceptions in your interfaces. To use it, simply put an "<tt>%include exception.i</tt>" in your interface file. This creates a function<tt> SWIG_exception()</tt> that can be used to raise scripting language exceptions in a portable manner. For example :<p>
-<p>
-<blockquote><pre>// Language independent exception handler
-%include exception.i
-
-%except {
- try {
- $function
- } catch(RangeError) {
- SWIG_exception(SWIG_ValueError, "Range Error");
- } catch(DivisionByZero) {
- SWIG_exception(SWIG_DivisionByZero, "Division by zero");
- } catch(OutOfMemory) {
- SWIG_exception(SWIG_MemoryError, "Out of memory");
- } catch(...) {
- SWIG_exception(SWIG_RuntimeError,"Unknown exception");
- }
-}
-
-</pre></blockquote>
-As arguments, <tt>SWIG_exception()</tt> takes an error type code (an integer) and an error message string. The currently supported error types are :<p>
-<p>
-<blockquote><pre>SWIG_MemoryError
-SWIG_IOError
-SWIG_RuntimeError
-SWIG_IndexError
-SWIG_TypeError
-SWIG_DivisionByZero
-SWIG_OverflowError
-SWIG_SyntaxError
-SWIG_ValueError
-SWIG_SystemError
-SWIG_UnknownError
-</pre></blockquote>
-<p>
-Since the <tt>SWIG_exception()</tt> function is defined at the C-level it can be used elsewhere in SWIG. This includes typemaps and helper functions. The exception library provides a language-independent exception handling mechanism, so many of SWIG's library files now rely upon the library as well.<p>
-<a name="n7"></a><h2> Debugging and other interesting uses for %except</h2>
-Since the <tt>%except </tt>directive allows you to encapsulate the actual C function call, it can also be used for debugging and tracing operations. For example :<p>
-<p>
-<blockquote><pre>%except(tcl) {
- printf("Entering function : $name\n");
- $function
- printf("Leaving function : $name\n");
-}
-
-</pre></blockquote>
-allows you to follow the function calls in order to see where an application might be crashing. <p>
-<p>
-Exception handlers can also be chained. For example :<p>
-<p>
-<blockquote><pre>%except(tcl) {
- printf("Entering function : $name\n");
- $except
- printf("Leaving function : $name\n");
-}
-
-</pre></blockquote>
-Any previously defined exception handler will be inserted in place of the "<tt>$except</tt>" symbol. As a result, you can attach debugging code to existing handlers if necessary. However, it should be noted that this must be done before any C/C++ declarations are made (as exception handlers are applied immediately to all functions that follow them).<p>
-<a name="n8"></a><h2> More Examples</h2>
-By now, you know most of the exception basics. See the SWIG Examples directory for more examples and ideas. Further chapters show how to generate exceptions in specific scripting languages.<p>
-<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:46:57 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Extending.html b/swigweb/Doc1.1/HTML/Extending.html
deleted file mode 100644
index 06d2d2f14..000000000
--- a/swigweb/Doc1.1/HTML/Extending.html
+++ /dev/null
@@ -1,1848 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Extending SWIG</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>12 Extending SWIG</h1><p><ul>
-<li> <a href="#n1">Introduction</a>
-<li> <a href="#n2">Compiling a SWIG extension</a>
-<li> <a href="#n3">SWIG output</a>
-<li> <a href="#n4">The Language class (simple version)</a>
-<li> <a href="#n5">A tour of SWIG datatypes</a>
-<li> <a href="#n6">Typemaps (from C)</a>
-<li> <a href="#n7">File management</a>
-<li> <a href="#n8">Naming Services</a>
-<li> <a href="#n9">Code Generation Functions</a>
-<li> <a href="#n10">Writing a Real Language Module</a>
-<li> <a href="#n11">C++ Processing</a>
-<li> <a href="#n12">Documentation Processing</a>
-<li> <a href="#n13">The Future of SWIG</a>
-</ul>
-
-<a name="n1"></a><h2> Introduction</h2>
-This chapter attempts to describe the process of extending SWIG to support new target languages and documentation methods. First a word of warning--SWIG started out being a relatively simple system for building interfaces to ANSI C programs. Since then, it has grown into something much more than that (although I'm still trying to figure out what). As a result, it is undergoing a number of growing pains. Certain parts of the code have been rewritten and others can probably be described as a hackish nightmare. I'm always working on ways to improve the implementation, but expect to find a few warts and inconsistencies.<p>
-<a name="n14"></a><h3> Prerequisites</h3>
-In order to develop or modify a SWIG module, I assume the following :<p>
-<p>
-<ul>
-<li>That you understand the C API for the scripting language of interest.
-<li>You have a good understanding of how SWIG operates and a good idea of how typemaps work.
-<li>That you have some experience with C++. SWIG is written in C++, but doesn't use it maximally. However, familiarity with classes, inheritance, and operator overloading will help.
-<li>That you're just a little crazy (this will help alot).
-</ul>
-<a name="n15"></a><h3> SWIG Organization</h3>
-SWIG is built around a central core of functions and classes responsible for parsing interface files, managing documentation, handling datatypes, and utility functions. This code is contained in the "SWIG" directory of the distribution, but contains no information specific to any one scripting language. The various scripting language modules are implemented as C++ classes and found in the "Modules" directory of the distribution. The basic idea behind writing a module is that you write a language class containing about a dozen methods for creating wrapper functions, variables, constants, etc.... To use the language, you simply create a language "object", pass it on the parser and you magically get wrapper code. Documentation modules are written in a similar manner.<p>
-<p>
-An important aspect of the design is the relationship between ANSI C and C++. The original version of SWIG was developed to support ANSI C programs. To add C++ support, an additional "layer" was added to the system---that is, all of the C++ support is really built on top of the ANSI C support. Language modules can take advantage of both C and C++ although a module written only for C can still work with C++ (due to the layered implementation). <p>
-<p>
-As for making modifications to SWIG, all files in the "SWIG" directory should be considered "critical." Making changes here can cause serious problems in all SWIG language modules. When making customizations, one should only consider files in the "Modules" directory if at all possible.<p>
-<a name="n16"></a><h3> The organization of this chapter</h3>
-The remainder of this chapter is a bottom-up approach is to building SWIG modules. It will start with the basics and gradually build up a working language module, introducing new concepts as needed.<p>
-<a name="n2"></a><h2> Compiling a SWIG extension</h2>
-The first order of business is that of compiling an extension to SWIG and using it. This is the easy part.<p>
-<a name="n17"></a><h3> Required files</h3>
-To build any SWIG extension you need to locate the files "<tt>swig.h</tt>" and "<tt>libswig.a</tt>". In a typical installation, these will usually be found in <tt>/usr/local/include</tt> and <tt>/usr/local/lib</tt> respectively. All extension modules will need to include the "<tt>swig.h</tt>" header file and link against the <tt>libswig.a</tt> library. <p>
-<a name="n18"></a><h3> Required C++ compiler</h3>
-Due to name-mangling in the C++ compiler (which is different between compiler implementations), you will need to use the same C++ compiler used to compile SWIG. If you don't know which C++ compiler was used, typing `<tt>swig -version</tt>' will cause SWIG to print out its version number and the C++ compiler that was used to build it.<p>
-<a name="n19"></a><h3> Writing a main program</h3>
-To get any extension to work, it is necessary to write a small <tt>main()</tt> program to create a language object and start the SWIG parser. For example :<br><p>
-<blockquote><pre>#include &lt;swig.h&gt;
-#include "swigtcl.h" // Language specific header
-
-extern int SWIG_main(int, char **, Language *, Documentation *);
-int main(int argc, char **argv) {
-
- TCL *l = new Tcl; // Create a new Language object
- init_args(argc, argv); // Initialize args
- return SWIG_main(argc, argv, l, 0);
-}
-</pre></blockquote>
-<a name="n20"></a><h3> Compiling</h3>
-To compile your extension, do the following :<p>
-<p>
-<blockquote><pre>% c++ tcl.cxx main.cxx -lswig -o myswig
-
-</pre></blockquote>
-In this case we get a special version of SWIG that compiles Tcl extensions.<p>
-<a name="n3"></a><h2> SWIG output</h2>
-The output of SWIG is a single file that is organized as follows :<p>
-<center><img src="ch12.1.png"></center><p>
-<p>
-<p>
-During code generation, the three sections are created as separate files that are accessed using the following file handles :<p>
-<p>
-<blockquote><pre>FILE *f_header; // Header section
-FILE *f_wrappers; // Wrapper section
-FILE *f_init; // Initialization function
-
-</pre></blockquote>
-On exit, the three files are merged into a single output file.<p>
-<p>
-When generating code, your language module should use the I/O functions in the C <tt>&lt;stdio.h&gt;</tt> library. SWIG does not use the C++ streams library.<p>
-<p>
-The use of each output section can be roughly described as follows :<p>
-<p>
-<ul>
-<li>The header section contains forward declarations, header files, helper functions, and run-time functions (such as the pointer type-checker). All code included with %{,%} also ends up here.
-<li>The wrapper section contains all of the SWIG generated wrapper functions.
-<li>The initialization section is a single C function used to initialize the module. For large modules, this function can be quite large. In any case, output to <tt>f_init</tt> should be treated with some care considering that the file is essentially one big C function.
-</ul>
-<a name="n4"></a><h2> The Language class (simple version)</h2>
-Writing a new language module involves inheriting from the SWIG <tt>Language</tt> class and implementing methods for a few virtual functions. A minimal definition of a new Language module is as follows :<p>
-<p>
-<blockquote><pre>// File : mylang.h
-// A minimal SWIG Language module
-
-class MYLANG : public Language {
-private:
- char *module;
-public :
- MYLANG() {
- module = 0;
- };
- // Virtual functions required by the SWIG parser
- void parse_args(int, char *argv[]);
- void parse();
- void create_function(char *, char *, DataType *, ParmList *);
- void link_variable(char *, char *, DataType *);
- void declare_const(char *, char *, DataType *, char *);
- void initialize(void);
- void headers(void);
- void close(void);
- void set_module(char *,char **);
- void create_command(char *, char *);
-};
-
-</pre></blockquote>
-<p>
-Given the above header file, we can create a very simplistic language module as follows :<p>
-<p>
-<blockquote><pre>// ---------------------------------------------------------------------
-// A simple SWIG Language module
-// ---------------------------------------------------------------------
-
-#include "swig.h"
-#include "mylang.h"
-
-// ---------------------------------------------------------------------
-// MYLANG::parse_args(int argc, char *argv[])
-//
-// Parse command line options and initializes variables.
-// ---------------------------------------------------------------------
-void MYLANG::parse_args(int argc, char *argv[]) {
- printf("Getting command line options\n");
- typemap_lang = "mylang";
-}
-
-// ---------------------------------------------------------------------
-// void MYLANG::parse()
-//
-// Start parsing an interface file.
-// ---------------------------------------------------------------------
-void MYLANG::parse() {
- fprintf(stderr,"Making wrappers for My Language\n");
- headers();
- yyparse(); // Run the SWIG parser
-}
-
-// ---------------------------------------------------------------------
-// MYLANG::set_module(char *mod_name,char **mod_list)
-//
-// Sets the module name. Does nothing if it's already set (so it can
-// be overridden as a command line option).
-//
-// mod_list is a NULL-terminated list of additional modules. This
-// is really only useful when building static executables.
-//----------------------------------------------------------------------
-
-void MYLANG::set_module(char *mod_name, char **mod_list) {
- if (module) return;
- module = new char[strlen(mod_name)+1];
- strcpy(module,mod_name);
-}
-
-// ----------------------------------------------------------------------
-// MYLANG::headers(void)
-//
-// Generate the appropriate header files for MYLANG interface.
-// ----------------------------------------------------------------------
-void MYLANG::headers(void) {
- emit_banner(f_header); // Print the SWIG banner message
- fprintf(f_header,"/* Implementation : My Language */\n\n");
-}
-
-// ---------------------------------------------------------------------
-// MYLANG::initialize(void)
-//
-// Produces an initialization function. Assumes that the module
-// name has already been specified.
-// ---------------------------------------------------------------------
-void MYLANG::initialize() {
- if (!module) module = "swig"; // Pick a default name
- // Start generating the initialization function
- fprintf(f_init,"int %s_initialize() {\n", module);
-}
-
-// ---------------------------------------------------------------------
-// MYLANG::close(void)
-//
-// Finish the initialization function. Close any additional files and
-// resources in use.
-// ---------------------------------------------------------------------
-void MYLANG::close(void) {
- // Finish off our init function
- fprintf(f_init,"}\n");
-}
-
-// ---------------------------------------------------------------------
-// MYLANG::create_command(char *cname, char *iname)
-//
-// Creates a new command from a C function.
-// cname = Name of the C function
-// iname = Name of function in scripting language
-// ---------------------------------------------------------------------
-void MYLANG::create_command(char *cname, char *iname) {
- fprintf(f_init,"\t Creating command %s\n", iname);
-}
-
-// ---------------------------------------------------------------------
-// MYLANG::create_function(char *name, char *iname, DataType *d, ParmList *l)
-//
-// Create a function declaration and register it with the interpreter.
-// name = Name of real C function
-// iname = Name of function in scripting language
-// d = Return datatype
-// l = Function parameters
-// ---------------------------------------------------------------------
-void MYLANG::create_function(char *name, char *iname, DataType *d, ParmList *l) {
- fprintf(f_wrappers,"\nwrap_%s() { }\n\n", name);
- create_command(name,iname);
-}
-
-
-// ---------------------------------------------------------------------
-// MYLANG::link_variable(char *name, char *iname, DataType *t)
-//
-// Create a link to a C variable.
-// name = Name of C variable
-// iname = Name of variable in scripting language
-// t = Datatype of the variable
-// ---------------------------------------------------------------------
-void MYLANG::link_variable(char *name, char *iname, DataType *t) {
- fprintf(f_init,"\t Linking variable : %s\n", iname);
-}
-
-// ---------------------------------------------------------------------
-// MYLANG::declare_const(char *name, char *iname, DataType *type, char *value)
-//
-// Makes a constant.
-// name = Name of the constant
-// iname = Scripting language name of constant
-// type = Datatype of the constant
-// value = Constant value (as a string)
-// ---------------------------------------------------------------------
-void MYLANG::declare_const(char *name, char *iname, DataType *type, char *value) {
- fprintf(f_init,"\t Creating constant : %s = %s\n", name, value);
-}
-</pre></blockquote>
-<p>
-To compile our new language, we write a main program (as described previously) and do this :<p>
-<p>
-<blockquote><pre>% g++ main.cxx mylang.cxx -I/usr/local/include -L/usr/local/lib -lswig -o myswig
-
-</pre></blockquote>
-Now, try running this new version of SWIG on a few interface files to see what happens. The various <tt>printf()</tt> statements will show you where output appears and how it is structured. For example, if we run this module on the following interface file :<p>
-<p>
-<blockquote><pre>/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-%}
-
-// A function
-extern double foo(double a, double b);
-
-// A variable
-extern int bar;
-
-// A constant
-#define SPAM 42
-
-</pre></blockquote>
-We get the following output :<p>
-<p>
-<blockquote><pre>/*
- * FILE : example_wrap.c
- *
- * This file was automatically generated by :
- * Simplified Wrapper and Interface Generator (SWIG)
- * Version 1.1 (Final)
- *
- * Portions Copyright (c) 1995-1997
- * The University of Utah and The Regents of the University of California.
- * Permission is granted to distribute this file in any manner provided
- * this notice remains intact.
- *
- * Do not make changes to this file--changes will be lost!
- *
- */
-
-
-#define SWIGCODE
-/* Implementation : My Language */
-
-
-/* Put headers and other declarations here */
-extern double foo(double ,double );
-extern int bar;
-
-wrap_foo() { }
-
-int example_initialize() {
- Creating command foo
- Linking variable : bar
- Creating constant : SPAM = 42
-}
-
-</pre></blockquote>
-Looking at the language module and the output gives some idea of how things are structured. The first part of the file is a banner message printed by the <tt>emit_banner()</tt> function. The "extern" declarations are automatically supplied by the SWIG compiler when use an extern modifier. The wrapper functions appear after all of the headers and forward declarations. Finally, the initialization function is written.<p>
-<p>
-It is important to note that this minimal module is enough to use virtually all aspects of SWIG. If we feed SWIG a C++ file, we will see our low-level module functions being called even though we have not explicitly defined any C++ handling (this is due to the layered approach of implementing C++ on top of C). For example, the following interface file <p>
-<blockquote><pre>
-%module example
-struct Vector {
- double x,y,z;
- Vector();
- ~Vector();
- double magnitude();
-};
-</pre></blockquote>
-<p>
-produces accessor functions and the following output :<p>
-<p>
-<blockquote><pre>/*
- * FILE : example_wrap.c
- *
- * This file was automatically generated by :
- * Simplified Wrapper and Interface Generator (SWIG)
- * Version 1.1 (Final)
- *
- * Portions Copyright (c) 1995-1997
- * The University of Utah and The Regents of the University of California.
- * Permission is granted to distribute this file in any manner provided
- * this notice remains intact.
- *
- * Do not make changes to this file--changes will be lost!
- *
- */
-
-
-#define SWIGCODE
-/* Implementation : My Language */
-
-static double Vector_x_set(Vector *obj, double val) {
- obj-&gt;x = val;
- return val;
-}
-
-wrap_Vector_x_set() { }
-
-static double Vector_x_get(Vector *obj) {
- double result;
- result = (double ) obj-&gt;x;
- return result;
-}
-
-wrap_Vector_x_get() { }
-
-static double Vector_y_set(Vector *obj, double val) {
- obj-&gt;y = val;
- return val;
-}
-
-wrap_Vector_y_set() { }
-
-static double Vector_y_get(Vector *obj) {
- double result;
- result = (double ) obj-&gt;y;
- return result;
-}
-
-wrap_Vector_y_get() { }
-
-static double Vector_z_set(Vector *obj, double val) {
- obj-&gt;z = val;
- return val;
-}
-
-wrap_Vector_z_set() { }
-
-static double Vector_z_get(Vector *obj) {
- double result;
- result = (double ) obj-&gt;z;
- return result;
-}
-
-wrap_Vector_z_get() { }
-
-static Vector *new_Vector() {
- return new Vector();
-}
-
-wrap_new_Vector() { }
-
-static void delete_Vector(Vector *obj) {
- delete obj;
-}
-
-wrap_delete_Vector() { }
-
-static double Vector_magnitude(Vector *obj) {
- double _result = (double )obj-&gt;magnitude();
- return _result;
-}
-
-wrap_Vector_magnitude() { }
-
-int example_initialize() {
- Creating command Vector_x_set
- Creating command Vector_x_get
- Creating command Vector_y_set
- Creating command Vector_y_get
- Creating command Vector_z_set
- Creating command Vector_z_get
- Creating command new_Vector
- Creating command delete_Vector
- Creating command Vector_magnitude
-}
-</pre></blockquote>
-<p>
-With just a little work, we already see that SWIG does quite alot for us. Now our task is to fill in the various Language methods with the real code needed to produce a working module. Before doing that, we first need to take a tour of some important SWIG datatypes and functions.<p>
-<a name="n5"></a><h2> A tour of SWIG datatypes</h2>
-While SWIG has become somewhat complicated over the last year, its internal operation is based on just a few fundamental datatypes. These types are described now although examples of using the various datatypes are shown later.<p>
-<a name="n21"></a><h3> The DataType class</h3>
-All C datatypes are represented by the following structure :<p>
-<blockquote><pre>
-
-class DataType {
-public:
- DataType();
- DataType(DataType *);
- ~DataType();
- int type; // SWIG Type code
- char name[MAXNAME]; // Name of type
- char is_pointer; // Is this a pointer?
- char implicit_ptr; // Implicit ptr
- char is_reference; // A C++ reference type
- char status; // Is this datatype read-only?
- char *qualifier; // A qualifier string (ie. const).
- char *arraystr; // String containing array part
- int id; // type identifier (unique for every type).
- // Output methods
- char *print_type(); // Return string containing datatype
- char *print_full(); // Return string with full datatype
- char *print_cast(); // Return string for type casting
- char *print_mangle(); // Return mangled version of type
- char *print_mangle_default(); // Default mangling scheme
- char *print_real(); // Print the real datatype
- char *print_arraycast(); // Prints an array cast
- // Array query functions
- int array_dimensions(); // Return number of array dimensions (if any)
- char *get_dimension(int); // Return string for a particular dimension
-};
-
-
-</pre></blockquote>
-The fundamental C datatypes are given a unique numerical code which is stored in the <tt>type</tt> field. The current list of types is as follows :<p>
-<p>
-<blockquote><pre>C Datatype SWIG Type Code
-int T_INT
-short T_SHORT
-long T_LONG
-char T_CHAR
-float T_FLOAT
-double T_DOUBLE
-void T_VOID
-unsigned int T_UINT
-unsigned short T_USHORT
-unsigned long T_ULONG
-unsigned char T_UCHAR
-signed char T_SCHAR
-bool T_BOOL
-&lt;user&gt; T_USER
-error T_ERROR
-</pre></blockquote>
-<p>
-The <tt>T_USER</tt> type is used for all derived datatypes including structures and classes. The <tt>T_ERROR</tt> type indicates that a parse/type error has occurred and went undetected (as far as I know this doesn't happen).<p>
-<p>
-The <tt>name[]</tt> field contains the actual name of the datatype as seen by the parser and is currently limited to a maximum of 96 bytes (more than enough for most applications). If a typedef has been used, the name field contains the actual name used, not the name of the primitive C datatype. Here are some examples :<p>
-<p>
-<blockquote><pre>C Datatype type name[]
-double T_DOUBLE double
-unsigned int T_UINT unsigned int
-signed long T_LONG signed long
-struct Vector T_USER struct Vector
-Real T_DOUBLE Real
-
-</pre></blockquote>
-C qualifiers such as "<tt>const</tt>" or "<tt>volatile</tt>" are stored separately in the <tt>qualifier</tt> field. In order to produce usable wrapper code, SWIG often needs to strip the qualifiers. For example, trying to assign a passed function argument into a type of "<tt>const int</tt>" will irritate most compilers. Unfortunately, this kind of assignment is unavoidable when converting arguments between a scripting and C representation.<p>
-<p>
-The <tt>is_pointer</tt> field indicates whether or not a particular datatype is a pointer. The value of <tt>is_pointer</tt> determines the level of indirection used. For example :<p>
-<p>
-<blockquote><pre>C Datatype type is_pointer
-double * T_DOUBLE 1
-int *** T_INT 3
-char * T_CHAR 1
-
-</pre></blockquote>
-The <tt>implicit_ptr</tt> field is an internally used parameter that is used to properly handle the use of pointers in typedef statements. However, for the curious, in indicates the level of indirection implicitly defined in a datatype. For example :<p>
-<p>
-<blockquote><pre>typedef char *String;
-
-</pre></blockquote>
-is represented by a datatype with the following parameters :<p>
-<p>
-<blockquote><pre>type = T_CHAR;
-name[] = "String";
-is_pointer = 1;
-implicit_ptr = 1;
-
-</pre></blockquote>
-Normally, language modules do not worry about the <tt>implicit_ptr </tt>field.<p>
-<p>
-C++ references are indicated by the <tt>is_reference</tt> field. By default, the parser converts references into pointers which makes them indistinguishable from other pointer datatypes. However, knowing that something is a reference effects some code generation procedures so this field can be checked to see if a datatype really is a C++ reference.<p>
-<p>
-The <tt>arraystr</tt> field is used to hold the array dimensions of array datatypes. The dimensions are simply represented by a string. For example :<p>
-<p>
-<blockquote><pre>C Datatype type is_pointer arraystr
-double a[50] T_DOUBLE 1 [50]
-int b[20][30][50] T_INT 1 [20][30][50]
-char *[MAX] T_CHAR 2 [MAX]
-
-</pre></blockquote>
-SWIG converts all arrays into pointers. Thus a "<tt>double [50]</tt>" is really just a special version of "<tt>double *</tt>". If a datatype is not declared as an array, the <tt>arraystr</tt> field contains the NULL pointer.<p>
-<p>
-A collection of "output" methods are available for datatypes. The names of these methods are mainly "historical" in that they don't actually "print" anything, but now return character strings instead. Assuming that <tt>t</tt> is a datatype representing the C datatype "<tt>const int *</tt>", here's what the methods produce :<p>
-<p>
-<blockquote><pre>Operation Output
-t-&gt;print_type() int *
-t-&gt;print_full() const int *
-t-&gt;print_cast() (int *)
-t-&gt;print_mangle() &lt; language dependent &gt;
-t-&gt;print_mangle_default() _int_p
-</pre></blockquote>
-<p>
-A few additional output methods are provided for dealing with arrays :<p>
-<p>
-<blockquote><pre>type Operation Output
-int a[50] t-&gt;print_type() int *
-int a[50] t-&gt;print_real() int [50]
-int a[50] t-&gt;print_arraycast() (int *)
-int a[50][50] t-&gt;print_arraycast() (int (*)[50])
-
-</pre></blockquote>
-Additional information about arrays is also available using the following functions :<p>
-<p>
-<blockquote><pre>type Operation Result
-int a[50] t-&gt;array_dimension() 1
-int a[50] t-&gt;get_dimension(0) 50
-int b[MAXN][10] t-&gt;array_dimension() 2
-int b[MAXN][10] t-&gt;get_dimension(0) MAXN
-int b[MAXN][10] t-&gt;get_dimension(1) 10
-
-</pre></blockquote>
-The <tt>DataType</tt> class contains a variety of other methods for managing typedefs, scoping, and other operations. These are usually only used by the SWIG parser. While available to language modules too, they are never used (at least not in the current implementation), and should probably be avoided unless you absolutely know what you're doing (not that this is a strict requirement of course).<p>
-<a name="n22"></a><h3> Function Parameters</h3>
-Each argument of a function call is represented using the <tt>Parm</tt> structure :<p>
-<p>
-<blockquote><pre>struct Parm {
- Parm(DataType *type, char *name);
- Parm(Parm *p);
- ~Parm();
- DataType *t; // Datatype of this parameter
- int call_type; // Call type (value or reference or value)
- char *name; // Name of parameter (optional)
- char *defvalue; // Default value (as a string)
- int ignore; // Ignore flag
-};
-
-</pre></blockquote>
-<tt>t</tt> is the datatype of the parameter, <tt>name</tt> is an optional parameter name, and <tt>defvalue</tt> is a default argument value (if supplied). <p>
-<p>
-<tt>call_type</tt> is an integer code describing any special processing. It can be one of two values :<p>
-<p>
-<ul>
-<li><tt>CALL_VALUE</tt>. This means that the argument is a pointer, but we should make it work like a call-by-value argument in the scripting interface. This value used to be set by the <tt>%val</tt> directive, but this approach is now deprecated (since the same effect can be achieved by typemaps).
-<li><tt>CALL_REFERENCE</tt>. This is set when a complex datatype is being passed by value to a function. Since SWIG can't handle complex datatypes by value, the datatype is implicitly changed into a pointer and<tt> call_type</tt> set to <tt>CALL_REFERENCE</tt>. Many of SWIG's internals look at this when generating code. A common mistake is forgetting that all complex datatypes in SWIG are pointers. This is even the case when writing a language-module---the conversion to pointers takes place in the parser before data is even passed into a particular module.
-</ul>
-<p>
-The <tt>ignore</tt> field is set when SWIG detects that a function parameter is to be "ignored" when generating wrapper functions. An "ignored" parameter is usually set to a default value and effectively disappears when a function call is made from a scripting language (that is, the function is called with fewer arguments than are specified in the interface file). The <tt>ignore</tt> field is normally only set when an "ignore" typemap has been used.<p>
-<p>
-All of the function parameters are passed in the structure <tt>ParmList</tt>. This structure has the following user-accesible methods available :<p>
-<p>
-<blockquote><pre>class ParmList {
-public:
- int nparms; // Number of parms in list
- void append(Parm *p); // Append a parameter to the end
- void insert(Parm *p, int pos); // Insert a parameter into the list
- void del(int pos); // Delete a parameter at position pos
- int numopt(); // Get number of optional arguments
- int numarg(); // Get number of active arguments
- Parm *get(int pos); // Get the parameter at position pos
-};
-
-</pre></blockquote>
-The methods operate in the manner that you would expect. The most common operation that will be performed in a language module is walking down the parameter list and processing individual parameters. This can be done as follows :<p>
-<p>
-<blockquote><pre>// Walk down a parameter list
-ParmList *l; // Function parameter list (already created)
-Parm *p;
-
-for (int i = 0; i &lt; l-&gt;nparms; i++) {
- p = l-&gt;get(i); // Get ith parameter
- // do something with the parameter
- ...
-}
-
-</pre></blockquote>
-<a name="n23"></a><h3> The String Class</h3>
-The process of writing wrapper functions is mainly just a tedious exercise in string manipulation. To make this easier, the <tt>String</tt> class provides relatively simple mechanism for constructing strings, concatenating values, replacing symbols, and so on. <p>
-<p>
-<blockquote><pre>class String {
-public:
- String();
- String(const char *s);
- ~String();
- char *get() const;
- friend String&amp; operator&lt;&lt;(String&amp;,const char *s);
- friend String&amp; operator&lt;&lt;(String&amp;,const int);
- friend String&amp; operator&lt;&lt;(String&amp;,const char);
- friend String&amp; operator&lt;&lt;(String&amp;,String&amp;);
- friend String&amp; operator&gt;&gt;(const char *s, String&amp;);
- friend String&amp; operator&gt;&gt;(String&amp;,String&amp;);
- String&amp; operator=(const char *);
- operator char*() const { return str; }
- void untabify();
- void replace(char *token, char *rep);
- void replaceid(char *id, char *rep);
-};
-</pre></blockquote>
-<p>
-Strings can be manipulated in a manner that looks similar to C++ I/O operations. For example :<p>
-<p>
-<blockquote><pre>String s;
-
-s &lt;&lt; "void" &lt;&lt; " foo() {\n"
- &lt;&lt; tab4 &lt;&lt; "printf(\"Hello World\");\n"
- &lt;&lt; "}\n";
-
-fprintf(f_wrappers,"%s", (char *) s);
-
-</pre></blockquote>
-produces the output :<p>
-<p>
-<blockquote><pre>void foo() {
- printf("Hello World");
-}
-
-</pre></blockquote>
-The <tt>&lt;&lt;</tt> operator always appends to the end of a string while <tt>&gt;&gt;</tt> can be used to insert a string at the beginning. Strings may be used anywhere a <tt>char *</tt> is expected. For example :<p>
-<p>
-<blockquote><pre>String s1,s2;
-...
-if (strcmp(s1,s2) == 0) {
- printf("Equal!\n");
-}
-
-</pre></blockquote>
-The <tt>get()</tt> method can be used to explicitly return the <tt>char *</tt> containing the string data. The <tt>untabify()</tt> method replaces tabs with whitespace. The <tt>replace()</tt> method can be used to perform substring replacement and is used by typemaps. For example :<p>
-<p>
-<blockquote><pre>s.replace("$target","_arg3");
-
-</pre></blockquote>
-The <tt>replaceid()</tt> method can be used to replace valid C identifiers with a new value. C identifiers must be surrounded by white-space or other non-identifier characters. The <tt>replace()</tt> method does not have this restriction.<p>
-<a name="n24"></a><h3> Hash Tables</h3>
-Hash tables can be created using the <tt>Hash</tt> class :<p>
-<p>
-<blockquote><pre>class Hash {
-public:
- Hash();
- ~Hash();
- int add(const char *key, void *object);
- int add(const char *key, void *object, void (*del)(void *));
- void *lookup(const char *key);
- void remove(const char *key);
- void *first();
- void *next();
- char *firstkey();
- char *nextkey();
-};
-
-</pre></blockquote>
-Hash tables store arbitrary objects (cast to <tt>void *</tt>) with string keys. An optional object deletion function may be registered with each entry to delete objects when the hash is destroyed. Hash tables are primarily used for managing internal symbol tables although language modules may also use them to keep track of special symbols and other state.<p>
-<p>
-The following hash table shows how one might keep track of real and renamed function names.<p>
-<p>
-<blockquote><pre>Hash wrapped_functions;
-
-int add_function(char *name, char *renamed) {
- char *nn = new char[strlen(renamed)+1];
- strcpy(nn,renamed);
- if (wrapped_functions.add(name,nn) == -1) {
- printf("Function multiply defined!\n");
- delete [] nn;
- return -1;
- }
-}
-char *get_renamed(char *name) {
- char *rn = (char *) wrapped_functions.lookup(name);
- return rn;
-}
-
-</pre></blockquote>
-The <tt>remove()</tt> method removes a hash-table entry. The <tt>first()</tt> and <tt>next()</tt> methods are iterators for extracting all of the hashed objects. They return NULL when no more objects are found in the hash. The <tt>firstkey()</tt> and <tt>nextkey() </tt>methods are iterators that return the hash keys. NULL is returned when no more keys are found.<p>
-<a name="n25"></a><h3> The WrapperFunction class</h3>
-Finally, a <tt>WrapperFunction</tt> class is available for simplifying the creation of wrapper functions. The class is primarily designed to organize code generation and provide a few supporting services. The class is defined as follows :<p>
-<p>
-<blockquote><pre>class WrapperFunction {
-public:
- String def;
- String locals;
- String code;
- void print(FILE *f);
- void print(String &amp;f);
- void add_local(char *type, char *name, char *defvalue = 0);
- char *new_local(char *type, char *name, char *defvalue = 0);
-};
-
-</pre></blockquote>
-Three strings are available. The <tt>def</tt> string contains the actual function declaration, the <tt>locals</tt> string contain local variable declarations, and the <tt>code</tt> string contains the resulting wrapper code.<p>
-<p>
-The method <tt>add_local()</tt> creates a new local variable which is managed with an internal symbol table (that detects variable conflicts and reports potential errors). The <tt>new_local()</tt> method can be used to create a new local variable that is guaranteed to be unique. Since a renaming might be required, this latter method returns the name of the variable that was actually selected for use (typically, this is derived from the original name).<p>
-<p>
-The <tt>print()</tt> method can be used to emit the wrapper function to a file. The printing process consolidates all of the strings into a single result.<p>
-<p>
-Here is a very simple example of the wrapper function class :<p>
-<p>
-<blockquote><pre>WrapperFunction f;
-
-f.def &lt;&lt; "void count_n(int n) {";
-f.add_local("int","i");
-f.code &lt;&lt; tab4 &lt;&lt; "for (i = 0; i &lt; n; i++) {\n"
- &lt;&lt; tab8 &lt;&lt; "printf(\"%d\\n\",i);\n"
- &lt;&lt; tab4 &lt;&lt; "}\n"
- &lt;&lt; "}\n";
-
-f.print(f_wrappers);
-
-</pre></blockquote>
-This produces the following output :<p>
-<p>
-<blockquote><pre>void count_n(int n) {
- int i;
- for (i = 0; i &lt; n; i++) {
- printf("%d\n",i);
- }
-}
-
-</pre></blockquote>
-Of course, as you can guess, the functions actually generated by your language module will be more complicated than this.<p>
-<a name="n6"></a><h2> Typemaps (from C)</h2>
-The typemapper plays a big role in generating code for all of SWIG's modules. Understanding the <tt>%typemap</tt> directive and how it works is probably a good starting point for understanding this section.<p>
-<a name="n26"></a><h3> The typemap C API.</h3>
- There is a relatively simple C API for managing typemaps in language modules.<p>
-<p>
-<h6> <b>void typemap_register(char *op, char *lang, DataType *type, char *pname,</b> <b> char *code, ParmList *l = 0);</b></h6>
-<dl>
-<dt><dd>
-<dt><dd>Registers a new typemap with the typemapper. This is the C equivalent of the <tt>%typemap </tt>directive. For example :
-<dt><dd>
-<blockquote><pre> %typemap(lang,op) type pname { ... code ... };
- %typemap(lang,op) type pname(ParmList) { ... code ... };
-
-</pre></blockquote>
-<dt><dd><tt>code</tt> contains the actual typemap code, while <tt>l</tt> is a parameter list containing local variable declarations. Normally, it is not necessary to execute this function from language modules.
-<dt><dd>
-</dl>
-<h6> void typemap_register_default(char *op, char *lang, int type, int ptr, char *arraystr, char *code, ParmList *args)</h6>
-<dl>
-<dt><dd>
-<dt><dd>Registers a default typemap. This works in the same way as the normal registration function, but takes a type code (an integer) instead. Default typemaps are more general than normal typemaps (see below).
-<dt><dd>
-</dl>
-<h6> char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *source, char *target, WrapperFunction *f = 0);</h6>
-<dl>
-<dt><dd>
-<dt><dd>Looks up a typemap, performs variable substitutions, and returns a string with the corresponding typemap code. The tuple <tt>(op, lang, type, pname)</tt> determine which typemap to find. <tt>source</tt> contains the string to be assigned to the <tt>$source</tt> variable, <tt>target</tt> contains the string to be assigned to the<tt> $target</tt> variable. <tt>f</tt> is an optional wrapper function object. It should be supplied to support parameterized typemaps (ie. typemaps that declare additional local variables).
-<dt><dd>
-<dt><dd><tt>typemap_lookup()</tt> returns NULL is no typemap is found. Otherwise it returns a string containing the updated typemap code. This code has a number of variables substituted including <tt>$source</tt>, <tt>$target</tt>, <tt>$type</tt>, <tt>$mangle</tt>, and <tt>$basetype</tt>.
-<dt><dd>
-</dl>
-<h6> char *typemap_check(char *op, char *lang, DataType *type, char *pname)</h6>
-<p>
-<dl>
-<dt><dd>Checks to see if a typemap exists. The tuple <tt>(op, lang, type, pname)</tt> determine which typemap to find. If the typemap exists, the raw typemap code is returned. Otherwise, NULL is returned. While <tt>typemap_lookup()</tt> could be used to accomplish the same thing, this function is more compact and is significantly faster since it does not perform any variable substitutions.
-<dt><dd>
-</dl>
-<a name="n27"></a><h3> What happens on typemap lookup?</h3>
-When looking for a typemap, SWIG searches for a match in a series of steps.<p>
-<p>
-<ul>
-<li>Explicit typemaps. These are specified directly with the <tt>%typemap()</tt> directive. Named typemaps have the highest precedence while arrays have higher precedence than pointers (see the typemap chapter for more details).
-<li>If no explicit typemap is found, mappings applied with the <tt>%apply </tt>directive are checked. Basically, <tt>%apply </tt>is nothing more than a glorified renaming operation. We rename the datatype and see if there are any explicit typemaps that match. If so, we use the typemap that was found.
-<li>Default typemaps. If no match is found with either explicit typemaps or apply directives, we make a final search using the default typemap. Unlike other typemaps, default typemaps are applied to the raw SWIG internal datatypes (<tt>T_INT</tt>, <tt>T_DOUBLE</tt>, <tt>T_CHAR</tt>, etc...). As a result, they are insentive to typedefs and renaming operations. If nothing is found here, a NULL pointer is returned indicating that no mapping was found for that particular datatype.
-</ul>
-<p>
-Another way to think of the typemap mechanism is that it always tries to apply the most specific typemap that can be found for any particular datatype. When searching, it starts with the most specific and works its way out to the most general specification. If nothing is found it gives up and returns a NULL pointer.<p>
-<a name="n28"></a><h3> How many typemaps are there?</h3>
-All typemaps are identified by an operation string such as "in", "out", "memberin", etc... A number of typemaps are defined by other parts of SWIG, but you can create any sort of typemap that you wish by simply picking a new name and using it when making calls to <tt>typemap_lookup()</tt> and <tt>typemap_check()</tt>. <p>
-<a name="n7"></a><h2> File management</h2>
-The following functions are provided for managing files within SWIG. <p>
-<p>
-<h6> void add_directory(char *dirname);</h6>
-<dl>
-<dt><dd>
-<dt><dd>Adds a new directory to the search path used to locate SWIG library files. This is the C equivalent of the <tt>swig</tt> <tt>-I</tt> option.
-<dt><dd>
-</dl>
-<h6> int insert_file(char *filename, FILE *output);</h6>
-<dl>
-<dt><dd>
-<dt><dd>Searches for a file and copies it into the given output stream. The search process goes through the SWIG library mechanism which first checks the current directory, then in various parts of the SWIG library for a match. Returns -1 if the file is not found. Language modules often use this function to insert supporting code. Usually these code fragments are given a `<tt>.swg</tt>' suffix and are placed in the SWIG library.
-<dt><dd>
-</dl>
-<h6> int get_file(char *filename, String &amp;str);</h6>
-<dl>
-<dt><dd>
-<dt><dd> Searches for a file and returns its contents in the String <tt>str.</tt>Returns a -1 if the file is not found.
-</dl>
-<p>
-<h6> int checkout_file(char *source, char *dest);</h6>
-<dl>
-<dt><dd>
-<dt><dd>Copies a file from the SWIG library into the current directory. <tt>dest </tt>is the filename of the desired file. This function will not replace a file that already exists. The primary use of this function is to give the user supporting code. For example, we could check out a Makefile if none exists. Returns -1 on failure.
-<dt><dd>
-</dl>
-<h6> int include_file(char *filename);</h6>
-<dl>
-<dt><dd>
-<dt><dd>The C equivalent of the SWIG <tt>%include</tt> directive. When called, SWIG will attempt to open <tt>filename</tt> and start parsing all of its contents. If successful, parsing of the new file will take place immediately. When the end of the file is reached, the parser switches back to the input file being read prior to this call. Returns -1 if the file is not found.
-</dl>
-<a name="n8"></a><h2> Naming Services</h2>
-The naming module provides methods for generating the names of wrapper functions, accessor functions, and other aspects of SWIG. Each function returns a new name that is a syntactically correct C identifier where invalid characters have been converted to a "_". <p>
-<p>
-<h6> char *name_wrapper(char *fname, char *prefix);</h6>
-<dl>
-<dt><dd>Returns the name of a wrapper function. By default, it will be "<tt>_wrap_prefixfname</tt>".
-<dt><dd>
-</dl>
-<h6> char *name_member(char *mname, char *classname;</h6>
-<dl>
-<dt><dd>Returns the name of a C++ accessor function. Normally, this is "<tt>classname_mname</tt>".
-<dt><dd>
-</dl>
-<h6> char *name_get(char *vname);</h6>
-<dl>
-<dt><dd>Returns the name of a function to get the value of a variable or class data member. Normally "<tt>vname_get</tt>" is returned.
-<dt><dd>
-</dl>
-<h6> char *name_set(char *vname);</h6>
-<dl>
-<dt><dd>Returns the name of a function to set the value of a variable or class data member. Normally, "<tt>vname_set</tt>" is returned.
-<dt><dd>
-</dl>
-<h6> char *name_construct(char *classname);</h6>
-<dl>
-<dt><dd>Returns the name of a constructor function. Normally returns "<tt>new_classname</tt>".
-<dt><dd>
-</dl>
-<h6> char *name_destroy(char *classname);</h6>
-<dl>
-<dt><dd>Returns the name of a destructor function. Normally returns "<tt>delete_classname</tt>".
-<dt><dd>
-</dl>
-Each function may also accept an optional parameter of <tt>AS_IS</tt>. This suppresses the conversion of illegal characters (a process that is sometimes required). For example :<p>
-<p>
-<blockquote><pre>char *name = name_member("foo","bar",AS_IS); // Produce a name, but don't change
- // illegal characters.
-
-</pre></blockquote>
-It is critical that language modules use the naming functions. These function are used throughout SWIG and provide a centralized mechanism for keeping track of functions that have been generated, managing multiple files, and so forth. In future releases, it may be possible to change the naming scheme used by SWIG. Using these functions should insure future compatibility.<p>
-<a name="n9"></a><h2> Code Generation Functions</h2>
-The following functions are used to emit code that is generally useful and used in essentially every SWIG language module.<p>
-<p>
-<h6> int emit_args(DataType *t, ParmList *l, WrapperFunction &amp;f);</h6>
-<dl>
-<dt><dd>Creates all of the local variables used for function arguments and return value. <tt>t</tt> is the return datatype of the function, <tt>l</tt> is the parameter list holding all of the function arguments. <tt>f</tt> is a WrapperFunction object where the local variables will be created.
-<dt><dd>
-</dl>
-<h6> void emit_func_call(char *name, DataType *t, ParmList *l, WrapperFunction &amp;f);</h6>
-<dl>
-<dt><dd>Creates a function call to a C function. <tt>name</tt> is the name of the C function, <tt>t</tt> is the return datatype, <tt>l</tt> is the function parameters and <tt>f</tt> is a WrapperFunction object. The code generated by this function assumes that one has first called <tt>emit_args()</tt>.
-<dt><dd>
-</dl>
-<h6> void emit_banner(FILE *file);</h6>
-<dl>
-<dt><dd>Emits the SWIG banner comment to the output file.
-</dl>
-<p>
-<h6> void emit_set_get(char *name, char *rename, DataType *t);</h6>
-<dl>
-<dt><dd>Given a variable of type <tt>t</tt>, this function creates two functions to set and get the value. These functions are then wrapped like normal C functions. <tt>name</tt> is the real name of the variable. <tt>rename</tt> is the renamed version of the variable.
-<dt><dd>
-</dl>
-<h6> void emit_ptr_equivalence(FILE *file);</h6>
-<dl>
-<dt><dd>To keep track of datatypes, SWIG maintains an internal table of "equivalent" datatypes. This table is updated by typedef, class definitions, and other C constructs. This function emits code compatible with the type-checker that is needed to make sure pointers work correctly. Typically this function is called after an interface file has been parsed completely.
-</dl>
-<a name="n10"></a><h2> Writing a Real Language Module</h2>
-Whew, assuming you've made it this far, we're ready to write a real language module. In this example, we'll develop a simple Tcl module. Tcl has been chosen because it has a relatively simple C API that is well documented and easy to understand. The module developed here is not the same as the real SWIG Tcl module (which is significantly more complicated). <p>
-<a name="n29"></a><h3> The header file</h3>
-We will start with the same header file as before :<p>
-<p>
-<blockquote><pre>// File : mylang.h
-// A simple SWIG Language module
-
-class MYLANG : public Language {
-private:
- char *module;
-public :
- MYLANG() {
- module = 0;
- };
- // Virtual functions required by the SWIG parser
- void parse_args(int, char *argv[]);
- void parse();
- void create_function(char *, char *, DataType *, ParmList *);
- void link_variable(char *, char *, DataType *);
- void declare_const(char *, char *, DataType *, char *);
- void initialize(void);
- void headers(void);
- void close(void);
- void set_module(char *,char **);
- void create_command(char *, char *);
-};
-
-</pre></blockquote>
-<a name="n30"></a><h3> Command Line Options and Basic Initialization</h3>
-Command line options are parsed using the <tt>parse_args()</tt> method :<p>
-<blockquote><pre>
-// ------------------------------------------------------------------------
-// A simple SWIG Language module
-//
-// ------------------------------------------------------------------------
-
-#include "swig.h"
-#include "mylang.h"
-
-static char *usage = "\
-My Language Options\n\
- -module name - Set name of module\n\n";
-
-// ---------------------------------------------------------------------
-// MYLANG::parse_args(int argc, char *argv[])
-//
-// Parse my command line options and initialize by variables.
-// ---------------------------------------------------------------------
-
-void MYLANG::parse_args(int argc, char *argv[]) {
- // Look for certain command line options
- for (int i = 1; i &lt; argc; i++) {
- if (argv[i]) {
- if (strcmp(argv[i],"-module") == 0) {
- if (argv[i+1]) {
- set_module(argv[i+1],0);
- mark_arg(i);
- mark_arg(i+1);
- i++;
- } else {
- arg_error();
- }
- } else if (strcmp(argv[i],"-help") == 0) {
- fprintf(stderr,"%s\n", usage);
- }
- }
- }
- // Set location of SWIG library
- strcpy(LibDir,"tcl");
-
- // Add a symbol to the parser for conditional compilation
- add_symbol("SWIGTCL",0,0);
-
- // Add typemap definitions
- typemap_lang = "tcl";
-}
-
-</pre></blockquote>
-Parsing command line options follows the same conventions as for writing a C++ main program with one caveat. For each option that your language module parses, you need to call the function <tt>mark_arg()</tt>. This tells the SWIG main program that your module found a valid option and used it. If you don't do this, SWIG will exit with an error message about unrecognized command line options.<p>
-<p>
-After processing command line options, you next need to set the variable <tt>LibDir</tt> with the name of the subdirectory your language will use to find files in the SWIG library. Since we are making a new Tcl module, we'll just set this to "<tt>tcl</tt>".<p>
-<p>
-Next, we may want to add a symbol to SWIG's symbol table. In this case we're adding "<tt>SWIGTCL</tt>" to indicate that we're using Tcl. SWIG modules can use this for conditional compilation and detecting your module using <tt>#ifdef</tt>. <p>
-<p>
-Finally, we need to set the variable <tt>typemap_lang</tt>. This should be assigned a name that you would like to use for all typemap declarations. When a user gives a typemap, they would use this name as the target language.<p>
-<a name="n31"></a><h3> Starting the parser</h3>
-To start the SWIG parser, the <tt>parse()</tt> method is used :<p>
-<p>
-<blockquote><pre>// ---------------------------------------------------------------------
-// void MYLANG::parse()
-//
-// Start parsing an interface file for MYLANG.
-// ---------------------------------------------------------------------
-
-void MYLANG::parse() {
-
- fprintf(stderr,"Making wrappers for Tcl\n");
- headers(); // Emit header files and other supporting code
-
- // Tell the parser to first include a typemap definition file
-
- if (include_file("lang.map") == -1) {
- fprintf(stderr,"Unable to find lang.map!\n");
- SWIG_exit(1);
- }
- yyparse(); // Run the SWIG parser
-}
-</pre></blockquote>
-<p>
-This function should print some kind of message to the user indicating what language is being targeted. The <tt>headers()</tt> method is called (see below) to emit support code and header files. Finally, we make a call to <tt>yyparse()</tt>. This starts the SWIG parser and does not return until the entire interface file has been read. <p>
-<p>
-In our implementation, we have also added code to immediately include a file `<tt>lang.map</tt>'. This file will contain typemap definitions to be used by our module and is described in detail later. <p>
-<a name="n32"></a><h3> Emitting headers and support code</h3>
-Prior to emitting any code, our module should emit standard header files and support code. This is done using the <tt>headers()</tt> method :<p>
-<blockquote><pre>// ---------------------------------------------------------------------
-// MYLANG::headers(void)
-//
-// Generate the appropriate header files for MYLANG interface.
-// ----------------------------------------------------------------------
-
-void MYLANG::headers(void)
-{
- emit_banner(f_header); // Print the SWIG banner message
- fprintf(f_header,"/* Implementation : My TCL */\n\n");
-
- // Include header file code fragment into the output
- if (insert_file("header.swg",f_header) == -1) {
- fprintf(stderr,"Fatal Error. Unable to locate 'header.swg'.\n");
- SWIG_exit(1);
- }
-
- // Emit the default SWIG pointer type-checker (for strings)
- if (insert_file("swigptr.swg",f_header) == -1) {
- fprintf(stderr,"Fatal Error. Unable to locate 'swigptr.swg'.\n");
- SWIG_exit(1);
- }
-}
-</pre></blockquote>
-In this implementation, we emit the standard SWIG banner followed by a comment indicating which language module is being used. After that, we are going to include two different files. `<tt>header.swg'</tt> is a file containing standard declarations needed to build a Tcl extension. For our example, it will look like this :<p>
-<p>
-<blockquote><pre>/* File : header.swg */
-#include &lt;tcl.h&gt;
-
-</pre></blockquote>
-The file `<tt>swigptr.swg'</tt> contains the standard SWIG pointer-type checking library. This library contains about 300 lines of rather nasty looking support code that define the following 3 functions :<p>
-<p>
-<h6> void SWIG_RegisterMapping(char *type1, char *type, void *(*cast)(void *))</h6>
-<dl>
-<dt><dd>Creates a mapping between C datatypes <tt>type1</tt> and <tt>type2</tt>. This is registered with the runtime type-checker and is similiar to a typedef. <tt>cast</tt> is an optional function pointer defining a method for proper pointer conversion (if needed). Normally, cast is only used when converting between base and derived classes in C++ and is needed for proper implementation of multiple inheritance.
-</dl>
-<p>
-<h6> void SWIG_MakePtr(char *str, void *ptr, char *type);</h6>
-<dl>
-<dt><dd>Makes a string representation of a C pointer. The result is stored in <tt>str</tt> which is assumed to be large enough to hold the result. <tt>ptr</tt> contains the pointer value and <tt>type</tt> is a string code corresponding to the datatype.
-<dt><dd>
-</dl>
-<h6> char *SWIG_GetPtr(char *str, void **ptr, char *type);</h6>
-<dl>
-<dt><dd>Extracts a pointer from its string representation, performs type-checking, and casting. <tt>str</tt> is the string containing the pointer-value representation, <tt>ptr</tt> is the address of the pointer that will be returned, and <tt>type </tt>is the string code corresponding to the datatype. If a type-error occurs, the function returns a <tt>char *</tt> corresponding to the part of the input string that was invalid, otherwise the function returns NULL. If a NULL pointer is given for <tt>type</tt>, the function will accept a pointer of any type.
-</dl>
-<p>
-We will use these functions later.<p>
-<a name="n33"></a><h3> Setting a module name</h3>
-The <tt>set_module()</tt> method is used whenever the <tt>%module</tt> directive is encountered.<p>
-<blockquote><pre>
-// ---------------------------------------------------------------------
-// MYLANG::set_module(char *mod_name,char **mod_list)
-//
-// Sets the module name. Does nothing if it's already set (so it can
-// be overriddent as a command line option).
-//
-// mod_list is a NULL-terminated list of additional modules to initialize
-// and is only provided if the user specifies something like this :
-// %module foo, mod1, mod2, mod3, mod4
-//----------------------------------------------------------------------
-
-void MYLANG::set_module(char *mod_name, char **mod_list) {
- if (module) return;
- module = new char[strlen(mod_name)+1];
- strcpy(module,mod_name);
- // Make sure the name conforms to Tcl naming conventions
- for (char *c = module; (*c); c++)
- *c = tolower(*c);
- toupper(module);
-}
-
-
-</pre></blockquote>
-This function may, in fact, be called multiple times in the course of processing. Normally, we only allow a module name to be set once and ignore all subsequent calls however.<p>
-<a name="n34"></a><h3> Final Initialization</h3>
-The initialization of a module takes several steps--parsing command line options, printing standard header files, starting the parser, and setting the module name. The final step in initialization is calling the <tt>initialize()</tt> method :<p>
-<p>
-<blockquote><pre>// --------------------------------------------------------------------
-// MYLANG::initialize(void)
-//
-// Produces an initialization function. Assumes that the module
-// name has already been specified.
-// ---------------------------------------------------------------------
-
-void MYLANG::initialize()
-{
- // Check if a module has been defined
- if (!module) {
- fprintf(stderr,"Warning. No module name given!\n");
- module = "swig";
- }
-
- // Generate a CPP symbol containing the name of the initialization function
- fprintf(f_header,"#define SWIG_init %s_Init\n\n\n", module);
-
- // Start generating the initialization function
- fprintf(f_init,"int SWIG_init(Tcl_Interp *interp) {\n");
- fprintf(f_init,"\t if (interp == 0) return TCL_ERROR;\n");
-}
-
-</pre></blockquote>
-The <tt>initialize()</tt> method should create the module initialization function by emitting code to <tt>f_init</tt> as shown. By this point, we should already know the name of the module, but should check just in case. The preferred style of creating the initialization function is to create a C preprocessor symbol <tt>SWIG_init</tt>. Doing so may look weird, but it turns out that many SWIG library files may want to know the name of the initialization function. If we define a symbol for it, these files can simply assume that it's called <tt>SWIG_init()</tt> and everything will work out (okay, so it's a hack).<p>
-<a name="n35"></a><h3> Cleanup </h3>
-When an interface file has finished parsing, we need to clean everything up. This is done using the <tt>close()</tt> method :<p>
-<p>
-<blockquote><pre>// ---------------------------------------------------------------------
-// MYLANG::close(void)
-//
-// Wrap things up. Close initialization function.
-// ---------------------------------------------------------------------
-
-void MYLANG::close(void)
-{
- // Dump the pointer equivalency table
- emit_ptr_equivalence(f_init);
-
- // Finish off our init function and print it to the init file
- fprintf(f_init,"\t return TCL_OK;\n");
- fprintf(f_init,"}\n");
-}
-
-</pre></blockquote>
-The <tt>close()</tt> method should first call <tt>emit_ptr_equivalence()</tt> if the SWIG pointer type checker has been used. This dumps out support code to make sure the type-checker works correctly. Afterwards, we simply need to terminate our initialization function as shown. After this function has been called, SWIG dumps out all of its documentation files and exits.<p>
-<a name="n36"></a><h3> Creating Commands</h3>
-Now, we're moving into the code generation part of SWIG. The first step is to make a function to create scripting language commands. This is done using the <tt>create_command()</tt> function :<p>
-<p>
-<blockquote><pre>// ----------------------------------------------------------------------
-// MYLANG::create_command(char *cname, char *iname)
-//
-// Creates a Tcl command from a C function.
-// ----------------------------------------------------------------------
-void MYLANG::create_command(char *cname, char *iname) {
- // Create a name for the wrapper function
- char *wname = name_wrapper(cname,"");
-
- // Create a Tcl command
- fprintf(f_init,"\t Tcl_CreateCommand(interp,\"%s\",%s, (ClientData) NULL,
- (Tcl_CmdDeleteProc *) NULL);\n", iname, wname);
-}
-</pre></blockquote>
-<p>
-For our Tcl module, this just calls Tcl_CreateCommand to make a new scripting language command. <p>
-<a name="n37"></a><h3> Creating a Wrapper Function</h3>
-The most complicated part of writing a language module is the process of creating wrapper functions. This is done using the <tt>create_function()</tt> method as shown here :<p>
-<blockquote><pre>
-// ----------------------------------------------------------------------
-// MYLANG::create_function(char *name, char *iname, DataType *d, ParmList *l)
-//
-// Create a function declaration and register it with the interpreter.
-// ----------------------------------------------------------------------
-
-void MYLANG::create_function(char *name, char *iname, DataType *t, ParmList *l)
-{
- String source, target;
- char *tm;
- String cleanup, outarg;
- WrapperFunction f;
-
- // Make a wrapper name for this function
- char *wname = name_wrapper(iname,"");
-
- // Now write the wrapper function itself
- f.def &lt;&lt; "static int " &lt;&lt; wname &lt;&lt; "(ClientData clientData, Tcl_Interp *interp, int
-argc, char *argv[]) {\n";
-
- // Emit all of the local variables for holding arguments.
- int pcount = emit_args(t,l,f);
-
- // Get number of optional/default arguments
- int numopt = l-&gt;numopt();
-
- // Emit count to check the number of arguments
- f.code &lt;&lt; tab4 &lt;&lt; "if ((argc &lt; " &lt;&lt; (pcount-numopt) + 1 &lt;&lt; ") || (argc &gt; "
- &lt;&lt; l-&gt;numarg()+1 &lt;&lt; ")) {\n"
- &lt;&lt; tab8 &lt;&lt; "Tcl_SetResult(interp, \"Wrong # args.\",TCL_STATIC);\n"
- &lt;&lt; tab8 &lt;&lt; "return TCL_ERROR;\n"
- &lt;&lt; tab4 &lt;&lt; "}\n";
-
- // Now walk the function parameter list and generate code to get arguments
- int j = 0; // Total number of non-optional arguments
-
- for (int i = 0; i &lt; pcount ; i++) {
- Parm &amp;p = (*l)[i]; // Get the ith argument
- source = "";
- target = "";
-
- // Produce string representation of source and target arguments
- source &lt;&lt; "argv[" &lt;&lt; j+1 &lt;&lt; "]";
- target &lt;&lt; "_arg" &lt;&lt; i;
- if (!p.ignore) {
- if (j &gt;= (pcount-numopt)) // Check if parsing an optional argument
- f.code &lt;&lt; tab4 &lt;&lt; "if argc &gt;" &lt;&lt; j+1 &lt;&lt; ") {\n";
-
- // Get typemap for this argument
- tm = typemap_lookup("in",typemap_lang,p.t,p.name,source,target,&amp;f);
- if (tm) {
- f.code &lt;&lt; tm &lt;&lt; "\n";
- f.code.replace("$arg",source); // Perform a variable replacement
- } else {
- fprintf(stderr,"%s : Line %d. No typemapping for datatype %s\n",
- input_file,line_number, p.t-&gt;print_type());
- }
- if (j &gt;= (pcount-numopt))
- f.code &lt;&lt; tab4 &lt;&lt; "} \n";
- j++;
- }
-
- // Check to see if there was any sort of a constaint typemap
- if ((tm = typemap_lookup("check",typemap_lang,p.t,p.name,source,target))) {
- f.code &lt;&lt; tm &lt;&lt; "\n";
- f.code.replace("$arg",source);
- }
-
- // Check if there was any cleanup code (save it for later)
- if ((tm = typemap_lookup("freearg",typemap_lang,p.t,p.name,target,
- "interp-&gt;result"))) {
- cleanup &lt;&lt; tm &lt;&lt; "\n";
- cleanup.replace("$arg",source);
- }
- if ((tm = typemap_lookup("argout",typemap_lang,p.t,p.name,target,
- "interp-&gt;result"))) {
- outarg &lt;&lt; tm &lt;&lt; "\n";
- outarg.replace("$arg",source);
- }
- }
-
- // Now write code to make the function call
- emit_func_call(name,t,l,f);
-
- // Return value if necessary
- if ((t-&gt;type != T_VOID) || (t-&gt;is_pointer)) {
- if ((tm = typemap_lookup("out",typemap_lang,t,name,"_result","interp-&gt;result"))) {
- // Yep. Use it instead of the default
- f.code &lt;&lt; tm &lt;&lt; "\n";
- } else {
- fprintf(stderr,"%s : Line %d. No return typemap for datatype %s\n",
- input_file,line_number,t-&gt;print_type());
- }
- }
-
- // Dump argument output code;
- f.code &lt;&lt; outarg;
-
- // Dump the argument cleanup code
- f.code &lt;&lt; cleanup;
-
- // Look for any remaining cleanup. This processes the %new directive
- if (NewObject) {
- if ((tm = typemap_lookup("newfree",typemap_lang,t,iname,"_result",""))) {
- f.code &lt;&lt; tm &lt;&lt; "\n";
- }
- }
-
- // Special processing on return value.
- if ((tm = typemap_lookup("ret",typemap_lang,t,name,"_result",""))) {
- f.code &lt;&lt; tm &lt;&lt; "\n";
- }
-
- // Wrap things up (in a manner of speaking)
- f.code &lt;&lt; tab4 &lt;&lt; "return TCL_OK;\n}";
-
- // Substitute the cleanup code (some exception handlers like to have this)
- f.code.replace("$cleanup",cleanup);
-
- // Emit the function
- f.print(f_wrappers);
-
- // Now register the function with the language
- create_command(iname,iname);
-}
-</pre></blockquote>
-<p>
-Creating a wrapper function really boils down to 3 components :<p>
-<p>
-<ul>
-<li>Emit local variables and handling input arguments.
-<li>Call the real C function.
-<li>Convert the return value to a scripting language representation.
-</ul>
-<p>
-In our implementation, most of this work is done using typemaps. In fact, the role of the C++ code is really just to process typemaps in the appropriate order and to combine strings in the correct manner. The following typemaps are used in this procedure :<p>
-<p>
-<ul>
-<li>"in". This is used to convert function arguments from Tcl to C.
-<li>"out". This is used to convert the return value from C to Tcl.
-<li>"check". This is used to apply constraints to the input values.
-<li>"argout". Used to return values through function parameters.
-<li>"freearg". Used to clean up arguments after a function call (possibly to release memory, etc...)
-<li>"ret". Used to clean up the return value of a C function (possibly to release memory).
-<li>"newfree" this is special processing applied when the <tt>%new</tt> directive has been used. Usually its used to clean up memory.
-</ul>
-<p>
-It may take awhile for this function to sink in, but its operation will hopefully become more clear shortly. <p>
-<a name="n38"></a><h3> Manipulating Global Variables</h3>
-To provide access to C global variables, the <tt>link_variable()</tt> method is used. In the case of Tcl, only <tt>int</tt>, <tt>double</tt>, and <tt>char * </tt>datatypes can be safely linked.<p>
-<p>
-<blockquote><pre>// -----------------------------------------------------------------------
-// MYLANG::link_variable(char *name, char *iname, DataType *t)
-//
-// Create a Tcl link to a C variable.
-// -----------------------------------------------------------------------
-
-void MYLANG::link_variable(char *name, char *iname, DataType *t) {
- char *tm;
-
- // Uses a typemap to stick code into the module initialization function
- if ((tm = typemap_lookup("varinit",typemap_lang,t,name,name,iname))) {
- String temp = tm;
- if (Status &amp; STAT_READONLY)
- temp.replace("$status"," | TCL_LINK_READ_ONLY");
- else
- temp.replace("$status","");
- fprintf(f_init,"%s\n",(char *) temp);
- } else {
- fprintf(stderr,"%s : Line %d. Unable to link with variable type %s\n",
- input_file,line_number,t-&gt;print_type());
- }
-}
-</pre></blockquote>
-<p>
-In this case, the procedure is looking for a typemap "varinit". We'll use the code specified with this typemap to create variable links. If no typemap is supplied or the user gives an unsupported datatypes, a warning message will be generated.<p>
-<p>
-It is also worth noting that the <tt>Status</tt> variable contains information about whether or not a variable is read-only or not. To test for this, use the technique shown in the code above. Read-only variables may require special processing as shown.<p>
-<a name="n39"></a><h3> Constants</h3>
-Finally, creating constants is accomplished using the <tt>declare_const()</tt> method. For Tcl, we could do this :<p>
- <p>
-<blockquote><pre>// -----------------------------------------------------------------------
-// MYLANG::declare_const(char *name, char *iname, DataType *type, char *value)
-//
-// Makes a constant.
-// ------------------------------------------------------------------------
-
-void MYLANG::declare_const(char *name, char *iname, DataType *type, char *value) {
-
- char *tm;
- if ((tm = typemap_lookup("const",typemap_lang,type,name,name,iname))) {
- String str = tm;
- str.replace("$value",value);
- fprintf(f_init,"%s\n", (char *) str);
- } else {
- fprintf(stderr,"%s : Line %d. Unable to create constant %s = %s\n",
- input_file, line_number, type-&gt;print_type(), value);
- }
-}
-
-</pre></blockquote>
-We take the same approach used to create variables. In this case, the `<tt>const</tt>' typemap specifies the special processing.<p>
-<p>
-The value of a constant is a string produced by the SWIG parser. It may contain an arithmetic expression such as "3 + 4*(7+8)". Because of this, it is critical to use this string in a way that allows it to be evaluated by the C compiler (this will be apparent when the typemaps are given).<p>
-<a name="n40"></a><h3> A Quick Intermission</h3>
-We are now done writing all of the methods for our language class. Of all of the methods, <tt>create_function()</tt> is the most complicated and tends to do most of the work. We have also ignored issues related to documentation processing and C++ handling (although C++ will work with the functions we have defined so far).<p>
-<p>
-While our C++ implementation is done, we still do not have a working language module. In fact, if we run SWIG on the following interface file :<p>
-<p>
-<blockquote><pre>/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-%}
-
-// A function
-extern double foo(double a, double b);
-
-// A variable
-extern int bar;
-
-// A constant
-#define SPAM 42
-
-</pre></blockquote>
-we get the following errors :<p>
-<p>
-<blockquote><pre>[beazley@guinness lang]$ ./myswig example.i
-Making wrappers for My Tcl
-example.i : Line 9. No typemapping for datatype double
-example.i : Line 9. No typemapping for datatype double
-example.i : Line 9. No return typemap for datatype double
-example.i : Line 12. Unable to link with variable type int
-example.i : Line 16. Unable to create constant int = 42
-[beazley@guinness lang]$
-
-</pre></blockquote>
-The reason for this is that we have not yet defined any processing for real datatypes. For example, our language module has no idea how to convert doubles into Tcl strings, how to link with C variables and so on. To do this, we need to write a collection of typemaps.<p>
-<a name="n41"></a><h3> Writing the default typemaps</h3>
-In our earlier <tt>parse()</tt> method, there is a statement to include the file `<tt>lang.map</tt>'. We will use this file to write typemaps for our new language module. The `<tt>lang.map</tt>' file will actually go through the SWIG parser so we can write our typemaps using the normal <tt>%typemap</tt> directive. This approach makes it easy for us to debug and test our module because the typemaps can be developed and tested without having to repeatedly recompile the C++ part of the module. <p>
-<p>
-Without further delay, here is the typemap file for our module (you might want to sit down) :<p>
-<p>
-<blockquote><pre>// ----------------------------------------------------------------------
-// lang.map
-//
-// This file defines all of the type-mappings for our language (TCL).
-// A typemap of 'SWIG_DEFAULT_TYPE' should be used to create default
-// mappings.
-// ----------------------------------------------------------------------
-
-/**************************** FUNCTION INPUTS ****************************/
-
-// Integers
-%typemap(in) int SWIG_DEFAULT_TYPE,
- short SWIG_DEFAULT_TYPE,
- long SWIG_DEFAULT_TYPE,
- unsigned int SWIG_DEFAULT_TYPE,
- unsigned short SWIG_DEFAULT_TYPE,
- unsigned long SWIG_DEFAULT_TYPE,
- signed char SWIG_DEFAULT_TYPE,
- unsigned char SWIG_DEFAULT_TYPE
-{
- int temp;
- if (Tcl_GetInt(interp, $source, &amp;temp) == TCL_ERROR) return TCL_ERROR;
- $target = ($type) temp;
-}
-
-// Floating point
-%typemap(in) float SWIG_DEFAULT_TYPE,
- double SWIG_DEFAULT_TYPE
-{
- double temp;
- if (Tcl_GetDouble(interp, $source, &amp;temp) == TCL_ERROR) return TCL_ERROR;
- $target = ($type) temp;
-}
-
-// Strings
-%typemap(in) char * SWIG_DEFAULT_TYPE
-{
- $target = $source;
-}
-
-// void *
-%typemap(in) void * SWIG_DEFAULT_TYPE
-{
- if (SWIG_GetPtr($source,(void **) &amp;$target, (char *) 0)) {
- Tcl_SetResult(interp,"Type error. Expected a pointer",TCL_STATIC);
- return TCL_ERROR;
- }
-}
-
-// User defined types and all other pointers
-%typemap(in) User * SWIG_DEFAULT_TYPE
-{
- if (SWIG_GetPtr($source,(void **) &amp;$target, "$mangle")) {
- Tcl_SetResult(interp,"Type error. Expected a $mangle",TCL_STATIC);
- return TCL_ERROR;
- }
-}
-
-/**************************** FUNCTION OUTPUTS ****************************/
-
-// Signed integers
-%typemap(out) int SWIG_DEFAULT_TYPE,
- short SWIG_DEFAULT_TYPE,
- long SWIG_DEFAULT_TYPE,
- signed char SWIG_DEFAULT_TYPE
-{
- sprintf($target,"%ld", (long) $source);
-}
-
-// Unsigned integers
-%typemap(out) unsigned SWIG_DEFAULT_TYPE,
- unsigned short SWIG_DEFAULT_TYPE,
- unsigned long SWIG_DEFAULT_TYPE,
- unsigned char SWIG_DEFAULT_TYPE
-{
- sprintf($target,"%lu", (unsigned long) $source);
-}
-
-// Floating point
-%typemap(out) double SWIG_DEFAULT_TYPE,
- float SWIG_DEFAULT_TYPE
-{
- Tcl_PrintDouble(interp,(double) $source,interp-&gt;result);
-}
-
-// Strings
-%typemap(out) char *SWIG_DEFAULT_TYPE
-{
- Tcl_SetResult(interp,$source,TCL_VOLATILE);
-}
-
-// Pointers
-%typemap(out) User *SWIG_DEFAULT_TYPE
-{
- SWIG_MakePtr($target,(void *) $source, "$mangle");
-}
-
-/**************************** VARIABLE CREATION ****************************/
-
-// Integers
-%typemap(varinit) int SWIG_DEFAULT_TYPE,
- unsigned int SWIG_DEFAULT_TYPE
-{
- Tcl_LinkVar(interp, "$target", (char *) &amp;$source, TCL_LINK_INT $status);
-}
-
-// Doubles
-%typemap(varinit) double SWIG_DEFAULT_TYPE {
- Tcl_LinkVar(interp,"$target", (char *) &amp;$source, TCL_LINK_DOUBLE $status);
-}
-
-// Strings
-%typemap(varinit) char * SWIG_DEFAULT_TYPE {
- Tcl_LinkVar(interp,"$target", (char *) &amp;$source, TCL_LINK_STRING $status);
-}
-
-/****************************** CONSTANTS **********************************/
-
-// Signed Integers
-%typemap(const) int SWIG_DEFAULT_TYPE,
- short SWIG_DEFAULT_TYPE,
- long SWIG_DEFAULT_TYPE,
- signed char SWIG_DEFAULT_TYPE
-{
- static char *_wrap_$target;
- _wrap_$target = (char *) malloc(40);
- sprintf(_wrap_$target,"%ld",$value);
- Tcl_LinkVar(interp,"$target", (char *) &amp;_wrap_$target, TCL_LINK_STRING |
-TCL_LINK_READ_ONLY);
-}
-
-// Unsigned integers
-%typemap(const) unsigned SWIG_DEFAULT_TYPE,
- unsigned short SWIG_DEFAULT_TYPE,
- unsigned long SWIG_DEFAULT_TYPE,
- unsigned char SWIG_DEFAULT_TYPE
-{
- static char *_wrap_$target;
- _wrap_$target = (char *) malloc(40);
- sprintf(_wrap_$target,"%lu",$value);
- Tcl_LinkVar(interp,"$target", (char *) &amp;_wrap_$target, TCL_LINK_STRING |
-TCL_LINK_READ_ONLY);
-}
-
-// Doubles and floats
-%typemap(const) double SWIG_DEFAULT_TYPE,
- float SWIG_DEFAULT_TYPE
-{
- static char *_wrap_$target;
- _wrap_$target = (char *) malloc(40);
- sprintf(_wrap_$target,"%f",$value);
- Tcl_LinkVar(interp,"$target", (char *) &amp;_wrap_$target, TCL_LINK_STRING |
-TCL_LINK_READ_ONLY);
-}
-
-// Strings
-%typemap(const) char *SWIG_DEFAULT_TYPE
-{
- static char *_wrap_$target = "$value";
- Tcl_LinkVar(interp,"$target", (char *) &amp;_wrap_$target, TCL_LINK_STRING |
-TCL_LINK_READ_ONLY);
-}
-
-// Pointers
-%typemap(const) User *SWIG_DEFAULT_TYPE
-{
- static char *_wrap_$target;
- _wrap_$target = (char *) malloc(20+strlen("$mangle"));
- SWIG_MakePtr(_wrap_$target, (void *) $value, "$mangle");
- Tcl_LinkVar(interp,"$target", (char *) &amp;_wrap_$target, TCL_LINK_STRING |
-TCL_LINK_READ_ONLY);
-}
-
-</pre></blockquote>
-Now that we have our typemaps file, we are done and can start producing a variety of interesting Tcl extension modules. Should errors arrise, one will either have to pry into the C++ module or the typemaps file for a correction. <p>
-<a name="n42"></a><h3> The SWIG library and installation issues</h3>
-To make a new SWIG module generally usable, you will want to perform the following steps :<p>
-<p>
-<ul>
-<li>Put the new binary in a publicly accessible location (ie. <tt>/usr/local/bin</tt>).
-<li>Make a subdirectory for your language in the SWIG library. The library should match up with the name you assigned to the <tt>LibDir</tt> variable in <tt>parse_args()</tt>.
-<li>Copy the file `<tt>lang.map</tt>' to the SWIG library directory. Your new version of SWIG will now be able to find it no matter what directory SWIG is executed from.
-<li>Provide some documentation about how your module works.
-</ul>
-<p>
-SWIG extensions are only able to target a single scripting language. If you would like to make your module part of the full version of SWIG, you will need to modify the file `<tt>swigmain.cxx</tt>' in the <tt>SWIG1.1/Modules</tt> directory. To do this, follow these steps :<p>
-<p>
-<ul>
-<li>Add a <tt>#include "lang.h"</tt> to the<tt> swigmain.cxx</tt> file.
-<li>Create a command line option for your module and write code to create an instance of your language (just copy the technique used for the other languages).
-<li>Modify <tt>Modules/Makefile</tt> to include your module as part of its compilation process.
-<li>Rebuild SWIG by typing `make'.
-</ul>
-<a name="n11"></a><h2> C++ Processing</h2>
-Language modules have the option to provide special processing for C++ classes. Usually this is to provide some sort of object-oriented interface such as shadow classes. The process of developing these extensions is highly technical and the best approach may be to copy pieces from other SWIG modules that provide object oriented support.<p>
-<a name="n43"></a><h3> How C++ processing works</h3>
-The wrapping of C++ classes follows a "file" metaphor. When a class is encountered, the following steps are performed :<p>
-<p>
-<ul>
-<li>Open a new class.
-<li>Inherit from base classes.
-<li>Add members to the class (functions, variables, constants, etc...)
-<li>Close the class and emit object-oriented code.
-</ul>
-<p>
-As a class is constructed, a language module may need to keep track of a variety of data such as whether constructors or destructors have been given, are there any data members, have datatypes been renamed, and so on. It is not always a clear-cut process.<p>
-<a name="n44"></a><h3> Language extensions</h3>
-Providing additional support for object-oriented programming requires the use of the following Language extensions. These are additional methods that can be defined for the Language class.<p>
-<p>
-<h6> void cpp_open_class(char *name, char *rename, char *ctype, int strip);</h6>
-<dl>
-<dt><dd>Opens a new class. <tt>name</tt> is the name of the class, <tt>rename</tt> is the renamed version of the class (or NULL if not renamed), <tt>ctype</tt> is the class type (<tt>struct</tt>, <tt>class</tt>, <tt>union</tt>), and <tt>strip</tt> is a flag indicating whether or not its safe to drop the leading type specifier (this is often unsafe for ANSI C).
-<dt><dd>
-</dl>
-<h6> void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);</h6>
-<dl>
-<dt><dd>Inherits from base classes. <tt>baseclass</tt> is a NULL terminated array of class names corresponding to all of the base classes of an object. <tt>mode</tt> is an inheritance mode that is the or'd value of <tt>INHERIT_FUNC</tt> , <tt>INHERIT_VAR</tt>, <tt>INHERIT_CONST</tt>, or <tt>INHERIT_ALL</tt>.
-<dt><dd>
-</dl>
-<h6> void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);</h6>
-<dl>
-<dt><dd>Creates a member function. <tt>name</tt> is the real name of the member, <tt>iname</tt> is the renamed version (NULL if not renamed), <tt>t</tt> is the return datatype, and <tt>l</tt> is the function parameter list.
-<dt><dd>
-</dl>
-<h6> void cpp_static_func(char *name, char *iname, DataType *t, ParmList *l);</h6>
-<dl>
-<dt><dd>Create a static member function. The calling conventions are the same as for <tt>cpp_member_func()</tt>.
-<dt><dd>
-</dl>
-<h6> void cpp_variable(char *name, char *iname, DataType *t);</h6>
-<dl>
-<dt><dd>Creates a member variable. <tt>name</tt> is the real name of the member, <tt>iname</tt> is the renamed version (NULL is not renamed). <tt>t</tt> is the type of the member.
-<dt><dd>
-</dl>
-<h6> void cpp_static_var(char *name, char *iname, DataType *t);</h6>
-<dl>
-<dt><dd>Creates a static member variable. The calling convention is the same as for <tt>cpp_variable()</tt>.
-<dt><dd>
-</dl>
-<h6> void cpp_declare_const(char *name, char *iname, DataType *type, char *value);</h6>
-<dl>
-<dt><dd>Creates a constant inside a C++ class. Normally this is an enum or member declared as const. <tt>name</tt> is the real name, <tt>iname</tt> is the renamed version (NULL if not renamed), <tt>type</tt> is the type of the constant, and <tt>value</tt> is a string containing the value.
-<dt><dd>
-</dl>
-<h6> void cpp_constructor(char *name, char *iname, ParmList *l);</h6>
-<dl>
-<dt><dd>Creates a constructor. <tt>name</tt> is the name of the constructor, <tt>iname</tt> is the renamed version, and <tt>l</tt> is the function parameter list. Normally, <tt>name</tt> is the same name as the class. If not, this may actually be a member function with no declared return type (assumed to be an int in C++).
-<dt><dd>
-</dl>
-<h6> void cpp_destructor(char *name, char *newname);</h6>
-<dl>
-<dt><dd>Creates a destructor. <tt>name</tt> is the real name of the destructor (usually the same name as the class), and <tt>newname</tt> is the renamed version (NULL if not renamed).
-<dt><dd>
-</dl>
-<h6> void cpp_close_class();</h6>
-<dl>
-<dt><dd>Closes the current class. Language modules should finish off code generation for a class once this has been called.
-<dt><dd>
-</dl>
-<h6> void cpp_cleanup();</h6>
-<dl>
-<dt><dd>Called after all C++ classes have been generated. Only used to provide some kind of global cleanup for all classes.
-</dl>
-<a name="n45"></a><h3> Hints</h3>
-Special C++ code generation is not for the weak of heart. Most of SWIG's built in modules have been developed for well over a year and object oriented support has been in continual development. If writing a new language module, looking at the implementation for Python, Tcl, or Perl5 would be a good start.<p>
-<a name="n12"></a><h2> Documentation Processing</h2>
-The documentation system operates (for the most part), independently of the language modules. However, language modules are still responsible for generating a "usage" string describing how each function, variable, or constant is to be used in the target language.<p>
-<a name="n46"></a><h3> Documentation entries</h3>
-Each C/C++ declaration in an interface file gets assigned to a "Documentation Entry" that is described by the <tt>DocEntry</tt> object :<p>
-<p>
-<blockquote><pre>class DocEntry {
-public:
- String usage; // Short description
- String cinfo; // Information about C interface (optional).
- String text; // Supporting text (optional)
-};
-
-</pre></blockquote>
-The <tt>usage</tt> string is used to hold the calling sequence for the function. The <tt>cinfo</tt> field is used to provide additional information about the underlying C code. <tt>text</tt> is filled in with comment text.<p>
-<p>
-The global variable <tt>doc_entry</tt> always contains the documentation entry for the current declaration being processed. Language modules can choose to update the documentation by referring to and modifying its fields.<p>
-<a name="n47"></a><h3> Creating a usage string</h3>
-To create a documentation usage string, language modules need to modify the `usage' field of <tt>doc_entry</tt>. This can be done by creating a function like this :<p>
-<p>
-<blockquote><pre>// ---------------------------------------------------------------------------
-// char *TCL::usage_string(char *iname, DataType *t, ParmList *l),
-//
-// Generates a generic usage string for a Tcl function.
-// ---------------------------------------------------------------------------
-
-char * TCL::usage_string(char *iname, DataType *, ParmList *l) {
-
- static String temp;
- Parm *p;
- int i, numopt,pcount;
-
- temp = "";
- temp &lt;&lt; iname &lt;&lt; " ";
-
- /* Now go through and print parameters */
- i = 0;
- pcount = l-&gt;nparms;
- numopt = l-&gt;numopt();
- p = l-&gt;get_first();
- while (p != 0) {
- if (!p-&gt;ignore) {
- if (i &gt;= (pcount-numopt))
- temp &lt;&lt; "?";
-
- /* If parameter has been named, use that. Otherwise, just print a type */
-
- if ((p-&gt;t-&gt;type != T_VOID) || (p-&gt;t-&gt;is_pointer)) {
- if (strlen(p-&gt;name) &gt; 0) {
- temp &lt;&lt; p-&gt;name;
- }
- else {
- temp &lt;&lt; "{ " &lt;&lt; p-&gt;t-&gt;print_type() &lt;&lt; " }";
- }
- }
- if (i &gt;= (pcount-numopt))
- temp &lt;&lt; "?";
- temp &lt;&lt; " ";
- i++;
- }
- p = l-&gt;get_next();
- }
- return temp;
-}
-</pre></blockquote>
-<p>
-Now, within the function to create a wrapper function, include code such as the following :<p>
-<p>
-<blockquote><pre>// Fill in the documentation entry
-doc_entry-&gt;usage &lt;&lt; usage_string(iname,t,l);
-
-</pre></blockquote>
-To produce full documentation, each language module needs to fill in the documentation usage string for all declarations. Looking at existing SWIG modules can provide more information on how this should be implemented.<p>
-<a name="n48"></a><h3> Writing a new documentation module</h3>
-Writing a new documentation module is roughly the same idea as writing a new Language class. To do it, you need to implement a "Documentation Object" by inheriting from the following base class and defining all of the virtual methods :<p>
-<p>
-<blockquote><pre>class Documentation {
-public:
- virtual void parse_args(int argc, char **argv) = 0;
- virtual void title(DocEntry *de) = 0;
- virtual void newsection(DocEntry *de, int sectnum) = 0;
- virtual void endsection() = 0;
- virtual void print_decl(DocEntry *de) = 0;
- virtual void print_text(DocEntry *de) = 0;
- virtual void separator() = 0;
- virtual void init(char *filename) = 0;
- virtual void close(void) = 0;
- virtual void style(char *name, char *value) = 0;
-};
-
-
-</pre></blockquote>
-<h6> void parse_args(int argc, char **argv);</h6>
-<dl>
-<dt><dd>Parses command line options. Any special options you want to provide should be placed here.
-<dt><dd>
-</dl>
-<h6> void title(DocEntry *de;</h6>
-<dl>
-<dt><dd>Produces documentation output for a title.
-<dt><dd>
-</dl>
-<h6> void newsection(DocEntry *de, int sectnum;</h6>
-<dl>
-<dt><dd>Called whenever a new section is created. The documentation system is hierarchical in nature so each call to this function goes down one level in the hierarchy.
-<dt><dd>
-</dl>
-<h6> void endsection();</h6>
-<dl>
-<dt><dd>Ends the current section. Moves up one level in the documentation hierarchy.
-<dt><dd>
-</dl>
-<h6> void print_decl(DocEntry *de);</h6>
-<dl>
-<dt><dd>Creates documentation for a C declaration (function, variable, or constant).
-<dt><dd>
-</dl>
-<h6> void print_text(DocEntry *de);</h6>
-<dl>
-<dt><dd>Prints documentation that has been given with the <tt>%text %{ %}</tt> directive.
-<dt><dd>
-</dl>
-<h6> void separator();</h6>
-<dl>
-<dt><dd>Prints an optional separator between sections.
-<dt><dd>
-</dl>
-<h6> void init(char *filename);</h6>
-<dl>
-<dt><dd>Initializes the documentation system. This function is called after command line options have been parsed. <tt>filename</tt> is the file where documentation should be placed.
-<dt><dd>
-</dl>
-<h6> void close(void);</h6>
-<dl>
-<dt><dd>Closes the documentation file. All remaining output should be complete and files closed upon exit.
-<dt><dd>
-</dl>
-<h6> void style(char *name, char *value);</h6>
-<dl>
-<dt><dd>Called to set style parameters. This function is called by the <tt>%style</tt> and <tt>%localstyle</tt> directives. It is also called whenever style parameters are given after a section directive.
-</dl>
-<a name="n49"></a><h3> Using a new documentation module</h3>
-Using a new documentation module requires a change to SWIG's main program. If you are writing your own main() program, you can use a new documentation module as follows :<p>
-<p>
-<blockquote><pre>#include &lt;swig.h&gt;
-#include "swigtcl.h" // Language specific header
-#include "mydoc.h" // New Documentation module
-
-extern int SWIG_main(int, char **, Language *, Documentation *);
-int main(int argc, char **argv) {
-
- TCL *l = new TCL; // Create a new Language object
- MyDoc *d = new MyDoc; // New documentation object
- init_args(argc, argv); // Initialize args
- return SWIG_main(argc, argv, l, d);
-}
-</pre></blockquote>
-<a name="n50"></a><h3> Where to go for more information</h3>
-To find out more about documentation modules, look at some of the existing SWIG modules contained in the <tt>SWIG1.1/SWIG</tt> directory. The ASCII and HTML modules are good starting points for finding more information. <p>
-<a name="n13"></a><h2> The Future of SWIG</h2>
-SWIG's C++ API is the most rapidly evolving portion of SWIG. While interface-file compatibility will be maintained as much as possible in future releases, the internal structure of SWIG is likely to change significantly in the future. This will possibly have many ramifications on the construction of language modules. Here are a few significant changes that are coming :<p>
-<p>
-
-<dl>
-<dt>1. A complete reorganization of the SWIG type system. Datatypes will be represented in a more flexible manner that provide full support for arrays, function pointers, classes, structures, and types possibly coming from other languages (such as Fortran).
-<dt>2. Objectification of functions, variables, constants, classes, etc... Currently many of SWIG's functions take multiple arguments such as functions being described by name, return datatype, and parameters. These attributes will be consolidated into a single "Function" object, "Variable" object, "Constant" object, and so forth.
-<dt>3. A complete rewrite of the SWIG parser. This will be closely tied to the change in datatype representation among other things.
-<dt>4. Increased reliance on typemaps. Many of SWIG's older modules do not rely on typemaps, but this is likely to change. Typemaps provide a more concise implementation and are easier to maintain. Modules written for 1.1 that adopt typemaps now will be much easier to integrate into future releases.
-<dt>5. A possible reorganization of object-oriented code generation. The layered approach will probably remain in place however.
-<dt>6. Better support for multiple-files (exporting, importing, etc...)
-
-</dl>
-<p>
-In planning for the future, much of a language's functionality can be described in terms of typemaps. Sticking to this approach will make it significantly easier to move to new releases. I anticipate that there will be few drastic changes to the Language module presented in this section (other than changes to many of the calling mechanisms).<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:47:17 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Index.html b/swigweb/Doc1.1/HTML/Index.html
deleted file mode 100644
index b7662ea96..000000000
--- a/swigweb/Doc1.1/HTML/Index.html
+++ /dev/null
@@ -1,559 +0,0 @@
-
-<html>
-<head>
-<title> SWIG 1.1 Users Manual - Topic Index </title>
-</head>
-<body bgcolor="#ffffff">
-
-<h1> Alphabetical Topic Index </h1>
-<h2> - A - </h2>
-<blockquote>
-
-<a href="Python.html#n53">A complete application</a> (9 SWIG and Python)<br>
-<a href="Advanced.html#n7">A few dynamic loading gotchas</a> (11 Advanced Topics)<br>
-<a href="Tcl.html#n49">A few helper functions</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n10">A general interface building strategy</a> (3 SWIG Basics)<br>
-<a href="Python.html#n46">A mathematical function plotter</a> (9 SWIG and Python)<br>
-<a href="Extending.html#n40">A Quick Intermission</a> (12 Extending SWIG)<br>
-<a href="Python.html#n29">A simple example</a> (9 SWIG and Python)<br>
-<a href="Typemaps.html#n16">A simple example</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Perl5.html#n5">A simple Perl example</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n67">A simple shadow class</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n31">A simple SWIG interface file</a> (8 SWIG and Perl5)<br>
-<a href="Perl5.html#n37">A simple typemap example</a> (8 SWIG and Perl5)<br>
-<a href="Introduction.html#n5">A SWIG example</a> (1 Introduction)<br>
-<a href="Extending.html#n5">A tour of SWIG datatypes</a> (12 Extending SWIG)<br>
-<a href="Typemaps.html#n30">A Typemap Implementation</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Tcl.html#n5">About the examples</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n5">About the Examples</a> (9 SWIG and Python)<br>
-<a href="Preface.html#n3">About this manual</a> (Preface)<br>
-<a href="Python.html#n37">Accessing array data</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n43">Accessing array structure members</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n62">Accessing array structure members</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n8">Accessing arrays</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n6">Accessing arrays and other strange objects</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n36">Accessing member data</a> (10 SWIG and Tcl)<br>
-<a href="Documentation.html#n7">Adding Additional Text</a> (5 Documentation System)<br>
-<a href="SWIG.html#n40">Adding member functions to C structures</a> (3 SWIG Basics)<br>
-<a href="Python.html#n66">Adding native Python functions to a SWIG module</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n55">Adding new methods</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n71">Adding new methods</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n17">Additional SWIG options</a> (10 SWIG and Tcl)<br>
-<a href="Documentation.html#n9">An Example</a> (5 Documentation System)<br>
-<a href="Tcl.html#n50">An OpenGL package</a> (10 SWIG and Tcl)<br>
-<a href="Typemaps.html#n5">Applying constraints to input values</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Typemaps.html#n27">Applying constraints to new datatypes</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Exceptions.html#n9">Applying exception handlers to specific datatypes.</a> (7 Exception Handling)<br>
-<a href="SWIG.html#n38">Array members</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n30">Arrays</a> (3 SWIG Basics)<br>
-<a href="Documentation.html#n10">ASCII Documentation</a> (5 Documentation System)<br>
-<a href="Python.html#n31">Automated shadow class generation</a> (9 SWIG and Python)<br>
-<a href="Introduction.html#n10">Automatic documentation generation</a> (1 Introduction)<br></blockquote>
-<h2> - B - </h2>
-<blockquote>
-
-<a href="Perl5.html#n4">Basic Perl interface</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n3">Basic Tcl Interface</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n6">Binary trees in Tcl</a> (10 SWIG and Tcl)<br>
-<a href="Preface.html#n6">Bug reports</a> (Preface)<br>
-<a href="Tcl.html#n42">Building a C data structure in Tcl</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n20">Building a dynamic module with MakeMaker</a> (8 SWIG and Perl5)<br>
-<a href="Perl5.html#n11">Building a Perl5 interface to MATLAB</a> (8 SWIG and Perl5)<br>
-<a href="Introduction.html#n15">Building a Perl5 module</a> (1 Introduction)<br>
-<a href="Introduction.html#n16">Building a Python module</a> (1 Introduction)<br>
-<a href="Python.html#n45">Building a simple 2D imaging class</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n9">Building a simple OpenGL module</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n21">Building a static version of Perl</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n44">Building an object oriented C interface</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n7">Building C/C++ data structures with Tk</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n52">Building large multi-module systems</a> (9 SWIG and Python)<br>
-<a href="Introduction.html#n19">Building libraries and modules</a> (1 Introduction)<br>
-<a href="Tcl.html#n13">Building new kinds of Tcl interfaces (in Tcl)</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n2">Building Perl Extensions under Windows 95/NT</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n2">Building Python Extensions under Windows 95/NT</a> (9 SWIG and Python)<br>
-<a href="Scripting.html#n3">Building scripting language extensions</a> (2 Scripting Languages)<br>
-<a href="Tcl.html#n2">Building Tcl/Tk Extensions under Windows 95/NT</a> (10 SWIG and Tcl)<br></blockquote>
-<h2> - C - </h2>
-<blockquote>
-
-<a href="SWIG.html#n39">C constructors and destructors</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n40">C files</a> (10 SWIG and Tcl)<br>
-<a href="Documentation.html#n21">C Information</a> (5 Documentation System)<br>
-<a href="SWIG.html#n14">C Preprocessor directives</a> (3 SWIG Basics)<br>
-<a href="Introduction.html#n6">C syntax, but not a C compiler</a> (1 Introduction)<br>
-<a href="Tcl.html#n32">C++ Classes</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n28">C++ Classes</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n44">C++ example</a> (3 SWIG Basics)<br>
-<a href="Extending.html#n11">C++ Processing</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n6">C++ support</a> (3 SWIG Basics)<br>
-<a href="Documentation.html#n13">C++ Support</a> (5 Documentation System)<br>
-<a href="SWIG.html#n68">Categories</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n37">Changing member data</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n19">Character Strings</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n37">Character strings and structures</a> (3 SWIG Basics)<br>
-<a href="Library.html#n17">Checking in library files</a> (4 Multiple files and the SWIG library)<br>
-<a href="Library.html#n15">Checking out library files</a> (4 Multiple files and the SWIG library)<br>
-<a href="Documentation.html#n3">Choosing a documentation format</a> (5 Documentation System)<br>
-<a href="SWIG.html#n62">Class methods</a> (3 SWIG Basics)<br>
-<a href="Extending.html#n35">Cleanup</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n77">Code blocks</a> (3 SWIG Basics)<br>
-<a href="Extending.html#n9">Code Generation Functions</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n9">Code Insertion</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n66">Combining Tcl/Tk Extensions</a> (10 SWIG and Tcl)<br>
-<a href="Extending.html#n30">Command Line Options and Basic Initialization</a> (12 Extending SWIG)<br>
-<a href="Documentation.html#n16">Comment Formatting variables</a> (5 Documentation System)<br>
-<a href="Documentation.html#n18">Comment placement and formatting</a> (5 Documentation System)<br>
-<a href="SWIG.html#n13">Comments</a> (3 SWIG Basics)<br>
-<a href="Typemaps.html#n7">Common typemap methods</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Tcl.html#n22">Compilation problems</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n22">Compilation problems and compiling with C++</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n19">Compilation problems and compiling with C++</a> (9 SWIG and Python)<br>
-<a href="Extending.html#n20">Compiling</a> (12 Extending SWIG)<br>
-<a href="Perl5.html#n19">Compiling a dynamic module</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n16">Compiling a dynamic module</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n19">Compiling a dynamic module (Unix)</a> (10 SWIG and Tcl)<br>
-<a href="Extending.html#n2">Compiling a SWIG extension</a> (12 Extending SWIG)<br>
-<a href="Python.html#n32">Compiling modules with shadow classes</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n8">Conditional compilation</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n12">Configuration management with SWIG</a> (10 SWIG and Tcl)<br>
-<a href="Extending.html#n39">Constants</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n21">Constants</a> (3 SWIG Basics)<br>
-<a href="Python.html#n25">Constants</a> (9 SWIG and Python)<br>
-<a href="Scripting.html#n9">Constants</a> (2 Scripting Languages)<br>
-<a href="Tcl.html#n29">Constants</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n27">Constants</a> (8 SWIG and Perl5)<br>
-<a href="Typemaps.html#n26">Constraint methods</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="SWIG.html#n60">Constructors and destructors</a> (3 SWIG Basics)<br>
-<a href="Python.html#n72">Constructors and Destructors</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n45">Constructors and destructors</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n57">Converting a Tcl list to a char **</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n58">Converting Python list to a char **</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n41">Converting a Perl5 array to a char **</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n59">Converting a Python file object to a FILE *</a> (9 SWIG and Python)<br>
-<a href="Typemaps.html#n34">Copying a typemap</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Tcl.html#n65">Creating a new package initialization library</a> (10 SWIG and Tcl)<br>
-<a href="Typemaps.html#n32">Creating a new typemap</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Extending.html#n47">Creating a usage string</a> (12 Extending SWIG)<br>
-<a href="Extending.html#n37">Creating a Wrapper Function</a> (12 Extending SWIG)<br>
-<a href="Typemaps.html#n17">Creating arrays</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Extending.html#n36">Creating Commands</a> (12 Extending SWIG)<br>
-<a href="Library.html#n7">Creating Library Files</a> (4 Multiple files and the SWIG library)<br>
-<a href="Typemaps.html#n37">Creating local variables</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Advanced.html#n1">Creating multi-module packages</a> (11 Advanced Topics)<br>
-<a href="Tcl.html#n33">Creating new objects</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n31">Creating read-only variables</a> (3 SWIG Basics)<br>
-<a href="Preface.html#n4">Credits</a> (Preface)<br>
-<a href="Introduction.html#n22">Cross platform woes</a> (1 Introduction)<br></blockquote>
-<h2> - D - </h2>
-<blockquote>
-
-<a href="Exceptions.html#n7">Debugging and other interesting uses for %except</a> (7 Exception Handling)<br>
-<a href="Documentation.html#n15">Default Formatting</a> (5 Documentation System)<br>
-<a href="SWIG.html#n34">Default/optional arguments</a> (3 SWIG Basics)<br>
-<a href="Exceptions.html#n5">Defining different exception handlers</a> (7 Exception Handling)<br>
-<a href="SWIG.html#n73">Defining symbols</a> (3 SWIG Basics)<br>
-<a href="Typemaps.html#n33">Deleting a typemap</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Tcl.html#n35">Deleting objects</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n24">Derived types, structs, and classes</a> (3 SWIG Basics)<br>
-<a href="Documentation.html#n8">Disabling all documentation</a> (5 Documentation System)<br>
-<a href="Extending.html#n46">Documentation entries</a> (12 Extending SWIG)<br>
-<a href="Introduction.html#n18">Documentation generation</a> (1 Introduction)<br>
-<a href="Extending.html#n12">Documentation Processing</a> (12 Extending SWIG)<br>
-<a href="Tcl.html#n68">Dynamic loading</a> (10 SWIG and Tcl)<br>
-<a href="Advanced.html#n2">Dynamic Loading of C++ modules</a> (11 Advanced Topics)<br></blockquote>
-<h2> - E - </h2>
-<blockquote>
-
-<a href="Extending.html#n32">Emitting headers and support code</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n50">Enums and constants</a> (3 SWIG Basics)<br>
-<a href="Introduction.html#n9">Event driven C programming</a> (1 Introduction)<br>
-<a href="Python.html#n9">Exception handling</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n13">Exception handling</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n10">Exception handling</a> (10 SWIG and Tcl)<br>
-<a href="Exceptions.html#n3">Exception handling with longjmp()</a> (7 Exception Handling)<br>
-<a href="Python.html#n44">Extending and fixing the gd module</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n14">Extending the Tcl Netscape Plugin</a> (10 SWIG and Tcl)<br></blockquote>
-<h2> - F - </h2>
-<blockquote>
-
-<a href="Extending.html#n7">File management</a> (12 Extending SWIG)<br>
-<a href="Extending.html#n34">Final Initialization</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n18">Floating Point</a> (3 SWIG Basics)<br>
-<a href="Documentation.html#n6">Formatting</a> (5 Documentation System)<br>
-<a href="Python.html#n48">From C to SWIG to Python</a> (9 SWIG and Python)<br>
-<a href="Extending.html#n22">Function Parameters</a> (12 Extending SWIG)<br>
-<a href="Documentation.html#n4">Function usage and argument names</a> (5 Documentation System)<br>
-<a href="Tcl.html#n27">Functions</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n23">Functions</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n25">Functions</a> (8 SWIG and Perl5)<br></blockquote>
-<h2> - G - </h2>
-<blockquote>
-
-<a href="SWIG.html#n4">Getting down to business</a> (3 SWIG Basics)<br>
-<a href="Python.html#n39">Getting even more serious about array access</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n9">Getting serious</a> (8 SWIG and Perl5)<br>
-<a href="Perl5.html#n18">Getting the right header files</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n15">Getting the right header files</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n84">Getting the right header files</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n18">Getting the right header files and libraries</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n28">Global variables</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n26">Global variables</a> (8 SWIG and Perl5)<br>
-<a href="Perl5.html#n36">Graphical Web-Statistics in Perl5</a> (8 SWIG and Perl5)<br>
-<a href="Perl5.html#n30">Graphs</a> (8 SWIG and Perl5)<br></blockquote>
-<h2> - H - </h2>
-<blockquote>
-
-<a href="Exceptions.html#n4">Handling C++ exceptions</a> (7 Exception Handling)<br>
-<a href="Exceptions.html#n2">Handling exceptions in C code</a> (7 Exception Handling)<br>
-<a href="Perl5.html#n12">Handling output values (the easy way)</a> (8 SWIG and Perl5)<br>
-<a href="Introduction.html#n8">Hands off code generation</a> (1 Introduction)<br>
-<a href="Extending.html#n24">Hash Tables</a> (12 Extending SWIG)<br>
-<a href="Extending.html#n45">Hints</a> (12 Extending SWIG)<br>
-<a href="Extending.html#n43">How C++ processing works</a> (12 Extending SWIG)<br>
-<a href="Scripting.html#n2">How does a scripting language talk to C?</a> (2 Scripting Languages)<br>
-<a href="Documentation.html#n2">How it works</a> (5 Documentation System)<br>
-<a href="Extending.html#n28">How many typemaps are there?</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n88">How to avoid creating the interface from hell</a> (3 SWIG Basics)<br>
-<a href="Preface.html#n10">How to avoid reading the manual</a> (Preface)<br>
-<a href="Typemaps.html#n13">How to break everything with a typemap</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="SWIG.html#n87">How to cope with C++</a> (3 SWIG Basics)<br>
-<a href="Introduction.html#n23">How to survive this manual</a> (1 Introduction)<br>
-<a href="Documentation.html#n11">HTML Documentation</a> (5 Documentation System)<br></blockquote>
-<h2> - I - </h2>
-<blockquote>
-
-<a href="Documentation.html#n20">Ignoring comments</a> (5 Documentation System)<br>
-<a href="SWIG.html#n69">Implementations and Protocols</a> (3 SWIG Basics)<br>
-<a href="Python.html#n11">Implementing C callback functions in Python</a> (9 SWIG and Python)<br>
-<a href="Typemaps.html#n11">Implementing constraints with typemaps</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Tcl.html#n43">Implementing methods in C</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n7">Implementing methods in Perl</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n40">Implementing special Python methods in C</a> (9 SWIG and Python)<br>
-<a href="Library.html#n4">Including files on the command line</a> (4 Multiple files and the SWIG library)<br>
-<a href="Perl5.html#n54">Inheritance</a> (8 SWIG and Perl5)<br>
-<a href="SWIG.html#n52">Inheritance</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n66">Inheritance</a> (3 SWIG Basics)<br>
-<a href="Python.html#n77">Inheritance and shadow classes</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n79">Initialization blocks</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n78">Inlined code blocks</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n11">Input format</a> (3 SWIG Basics)<br>
-<a href="Typemaps.html#n21">Input Methods</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Typemaps.html#n23">Input/Output Methods</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Advanced.html#n3">Inside the SWIG type-checker</a> (11 Advanced Topics)<br>
-<a href="SWIG.html#n61">Instance methods</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n17">Integers</a> (3 SWIG Basics)<br>
-<a href="Typemaps.html#n1">Introduction</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Documentation.html#n1">Introduction</a> (5 Documentation System)<br>
-<a href="Preface.html#n1">Introduction</a> (Preface)<br>
-<a href="Extending.html#n1">Introduction</a> (12 Extending SWIG)<br>
-<a href="Typemaps.html#n3">Introduction to typemaps</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Tcl.html#n34">Invoking member functions</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n55">Iterators</a> (8 SWIG and Perl5)<br></blockquote>
-<h2> - L - </h2>
-<blockquote>
-
-<a href="Extending.html#n44">Language extensions</a> (12 Extending SWIG)<br>
-<a href="Documentation.html#n12">LaTeX Documentation</a> (5 Documentation System)<br>
-<a href="Library.html#n6">Library example</a> (4 Multiple files and the SWIG library)<br>
-<a href="Introduction.html#n3">Life after SWIG</a> (1 Introduction)<br>
-<a href="Introduction.html#n2">Life before SWIG</a> (1 Introduction)<br>
-<a href="SWIG.html#n16">Limitations in the Parser (and various things to keep in mind)</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n67">Limitations to this approach</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n29">Linking to complex variables</a> (3 SWIG Basics)<br>
-<a href="Scripting.html#n13">Linking with shared libraries</a> (2 Scripting Languages)<br></blockquote>
-<h2> - M - </h2>
-<blockquote>
-
-<a href="Tcl.html#n41">Making a quick a dirty Tcl module</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n35">Making a quick and dirty Python module</a> (9 SWIG and Python)<br>
-<a href="Library.html#n12">malloc.i</a> (4 Multiple files and the SWIG library)<br>
-<a href="Typemaps.html#n4">Managing input and output parameters</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Typemaps.html#n29">Managing special data-types with helper functions</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Extending.html#n38">Manipulating Global Variables</a> (12 Extending SWIG)<br>
-<a href="Tcl.html#n60">Mapping C structures into Tcl Lists</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n61">Mapping Python tuples into small arrays</a> (9 SWIG and Python)<br>
-<a href="Python.html#n73">Member data</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n48">Member data</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n63">Member data</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n46">Member functions</a> (3 SWIG Basics)<br>
-<a href="Python.html#n49">Merging modules</a> (9 SWIG and Python)<br>
-<a href="Python.html#n78">Methods that return new objects</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n49">Module and package names</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n68">Module names</a> (9 SWIG and Python)<br>
-<a href="Python.html#n22">Modules</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n3">Modules, packages, and classes</a> (8 SWIG and Perl5)<br>
-<a href="Library.html#n10">More about the SWIG library</a> (4 Multiple files and the SWIG library)<br>
-<a href="Exceptions.html#n8">More Examples</a> (7 Exception Handling)<br>
-<a href="Typemaps.html#n28">Motivations for using typemaps</a> (6 Pointers, Constraints, and Typemaps)<br></blockquote>
-<h2> - N - </h2>
-<blockquote>
-
-<a href="Tcl.html#n56">Name based type conversion</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n57">Name based type conversion</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n40">Name based type conversion</a> (8 SWIG and Perl5)<br>
-<a href="Extending.html#n8">Naming Services</a> (12 Extending SWIG)<br>
-<a href="Python.html#n76">Nested objects</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n52">Nested Objects</a> (8 SWIG and Perl5)<br>
-<a href="SWIG.html#n41">Nested structures</a> (3 SWIG Basics)<br>
-<a href="Introduction.html#n7">Non-intrusive interface building</a> (1 Introduction)<br></blockquote>
-<h2> - O - </h2>
-<blockquote>
-
-<a href="Perl5.html#n51">Object Ownership</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n71">Object ownership</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n7">Objective-C</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n59">Objective-C Example</a> (3 SWIG Basics)<br>
-<a href="Preface.html#n9">Organization of this manual</a> (Preface)<br>
-<a href="SWIG.html#n72">Other issues</a> (3 SWIG Basics)<br>
-<a href="Python.html#n12">Other odds and ends</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n42">Other things to note about structures</a> (3 SWIG Basics)<br>
-<a href="Typemaps.html#n22">Output Methods</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="SWIG.html#n33">Overriding call by reference</a> (3 SWIG Basics)<br></blockquote>
-<h2> - P - </h2>
-<blockquote>
-
-<a href="Typemaps.html#n18">Packing a data structure</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="SWIG.html#n56">Partial class definitions</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n27">Passing complex datatypes by value</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n39">Performance concerns and disabling the object oriented interface</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n79">Performance concerns and hints</a> (9 SWIG and Python)<br>
-<a href="Advanced.html#n11">Performance of the type-checker</a> (11 Advanced Topics)<br>
-<a href="Perl5.html#n38">Perl5 typemaps</a> (8 SWIG and Perl5)<br>
-<a href="Library.html#n13">Placing the files in the library</a> (4 Multiple files and the SWIG library)<br>
-<a href="Python.html#n47">Plotting an unstructured mesh</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n47">Pointer handling</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n63">Pointer handling</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n65">Pointer handling</a> (9 SWIG and Python)<br>
-<a href="Typemaps.html#n15">Pointer Library Functions</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Perl5.html#n28">Pointers</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n30">Pointers</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n26">Pointers</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n3">Pointers and complex objects</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n35">Pointers to functions</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n75">Predefined Symbols</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n1">Preliminaries</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n1">Preliminaries</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n1">Preliminaries</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n81">Preparing a C program for SWIG</a> (3 SWIG Basics)<br>
-<a href="Python.html#n42">Preparing a module</a> (9 SWIG and Python)<br>
-<a href="Preface.html#n8">Prerequisites</a> (Preface)<br>
-<a href="Extending.html#n14">Prerequisites</a> (12 Extending SWIG)<br>
-<a href="Python.html#n74">Printing</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n52">Problems with the OpenGL interface</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n49">Protection</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n64">Protection</a> (3 SWIG Basics)<br>
-<a href="Python.html#n8">Putting it all together</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n35">Putting it all together</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n4">Python shadow classes</a> (9 SWIG and Python)<br>
-<a href="Python.html#n55">Python typemaps</a> (9 SWIG and Python)<br></blockquote>
-<h2> - R - </h2>
-<blockquote>
-
-<a href="Python.html#n17">Rebuilding the Python interpreter (aka. static linking)</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n51">References</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n67">Referring to other classes</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n38">Relationship with pointers</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n10">Remapping C datatypes with typemaps</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n58">Remapping constants</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n14">Remapping datatypes with typemaps</a> (8 SWIG and Perl5)<br>
-<a href="SWIG.html#n70">Renaming</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n54">Renaming</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n32">Renaming declarations</a> (3 SWIG Basics)<br>
-<a href="Extending.html#n18">Required C++ compiler</a> (12 Extending SWIG)<br>
-<a href="Extending.html#n17">Required files</a> (12 Extending SWIG)<br>
-<a href="Tcl.html#n45">Required files</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n28">Return by value</a> (3 SWIG Basics)<br>
-<a href="Perl5.html#n48">Return values</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n59">Returning values in arguments</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n23">Run time pointer type checking</a> (3 SWIG Basics)<br>
-<a href="Perl5.html#n17">Running SWIG</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n14">Running SWIG</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n1">Running SWIG</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n16">Running SWIG</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n25">Running SWIG from Developer Studio</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n20">Running SWIG from Developer Studio</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n23">Running SWIG from Developer Studio</a> (8 SWIG and Perl5)<br>
-<a href="Advanced.html#n4">Runtime support (and potential problems)</a> (11 Advanced Topics)<br></blockquote>
-<h2> - S - </h2>
-<blockquote>
-
-<a href="Perl5.html#n32">Sample Perl Script</a> (8 SWIG and Perl5)<br>
-<a href="Typemaps.html#n36">Scope</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Extending.html#n33">Setting a module name</a> (12 Extending SWIG)<br>
-<a href="Tcl.html#n23">Setting a package prefix</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n8">Shadow classes</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n70">Shadow classes</a> (10 SWIG and Tcl)<br>
-<a href="Scripting.html#n11">Shadow classes</a> (2 Scripting Languages)<br>
-<a href="Perl5.html#n53">Shadow Functions</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n75">Shadow Functions</a> (9 SWIG and Python)<br>
-<a href="Scripting.html#n4">Shared libraries and dynamic loading</a> (2 Scripting Languages)<br>
-<a href="Introduction.html#n17">Shortcuts</a> (1 Introduction)<br>
-<a href="SWIG.html#n2">Simple C functions, variables, and constants</a> (3 SWIG Basics)<br>
-<a href="Typemaps.html#n25">Simple constraint example</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="SWIG.html#n22">Simple pointers</a> (3 SWIG Basics)<br>
-<a href="Python.html#n6">Solving a simple heat-equation</a> (9 SWIG and Python)<br>
-<a href="Documentation.html#n17">Sorting</a> (5 Documentation System)<br>
-<a href="Typemaps.html#n38">Special variables</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Python.html#n64">Standard typemaps</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n62">Standard typemaps</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n46">Standard typemaps</a> (8 SWIG and Perl5)<br>
-<a href="Extending.html#n31">Starting the parser</a> (12 Extending SWIG)<br>
-<a href="Library.html#n9">Static initialization of multiple modules</a> (4 Multiple files and the SWIG library)<br>
-<a href="Scripting.html#n12">Static linking</a> (2 Scripting Languages)<br>
-<a href="Tcl.html#n21">Static linking</a> (10 SWIG and Tcl)<br>
-<a href="SWIG.html#n47">Static members</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n31">Structures</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n27">Structures</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n29">Structures and C++ classes</a> (8 SWIG and Perl5)<br>
-<a href="Scripting.html#n10">Structures and classes</a> (2 Scripting Languages)<br>
-<a href="SWIG.html#n5">Structures, unions, and object oriented C programming</a> (3 SWIG Basics)<br>
-<a href="Introduction.html#n11">Summary</a> (1 Introduction)<br>
-<a href="Python.html#n41">Summary (so far)</a> (9 SWIG and Python)<br>
-<a href="SWIG.html#n43">Supported C++ features</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n15">SWIG Directives</a> (3 SWIG Basics)<br>
-<a href="Introduction.html#n12">SWIG for Windows and Macintosh</a> (1 Introduction)<br>
-<a href="Introduction.html#n13">SWIG interface file</a> (1 Introduction)<br>
-<a href="Preface.html#n7">SWIG is free</a> (Preface)<br>
-<a href="Introduction.html#n21">SWIG on the Power Macintosh</a> (1 Introduction)<br>
-<a href="Introduction.html#n20">SWIG on Windows 95/NT</a> (1 Introduction)<br>
-<a href="Extending.html#n15">SWIG Organization</a> (12 Extending SWIG)<br>
-<a href="Extending.html#n3">SWIG output</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n12">SWIG Output</a> (3 SWIG Basics)<br>
-<a href="Preface.html#n2">SWIG resources</a> (Preface)<br>
-<a href="SWIG.html#n57">SWIG, C++, and the Legislation of Morality</a> (3 SWIG Basics)<br></blockquote>
-<h2> - T - </h2>
-<blockquote>
-
-<a href="Documentation.html#n19">Tabs and other annoyances</a> (5 Documentation System)<br>
-<a href="Tcl.html#n54">Tcl typemaps</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n15">Tcl8.0 features</a> (10 SWIG and Tcl)<br>
-<a href="Library.html#n11">tclsh.i</a> (4 Multiple files and the SWIG library)<br>
-<a href="SWIG.html#n53">Templates</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n74">The #if directive</a> (3 SWIG Basics)<br>
-<a href="Exceptions.html#n1">The %except directive</a> (7 Exception Handling)<br>
-<a href="Library.html#n2">The %extern directive</a> (4 Multiple files and the SWIG library)<br>
-<a href="Library.html#n3">The %import directive</a> (4 Multiple files and the SWIG library)<br>
-<a href="Library.html#n1">The %include directive</a> (4 Multiple files and the SWIG library)<br>
-<a href="Python.html#n34">The C++ code</a> (9 SWIG and Python)<br>
-<a href="Extending.html#n21">The DataType class</a> (12 Extending SWIG)<br>
-<a href="Documentation.html#n14">The Final Word?</a> (5 Documentation System)<br>
-<a href="SWIG.html#n58">The future of C++ and SWIG</a> (3 SWIG Basics)<br>
-<a href="Extending.html#n13">The Future of SWIG</a> (12 Extending SWIG)<br>
-<a href="Python.html#n13">The gory details of shadow classes</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n15">The gory details on shadow classes</a> (8 SWIG and Perl5)<br>
-<a href="Extending.html#n29">The header file</a> (12 Extending SWIG)<br>
-<a href="Typemaps.html#n19">The idea (in a nutshell)</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Extending.html#n4">The Language class (simple version)</a> (12 Extending SWIG)<br>
-<a href="Python.html#n3">The low-level Python/C interface</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n33">The MATLAB engine interface</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n4">The object oriented interface</a> (10 SWIG and Tcl)<br>
-<a href="Extending.html#n16">The organization of this chapter</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n76">The output of SWIG</a> (3 SWIG Basics)<br>
-<a href="Tcl.html#n71">The step-by-step process for making a plugin extension.</a> (10 SWIG and Tcl)<br>
-<a href="Extending.html#n23">The String Class</a> (12 Extending SWIG)<br>
-<a href="Introduction.html#n14">The swig command</a> (1 Introduction)<br>
-<a href="SWIG.html#n82">The SWIG interface file</a> (3 SWIG Basics)<br>
-<a href="Library.html#n5">The SWIG library</a> (4 Multiple files and the SWIG library)<br>
-<a href="Extending.html#n42">The SWIG library and installation issues</a> (12 Extending SWIG)<br>
-<a href="Introduction.html#n4">The SWIG package</a> (1 Introduction)<br>
-<a href="Typemaps.html#n2">The SWIG Pointer Library</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Advanced.html#n6">The SWIG runtime library</a> (11 Advanced Topics)<br>
-<a href="Python.html#n70">The this pointer</a> (9 SWIG and Python)<br>
-<a href="Scripting.html#n1">The two language view of the world</a> (2 Scripting Languages)<br>
-<a href="Extending.html#n26">The typemap C API.</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n65">The use of id</a> (3 SWIG Basics)<br>
-<a href="Library.html#n16">The world's fastest way to write a Makefile</a> (4 Multiple files and the SWIG library)<br>
-<a href="Extending.html#n25">The WrapperFunction class</a> (12 Extending SWIG)<br>
-<a href="Documentation.html#n5">Titles, sections, and subsections</a> (5 Documentation System)<br>
-<a href="Tcl.html#n69">Turning a SWIG module into a Tcl Package.</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n44">Turning Perl references into C pointers</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n69">Two classes</a> (9 SWIG and Python)<br>
-<a href="Advanced.html#n9">Type casting</a> (11 Advanced Topics)<br>
-<a href="Advanced.html#n8">Type equivalence</a> (11 Advanced Topics)<br>
-<a href="SWIG.html#n26">Typedef</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n36">Typedef and structures</a> (3 SWIG Basics)<br>
-<a href="Typemaps.html#n12">Typemap examples</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Typemaps.html#n35">Typemap matching rules</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Perl5.html#n39">Typemap variables</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n56">Typemap variables</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n55">Typemap variables</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n11">Typemaps</a> (10 SWIG and Tcl)<br>
-<a href="Extending.html#n6">Typemaps (from C)</a> (12 Extending SWIG)<br>
-<a href="Typemaps.html#n14">Typemaps and the future</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Typemaps.html#n10">Typemaps and the SWIG Library</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Typemaps.html#n9">Typemaps for handling arrays</a> (6 Pointers, Constraints, and Typemaps)<br></blockquote>
-<h2> - U - </h2>
-<blockquote>
-
-<a href="Python.html#n38">Use Python for control, C for performance</a> (9 SWIG and Python)<br>
-<a href="Python.html#n51">Use static linking</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n61">Useful functions</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n45">Useful functions</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n63">Useful Functions</a> (9 SWIG and Python)<br>
-<a href="Python.html#n36">Using our new module</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n20">Using a dynamic module</a> (10 SWIG and Tcl)<br>
-<a href="Extending.html#n49">Using a new documentation module</a> (12 Extending SWIG)<br>
-<a href="Typemaps.html#n24">Using different names</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Python.html#n50">Using dynamic loading</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n24">Using NMAKE</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n26">Using NMAKE</a> (10 SWIG and Tcl)<br>
-<a href="Python.html#n21">Using NMAKE</a> (9 SWIG and Python)<br>
-<a href="Typemaps.html#n20">Using some typemaps</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Python.html#n43">Using the gd module</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n51">Using the OpenGL module</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n72">Using the plugin</a> (10 SWIG and Tcl)<br>
-<a href="Exceptions.html#n6">Using The SWIG exception library</a> (7 Exception Handling)<br>
-<a href="Python.html#n60">Using typemaps to return arguments</a> (9 SWIG and Python)<br>
-<a href="Perl5.html#n42">Using typemaps to return values</a> (8 SWIG and Perl5)<br>
-<a href="Python.html#n18">Using your module</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n24">Using [incr Tcl] namespaces</a> (10 SWIG and Tcl)<br></blockquote>
-<h2> - V - </h2>
-<blockquote>
-
-<a href="Python.html#n24">Variable Linking</a> (9 SWIG and Python)<br>
-<a href="Scripting.html#n8">Variable linking</a> (2 Scripting Languages)<br>
-<a href="SWIG.html#n20">Variables</a> (3 SWIG Basics)<br></blockquote>
-<h2> - W - </h2>
-<blockquote>
-
-<a href="Perl5.html#n50">What gets created?</a> (8 SWIG and Perl5)<br>
-<a href="Extending.html#n27">What happens on typemap lookup?</a> (12 Extending SWIG)<br>
-<a href="SWIG.html#n25">What happens when SWIG encounters an unknown datatype?</a> (3 SWIG Basics)<br>
-<a href="Python.html#n54">What is a typemap?</a> (9 SWIG and Python)<br>
-<a href="Tcl.html#n53">What is a typemap?</a> (10 SWIG and Tcl)<br>
-<a href="Typemaps.html#n31">What is a typemap?</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Introduction.html#n1">What is SWIG?</a> (1 Introduction)<br>
-<a href="SWIG.html#n85">What to do with main()</a> (3 SWIG Basics)<br>
-<a href="Preface.html#n5">What's new?</a> (Preface)<br>
-<a href="Python.html#n33">Where to go for more information</a> (9 SWIG and Python)<br>
-<a href="Extending.html#n50">Where to go for more information</a> (12 Extending SWIG)<br>
-<a href="Perl5.html#n16">Where to go from here?</a> (8 SWIG and Perl5)<br>
-<a href="Advanced.html#n10">Why a name based approach?</a> (11 Advanced Topics)<br>
-<a href="Advanced.html#n5">Why doesn't C++ inheritance work between modules?</a> (11 Advanced Topics)<br>
-<a href="SWIG.html#n83">Why use separate interface files?</a> (3 SWIG Basics)<br>
-<a href="Python.html#n30">Why write shadow classes in Python?</a> (9 SWIG and Python)<br>
-<a href="Scripting.html#n6">Will adding a scripting language to my C program make it unmanagable?</a> (2 Scripting Languages)<br>
-<a href="Scripting.html#n5">Will scripting languages make my C program inefficient?</a> (2 Scripting Languages)<br>
-<a href="Library.html#n8">Working with library files</a> (4 Multiple files and the SWIG library)<br>
-<a href="SWIG.html#n86">Working with the C preprocessor</a> (3 SWIG Basics)<br>
-<a href="SWIG.html#n80">Wrapper code blocks</a> (3 SWIG Basics)<br>
-<a href="Scripting.html#n7">Wrapper functions</a> (2 Scripting Languages)<br>
-<a href="Python.html#n7">Wrapping a C library</a> (9 SWIG and Python)<br>
-<a href="Library.html#n14">Wrapping a library file</a> (4 Multiple files and the SWIG library)<br>
-<a href="Perl5.html#n10">Wrapping C libraries and other packages</a> (8 SWIG and Perl5)<br>
-<a href="Tcl.html#n46">Wrapping gl.h</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n47">Wrapping glu.h</a> (10 SWIG and Tcl)<br>
-<a href="Tcl.html#n48">Wrapping the aux library</a> (10 SWIG and Tcl)<br>
-<a href="Perl5.html#n34">Wrapping the MATLAB matrix functions</a> (8 SWIG and Perl5)<br>
-<a href="Extending.html#n19">Writing a main program</a> (12 Extending SWIG)<br>
-<a href="Tcl.html#n64">Writing a main program and Tcl_AppInit()</a> (10 SWIG and Tcl)<br>
-<a href="Extending.html#n48">Writing a new documentation module</a> (12 Extending SWIG)<br>
-<a href="Extending.html#n10">Writing a Real Language Module</a> (12 Extending SWIG)<br>
-<a href="Typemaps.html#n6">Writing new typemaps</a> (6 Pointers, Constraints, and Typemaps)<br>
-<a href="Extending.html#n41">Writing the default typemaps</a> (12 Extending SWIG)<br>
-<a href="Typemaps.html#n8">Writing typemap code</a> (6 Pointers, Constraints, and Typemaps)<br></blockquote>
-
-<p><hr>
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:47:18 1997 </address>
-</body>
-</html> \ No newline at end of file
diff --git a/swigweb/Doc1.1/HTML/Introduction.html b/swigweb/Doc1.1/HTML/Introduction.html
deleted file mode 100644
index 98cfce9f0..000000000
--- a/swigweb/Doc1.1/HTML/Introduction.html
+++ /dev/null
@@ -1,323 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Introduction</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>1 Introduction</h1><p><ul>
-<li> <a href="#n1">What is SWIG?</a>
-<li> <a href="#n2">Life before SWIG</a>
-<li> <a href="#n3">Life after SWIG</a>
-<li> <a href="#n4">The SWIG package</a>
-<li> <a href="#n5">A SWIG example</a>
-<li> <a href="#n6">C syntax, but not a C compiler</a>
-<li> <a href="#n7">Non-intrusive interface building</a>
-<li> <a href="#n8">Hands off code generation</a>
-<li> <a href="#n9">Event driven C programming</a>
-<li> <a href="#n10">Automatic documentation generation</a>
-<li> <a href="#n11">Summary</a>
-<li> <a href="#n12">SWIG for Windows and Macintosh</a>
-</ul>
-
-<a name="n1"></a><h2> What is SWIG?</h2>
-SWIG is a code development tool that makes it possible to quickly build powerful scripting language interfaces to C, C++, or Objective-C programs. In a nutshell, SWIG is a compiler that takes C declarations and turns them into the "glue" needed to access them from common scripting languages including Perl, Python, and Tcl. SWIG usually requires no modifications to existing C code and can often be used to build a working interface in a matter of minutes. This makes it possible to do a number of interesting things including :<p>
-<p>
-<ul>
-<li>Building powerful interfaces to existing C programs.
-<li>Rapid prototyping and application development.
-<li>Interactive debugging.
-<li>Making a graphical user interface (using Tk for example).
-<li>Powerful testing of C libraries and programs (using scripts).
-<li>Building high performance C modules for scripting languages.
-<li>Making C programming more enjoyable (or tolerable depending on your point of view)
-<li>Impressing your friends.
-</ul>
-<p>
-There are some computer scientists who seem to believe that the only way to solve complicated problems is to create software of epic proportions and to have some sort of "grand" software design. Unfortunately this seems to lead to solutions that are even more complicated than the original problem. This, in turn enables the user to forget about the original problem and spend their time cursing at their machine (hence, the term "enabling technology"). SWIG, on the other hand, was developed because I was fed up with how much time I was wasting trying to develop flexible scientific applications. I wanted a tool that would let me use scripting languages to glue different things together, but didn't get in the way of the real problems I was working on. I wanted a simple tool that scientists and engineers could use to put together applications involving number crunching, data analysis, and visualization without having to worry about tedious systems programming, making substantial modifications to existing code, trying to figure out a big monolithic computing "environment," or having to get a second degree in computer science. In short, I wanted to have a tool that would improve application development, but stay out of the way as much as possible.<p>
-<a name="n2"></a><h2> Life before SWIG</h2>
-SWIG was developed to make my life easier as a C programmer. While C is great for high performance and systems programming, trying to make an interactive and highly flexible C program is a nightmare (in fact, it's much worse than that). The real problem is that for every C program I wrote, I needed to have some sort of interface, but being more interested in other problems, I would always end up writing a really bad interface that was hard to extend, hard to modify, and hard to use. I suppose I could have tried to do something fancy using X11, but who has time to waste weeks or months trying to come up with an interface that is probably going to end up being larger than the original C code? There are more interesting problems to work on.<p>
-<p>
-The real problem, perhaps, is that most C programs end up being structured as follows :<p>
-<p>
-<ul>
-<li>A collection of functions and variables.
-<li>A <tt>main()</tt> program that starts everything up.
-<li>A bunch of hacks added to make it usable.
-</ul>
-<p>
-The <tt>main()</tt> program may be written to handle command line arguments or to read data from <tt>stdin</tt>, but either way, modifying or extending the program to do something new requires changing the C code, recompiling, and testing. If you make a mistake, you need to repeat this cycle until things work. Of course, as more and more features are added, your C program turns into a hideous unintelligible mess that is even more difficult to modify than it was before (Of course, if you're lucky, your project starts out as an unintelligible mess).<p>
-<a name="n3"></a><h2> Life after SWIG</h2>
-With SWIG, I was hoping to avoid many of the headaches of working with C programs, by structuring things as follows :<p>
-<p>
-<ul>
-<li>A collection of functions and variables.
-<li>A nice interpreted interface language that can be used to access everything.
-</ul>
-<p>
-With this model, you keep all of the functionality of your C program, but access it through a scripting language interface instead of writing more C code. This is nice because you are given full freedom to call functions in any order, access variables, and write scripts to do all sorts of interesting things. If you want to change something, just modify a script, and rerun it. If you're trying to debug a collection of functions, you can call them individually and see what they do. If you're trying to build a package out of various components, you can just glue everything together with a scripting language and have a common interface to all of the various pieces. <p>
-<p>
-SWIG tries to make the integration between scripting languages and C as painless as possible. This allows you to focus on the underlying C program and using the high-level scripting language interface, but not the tedious and complex chore of making the two languages talk to each other.<p>
-<p>
-I like this model of programming. While it's certainly no "silver-bullet", it has made programming alot more enjoyable and has enabled us to solve complicated problems that would have been unneccessarily difficult using only C.<p>
-<a name="n4"></a><h2> The SWIG package</h2>
-SWIG is a compiler that takes ANSI C declarations and turns them into a file containing the C code for binding C functions, variables, and constants to a scripting language (SWIG also supports C++ class and Objective-C interface definitions). Input is specified in the form of an "interface file" containing declarations (input can also be given from C source files provided they are sufficiently clean). The SWIG parser takes this input file and passes it on to a code generation and documentation module. These modules produce an interface for a particular scripting language along with a document describing the interface that was created. Different scripting languages are supported by writing new back-end modules to the system.<p>
-<p><center><img src="ch1.1.png"></center><p>
-<p>
-<a name="n5"></a><h2> A SWIG example</h2>
-The best way to illustrate SWIG is with a simple example. Consider the following C code: <p>
-<p>
-<blockquote><pre>/* File : example.c */
-
-double My_variable = 3.0;
-
-/* Compute factorial of n */
-int fact(int n) {
- if (n &lt;= 1) return 1;
- else return n*fact(n-1);
-}
-
-/* Compute n mod m */
-int my_mod(int n, int m) {
- return(n % m);
-}
-</pre></blockquote>
-<p>
-Suppose that you wanted to access these functions and the global variable <tt>My_variable</tt> from Tcl. We start by making a SWIG interface file as shown below (by convention, these files carry a .i suffix) : <p>
-<a name="n13"></a><h3> SWIG interface file</h3>
-<blockquote><pre>
-/* File : example.i */
-%module example
-%{
-/* Put headers and other declarations here */
-%}
-
-extern double My_variable;
-extern int fact(int);
-extern int my_mod(int n, int m);
-</pre></blockquote>
-<p>
-The interface file contains ANSI C function prototypes and variable declarations. The <tt>%module</tt> directive defines the name of the module that will be created by SWIG. The <tt>%{,%}</tt> block provides a location for inserting additional code such as C header files or additional C functions. <p>
-<a name="n14"></a><h3> The swig command</h3>
-SWIG is invoked using the <tt>swig</tt> command. We can use this to build a Tcl module (under Linux) as follows :<p>
-<p>
-<blockquote><pre>unix &gt; swig -tcl example.i
-Generating wrappers for Tcl.
-unix &gt; gcc -c -fpic example.c example_wrap.c -I/usr/local/include
-unix &gt; gcc -shared example.o example_wrap.o -o example.so
-unix &gt; tclsh
-% load ./example.so
-% fact 4
-24
-% my_mod 23 7
-2
-% expr $My_variable + 4.5
-7.5
-%
-</pre></blockquote>
- <p>
-The <tt>swig</tt> command produced a new file called <tt>example_wrap.c</tt> that should be compiled along with the <tt>example.c</tt> file. Most operating systems and scripting languages now support dynamic loading of modules. In our example, our Tcl module has been compiled into a shared library that can be loaded into Tcl and used. When loaded, Tcl will now have our new functions and variables added to it. Taking a careful look at the file <tt>example_wrap.c</tt> reveals a hideous mess, but fortunately you almost never need to worry about it.<p>
-<a name="n15"></a><h3> Building a Perl5 module</h3>
-Now, let's turn these functions into a Perl5 module. Without making any changes type the following (shown for Solaris):<p>
-<p>
-<p>
-<blockquote><pre>unix &gt; swig -perl5 example.i
-Generating wrappers for Perl5
-unix &gt; gcc -c example.c example_wrap.c \
- -I/usr/local/lib/perl5/sun4-solaris/5.003/CORE
-unix&gt; ld -G example.o example_wrap.o -o example.so # This is for Solaris
-unix &gt; perl5.003
-use example;
-print example::fact(4), "\n";
-print example::my_mod(23,7), "\n";
-print $example::My_variable + 4.5, "\n";
-&lt;ctrl-d&gt;
-24
-2
-7.5
-unix &gt;
-</pre></blockquote>
-<a name="n16"></a><h3> Building a Python module</h3>
-Finally, let's build a module for Python1.4 (shown for Irix).<p>
-<p>
-<blockquote><pre>unix &gt; swig -python example.i
-Generating wrappers for Python
-unix &gt; gcc -c example.c example_wrap.c -I/usr/local/include/python1.4
-unix &gt; ld -shared example.o example_wrap.o -o examplemodule.so # Irix
-unix &gt; Python
-Python 1.4 (Sep 10 1996) [GCC 2.7.0]
-Copyright 1991-1996 Stichting Mathematisch Centrum,
-Amsterdam
-&gt;&gt;&gt; import example
-&gt;&gt;&gt; example.fact(4)
-24
-&gt;&gt;&gt; example.my_mod(23,7)
-2
-&gt;&gt;&gt; example.cvar.My_variable + 4.5
-7.5
-</pre></blockquote>
-<a name="n17"></a><h3> Shortcuts</h3>
-To the truly lazy programmer, one may wonder why we needed the extra interface file at all. As it turns out, we can often do without it. For example, we could also build a Perl5 module by just running SWIG on the C source and specifying a module name as follows<p>
-<p>
-<blockquote><pre>% swig -perl5 -module example example.c
-unix &gt; gcc -c example.c example_wrap.c \
- -I/usr/local/lib/perl5/sun4-solaris/5.003/CORE
-unix&gt; ld -G example.o example_wrap.o -o example.so
-unix &gt; perl5.003
-use example;
-print example::fact(4), "\n";
-print example::my_mod(23,7), "\n";
-print $example::My_variable + 4.5, "\n";
-&lt;ctrl-d&gt;
-24
-2
-7.5
-</pre></blockquote>
-<p>
-Of course, there are some restrictions as SWIG is not a full C/C++ parser. If you make heavy use of the C preprocessor, complicated declarations, or C++, giving SWIG a raw source file probably isn't going to work very well (in this case, you would probably want to use a separate interface file). <p>
-<p>
-SWIG also supports a limited form of conditional compilation. If we wanted to make a combination SWIG/C header file, we might do the following :<p>
-<p>
-<blockquote><pre>/* File : example.h */
-#ifdef SWIG
-%module example
-%include tclsh.i
-#endif
-extern double My_variable;
-extern int fact(int);
-extern int my_mod(int n, int m);
-
-</pre></blockquote>
-<a name="n18"></a><h3> Documentation generation</h3>
-In addition to producing an interface, SWIG also produces documentation. For our simple example, the documentation file may look like this :<p>
-<blockquote><pre>
-example_wrap.c
-
-[ Module : example, Package : example ]
-
-$My_variable
- [ Global : double My_variable ]
-
-fact(n);
- [ returns int ]
-
-my_mod(n,m);
- [ returns int ]
-
-get_time();
- [ returns char * ]
-
-</pre></blockquote>
-<p>
-C comments can be used to provide additional descriptions. SWIG can even grab these out of C source files in a variety of ways. For example, if we process <tt>example.c</tt> as follows :<p>
-<p>
-<blockquote><pre>swig -perl5 -Sbefore -module example example.c
-
-</pre></blockquote>
-We will get a documentation file that looks like this (with our C comments added) :<p>
-<blockquote><pre>
-example_wrap.c
-
-[ Module : example, Package : example ]
-
-
-$My_variable
- [ Global : double My_variable ]
-
-fact(n);
- [ returns int ]
- Compute factorial of n
-
-my_mod(n,m);
- [ returns int ]
- Compute n mod m
-
-</pre></blockquote>
-<a name="n19"></a><h3> Building libraries and modules</h3>
-In addition to generating wrapper code, SWIG provides extensive support for handling multiple files and building interface libraries. For example, our <tt>example.i</tt> file, could be used in another interface as follows :<p>
-<p>
-<blockquote><pre>%module foo
-%include example.i // Get definitions from example.i
-
-... Now more declarations ...
-
-</pre></blockquote>
-In a large system, an interface might be built from a variety of pieces like this :<p>
-<p>
-<blockquote><pre>%module package
-
-%include network.i
-%include file.i
-%include graphics.i
-%include objects.i
-%include simulation.i
-
-</pre></blockquote>
-SWIG comes with a library of existing functions known as the SWIG library. The library contains a mix of language independent and language dependent functionality. For example, the file `<tt>array.i</tt>' provides access to C arrays while the file `<tt>wish.i</tt>' includes specialized code for rebuilding the Tcl wish interpreter. Using the library, you can use existing modules to build up your own personalized environment for building interfaces. If changes are made to any of the components, they will appear automatically the next time SWIG is run. <p>
-<a name="n6"></a><h2> C syntax, but not a C compiler</h2>
-SWIG uses ANSI C syntax, but is not a full ANSI C compiler. By using C syntax, I hope to make SWIG easy to use with most C programs, easy to learn, and easy to remember. Other tools tend to use a precise interface definition language, but I personally find this approach to be painful. When I want to build an interface to a collection of several hundred C functions, I don't necessarily want to write a special interface definition for each one. Nor do I want to have to go dig up the manual because I can't remember the syntax.<p>
-<p>
-On the other hand, using C syntax can be ambiguous. For example, if you have the following declaration <p>
-<p>
-<blockquote><pre>int foo(double *a);
-
-</pre></blockquote>
-We don't really know if <tt>a</tt> is an array of some fixed size, a dynamically allocated block of memory, a single value, or an output value of the function. For the most part, SWIG takes a literal approach (<tt>a</tt> is obviously a <tt>double *</tt>) and leaves it up to the user to use the function in a correct manner. Fortunately, there are several ways to help SWIG out using additional directives and "helper" functions. Thus, the input to SWIG is often a mix of C declarations, special directives and hints. Like Perl programming, there is almost always more than one way to do almost anything.<p>
-<p>
-SWIG does not currently parse every conceivable type of C declaration that it might encounter in a C/C++ file. Many things may be difficult or impossible to integrate with a scripting language (C++ templates for example). Thus, SWIG may not recognize advanced C/C++ constructs. I make no apologies for this--SWIG was designed to access C, but was never intended to magically turn scripting languages into some sort of bizarre C++ interpreter. Of course, SWIG's parser is always being improved so currently unsupported features may be supported in later releases.<p>
-<a name="n7"></a><h2> Non-intrusive interface building</h2>
-When used as I intended, SWIG requires minimal modification to existing C code. This makes SWIG extremely easy to use with existing packages, but also promotes software reuse and modularity. By making the C code independent of the high level interface, you can change the interface and reuse the code in other applications. In a similar spirit, I don't believe that there is any one "best" scripting language--use whichever one you like (they're all pretty good). There's no real reason why a particular application couldn't support multiple scripting language interfaces to serve different needs (or to have no scripting language interface at all).<p>
-<a name="n8"></a><h2> Hands off code generation</h2>
-SWIG is designed to produce working code that needs no hand-modification (in fact, if you look at the output, you probably won't want to modify it). Ideally, SWIG should be invoked automatically inside a Makefile just as one would call the C compiler. You should think of your scripting language interface being defined entirely by the input to SWIG, not the resulting output file. While this approach may limit flexibility for hard-core hackers, it allows others to forget about the low-level implementation details. This is my goal.<p>
-<a name="n9"></a><h2> Event driven C programming</h2>
-By adding a scripting language interface to a program, SWIG encourages an event-driven style of programming (although it may not be immediately obvious). An event driven program basically consists of a large-collection of functions (called callback functions), and an infinite loop that just sits and waits for the user to do something. When the user does something like type a command, hit a key, or move the mouse the program will call a function to perform an operation--this is an event. Of course, unless you've been living in cave for the last 20 years, you've used this kind of approach when running any sort of graphical user interface.<p>
-<p>
-While you may not be using SWIG to develop a GUI, the underlying concept is the same. The scripting language acts as an event-loop waiting for you to issue commands. Unlike a traditional C application (that may use command line options), there is no longer a fixed sequence of operations. Functions may be issued in any order and at any time. Of course, this flexibility is exactly what we want! <p>
-<p>
-However, there are a number of things to keep in mind when developing an application with SWIG :<p>
-<p>
-<ul>
-<li>Functions may be called at any time and in any order. It is always a good idea for functions to check their arguments and internal state to see if it's legal to proceed (Not doing so usually results in mysterious crashes later on).
-<li>Code should be structured as a collection of independent modules, not a huge mess of interrelated functions and variables (ie. spaghetti code).
-<li>Global variables should be used with care.
-<li>Careful attention to the naming of variables and functions may be required to avoid namespace conflicts when combining packages.
-</ul>
-<p>
-While it may be hard (or impossible) to address all these problems in a legacy code, I believe that using SWIG encourages all of the above qualities when developing new applications. This results in code that is more reliable, more modular, and easier to integrate into larger packages. By providing a non-intrusive, easy to use tool, it is possible to develop highly reliable event-driven code from the start--not as a hack to be added later. As a final sales pitch, in the initial application for which SWIG was developed, code reliability and flexibility has increased substantially while code size has decreased by more than 25%. I believe this is a good thing.<p>
-<a name="n10"></a><h2> Automatic documentation generation</h2>
-SWIG makes it very easy to build large interactive C programs, but it can sometimes be hard to remember what C functions are available and how they are called in the scripting language interface. To address this problem, SWIG automatically generates a documentation file in a number of different formats. C comments can be used to provide additional descriptions of each function, and documentation can be grouped into a hierarchy of sections and subsections. The documentation file is intended to provide a reasonable description of the scripting language interface. While it's no competition for a full-blown C code documentation generator, the documentation system can do a reasonable job of documenting an interface.<p>
-<a name="n11"></a><h2> Summary</h2>
-At this point, you know about 95% of everything you need to know to start using SWIG. First, functions and variables are specified using ANSI C, C++, or Objective-C syntax. These may appear in a separate interface file or you can use a C source file (if it is sufficiently clean). SWIG requires no modifications to existing C code so it's easy to get started. To build a module, use the <tt>swig</tt> command with an appropriate target language option. This generates a C file that you need to compile with the rest of your code and you're ready to go. <p>
-<p>
-I don't consider there to be a "right" or "wrong" way to use SWIG, although I personally use separate interface files for a variety of reasons :<p>
-<p>
-<ul>
-<li>It helps keep me organized.
-<li>It's usually not necessary to wrap every single C function in a program.
-<li>SWIG provides a number of directives that I tend to use alot.
-<li>Having a special interface file makes it clear where the scripting language interface is defined. If you decide to change something in the interface, it's easy to track down if you have special file.
-</ul>
-<p>
-Of course, your mileage may vary. <p>
-<a name="n12"></a><h2> SWIG for Windows and Macintosh</h2>
-SWIG has been primarily developed and designed to work with Unix-based applications. However, most of the scripting languages supported by SWIG are available on a variety of other platforms including Windows 95/NT and Macintosh. SWIG generated code is mostly compatible with these versions (and SWIG itself can now run on these platforms). <p>
-<a name="n20"></a><h3> SWIG on Windows 95/NT</h3>
-The Windows 95/NT port of SWIG (provided by Kevin Butler), is a straightforward translation of the Unix version. At this time it is only known to work with Microsoft Visual C++ 4.x, but there is nothing to prevent its use with other compilers (at least not that I'm aware of). SWIG should be invoked from the MS-DOS prompt in exactly the same manner as in Unix. SWIG can also be used in NMAKE build files and added to Visual C++ projects under the custom build setting. As of this writing, SWIG is known to work with Windows versions of Tcl/Tk, Python, and Perl (including the ActiveWare Perl for Win32 port). SWIG makes extensive use of long filenames, so it is unlikely that the SWIG compiler will operate correctly under Windows 3.1 or DOS (the wrapper code generated by SWIG may compile however).<p>
-<a name="n21"></a><h3> SWIG on the Power Macintosh</h3>
-A Macintosh port of SWIG is also available, but is highly experimental at this time. It only works on PowerPC based Macintosh systems running System 7 or later. Modules can be compiled with the Metrowerks Code Warrior compiler, but support for other compilers is unknown. Due to the lack of command line options on the Mac, SWIG has been packaged in a Tcl/Tk interface that allows various settings and command line options to be specified with a graphical user interface. Underneath the hood, SWIG is identical to the Unix/Windows version. It recognizes the same set of options and generates identical code. Any SWIG command line option listed in this manual can be given to the Mac version under "Advanced Options" shown in the figure. At this writing, SWIG is only known to support Mac versions of Tcl/Tk. Work on Macintosh versions of Python and Perl is underway.<p>
-<p>Click <a href="ch1.2.png">here</a> to see a Macintosh screen shot.<p>
-<p>
-<p>
-<a name="n22"></a><h3> Cross platform woes</h3>
-While SWIG and various freely available scripting languages are supported on different platforms, developing cross platform applications with these tools is still immature and filled with pitfalls. In fact, it's probably only recommended for true masochists. Despite this, it's interesting to think about using freely available tools to provide common interfaces to C/C++ code. I believe that SWIG may help, but it is by no means a cross-platform solution by itself. <p>
-<a name="n23"></a><h3> How to survive this manual</h3>
-This manual was written to support the Unix version of SWIG. However, all of the main concepts and usage of SWIG also apply to the Windows and Macintosh versions. You should be forewarned that most of the examples are Unix-centric and may not compile correctly on other machines. However, most of the examples provided with the SWIG distribution have now been tested under both Unix and Windows-NT. When applicable, I will try to point out incompatibilities, but make no promises... <p>
-<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:46:50 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Library.html b/swigweb/Doc1.1/HTML/Library.html
deleted file mode 100644
index 93f713f10..000000000
--- a/swigweb/Doc1.1/HTML/Library.html
+++ /dev/null
@@ -1,225 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Multiple Files and the SWIG Library</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>4 Multiple files and the SWIG library</h1><p><ul>
-<li> <a href="#n1">The %include directive</a>
-<li> <a href="#n2">The %extern directive</a>
-<li> <a href="#n3">The %import directive</a>
-<li> <a href="#n4">Including files on the command line</a>
-<li> <a href="#n5">The SWIG library</a>
-<li> <a href="#n6">Library example</a>
-<li> <a href="#n7">Creating Library Files</a>
-<li> <a href="#n8">Working with library files</a>
-<li> <a href="#n9">Static initialization of multiple modules</a>
-<li> <a href="#n10">More about the SWIG library</a>
-</ul>
-
-For increased modularity and convenience, it is usually useful to break an interface specification up into multiple files or modules. SWIG provides a number of features for doing just this.<p>
-<a name="n1"></a><h2> The %include directive</h2>
-The <tt>%include</tt> directive inserts code from another file into the current interface file. It is primarily used to build a package from a collection of smaller modules. For example :<p>
-<p>
-<blockquote><pre>// File : interface.i
-%module package
-%include equations.i
-%include graphics.i
-%include fileio.i
-%include data.i
-%include network.c
-%include "../Include/user.h"
-</pre></blockquote>
-<p>
-When used in this manner, SWIG will create a single wrapper file containing all of the included functions. <p>
-<p>
-The <tt>%include</tt> directive can process SWIG interface files, C header files, and C source files (provided they are sufficiently clean). When processing a C source file, SWIG will automatically declare all functions it finds as "extern". Thus, use of a header file may not be required in this case.<p>
-<a name="n2"></a><h2> The %extern directive</h2>
-The <tt>%extern</tt> directive is like <tt>%include</tt> except that it only scans a file for type and class information. It does not actually wrap anything found in the input file. This directive is primarily used for handling class hierarchies and multiple modules. For example :<p>
-<p>
-<blockquote><pre>%module derived
-%extern baseclass.h // Grab definition of a base class
-
-// Now wrap a derived class
-class Derived : public BaseClass {
-public:
- ...
-};
-
-</pre></blockquote>
-This interface file would grab the member functions and data from a baseclass, but only use them in the specification of a derived class. <tt>%extern</tt> processing of files is also useful for picking up common typedefs and definitions in a large package.<p>
-<a name="n3"></a><h2> The %import directive</h2>
-The <tt>%extern</tt> directive is used to gather declarations from files that you don't want to wrap into an interface. Unfornunately, the exact role of these files is not always clear. They could just contain definitions, or they might correspond to an entrirely different SWIG module. The <tt>%import</tt> directive is a stronger version of <tt>%extern</tt> that tells SWIG that all of the declarations in the file are indeed, in an entirely different module. This information may affect the code generated by various language modules since they will have a better idea of where things are defined and how they are to be used.<p>
-<a name="n4"></a><h2> Including files on the command line</h2>
-Much like the C or C++ compiler, SWIG can also include library files on the command line using the <tt>-l</tt> option as shown<p>
-<p>
-<blockquote><pre>
-# Include a library file at compile time
-% swig -tcl -lwish.i interface.i
-
-</pre></blockquote>
-This approach turns out to be particularly useful for debugging and building extensions to different kinds of languages. When libraries are specified in this manner, they are included after all of the declarations in <tt>interface.i</tt> have been wrapped. Thus, this does not work if you are trying to include common declarations, typemaps, and other files.<p>
-<a name="n5"></a><h2> The SWIG library </h2>
-SWIG comes with a library of functions that can be used to build up more complex interfaces. As you build up a collection of modules, you may also find yourself with a large number of interface files. While the <tt>%include</tt> directive can be used to insert files, it also searches the files installed in the SWIG library (think of this as the SWIG equivalent of the C library). When you use <tt>%include</tt>, SWIG will search for the file in the following order :<p>
-<p>
-<ul>
-<li>The current directory
-<li>Directories specified with the -I option
-<li>.<tt>/swig_lib</tt>
-<li><tt>/usr/local/lib/swig_lib</tt> (or wherever you installed SWIG)
-</ul>
-<p>
-Within each directory, you can also create subdirectories for each target language. If found, SWIG will search these directories first, allowing the creation of language-specific implementations of a particular library file.<p>
-<p>
-You can override the location of the SWIG library by setting the <tt>SWIG_LIB</tt> environment variable.<p>
-<a name="n6"></a><h2> Library example</h2>
-The SWIG library is really a repository of "useful modules" that can be used to build better interfaces. To use a library file, you can simply use the <tt>%include </tt>directive with the name of a library file. For example :<p>
-<p>
-<blockquote><pre>%module example
-
-%include pointer.i // Grab the SWIG pointer library
-
-// a+b --&gt; c
-extern double add(double a, double b, double *c);
-
-</pre></blockquote>
-In this example, we are including the SWIG pointer library that adds functions for manipulating C pointers. These added functions become part of your module that can be used as needed. For example, we can write a Tcl script like this that involves both the <tt>add()</tt> function and two functions from the <tt>pointer.i</tt> library :<p>
-<p>
-<blockquote><pre>set c [ptrcreate double 0] ;# Create a double * for holding the result
-add 4 3.5 $c ;# Call our C function
-puts [ptrvalue $c] ;# Print out the result
-</pre></blockquote>
-<a name="n7"></a><h2> Creating Library Files</h2>
-It is easy to create your own library files. To illustrate the process, we consider two different library files--one to build a new <tt>tclsh</tt> program, and one to add a few memory management functions.<p>
-<a name="n11"></a><h3> tclsh.i</h3>
-To build a new <tt>tclsh</tt> application, you need to supply a <tt>Tcl_AppInit()</tt> function. This can be done using the following SWIG interface file (simplified somewhat for clarity) :<p>
-<blockquote><pre>
-// File : tclsh.i
-%{
-#if TCL_MAJOR_VERSION == 7 &amp;&amp; TCL_MINOR_VERSION &gt;= 4
-int main(int argc, char **argv) {
- Tcl_Main(argc, argv, Tcl_AppInit);
- return(0);
-}
-#else
-extern int main();
-#endif
-int Tcl_AppInit(Tcl_Interp *interp){
- int SWIG_init(Tcl_Interp *);
-
- if (Tcl_Init(interp) == TCL_ERROR)
- return TCL_ERROR;
-
- /* Now initialize our functions */
-
- if (SWIG_init(interp) == TCL_ERROR)
- return TCL_ERROR;
-
- return TCL_OK;
-}
-%}
-</pre></blockquote>
-In this case, the entire file consists of a single code block. This code will be inserted directly into the resulting wrapper file, providing us with the needed <tt>Tcl_AppInit()</tt> function.<p>
-<a name="n12"></a><h3> malloc.i</h3>
-Now suppose we wanted to write a file <tt>malloc.i</tt> that added a few memory management functions. We could do the following :<p>
-<p>
-<blockquote><pre>// File : malloc.i
-%{
-#include &lt;malloc.h&gt;
-%}
-
-%typedef unsigned int size_t
-void *malloc(size_t nbytes);
-void *realloc(void *ptr, size_t nbytes);
-void free(void *);
-</pre></blockquote>
-<p>
-In this case, we have a general purpose library that could be used whenever we needed access to the <tt>malloc()</tt> functions. Since this interface file is language independent, we can use it anywhere.<p>
-<a name="n13"></a><h3> Placing the files in the library</h3>
-While both of our examples are SWIG interface files, they are quite different in functionality since <tt>tclsh.i</tt> would only work with Tcl while <tt>malloc.i</tt> would work with any of the target languages. Thus, we should put these files into the SWIG library as follows :<p>
-<blockquote><pre><tt>
-./swig_lib/malloc.i
-./swig_lib/tcl/tclsh.i
-</tt></pre></blockquote>
-<p>
-When used in other interface files, this allows us to use <tt>malloc.i</tt> with any target language while <tt>tclsh.i</tt> will only be accessible if creating for wrappers for Tcl (ie. when creating a Perl5 module, SWIG will not look in the <tt>tcl</tt> subdirectory.<p>
-<p>
-It should be noted that language specific libraries can mask general libraries. For example, if you wanted to make a Perl specific modification to <tt>malloc.i</tt>, you could make a special version and call it <tt>./swig_lib/perl5/malloc.i</tt>. When using Perl, you'd get this version, while all other target languages would use the general purpose version.<p>
-<a name="n8"></a><h2> Working with library files</h2>
-There are a variety of additional methods for working with files in the SWIG library described next.<p>
-<a name="n14"></a><h3> Wrapping a library file</h3>
-If you would like to wrap a file in the SWIG library, simply give SWIG the name of the appropriate library file on the command line. For example :<p>
-<p>
-<blockquote><pre>unix &gt; swig -python pointer.i
-
-</pre></blockquote>
-If the file <tt>pointer.i</tt> is not in the current directory, SWIG will look it up in the library, generate wrapper code, and place the output in the current directory. This technique can be used to quickly make a module out of a library file regardless of where you are working.<p>
-<a name="n15"></a><h3> Checking out library files</h3>
-At times, it is useful to check a file out of the library and copy it into the working directory. This allows you to modify the file or to simply retrieve useful files. To check a file out of the library, run SWIG as follows :<p>
-<p>
-<blockquote><pre>unix &gt; swig -co -python array.i
-array.i checked out from the SWIG library
-unix &gt;
-
-</pre></blockquote>
-The library file will be placed in the current directory unless a file with the same name already exists (in which case nothing is done). <p>
-<p>
-The SWIG library is not restricted to interface files. Suppose you had a cool Perl script that you liked to use alot. You could place this in the SWIG library. Now whenever you wanted to use it, you could retrieve it by issuing :<p>
-<p>
-<blockquote><pre>unix &gt; swig -perl5 -co myscript.pl
-myscript.pl checked out from the SWIG library
-
-</pre></blockquote>
-Support files can also be checked out within an interface file using the <tt>%checkout</tt> directive.<p>
-<p>
-<blockquote><pre>%checkout myscript.pl
-
-</pre></blockquote>
-This will attempt to copy the file <tt>myscript.pl</tt> to the current directory when SWIG is run. If the file already exists, nothing is done.<p>
-<a name="n16"></a><h3> The world's fastest way to write a Makefile</h3>
-Since the SWIG library is not restricted to SWIG interface files, it can be used to hold other kinds of useful files. For example, if you need a quick Makefile for building Tcl extensions, type the following:<p>
-<blockquote><pre>
-unix&gt; swig -tcl -co Makefile
-Makefile checked out from the SWIG library
-
-</pre></blockquote>
-During installation, SWIG creates a collection of preconfigured Makefiles for various scripting languages. If you need to make a new module, just check out one of these Makefiles, make a few changes, and you should be ready to compile and extension for your system.<p>
-<a name="n17"></a><h3> Checking in library files</h3>
-It is also possible to check files into the SWIG library. If you've made an interesting interface that you would like to keep around, simply type :<p>
-<p>
-<blockquote><pre>unix &gt; swig -ci -python cool.i
-
-</pre></blockquote>
-and the file `<tt>cool.i</tt>' will be placed in the Python section of the library. If your interface file is general purpose, you can install it into the general library as follows :<p>
-<p>
-<blockquote><pre>unix &gt; swig -ci ../cool.i
-
-</pre></blockquote>
-When files are checked in, they are placed into the directory defined by the <tt>SWIG_LIB</tt> variable that was used during SWIG compilation or the <tt>SWIG_LIB</tt> environment variable (if set). If you don't know what the value of this variable is, type the following to display its location.<p>
-<p>
-<blockquote><pre>unix &gt; swig -swiglib
-/usr/local/lib/swig_lib
-unix &gt;
-</pre></blockquote>
-<p>
-In order to check files into the library, you must have write permission on the library directory. For this reason, one of the primary uses for the <tt>-ci</tt> option is to provide a simple mechanism for installing SWIG extensions. If these extensions need to install library files, that can be done by simply running SWIG.<p>
-<a name="n9"></a><h2> Static initialization of multiple modules</h2>
-When using static linking, some language modules allow multiple modules to be initialized as follows :<p>
-<p>
-<blockquote><pre>%module package, equations, graphics, fileio, data, network, user
-
-... More declarations ...
-
-</pre></blockquote>
-The module list can contain SWIG generated modules or third-party applications. Refer to the appropriate language chapter for a detailed description of this feature.<p>
-<a name="n10"></a><h2> More about the SWIG library</h2>
-Full documentation about the SWIG library is included in the SWIG source distribution. In fact, the documentation is automatically generated by SWIG, which leads us to the next section...<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:46:54 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Perl5.html b/swigweb/Doc1.1/HTML/Perl5.html
deleted file mode 100644
index cdcafb857..000000000
--- a/swigweb/Doc1.1/HTML/Perl5.html
+++ /dev/null
@@ -1,1919 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>SWIG and Perl5</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>8 SWIG and Perl5</h1><p><ul>
-<li> <a href="#n1">Preliminaries</a>
-<li> <a href="#n2">Building Perl Extensions under Windows 95/NT</a>
-<li> <a href="#n3">Modules, packages, and classes</a>
-<li> <a href="#n4">Basic Perl interface</a>
-<li> <a href="#n5">A simple Perl example</a>
-<li> <a href="#n6">Accessing arrays and other strange objects</a>
-<li> <a href="#n7">Implementing methods in Perl</a>
-<li> <a href="#n8">Shadow classes</a>
-<li> <a href="#n9">Getting serious</a>
-<li> <a href="#n10">Wrapping C libraries and other packages</a>
-<li> <a href="#n11">Building a Perl5 interface to MATLAB</a>
-<li> <a href="#n12">Handling output values (the easy way)</a>
-<li> <a href="#n13">Exception handling</a>
-<li> <a href="#n14">Remapping datatypes with typemaps</a>
-<li> <a href="#n15">The gory details on shadow classes</a>
-<li> <a href="#n16">Where to go from here?</a>
-</ul>
-
-In this chapter, we discuss SWIG's support of Perl5. While the Perl5 module is one of the earliest SWIG modules, it has continued to evolve and has been improved greatly with the help of SWIG users. For the best results, it is recommended that SWIG be used with Perl5.003 or later. Earlier versions are problematic and SWIG generated extensions may not compile or run correctly.<p>
-<a name="n1"></a><h2> Preliminaries</h2>
-In order for this section to make much sense, you will need to have Perl5.002 (or later) installed on your system. You should also determine if your version of Perl has been configured to use dynamic loading or not. SWIG will work with or without it, but the compilation process will be different.<p>
-<a name="n17"></a><h3> Running SWIG</h3>
-To build a Perl5 module, run swig using the <tt>-perl5</tt> option as follows :<p>
-<blockquote><pre>
-swig -perl5 example.i
-
-</pre></blockquote>
-This will produce 3 files. The first file, <tt>example_wrap.c</tt> contains all of the C code needed to build a Perl5 module. The second file, <tt>example.pm</tt> contains supporting Perl code needed to properly load the module into Perl. The third file will be a documentation file (the exact filename depends on the documentation style). To finish building a module, you will need to compile the file <tt>example_wrap.c</tt> and link it with the rest of your program (and possibly Perl itself). There are several methods for doing this.<p>
-<a name="n18"></a><h3> Getting the right header files</h3>
-In order to compile, you will need to use the following Perl5 header files :<p>
-<blockquote><pre>
-#include "Extern.h"
-#include "perl.h"
-#include "XSUB.h"
-</pre></blockquote>
-<p>
-These are usually located in a directory like this<p>
-<p>
-<blockquote><pre>/usr/local/lib/perl5/arch-osname/5.003/CORE
-</pre></blockquote>
-<p>
-The SWIG configuration script will try to find this directory, but it's not entirely foolproof. You may have to dig around yourself.<p>
-<a name="n19"></a><h3> Compiling a dynamic module</h3>
-To compile a dynamically loadable module, you will need to do something like the following, <p>
-<blockquote><pre>
-% gcc example.c
-% gcc example_wrap.c -I/usr/local/lib/perl5/arch-osname/5.003/CORE
- -Dbool=char -c
-% ld -shared example.o example_wrap.o -o example.so # Irix
-</pre></blockquote>
-<p>
-The name of the shared object file must match the module name used in the SWIG interface file. If you used `<tt>%module example</tt>', then the target should be named `<tt>example.so</tt>', `<tt>example.sl</tt>', or the appropriate name on your system (check the man pages for the linker).<p>
-<p>
-Unfortunately, the process of building dynamic modules varies on every single machine. Both the C compiler and linker may need special command line options. SWIG tries to guess how to build dynamic modules on your machine in order to run its example programs. Again, the configure script isn't foolproof .<p>
-<a name="n20"></a><h3> Building a dynamic module with MakeMaker</h3>
-It is also possible to use Perl to build dynamically loadable modules for you using the MakeMaker utility. To do this, write a simple Perl script such as the following :<p>
-<p>
-<blockquote><pre># File : Makefile.PL
-use ExtUtils::MakeMaker;
-WriteMakefile(
- `NAME' =&gt; `example', # Name of package
- `LIBS' =&gt; [`-lm'], # Name of custom libraries
- `OBJECT' =&gt; `example.o example_wrap.o' # Object files
-);
-
-</pre></blockquote>
-Now, to build a module, simply follow these steps :<p>
-<p>
-<blockquote><pre>% perl Makefile.PL
-% make
-% make install
-</pre></blockquote>
-<p>
-This is the preferred approach if you building general purpose Perl5 modules for distribution. More information about MakeMaker can be found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen, and Randal Schwartz.<p>
-<a name="n21"></a><h3> Building a static version of Perl</h3>
-If you machine does not support dynamic loading, or if you've tried to use it without success, you can build a new version of the Perl interpreter with your SWIG extensions added to it. To build a static extension, you first need to invoke SWIG as follows :<p>
-<p>
-<blockquote><pre>% swig -perl5 -static example.i
-</pre></blockquote>
-<p>
-By default SWIG includes code for dynamic loading, but the <tt>-static</tt> option takes it out.<p>
-<p>
-Next, you will need to supply a <tt>main()</tt> function that initializes your extension and starts the Perl interpreter. While, this may sound daunting, SWIG can do this for you automatically as follows :<p>
-<blockquote><pre>
-%module example
-
-extern double My_variable;
-extern int fact(int);
-
-// Include code for rebuilding Perl
-%include perlmain.i
-</pre></blockquote>
-<p>
-The same thing can be accomplished by running SWIG as follows :<p>
-<p>
-<blockquote><pre>% swig -perl5 -static -lperlmain.i example.i
-
-</pre></blockquote>
-The <tt>permain.i</tt> file inserts Perl's <tt>main()</tt> function into the wrapper code and automatically initializes the SWIG generated module. If you just want to make a quick a dirty module, this may be the easiest way. By default, the <tt>perlmain.i</tt> code does not initialize any other Perl extensions. If you need to use other packages, you will need to modify it appropriately. You can do this by just copying <tt>perlmain.i</tt> out of the SWIG library, placing it in your own directory, and modifying it to suit your purposes.<p>
-<p>
-To build your new Perl executable, follow the exact same procedure as for a dynamic module, but change the link line as follows :<p>
-<blockquote><pre>
-% ld example.o example_wrap.o -L/usr/local/lib/perl5/arch/5.003/CORE \
- -lperl -lsocket -lnsl -lm -o myperl
-</pre></blockquote>
-<p>
-This will produce a new version of Perl called <tt>myperl</tt>. It should be functionality identical to Perl with your C/C++ extension added to it. Depending on your machine, you may need to link with additional libraries such as <tt>-lsocket, -lnsl, -ldl</tt>, etc...<p>
-<a name="n22"></a><h3> Compilation problems and compiling with C++</h3>
-In some cases, you may get alot of error messages about the `<tt>bool</tt>' datatype when compiling a SWIG module. If you experience this problem, you can try the following :<p>
-<p>
-<ul>
-<li>Use <tt>-DHAS_BOOL</tt> when compiling the SWIG wrapper code
-<li>Or use <tt>-Dbool=char</tt> when compiling.
-</ul>
-<p>
-Compiling dynamic modules for C++ is also a tricky business. When compiling C++ modules, you may need to link using the C++ compiler such as :<p>
-<blockquote><pre>
-unix &gt; c++ -shared example_wrap.o example.o -o example.so
-</pre></blockquote>
-<p>
-It may also be necessary to link against the <tt>libgcc.a</tt>, <tt>libg++.a</tt>, and <tt>libstdc++.a</tt> libraries (assuming g++). C++ may also complain about one line in the Perl header file "<tt>perl.h</tt>" and the invalid use of the "explicit" keyword. To work around this problem, put the option <tt>-Dexplicit=</tt> in your compiler flags.<p>
-<p>
-If all else fails, put on your wizard cap and start looking around in the header files. Once you've figured out how to get one module to compile, you can compile just about all other modules.<p>
-<a name="n2"></a><h2> Building Perl Extensions under Windows 95/NT</h2>
-Building a SWIG extension to Perl under Windows 95/NT is roughly similar to the process used with Unix. Normally, you will want to produce a DLL that can be loaded into the Perl interpreter. This section assumes you are using SWIG with Microsoft Visual C++ 4.x although the procedure may be similar with other compilers. SWIG currently supports the ActiveWare Perl for Win32 port and Perl 5.004. If using the ActiveWare version, all Perl extensions must be compiled using C++!<p>
-<a name="n23"></a><h3> Running SWIG from Developer Studio</h3>
-If you are developing your application within Microsoft developer studio, SWIG can be invoked as a custom build option. The process roughly requires these steps :<p>
-<p>
-<ul>
-<li>Open up a new workspace and use the AppWizard to select a DLL project.
-<li>Add both the SWIG interface file (the .i file), any supporting C files, and the name of the wrapper file that will be created by SWIG (ie. <tt>example_wrap.c</tt>). Note : If using C++, choose a different suffix for the wrapper file such as <tt>example_wrap.cxx</tt>. Don't worry if the wrapper file doesn't exist yet--Developer studio will keep a reference to it around.
-<li>Select the SWIG interface file and go to the settings menu. Under settings, select the "Custom Build" option.
-<li>Enter "SWIG" in the description field.
-<li>Enter "<tt>swig -perl5 -o $(ProjDir)\$(InputName)_wrap.cxx $(InputPath)</tt>" in the "Build command(s) field"
-<li>Enter "<tt>$(ProjDir)\$(InputName)_wrap.c</tt>xx" in the "Output files(s) field".
-<li>Next, select the settings for the entire project and go to "C++:Preprocessor". Add the include directories for your Perl 5 installation under "Additional include directories".
-<li>Define the symbols WIN32 and MSWIN32 under preprocessor options. If using the ActiveWare port, also define the symbol PERL_OBJECT. Note that all extensions to the ActiveWare port must be compiled with the C++ compiler since Perl has been encapsulated in a C++ class.
-<li>Finally, select the settings for the entire project and go to "Link Options". Add the Perl library file to your link libraries. For example "perl.lib". Also, set the name of the output file to match the name of your Perl module (ie. example.dll).
-<li>Build your project.
-</ul>
-<p>
-Now, assuming all went well, SWIG will be automatically invoked when you build your project. Any changes made to the interface file will result in SWIG being automatically invoked to produce a new version of the wrapper file. To run your new Perl extension, simply run Perl and use the use command as normal. For example :<p>
-<p>
-<blockquote><pre>
-DOS &gt; perl
-use example;
-$a = example::fact(4);
-print "$a\n";
-
-</pre></blockquote>
-It appears that DLL's will work if they are placed in the current working directory. To make a generally DLL available, it should be place (along with its support files) in the <tt>Lib\Auto\[module] </tt>sub-directory of the Perl directory where [module] is the name of your module.<p>
-<a name="n24"></a><h3> Using NMAKE</h3>
-Alternatively, SWIG extensions can be built by writing a Makefile for NMAKE. To do this, make sure the environment variables for MSVC++ are available and the MSVC++ tools are in your path. Now, just write a short Makefile like this :<p>
-<p>
-<blockquote><pre># Makefile for building an ActiveWare Perl for Win32 extension
-# Note : Extensions must be compiled with the C++ compiler!
-
-SRCS = example.cxx
-IFILE = example
-INTERFACE = $(IFILE).i
-WRAPFILE = $(IFILE)_wrap.cxx
-
-# Location of the Visual C++ tools (32 bit assumed)
-
-TOOLS = c:\msdev
-TARGET = example.dll
-CC = $(TOOLS)\bin\cl.exe
-LINK = $(TOOLS)\bin\link.exe
-INCLUDE32 = -I$(TOOLS)\include
-MACHINE = IX86
-
-# C Library needed to build a DLL
-
-DLLIBC = msvcrt.lib oldnames.lib
-
-# Windows libraries that are apparently needed
-WINLIB = kernel32.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib
-winspool.lib
-
-# Libraries common to all DLLs
-LIBS = $(DLLIBC) $(WINLIB)
-
-# Linker options
-LOPT = -debug:full -debugtype:cv /NODEFAULTLIB /RELEASE /NOLOGO /
-MACHINE:$(MACHINE) -entry:_DllMainCRTStartup@12 -dll
-
-# C compiler flags
-
-CFLAGS = /Z7 /Od /c /W3 /nologo
-
-# Perl 5.004
-PERL_INCLUDE = -Id:\perl5\lib\CORE
-PERLLIB = d:\perl5\lib\CORE\perl.lib
-PERLFLAGS = /DWIN32 /DMSWIN32 /DWIN32IO_IS_STDIO
-
-# ActiveWare
-PERL_INCLUDE = -Id:\perl -Id:\perl\inc
-PERL_LIB = d:\perl\Release\perl300.lib
-PERLFLAGS = /DWIN32 /DMSWIN32 /DPERL_OBJECT
-
-perl::
- ..\..\swig -perl5 -o $(WRAPFILE) $(INTERFACE)
- $(CC) $(CFLAGS) $(PERLFLAGS) $(PERL_INCLUDE) $(SRCS) $(WRAPFILE)
- set LIB=$(TOOLS)\lib
- $(LINK) $(LOPT) -out:example.dll $(LIBS) $(PERLLIB) example.obj
-example_wrap.obj
-</pre></blockquote>
-<p>
-To build the extension, run NMAKE (note that you may be to run <tt>vcvars32</tt> before doing this to set the correct environment variables). This is a simplistic Makefile, but hopefully its enough to get you started. <p>
-<a name="n3"></a><h2> Modules, packages, and classes</h2>
-When you create a SWIG extension, everything gets thrown together into a single Perl5 module. The name of the module is determined by the <tt>%module</tt> directive. To use the module, do the following :<p>
-<p>
-<blockquote><pre>% perl5
-use example; # load the example module
-print example::fact(4),"\n" # Call a function in it
-24
-</pre></blockquote>
-<p>
-Usually, a module consists of a collection of code that is contained within a single file. A package, on the other hand, is the Perl equivalent of a namespace. A package is alot like a module, except that it is independent of files. Any number of files may be part of the same package--or a package may be broken up into a collection of modules if you prefer to think about it in this way.<p>
-<p>
-By default, SWIG installs its functions into a package with the same name as the module. This can be changed by giving SWIG the -package option :<p>
-<p>
-<blockquote><pre>% swig -perl5 -package FooBar example.i
-</pre></blockquote>
-<p>
-In this case, we still create a module called `<tt>example</tt>', but all of the functions in that module will be installed into the package `<tt>FooBar</tt>.' For example :<p>
-<p>
-<blockquote><pre>use example; # Load the module like before
-print FooBar::fact(4),"\n"; # Call a function in package FooBar
-</pre></blockquote>
-<p>
-Perl supports object oriented programming using packages. A package can be thought of as a namespace for a class containing methods and data. The reader is well advised to consult "Programming Perl, 2nd Ed." by Wall, Christiansen, and Schwartz for most of the gory details. <p>
-<a name="n4"></a><h2> Basic Perl interface</h2>
-<a name="n25"></a><h3> Functions</h3>
-C functions are converted into new Perl commands (or subroutines). Default/optional arguments are also allowed. An interface file like this :<p>
-<p>
-<blockquote><pre>%module example
-int foo(int a);
-double bar (double, double b = 3.0);
-...
-
-</pre></blockquote>
-Will be used in Perl like this :<p>
-<p>
-<blockquote><pre>use example;
-$a = &amp;example::foo(2);
-$b = &amp;example::bar(3.5,-1.5);
-$c = &amp;example::bar(3.5); # Use default argument for 2nd parameter
-
-</pre></blockquote>
-Okay, this is pretty straightforward...enough said.<p>
-<a name="n26"></a><h3> Global variables</h3>
-Global variables are handled using pure magic--well, Perl's magic variable mechanism that is. In a nutshell, it is possible to make certain Perl variables "magical" by attaching methods for getting and setting values among other things. SWIG generates a pair of functions for accessing C global variables and attaches them to a Perl variable of the same name. Thus, an interface like this <p>
-<p>
-<blockquote><pre>%module example;
-...
-double Spam;
-...
-
-</pre></blockquote>
-is accessed as follows :<p>
-<p>
-<blockquote><pre>use example;
-print $example::Spam,"\n";
-$example::Spam = $example::Spam + 4
-# ... etc ...
-
-</pre></blockquote>
-SWIG supports global variables of all C datatypes including pointers and complex objects.<p>
-<a name="n27"></a><h3> Constants</h3>
-Constants are created as read-only magical variables and operate in exactly the same manner.<p>
-<a name="n28"></a><h3> Pointers</h3>
-SWIG represents pointers as blessed references. A blessed reference is the same as a Perl reference except that it has additional information attached to it indicating what kind of reference it is. That is, if you have a C declaration like this :<p>
-<p>
-<blockquote><pre>Matrix *new_Matrix(int n, int m);
-</pre></blockquote>
-<p>
-SWIG will return a value as if you had done this :<p>
-<blockquote><pre>
-$ptr = new_Matrix(int n, int m); # Save pointer return result
-bless $ptr, "MatrixPtr"; # Bless it as a MatrixPtr
-</pre></blockquote>
-<p>
-SWIG uses the "blessing" to check the datatype of various pointers. In the event of a mismatch, an error or warning message will be generated.<p>
-<p>
-To check to see if a value is the NULL pointer, use the <tt>defined()</tt> command :<p>
-<blockquote><pre>
-if (defined($ptr)) {
- print "Not a NULL pointer.";
-} else {
- print "Is a NULL pointer.";
-}
-
-</pre></blockquote>
-To create a NULL pointer, you should pass the <tt>undef </tt>value to a function. <p>
-<p>
-The "value" of a Perl reference is not the same as the underlying C pointer that SWIG wrapper functions return. Suppose that <tt>$a</tt> and <tt>$b</tt> are two references that point to the same C object. In general, <tt>$a</tt> and <tt>$b</tt> will be different--since they are different references. Thus, it is a mistake to check the equality of <tt>$a </tt>and <tt>$b</tt> to check the equality of two C pointers. The correct method to check equality of C pointers is to dereference them as follows :<p>
-<p>
-<blockquote><pre>if ($$a == $$b) {
- print "a and b point to the same thing in C";
-} else {
- print "a and b point to different objects.";
-}
-
-</pre></blockquote>
-It is easy to get burned by references in more subtle ways. For example, if you are storing a hash table of objects, it may be best to use the actual C pointer value rather than the Perl reference as a key. Since each Perl reference to the same C object may be different, it would be impossible to find anything in the hash without this. As a general rule, the best way to avoid problems with references is to make sure hash tables, comparisons, and other pointer operations use the value of the reference (ie. <tt>$$a</tt>), not the reference itself.<p>
-<a name="n29"></a><h3> Structures and C++ classes</h3>
-For structures and classes, SWIG produces a set of accessor functions for member functions and member data. For example :<p>
-<p>
-<blockquote><pre>%module vector
-
-class Vector {
-public:
- double x,y,z;
- Vector();
- ~Vector();
- double magnitude();
-};
-
-</pre></blockquote>
-This gets turned into the following collection of Perl functions :<p>
-<blockquote><pre>vector::Vector_x_get($obj);
-vector::Vector_x_set($obj,$x);
-vector::Vector_y_get($obj);
-vector::Vector_y_set($obj,$y);
-vector::Vector_z_get($obj);
-vector::Vector_z_set($obj,$z);
-vector::new_Vector();
-vector::delete_Vector($obj);
-vector::Vector_magnitude($obj);
-
-</pre></blockquote>
-To use the class, simply use these functions. As it turns out, SWIG has a mechanism for creating shadow classes that hides these functions and uses an object oriented interface instead--keep reading.<p>
-<a name="n5"></a><h2> A simple Perl example</h2>
-In the next few sections, use of the Perl5 module will be illustrated through a series of increasingly complex examples. In the example, we will write some simple graph algorithms to illustrate how C and Perl can interact with each other. <p>
-<a name="n30"></a><h3> Graphs</h3>
-A directed graph is simply a collection of nodes (or vertices) that are connected to each other by a collection of edges :<p>
-<p>
-<center><img src="ch8.1.png"></center><p><p>
-<p>
-To represent simple graphs, we can use the following C data structures :<p>
-<p>
-<blockquote><pre>/* File : graph.h */
-/* Simple data structures for directed graph of Nodes and Edges */
-
-struct Edge;
-typedef struct Node {
- int v; /* Vertex number */
- struct Edge *adj; /* Adjacency List */
-} Node;
-
-typedef struct Edge {
- Node *node; /* Connecting Node */
- double w; /* Weight (optional) */
- struct Edge *next; /* Next edge */
-} Edge;
-
-</pre></blockquote>
-Each node contains a unique number v for identifying it, and a linked list of other nodes that are nearby. This linked list is managed by the <tt>Edge</tt> structure. Associated with each edge is an optional weighting factor. This could be something like miles between cities, bandwidth, or some other numerical property about a particular link. Okay, enough talk about data structures for now.<p>
-<p>
-To construct nodes and add edges, we can use the following C code :<p>
-<p>
-<blockquote><pre>/* File : graph.c */
-/* Directed graph functions */
-
-#include "graph.h"
-static int node_count = 0; /* Number of nodes created */
-
-/* Create a new Node */
-Node *new_Node() {
- Node *node;
- node = (Node *) malloc(sizeof(Node));
- node-&gt;v = node_count++; /* Bump up the count */
- node-&gt;adj = (Edge *) 0;
- return node;
-}
-
-/* Add an "edge" to another node. */
-
-Edge *Node_addedge(Node *mynode, Node *othernode, double w) {
- Edge *edge;
- edge = (Edge *) malloc(sizeof(Edge));
- edge-&gt;node = othernode;
- edge-&gt;w = w;
- edge-&gt;next = mynode-&gt;adj; /* add to my adjacency list */
- mynode-&gt;adj = edge;
- return edge;
-}
-
-</pre></blockquote>
-<a name="n31"></a><h3> A simple SWIG interface file</h3>
-So far, the code doesn't do much, but it's enough to wrap into Perl5 module. Since the C code is fairly simple right now, we can do this by creating the following interface file :<p>
-<blockquote><pre>
-%module graph
-%{
-#include "graph.h"
-%}
-%include graph.h // Get structure definition
-%include graph.c // Get support functions
-</pre></blockquote>
-<p>
-We'll call our module "graph" and simply read in both the files <tt>graph.h</tt> and <tt>graph.c</tt> to build an interface. <p>
-<a name="n32"></a><h3> Sample Perl Script</h3>
-Once compiled, we can now start using our new module. All of the C functions found in <tt>graph.h</tt> and <tt>graph.c</tt> can be called normally . Even though we are using pointers, this is not a problem. Here is a very simple script :<p>
-<blockquote><pre>
-# Perl code to use our graph code
-
-use graph;
-package graph;
-
-# Create some nodes
-$n0 = new_Node();
-$n1 = new_Node();
-$n2 = new_Node();
-
-# Make some edges
-Node_addedge($n0,$n1,0); # 0 -&gt; 1
-Node_addedge($n0,$n2,0); # 0 -&gt; 2
-Node_addedge($n1,$n2,0); # 1 -&gt; 2
-Node_addedge($n2,$n0,0); # 2 -&gt; 0
-
-# A procedure to print out a node and its adjacency list
-sub print_node {
- my $node = shift;
- print "Node : ", Node_v_get($node), ", Adj : ";
- my $adj = Node_adj_get($node);
- while (defined($adj)) { # This checks for a NULL pointer
- my $anode = Edge_node_get($adj);
- my $v = Node_v_get($anode);
- print "$v ";
- $adj = Edge_next_get($adj); # Move to next node
- }
- print "\n";
-}
-
-# Print out node information
-print_node($n0);
-print_node($n1);
-print_node($n2);
-
-</pre></blockquote>
-When executed, this script produces the following output :<p>
-<p>
-<blockquote><pre>Node : 0, Adj : 2 1
-Node : 1, Adj : 2
-Node : 2, Adj : 0
-
-</pre></blockquote>
-<p>
-While our two C functions are used in the script, SWIG also created a collection of accessor functions for managing the two C data structures. The functions <tt>Node_v_get()</tt>, <tt>Node_adj_get()</tt>, <tt>Edge_node_get()</tt>, and <tt>Edge_next_get()</tt> are used to access the corresponding members of our <tt>Node</tt> and <tt>Edge</tt> structures. As arguments, these functions simply take a pointer to the corresponding structure.<p>
-<p>
-There are a few other things to notice about the code.<p>
-<p>
-<ul>
-<li>Pointers to complex objects are manipulated like ordinary scalar values, but in reality they are blessed references. For all practical purposes, you should think of them as funny opaque objects (in other words, don't worry about it).
-<li>To check for a NULL pointer, use the expression <tt>defined($ptr)</tt>. This will return true if a pointer is non-NULL, false if it isn't. In our example, we use this to walk down a linked list of pointers until we reach a NULL value.
-</ul>
-<p>
-Even though the original C code was rather useless by itself, we have used it to build a simple graph in Perl along with a debugging function for printing out node information. In fact, without making any modifications to the C code, we can use this to build up something more complex such as a database of cities and mileages. <p>
-<p>
-<em>Some cities and mileages</em><p>
-<p>
-Here's a slightly more complicated Perl script to read in the above mileage table and turn it into a graph:<p>
-<p>
-<blockquote><pre># Read a file with cities into a graph
-
-use graph;
-package graph;
-
-%Cities = (); # Hash table mapping cities to nodes
-%Nodes = (); # Mapping of Node indicies to cities
-sub read_cities {
- my $filename = shift;
- open(CITIES,$filename);
- while (&lt;CITIES&gt;) {
- chop;
- my @a = split(/, +/);
- my $node1;
- my $node2;
- # Check to see if a given city is already a node
- if (!exists $Cities{$a[0]}) {
- $node1 = new_Node();
- $Cities{$a[0]} = $node1;
- my $node_num = Node_v_get($node1);
- $Nodes{$node_num} = $a[0];
- } else {
- $node1 = $Cities{$a[0]};
- }
- if (!exists $Cities{$a[1]}) {
- $node2 = new_Node();
- $Cities{$a[1]} = $node2;
- my $node_num = Node_v_get($node2);
- $Nodes{$node_num} = $a[1];
- } else {
- $node2 = $Cities{$a[1]};
- }
- # Add edges
- Node_addedge($node1,$node2,$a[2]);
- Node_addedge($node2,$node1,$a[2]);
- }
-}
-
-
-
-sub print_near {
- my $city = shift;
- if (exists $Cities{$city}) {
- my $node = $Cities{$city};
- print "Cities near $city : ";
- my $adj = Node_adj_get($node);
- while (defined($adj)) {
- my $anode = Edge_node_get($adj);
- my $v = Node_v_get($anode);
- print $Nodes{$v},", ";
- $adj = Edge_next_get($adj);
- }
- }
- print "\n";
-}
-read_cities("cities");
-print_near("Denver");
-print_near("Las Vegas");
-
-</pre></blockquote>
-This produces the following output :<p>
-<p>
-<blockquote><pre>Cities near Denver : Moab, Kansas City, Santa Fe, Cheyenne, Albuquerque,
-Cities near Las Vegas : Flagstaff, Los Angeles, Moab, Salt Lake City,
-
-</pre></blockquote>
-In this example, we are using the same functions as before, but we are now introducing two Perl hash tables. The <tt>%Cities</tt> hash is used to associate city names with a corresponding node in the graph. The <tt>%Nodes</tt> hash does exactly the opposite---mapping node numbers back to the names of cities. Both of these will come in quite handy for mapping things between the Perl world and the C world later.<p>
-<p>
-Before proceeding, let's stop and summarize what we have done. Given a couple of very simple C data structures for a graph, we have written a program that can read in a mileage table, construct a weighted graph of the data and print out a list of the cities that are nearby other cities. Yet, the C code knows nothing about the Perl interface or this whole mileage program we've built up around it. While we could have written the entire program in C, we would have had to write a main program, some code to read the input file, and a hash table structure to keep track of the mapping between nodes and cities. Perl, on the other hand, is very good at managing these tasks.<p>
-<a name="n6"></a><h2> Accessing arrays and other strange objects</h2>
-Now let's add some new functionality to our graph program from the previous example. In this case, we'll add a depth-first search algorithm to see if two nodes are connected to each other (possibly through many other nodes in-between). <p>
-<p>
-We'll first add the following constants to the file <tt>graph.h</tt><p>
-<blockquote><pre>
-/* File : graph.h */
-...
-#define MAX_NODES 1000
-#define UNSEEN -1
-</pre></blockquote>
-<p>
-Now, a modified version of <tt>graph.c</tt> :<p>
-<p>
-<blockquote><pre>/* File : graph.c */
-/* Directed graph functions */
-
-#include &lt;stdio.h&gt;
-#include "graph.h"
-
-int node_count = 0; /* Number of nodes created */
-int seen[MAX_NODES]; /* Used by the search function */
-
-...
-
-/* Function to search for node with given vertex number */
-static int visit(Node *n,int v) {
- Edge *e;
-
- if (seen[n-&gt;v] != UNSEEN) return UNSEEN; /* Cycle detected */
- if (n-&gt;v == v) return 1; /* Match found */
- e = n-&gt;adj;
- while (e) {
- seen[n-&gt;v] = e-&gt;node-&gt;v;
- if (visit(e-&gt;node,v) &gt; 0) return 1;
- e = e-&gt;next;
- }
- return 0;
-}
-
-
-/* Depth-first search for a given node */
-int Node_search(Node *start, int v) {
- int i;
-
- for (i = 0; i &lt; node_count; i++)
- seen[i] = UNSEEN;
- return visit(start,v);
-}
-
-</pre></blockquote>
-The idea here is simple, the function <tt>Node_search()</tt> takes a starting node and starts looking for a node with given vertex. Upon startup, the search function clears an array of values indicating whether a node has been seen or not. While this array is primarily used to detect cycles, it can also be used to store the path between two nodes as we proceed through the algorithm. Upon exit, we can then use the array to figure out how we got between the starting and ending node. Of course, this leads us to the question of how we access this array in Perl.<p>
-<p>
-As a general rule, handling arrays is somewhat problematic since the mapping between arrays and pointers may not be what you expect (even in C) and there is not necessarily a natural mapping between arrays in C and arrays in Perl (for example, if we've got a C array with 1 million elements in it, we almost certainly wouldn't want to convert it to a Perl array!).<p>
-<p>
-To access our array, we will write a C helper function that allows us to access invidual elements. However, rather than adding this function to the C code, we can insert it directly into our SWIG interface file. We will also strip the function names out of the <tt>.c</tt> file and put their prototypes in the header file : <p>
-<p>
-<blockquote><pre>%module graph
-%{
-#include "graph.h"
-%}
-%include graph.h
-
-%inline %{
-/* Get seen value for a particular node */
-int get_seen(int index) {
- extern int node_count;
- extern int seen[];
- if ((index &lt; 0) || (index &gt;= node_count)) return -1;
- else return seen[index];
-}
-%}
-</pre></blockquote>
-<p>
-This interface file illustrates one of the key points about SWIG--even though SWIG uses C syntax, wrapping arbitrary C code doesn't always result in a good interface. Almost any significant package will require the use of a few "helper" functions to get at certain data structures or to change the way in which a function is called. <p>
-<p>
-With our new C search function, we can now write a Perl function to find a route between two cities. This function simply takes the names of two cities, uses the <tt>Cities</tt> hash to look up their nodes and calls the C <tt>Node_search()</tt> function. Afterwards, we walk through the <tt>seen[]</tt> array using our helper function and print the route.<p>
-<blockquote><pre>
-sub find_route {
- my $start = shift;
- my $dest = shift;
- # Lookup nodes from names
- if ((!exists $Cities{$start}) || (!exists $Cities{$dest})) {
- return;
- }
- my $node1 = $Cities{$start};
- my $node2 = $Cities{$dest};
- print "$start --&gt; $dest :\n";
-
- # Depth first search for a route between cities
- my $found = Node_search($node1,Node_v_get($node2));
- if ($found) {
- $v = Node_v_get($node1);
- while ($v != $UNSEEN) {
- print " $Nodes{$v}\n";
- $v = get_seen($v);
- }
- } else {
- print " You can't get there from here\n";
- }
-}
-
-read_cities("cities");
-find_route("Salt Lake City","Denver");
-</pre></blockquote>
-<p>
-Of course, depth first search isn't very good at finding an optimal route---obviously this output must be the very scenic route!<p>
-<p>
-<blockquote><pre>Salt Lake City --&gt; Denver :
- Salt Lake City
- Twin Falls
- Boise
- Portland
- Eugene
- San Francisco
- Los Angeles
- Las Vegas
- Flagstaff
- Albuquerque
- Santa Fe
- Durango
- Moab
- Denver
-</pre></blockquote>
-<a name="n7"></a><h2> Implementing methods in Perl</h2>
-Obviously, our depth search algorithm isn't so useful in this specific application. Perhaps we would like to try a breadth-first search algorithm instead. We could choose to write it in C, but the breadth first search algorithm depends on the use of a queue to hold the list of nodes to visit. Thus, we'd have to write a queue data structure first. However, a Perl array smells alot like a queue if we manipulate it in the right way. So we can use Perl to come up with a quick and dirty breadth first search without dropping down into C :<p>
-<p>
-<blockquote><pre>%visit = ();
-sub breadth_search {
- my $node1 = shift;
- my $node2 = shift;
- my @queue;
- %visit = ();
- # Put starting node into queue
- push @queue, $node1;
- $visit{Node_v_get($node1)} = Node_v_get($node1);
- while (@queue) { # Loop until queue is empty
- my $n = shift @queue; # Pop off an node
- my $nv = Node_v_get($n);
- return 1 if ($$n == $$node2); # Exit if we found the destination
- # Put children onto the queue
- my $e = Node_adj_get($n);
- while (defined($e)) {
- my $m = Edge_node_get($e);
- my $v = Node_v_get($m);
- if (!exists $visit{$v}) {
- push @queue, $m;
- $visit{$v} = $nv;
- }
- $e = Edge_next_get($e);
- }
- }
- return 0;
-}
-
-sub find_route {
- my $start = shift;
- my $dest = shift;
- # Lookup nodes from names
- return if ((!exists $Cities{$start}) || (!exists $Cities{$dest}));
- print "$start --&gt; $dest :\n";
- my $node1 = $Cities{$start};
- my $node2 = $Cities{$dest};
- my $found = breadth_search($node1,$node2);
- my @path;
- if ($found) {
- my $v = Node_v_get($node2);
- delete $visit{Node_v_get($node1)};
- while (exists($visit{$v})) {
- unshift @path,$Nodes{$v};
- $v = $visit{$v};
- }
- unshift @path,$start;
- foreach $c (@path) { print " $c\n";}
- } else {
- print " You can't get there from here\n";
- }
-}
-</pre></blockquote>
-<p>
-Our Perl implementation creates a queue using an array and manipulating it with shift and push operations. The global hash <tt>%visit</tt> is used to detect cycles and to determine how we got to each node. When we find a route, we can march backwards through the route to determine the entire path. When we run our new code, we get the following :<p>
-<p>
-<blockquote><pre>find_route("Salt Lake City", "Denver");
-Salt Lake City --&gt; Denver :
- Salt Lake City
- Cheyenne
- Denver
-
-</pre></blockquote>
-Clearly this is a more efficient route--although admittedly not very scenic. If we wanted to get even more serious, we could add a priority search based on mileages. Later on we might implement these features in C for better performance. Either way, it is reasonably easy to manipulate complex structures in Perl and to mix them with C code (well, with a little practice perhaps). <p>
-<a name="n8"></a><h2> Shadow classes</h2>
-By now, you've probably noticed that examples have been using alot of accessor functions to get at the members of our <tt>Node</tt> and <tt>Edge</tt> structures. This tends to make the Perl code look rather cluttered (well, more than normal Perl code in any case) and it isn't very object oriented.<p>
-<p>
-With a little magic, SWIG can turn C structs and C++ classes into fully functional Perl classes that work in a more-or-less normal fashion. This transformation is done by writing an additional Perl layer that builds Perl classes on top of the low-level SWIG interface. These Perl classes are said to "shadow" an underlying C/C++ class. <p>
-<p>
-To have SWIG create shadow classes, use the <tt>-shadow </tt>option :<p>
-<p>
-<blockquote><pre>% swig -perl5 -shadow graph.i
-</pre></blockquote>
-<p>
-This will produce the same files as before except that the <tt>.pm</tt> file will now contain significantly more supporting Perl code. While there are some rather subtle aspects of this transformation, for now we'll omit the details and illustrate the changes in an example first (the use of shadow classes has been underlined)<p>
-<p>
-<blockquote><pre># Read a file with cities into a graph
-# Uses shadow classes
-
-use graph;
-package graph;
-
-%Cities = (); # Hash table mapping cities to nodes
-%Nodes = (); # Mapping of Node indicies to cities
-
-sub read_cities {
- my $filename = shift;
- open(CITIES,$filename);
- while (&lt;CITIES&gt;) {
- chop;
- my @a = split(/, +/);
- my $node1;
- my $node2;
- # Check to see if a given city is already a node
- if (!exists $Cities{$a[0]}) {
- $node1 = new_Node();
- $Cities{$a[0]} = $node1;
- $Nodes{$node1-&gt;{v}} = $a[0]; # Note access of `v'
- } else {
- $node1 = $Cities{$a[0]};
- }
- if (!exists $Cities{$a[1]}) {
- $node2 = new_Node;
- $Cities{$a[1]} = $node2;
- $Nodes{$node2-&gt;{v}} = $a[1];
- } else {
- $node2 = $Cities{$a[1]};
- }
- # Add edges
- Node_addedge($node1,$node2,$a[2]);
- Node_addedge($node2,$node1,$a[2]);
- }
-}
-
-%visit;
-sub breadth_search {
- my $node1 = shift;
- my $node2 = shift;
- my @queue;
- %visit = ();
- my $dest = $node2-&gt;{v};
- # Put starting node into queue
- push @queue, $node1;
- $visit{$node1-&gt;{v}} = $node1-&gt;{v};
- while (@queue) {
- my $n = shift @queue;
- return 1 if ($n-&gt;{v} == $node2-&gt;{v});
- # Put children onto the queue
- my $e = $n-&gt;{adj};
- while (defined($e)) {
- if (!exists $visit{$e-&gt;{node}-&gt;{v}}) {
- push @queue, $e-&gt;{node};
- $visit{$e-&gt;{node}-&gt;{v}} = $n-&gt;{v};
- }
- $e = $e-&gt;{next};
- }
- }
- return 0;
-}
-
-sub find_route {
- my $start = shift;
- my $dest = shift;
- # Lookup nodes from names
- return if ((!exists $Cities{$start}) || (!exists $Cities{$dest}));
- print "$start --&gt; $dest :\n";
- my $node1 = $Cities{$start};
- my $node2 = $Cities{$dest};
- my $found = breadth_search($node1,$node2);
- my @path;
- if ($found) {
- my $v = $node2-&gt;{v};
- delete $visit{$node1-&gt;{v}};
- while (exists($visit{$v})) {
- unshift @path,$Nodes{$v};
- $v = $visit{$v};
- }
- unshift @path,$start;
- foreach $c (@path) {
- print " $c\n";
- }
- } else {
- print " You can't get there from here\n";
- }
-}
-read_cities("cities");
-
-find_route("Salt Lake City","Denver");
-</pre></blockquote>
-<p>
-For the most part, the code is the same except that we can now access members of complex data structures using <tt>-&gt;</tt> instead of the low level accessor functions. like before. However, this example is only scratching the surface of what can be done with shadow classes...keep reading.<p>
-<a name="n9"></a><h2> Getting serious</h2>
-Now that we've got a very simple example working, it's time to get really serious. Suppose that in addition to working with the mileage data of various cities, we want to make a graphical representation from geographical data (lattitude/longitude). To do this, we'll use SWIG to glue together a bunch of stuff. First, for the purposes of illustration, let's create a new C data structure for holding a geographical location with the assumption that we might want to use it in some C functions later :<p>
-<p>
-<blockquote><pre>/* File : location.h */
-/* Data structure for holding longitude and lattitude information */
-
-typedef struct Location {
- char *name;
- double lat_degrees;
- double lat_minutes;
- double lat_seconds;
- char lat_direction;
- double long_degrees;
- double long_minutes;
- double long_seconds;
- char long_direction;
-} Location;
-
-extern Location *new_Location(char *name);
-
-</pre></blockquote>
-We also probably want a C function for creating one of these objects:<p>
-<p>
-<blockquote><pre>/* File : location.c */
-#include &lt;string.h&gt;
-
-/* Make a new location */
-Location *new_Location(char *name) {
- Location *l;
- l = (Location *) malloc(sizeof(Location));
- l-&gt;name = (char *) malloc(strlen(name)+1);
- strcpy(l-&gt;name,name);
- return l;
-}
-</pre></blockquote>
-<p>
-Now let's make an interface file for this module :<p>
-<blockquote><pre>
-// File : location.i
-%module location
-%{
-#include "location.h"
-%}
-
-%include location.h
-
-</pre></blockquote>
-We could use this interface file to make an entirely new Perl5 module or we can combine it with the graph module. In this latter case, we simply need to put "<tt>%include location.i</tt>" in the file <tt>graph.i</tt>.<p>
-<p>
-Now, finally, we could write a Perl function to read data in the following format :<p>
-<p>
-<em>Geographic data</em><p>
-<blockquote><pre>sub read_locations {
- my $filename = shift;
- open(LOCATIONS,$filename);
- while (&lt;LOCATIONS&gt;) {
- chop;
- my @a = split(/, +/);
- my $loc;
- # Check to see if this is a city I know about
- if (exists $Cities{$a[0]}) {
- # Create a new location
- $loc = new_Location($a[0]);
- my @coords = split(' ',$a[1]);
- # A nice way to assign attributes to an object
- %$loc = (lat_degrees =&gt; $coords[0],
- lat_minutes =&gt; $coords[1],
- lat_seconds =&gt; $coords[2],
- lat_direction =&gt; $coords[3],
- long_degrees =&gt; $coords[4],
- long_minutes =&gt; $coords[5],
- long_seconds =&gt; $coords[6],
- long_direction =&gt; $coords[7]);
- my $v = $Cities{$a[0]}-&gt;{v};
- $Locations{$v} = $loc;
- }
- }
- close LOCATIONS;
-}
-</pre></blockquote>
-Again, we are using shadow classes which are allowing us to assign all of the attributes of a C structure in the same way as one would create a Perl hash table. We have also created the <tt>%Locations</tt> hash to associate node numbers with a given location object.<p>
-<p>
-Of course, having locations isn't too useful without a way to look at them so we'll grab the public domain <tt>gd</tt> library by Thomas Boutell. First, we'll write a simple C function to draw two locations and draw a line between them (some code has been omitted for clarity) :.<p>
-<p>
-<blockquote><pre>/* File : plot.c */
-#include &lt;gd.h&gt;
-#include &lt;gdfonts.h&gt;
-#include "location.h"
-double xmin,ymin,xmax,ymax; /* Plotting range */
-
-/* Make a plot of two locations with a line between them */
-void plot_cities(gdImagePtr im, Location *city1, Location *city2,
- int color) {
-...
- /* Convert the two locations into screen coordinates (bunch `o math) */
-...
- /* Draw the cities */
- gdImageString(im,gdFontSmall,...)
- gdImageString(im,gdFontSmall,...)
- gdImageLine(im,ix1,height-iy1,ix2,height-iy2,color);
-}
-</pre></blockquote>
-<p>
-Next, we'll wrap a few critical gd functions into Perl. We don't need the entire library so there's not much sense in wrapping the whole thing (it's easy enough to do if you really want to of course). We'll just wrap a couple of functions to illustrate how it can be used (one might also consider using the already existing gd module for Perl as well). <p>
-<p>
-<blockquote><pre>%module gd
-%{
-#include "gd.h"
-%}
-typedef struct gdImageStruct gdImage;
-typedef gdImage * gdImagePtr;
-
-/* Functions to manipulate images. */
-gdImagePtr gdImageCreate(int sx, int sy);
-int gdImageColorAllocate(gdImagePtr im, int r, int g, int b);
-%inline %{
- /* Shortcut for dumping a file */
- void dump_gif(gdImagePtr im, char *filename) {
- FILE *f;
- f = fopen(filename, "w");
- gdImageGif(im,f);
- fclose(f);
- }
-%}
-
-</pre></blockquote>
-We can now slap everything together using a new interface file like this. we'll keep the old graph module name so our existing scripts still work :<p>
-<blockquote><pre>
-// File : package.i
-%module graph
-%include graph.i // The original graph program
-%include location.i // The location data structure and functions
-%include gd.i // gd module
-%include plot.c // Function to plot cities
-</pre></blockquote>
-<p>
-Whew! After all of that work, we can do the following :<p>
-<p>
-<blockquote><pre>read_cities("cities");
-read_locations("locations");
-
-# Create a new image with gd
-$im = gdImageCreate(500,500);
-$white = gdImageColorAllocate($im,255,255,255);
-$black = gdImageColorAllocate($im,0,0,0);
-
-# Set plotting range (variables in the C code)
-$xmin = -130;
-$xmax = -90;
-$ymin = 30;
-$ymax = 50;
-
-# Make a plot of the entire graph
-@loc = each %Cities;
-while (@loc) {
- my $city = $loc[0];
- my $node = $Cities{$city};
- if (exists $Locations{$node-&gt;{v}}) {
- my $loc1 = $Locations{$node-&gt;{v}};
- my $e = $node-&gt;{adj};
- while (defined($e)) {
- if (exists $Locations{$e-&gt;{node}-&gt;{v}}) {
- my $loc2 = $Locations{$e-&gt;{node}-&gt;{v}};
- plot_cities($im,$loc1,$loc2,$black);
- }
- $e = $e-&gt;{next};
- }
- }
- @loc = each %Cities;
-}
-# Dump out a GIF file
-dump_gif($im,"test.gif");
-</pre></blockquote>
-<p>
-When run, we now get the following :<p>
-<p><center><img src="ch8.2.png"></center><p>
-<p>
-<p>
-Not too bad for just a little work....<p>
-<a name="n10"></a><h2> Wrapping C libraries and other packages</h2>
-SWIG can be used to build Perl interfaces to existing C libraries and packages. The general strategy for doing this is as follows :<p>
-<p>
-<ul>
-<li>Locate important header files for the package.
-<li>Copy them into a SWIG interface file.
-<li>Edit the interface file by removing problematic declarations, unneeded functions, and other clutter (this can often be found by just running SWIG).
-<li>Add support functions to improve the interface.
-</ul>
-<p>
-While SWIG can sometimes be used to simply process a raw header file, the results aren't always what you would expect. By working with a separate interface file, you get an opportunity to clean things up. If you're using a stable package, chances are that it's not going to change suddenly so there is really little problem in doing this. To illustrate the process, we will build a Perl5 interface to MATLAB in the next example.<p>
-<a name="n11"></a><h2> Building a Perl5 interface to MATLAB</h2>
-To illustrate the process, we can build a Perl5 interface to MATLAB by wrapping its C API. The MATLAB system consists of the MATLAB engine, and library of functions for creating and manipulating matrices, and a collection of utility function. A full description can be found in the "External Interface Guide" provided with MATLAB. Even if you don't have MATLAB, this section can provide some ideas on how to handle other libraries.<p>
-<a name="n33"></a><h3> The MATLAB engine interface</h3>
-The first step in building an interface will be to provide access to the MATLAB engine. This is a separate process that runs in the background, but we need to have some mechanism for starting it and issuing commands. The following functions are defined in the MATLAB interface.,<p>
-<p>
-<blockquote><pre><tt>int engClose(Engine *ep);
-int engEvalString(Engine *ep, char *string);
-Matrix *engGetMatrix(Engine *ep, char *name);
-int engPutMatrix(Engine *ep, Matrix *mp);
-Engine *engOpen(char *startcommand);
-void engOutputBuffer(Engine *ep, char *p, int size);
-
-</tt></pre></blockquote>
-While we could wrap these directly, each function requires an object "Engine". They could be a little annoying to use in Perl since we would have to pass a pointer to the engine with every command. This probably isn't necessary or desired. Thus, we could write some wrappers around these to produce a better interface as follows :<p>
-<p>
-<blockquote><pre>// engine.i : SWIG file for MATLAB engine
-%{
-#define BUFFER_SIZE 32768
-static Engine *eng = 0;
-static char ml_output[BUFFER_SIZE]; /* Result Buffer */
-%}
-
-%inline %{
-
-
-/* Initialize the MATLAB engine */
-int init(void) {
- if (eng) return -1; /* Already open */
- if (!(eng = engOpen("matlab42"))) {
- fprintf(stderr,"Unable to open matlab.\n");
- return -1;
- }
- engOutputBuffer(eng,ml_output,BUFFER_SIZE);
- return 0;
-}
-/* Execute a MATLAB command */
-char *matlab(char *c) {
- if (!eng) return "not initialized!";
- engEvalString(eng, c);
- return &amp;ml_output[0];
-}
-
-/* Get a matrix from MATLAB */
-Matrix *GetMatrix(char *name) {
- if (!eng) return (Matrix *) 0;
- return(engGetMatrix(eng,name));
-}
-
-/* Send a matrix to MATLAB */
-int PutMatrix(Matrix *m) {
- if (!eng) return -1;
- return(engPutMatrix(eng,m));
-}
-%}
-
-</pre></blockquote>
-<a name="n34"></a><h3> Wrapping the MATLAB matrix functions</h3>
-Next, we need to build an interface to the MATLAB matrix manipulation library. This library contains about 30 functions to manipulate both real and complex valued matrices. Here we will only consider real-valued matrices. To provide access to the matrices, we'll write a different interface file with a list of the functions along with a few helper functions.<p>
-<blockquote><pre>
-//
-// mx.i : SWIG file for MATLAB matrix manipulation
-%inline %{
-/* Get an element from a matrix */
-double getr(Matrix *mat, int i, int j) {
- double *pr;
- int m;
- pr = mxGetPr(mat);
- m = mxGetM(mat);
- return pr[m*j + i];
-}
-/* Set an element of a matrix */
-void setr(Matrix *mat, int i, int j, double val) {
- double *pr;
- int m;
- pr = mxGetPr(mat);
- m = mxGetM(mat);
- pr[m*j + i] = val;
-}
-%}
-
-/* Now some MATLAB command */
-Matrix *mxCreateFull(int m, int n, int ComplexFlag);
-int mxGetM(Matrix *mat);
-int mxGetN(Matrix *mat);
-char *mxGetName(Matrix *mat);
-void mxSetName(Matrix *mat, char *name);
-double *mxGetPr(Matrix *mat);
-void mxSetPr(Matrix *mat, double *pr);
-double mxGetScalar(Matrix *mat);
-void mxFreeMatrix(Matrix *pm);
-</pre></blockquote>
-<a name="n35"></a><h3> Putting it all together</h3>
-Finally we are ready to put our interface together. There is no need to build a big monolithic interface file--we can simply build it up in pieces :<p>
-<p>
-<blockquote><pre>// matlab.i
-// Simple SWIG interface to MATLAB
-%module matlab
-%{
-#include "engine.h"
-%}
-%include engine.i
-%include mx.i
-</pre></blockquote>
-<p>
-Our module can be compiled as follows :<p>
-<p>
-<blockquote><pre>unix &gt; swig -perl5 matlab.i
-unix &gt; gcc -c matlab_wrap.c -I/usr/local/lib/perl5/arch-osname/5.003/CORE -Dbool=char
- -I$(MATLAB)/extern/include
-unix &gt; ld -shared matlab_wrap.o -L$(MATLAB)/extern/lib -lmat -o matlab.so
-
-</pre></blockquote>
-Where<tt> $(MATLAB) </tt>is the location of the MATLAB installation (you may have to dig for this).<p>
-<p>
-With our new MATLAB module, we can now write Perl scripts that issue MATLAB commands. For example :<p>
-<p>
-<blockquote><pre>use matlab;
-matlab::init();
-matlab::matlab("x = -8:.25:8; \
- y = x; \
- [X,Y] = meshgrid(x,y); \
- R = sqrt(X.^2 + Y.^2)+eps; \
- Z = sin(R)./R; \
- mesh(Z); ");
-
-</pre></blockquote>
-Creates a simple 3D surface plot.<p>
-<a name="n36"></a><h3> Graphical Web-Statistics in Perl5</h3>
-Now, lets use our MATLAB module to generate plots of web-server hits for a given month. To do this, we'll use our MATLAB module, and create a special purpose function for processing days and hours. <p>
-<p>
-<blockquote><pre>// Simple C function for recording a hit
-%module webgraph
-%inline %
- void hit(double *m, int day, int hour) {
- if ((day &gt;= 0) &amp;&amp; (day &lt;= 31)) {
- *(m+24*(day-1)+hour) += 1.0;
- }
- }
-%}
-
-</pre></blockquote>
-While we could write this function in Perl, it will be much faster in C. If we're processing a huge file, then the extra bit of performance will help us out. Once compiled, we can now write a Perl5 script like the following :<p>
-<p>
-<blockquote><pre>use matlab;
-use webgraph;
-
-# Initialize matlab engine
-matlab::init();
-# Make a matrix for all hits
-$m_all = matlab::mxCreateFull(24,31,0);
-matlab::mxSetName($m_all,"all");
-$all = matlab::mxGetPr($m_all); # Get double * of Matrix
-
-foreach $file (@ARGV) {
- open(FILE,$file);
- print "Processing ",$file,"\n";
- while (&lt;FILE&gt;) {
- @fields = split(/\s+/, $_);
- next if ($fields[8] != 200);
- @datetime = split(/\[|\/|:/, $fields[3]);
- if ($datetime[2] =~ /Apr/) {
- webgraph::hit($all, $datetime[1],$datetime[4]);
- }
- }
- # Dump temporary results
-} #foreach
-matlab::PutMatrix($m_all);
-matlab::matlab("figure(1); \
- surf(all); \
- view(40,40); \
- shading interp; \
- title('All hits'); \
- set(gca,'xlabel',text(0,0,'Day')); \
- set(gca,'ylabel',text(0,0,'Hour')); \
- print -dgif8 stats_all.gif");
-
-</pre></blockquote>
-When run on the web-server logs for the University of Utah, this script produces the following GIF file (showing hits per hour) :<p>
-<p><center><img src="ch8.3.png"></center><p>
-<p>
-<p>
-<a name="n12"></a><h2> Handling output values (the easy way)</h2>
-Some C libraries rely on functions that return values in their arguments. For example :<p>
-<p>
-<blockquote><pre>void fadd(double a, double b, double *result) {
- *result = a+b;
-}
-
-</pre></blockquote>
-By default, SWIG does not handle this case (leaving it up to you to figure out what to do about the <tt>result</tt> parameter). However, this problem is easily fixed using the <tt>typemaps.i</tt> library file (see the Typemaps chapter for more information). For example :<p>
-<p>
-<blockquote><pre>// SWIG interface file with output arguments
-%module example
-
-%include typemaps.i // Load the typemaps librayr
-%apply double *OUTPUT {double *result}; // Make "result" an output parameter
-
-void fadd(double a, double b, double *result);
-</pre></blockquote>
-<p>
-When used in a Perl script, the fadd function now takes 2 parameters and returns the result.<p>
-<p>
-<blockquote><pre>$a = fadd(3,4); # $a gets the value of double *result
-
-</pre></blockquote>
-When multiple output arguments are involved, a Perl array of values will be returned instead. It is also possible to use Perl references as function values. This is done as shown :<p>
-<p>
-<blockquote><pre>// SWIG interface file with output arguments
-%module
-%include typemaps.i
-
-%apply double *REFERENCE {double *result}; // Make "result" a Perl reference
-
-void fadd(double a, double b, double *result);
-
-</pre></blockquote>
-Now in a Perl script, the function works like this :<p>
-<p>
-<blockquote><pre>$c = 0.0; # Variable for holding the result
-fadd(3,4,\$c); # fadd() places the result in $c
-
-</pre></blockquote>
-In addition to handling pointers as output values or references, two other methods are available. The <tt>INPUT</tt> method indicates that a pointer is an input value and the <tt>BOTH</tt> method indicates that a pointer is both an input and output value. These would be specified as follows :<p>
-<p>
-<blockquote><pre>%apply double *INPUT {double *in}; // double *in is an input value
-%apply double *BOTH {double *r}; // double *r is both an input/output value
-
-</pre></blockquote>
-This processing of datatypes is built using SWIG's typemap mechanism. The details of typemaps is described shortly although the <tt>typemaps.i</tt> library already includes a variety of useful typemaps ready for use.<p>
-<a name="n13"></a><h2> Exception handling </h2>
-The SWIG <tt>%except</tt> directive can be used to create a user-definable exception handler for converting exceptions in your C/C++ program into Perl exceptions. The chapter on exception handling contains more details, but suppose you have a C++ class like the following :<p>
-<blockquote><pre>
-class RangeError {}; // Used for an exception
-
-class DoubleArray {
- private:
- int n;
- double *ptr;
- public:
- // Create a new array of fixed size
- DoubleArray(int size) {
- ptr = new double[size];
- n = size;
- }
- // Destroy an array
- ~DoubleArray() {
- delete ptr;
- }
- // Return the length of the array
- int length() {
- return n;
- }
-
- // Get an item from the array and perform bounds checking.
- double getitem(int i) {
- if ((i &gt;= 0) &amp;&amp; (i &lt; n))
- return ptr[i];
- else
- throw RangeError();
- }
-
- // Set an item in the array and perform bounds checking.
- void setitem(int i, double val) {
- if ((i &gt;= 0) &amp;&amp; (i &lt; n))
- ptr[i] = val;
- else {
- throw RangeError();
- }
- }
- };
-</pre></blockquote>
-<p>
-The functions associated with this class can throw a range exception for an out-of-bounds array access. We can catch this in our Perl extension by specifying the following in an interface file :<p>
-<p>
-<blockquote><pre>%except(perl5) {
- try {
- $function // Gets substituted by actual function call
- }
- catch (RangeError) {
- croak("Array index out-of-bounds");
- }
-}
-
-</pre></blockquote>
-Now, when the C++ class throws a RangeError exception, our wrapper functions will catch it, turn it into a Perl exception, and allow a graceful death as opposed to just having some sort of mysterious program crash. Since SWIG's exception handling is user-definable, we are not limited to C++ exception handling. It is also possible to write a language-independent exception handler that works with other scripting languages. Please see the chapter on exception handling for more details.<p>
-<a name="n14"></a><h2> Remapping datatypes with typemaps</h2>
-While SWIG does a reasonable job with most C/C++ datatypes, it doesn't always do what you want. However, you can remap SWIG's treatment of just about any datatype using a typemap. A typemap simply specifies a conversion between Perl and C datatypes and can be used to process function arguments, function return values, and more. A similiar mechanism is used by the xsubpp compiler provided with Perl although the SWIG version provides many more options.<p>
-<a name="n37"></a><h3> A simple typemap example</h3>
-The following example shows how a simple typemap can be written :<p>
-<p>
-<blockquote><pre>%module example
-
-%typemap(perl5,in) int {
- $target = (int) SvIV($source);
- printf("Received an integer : %d\n", $target);
-}
-...
-extern int fact(int n);
-
-</pre></blockquote>
-Typemap specifications require a language name, method name, datatype, and conversion code. For Perl5, "perl5" should be used as the language name. The "in" method refers to the input arguments of a function. The `int' datatype tells SWIG that we are remapping integers. The conversion code is used to convert from a Perl scalar value to the corresponding datatype. Within the support code, the variable<tt> $source</tt> contains the source data (a Perl object) and <tt>$target</tt> contains the destination of the conversion (a C local variable). <p>
-<p>
-When this example is used in Perl5, it will operate as follows :<p>
-<p>
-<blockquote><pre>use example;
-$n = example::fact(6);
-print "$n\n";
-...
-
-Output :
-Received an integer : 6
-720
-</pre></blockquote>
-<p>
-General discussion of typemaps can be found in the main SWIG users reference. <p>
-<a name="n38"></a><h3> Perl5 typemaps</h3>
-The following typemap methods are available to Perl5 modules<p>
-<p>
-<tt>%typemap(perl5,in)</tt> Converts Perl5 object to input function arguments.<p>
-<tt>%typemap(perl5,out)</tt> Converts function return value to a Perl5 value.<p>
-<tt>%typemap(perl5,varin)</tt> Converts a Perl5 object to a global variable.<p>
-<tt>%typemap(perl5,varout)</tt> Converts a global variable to a Perl5 object.<p>
-<tt>%typemap(perl5,freearg)</tt> Cleans up a function argument after a function call<p>
-<tt>%typemap(perl5,argout)</tt> Output argument handling<p>
-<tt>%typemap(perl5,ret) </tt>Clean up return value from a function.<p>
-<tt>%typemap(memberin)</tt> Setting of C++ member data (all languages).<p>
-<tt>%typemap(memberout)</tt> Return of C++ member data (all languages).<p>
-<tt>%typemap(perl5,check)</tt> Check value of input parameter.<p>
-<a name="n39"></a><h3> Typemap variables</h3>
-The following variables may be used within the C code used in a typemap :<p>
-<p>
-<tt>$source</tt> Source value of a conversion<p>
-<tt>$target</tt> Target of conversion (where result should be stored)<p>
-<tt>$type</tt> C datatype being remapped<p>
-<tt>$mangle</tt> Mangled version of datatype (for blessing objects)<p>
-<tt>$arg</tt> Function argument (when applicable).<p>
-<a name="n40"></a><h3> Name based type conversion</h3>
-Typemaps are based both on the datatype and an optional name attached to a datatype. For example :<p>
-<p>
-<blockquote><pre>%module foo
-
-// This typemap will be applied to all char ** function arguments
-%typemap(perl5,in) char ** { ... }
-
-// This typemap is applied only to char ** arguments named `argv'
-%typemap(perl5,in) char **argv { ... }
-
-</pre></blockquote>
-In this example, two typemaps are applied to the char ** datatype. However, the second typemap will only be applied to arguments named `argv'. A named typemap will always override an unnamed typemap.<p>
-<p>
-Due to the name matching scheme, typemaps do not follow typedef declarations. For example :<p>
-<p>
-<blockquote><pre>%typemap(perl5,in) double {
- ... get a double ...
-}
-
-double foo(double); // Uses the double typemap above
-typedef double Real;
-Real bar(Real); // Does not use the typemap above (double != Real)
-
-</pre></blockquote>
-Is is odd behavior to be sure, but you can work around the problem using the <tt>%apply</tt> directive as follows :<p>
-<p>
-<blockquote><pre>%typemap(perl5,in) double {
- ... get a double ...
-}
-double foo(double); // Uses the double typemap above
-
-typedef double Real;
-%apply double { Real }; // Apply the double typemap to Reals.
-Real bar(Real); // Uses the double typemap already defined.
-</pre></blockquote>
-<p>
-Named typemaps are extremely useful for managing special cases. It is also possible to use named typemaps to process output arguments (ie. function arguments that have values returned in them).<p>
-<a name="n41"></a><h3> Converting a Perl5 array to a char ** </h3>
-A common problem in many C programs is the processing of command line arguments, which are usually passed in an array of NULL terminated strings. The following SWIG interface file allows a Perl5 array reference to be used as a char ** datatype.<p>
-<p>
-<blockquote><pre>%module argv
-
-// This tells SWIG to treat char ** as a special case
-%typemap(perl5,in) char ** {
- AV *tempav;
- I32 len;
- int i;
- SV **tv;
- if (!SvROK($source))
- croak("$source is not a reference.");
- if (SvTYPE(SvRV($source)) != SVt_PVAV)
- croak("$source is not an array.");
- tempav = (AV*)SvRV($source);
- len = av_len(tempav);
- $target = (char **) malloc((len+2)*sizeof(char *));
- for (i = 0; i &lt;= len; i++) {
- tv = av_fetch(tempav, i, 0);
- $target[i] = (char *) SvPV(*tv,na);
- }
- $target[i] = 0;
-};
-
-// This cleans up our char ** array after the function call
-%typemap(perl5,freearg) char ** {
- free($source);
-}
-
-// Creates a new Perl array and places a char ** into it
-%typemap(perl5,out) char ** {
- AV *myav;
- SV **svs;
- int i = 0,len = 0;
- /* Figure out how many elements we have */
- while ($source[len])
- len++;
- svs = (SV **) malloc(len*sizeof(SV *));
- for (i = 0; i &lt; len ; i++) {
- svs[i] = sv_newmortal();
- sv_setpv((SV*)svs[i],$source[i]);
- };
- myav = av_make(len,svs);
- free(svs);
- $target = newRV((SV*)myav);
- sv_2mortal($target);
-}
-
-// Now a few test functions
-%inline %{
-int print_args(char **argv) {
- int i = 0;
- while (argv[i]) {
- printf("argv[%d] = %s\n", i,argv[i]);
- i++;
- }
- return i;
-}
-
-// Returns a char ** list
-char **get_args() {
- static char *values[] = { "Dave", "Mike", "Susan", "John", "Michelle", 0};
- return &amp;values[0];
-}
-%}
-
-</pre></blockquote>
-When this module is compiled, our wrapped C functions can be used in a Perl script as follows :<p>
-<blockquote><pre>
-use argv;
-@a = ("Dave", "Mike", "John", "Mary"); # Create an array of strings
-argv::print_args(\@a); # Pass it to our C function
-$b = argv::get_args(); # Get array of strings from C
-print @$b,"\n"; # Print it out
-</pre></blockquote>
-<p>
-Of course, there are many other possibilities. As an alternative to array references, we could pass in strings separated by some delimeter and perform a splitting operation in C. <p>
-<a name="n42"></a><h3> Using typemaps to return values</h3>
-Sometimes it is desirable for a function to return a value in one of its arguments. A named typemap can be used to handle this case. For example :<p>
-<p>
-<blockquote><pre>%module return
-
-// This tells SWIG to treat an double * argument with name 'OutDouble' as
-// an output value.
-
-%typemap(perl5,argout) double *OutDouble {
- $target = sv_newmortal();
- sv_setnv($target, *$source);
- argvi++; /* Increment return count -- important! */
-}
-
-// If we don't care what the input value is, we can make the typemap ignore it.
-
-%typemap(perl5,ignore) double *OutDouble(double junk) {
- $target = &amp;junk; /* junk is a local variable that has been declared */
-}
-
-// Now a function to test it
-%{
-/* Returns the first two input arguments */
-int multout(double a, double b, double *out1, double *out2) {
- *out1 = a;
- *out2 = b;
- return 0;
-};
-%}
-
-// If we name both parameters OutDouble both will be output
-
-int multout(double a, double b, double *OutDouble, double *OutDouble);
-...
-</pre></blockquote>
-<p>
-When output arguments are encountered, they are simply appended to the stack used to return results. This will show up as an array when used in Perl. For example :<p>
-<p>
-<blockquote><pre>@r = multout(7,13);
-print "multout(7,13) = @r\n";
-
-</pre></blockquote>
-<a name="n43"></a><h3> Accessing array structure members</h3>
-Consider the following data structure :<p>
-<p>
-<blockquote><pre>#define NAMELEN 32
-typedef struct {
- char name[NAMELEN];
- ...
-} Person;
-
-</pre></blockquote>
-By default, SWIG doesn't know how to the handle the name structure since it's an array, not a pointer. In this case, SWIG will make the array member readonly. However, member typemaps can be used to make this member writable from Perl as follows :<p>
-<p>
-<blockquote><pre>%typemap(memberin) char[NAMELEN] {
- /* Copy at most NAMELEN characters into $target */
- strncpy($target,$source,NAMELEN);
-}
-
-</pre></blockquote>
-Whenever a <tt>char[NAMELEN]</tt> type is encountered in a structure or class, this typemap provides a safe mechanism for setting its value. An alternative implementation might choose to print an error message if the name was too long to fit into the field.<p>
-<p>
-It should be noted that the <tt>[NAMELEN]</tt> array size is attached to the typemap. A datatype involving some other kind of array would be affected. However, we can write a typemap that will work for any array dimension as follows :<p>
-<blockquote><pre>
-%typemap(memberin) char [ANY] {
- strncpy($target,$source,$dim0);
-}
-
-</pre></blockquote>
-When code is generated, <tt>$dim0</tt> gets filled in with the real array dimension.<p>
-<a name="n44"></a><h3> Turning Perl references into C pointers</h3>
-A frequent confusion on the SWIG mailing list is errors caused by the mixing of Perl references and C pointers. For example, suppose you have a C function that modifies its arguments like this :<p>
-<p>
-<blockquote><pre>void add(double a, double b, double *c) {
- *c = a + b;
-}
-
-</pre></blockquote>
-A common misinterpretation of this function is the following Perl script :<p>
-<p>
-<blockquote><pre># Perl script
-$a = 3.5;
-$b = 7.5;
-$c = 0.0; # Output value
-add($a,$b,\$c); # Place result in c (Except that it doesn't work)
-</pre></blockquote>
-<p>
-Unfortunately, this does NOT work. There are many reasons for this, but the main one is that SWIG has no idea what a <tt>double *</tt> really is. It could be an input value, an output value, or an array of 2 million elements. As a result, SWIG leaves it alone and looks exclusively for a C pointer value (which is not the same as a Perl reference--well, at least note of the type used in the above script).<p>
-<p>
-However, you can use a typemap to get the desired effect. For example :<p>
-<p>
-<blockquote><pre>%typemap(perl5,in) double * (double dvalue) {
- SV* tempsv;
- if (!SvROK($source)) {
- croak("expected a reference\n");
- }
- tempsv = SvRV($source);
- if ((!SvNOK(tempsv)) &amp;&amp; (!SvIOK(tempsv))) {
- croak("expected a double reference\n");
- }
- dvalue = SvNV(tempsv);
- $target = &amp;dvalue;
-}
-
-%typemap(perl5,argout) double * {
- SV *tempsv;
- tempsv = SvRV($arg);
- sv_setnv(tempsv, *$source);
-}
-</pre></blockquote>
-<p>
-Now, if you place this before our add function, we can do this :<p>
-<p>
-<blockquote><pre>$a = 3.5;
-$b = 7.5;
-$c = 0.0;
-add($a,$b,\$c); # Now it works!
-print "$c\n";
-
-</pre></blockquote>
-You'll get the output value of "11.0" which is exactly what we wanted. While this is pretty cool, it should be stressed that you can easily shoot yourself in the foot with typemaps--of course SWIG is has never been too concerned about legislating morality....<p>
-<a name="n45"></a><h3> Useful functions</h3>
-When writing typemaps, it is necessary to work directly with Perl5 objects. This, unfortunately, can be a daunting task. Consult the "perlguts" man-page for all of the really ugly details. A short summary of commonly used functions is provided here for reference. It should be stressed that SWIG can be usef quite effectively without knowing any of these details--especially now that there are typemap libraries that can already been written.<p>
-<center>
-<img src="ch8.table.1.png"><br>
-<img src="ch8.table.2.png"><br>
-<img src="ch8.table.3.png"><br>
-<img src="ch8.table.4.png"><br>
-</center><p>
-<p>
-<a name="n46"></a><h3> Standard typemaps</h3>
-The following typemaps show how to convert a few common types of objects between Perl and C (and to give a better idea of how everything works). <p>
-<center>
-<img src="ch8.table.5.png"><br>
-<img src="ch8.table.6.png"><br>
-</center><p>
-<p>
-<a name="n47"></a><h3> Pointer handling</h3>
-SWIG pointers are represented as blessed references. The following functions can be used to create and read pointer values.<p>
-<center>
-<img src="ch8.table.7.png">
-</center><p>
-<a name="n48"></a><h3> Return values </h3>
-Return values are placed on the argument stack of each wrapper function. The current value of the argument stack pointer is contained in a variable <tt>argvi</tt>. Whenever a new output value is added, it is critical that this value be incremented. For multiple output values, the final value of <tt>argvi</tt> should be the total number of output values. <p>
-<p>
-The total number of return values should not exceed the number of input values unless you explicitly extend the argument stack. This can be done using the <tt>EXTEND()</tt> macro as in :<p>
-<p>
-<blockquote><pre>%typemap(perl5,argout) int *OUTPUT {
- if (argvi &gt;= items) {
- EXTEND(sp,1); /* Extend the stack by 1 object */
- }
- $target = sv_newmortal();
- sv_setiv($target,(IV) *($source));
- argvi++;
-}
-</pre></blockquote>
-<a name="n15"></a><h2> The gory details on shadow classes</h2>
-Perl5 shadow classes are constructed on top of the low-level C interface provided by SWIG. By implementing the classes in Perl instead of C, we get a number of advantages :<p>
-<p>
-<ul>
-<li>The classes are easier to implement (after all Perl makes lots of things easier).
-<li>By writing in Perl, the classes tend to interact better with other Perl objects and programs.
-<li>You can modify the resulting Perl code without recompiling the C module.
-</ul>
-<p>
-Shadow classes are new in SWIG 1.1 and still somewhat experimental. The current implementation is a combination of contributions provided by Gary Holt and David Fletcher--many thanks!<p>
-<a name="n49"></a><h3> Module and package names</h3>
-When shadow classing is enabled, SWIG generates a low-level package named `modulec' where `module' is the name of the module you provided with the <tt>%module</tt> directive (SWIG appends a `c' to the name to indicate that it is the low-level C bindings). This low-level package is exactly the same module that SWIG would have created without the <tt>`-shadow</tt>' option, only renamed.<p>
-<p>
-Using the low-level interface, SWIG creates Perl wrappers around classes, structs, and functions. This collection of wrappers becomes the Perl module that you will use in your Perl code, not the low-level package (the original package is hidden, but working behind the scenes).<p>
-<a name="n50"></a><h3> What gets created?</h3>
-Suppose you have the following SWIG interface file :<p>
-<p>
-<blockquote><pre>%module vector
-struct Vector {
- Vector(double x, double y, double z);
- ~Vector();
- double x,y,z;
-};
-
-</pre></blockquote>
-When wrapped, SWIG creates the following set of low-level accessor functions.<p>
-<p>
-<blockquote><pre>Vector *new_Vector(double x, double y, double z);
-void delete_Vector(Vector *v);
-double Vector_x_get(Vector *v);
-double Vector_x_set(Vector *v, double value);
-double Vector_y_get(Vector *v);
-double Vector_y_set(Vector *v, double value);
-double Vector_z_get(Vector *v);
-double Vector_z_set(Vector *v, double value);
-
-</pre></blockquote>
-These functions can now be used to create a Perl shadow class that looks like this :<p>
-<p>
-<blockquote><pre>package Vector;
-@ISA = qw( vector );
-%OWNER = ();
-%BLESSEDMEMBERS = ();
-
-sub new () {
- my $self = shift;
- my @args = @_;
- $self = vectorc::new_Vector(@args);
- return undef if (!defined($self));
- bless $self, "Vector";
- $OWNER{$self} = 1;
- my %retval;
- tie %retval, "Vector", $self;
- return bless \%retval,"Vector";
-}
-
-sub DESTROY {
- my $self = shift;
- if (exists $OWNER{$self}) {
- delete_Vector($self));
- delete $OWNER{$self};
-}
-
-sub FETCH {
- my ($self,$field) = @_;
- my $member_func = "vectorc::Vector_${field}_get";
- my $val = &amp;$member_func($self);
- if (exists $BLESSEDMEMBERS{$field}) {
- return undef if (!defined($val));
- my %retval;
- tie %retval,$BLESSEDMEMBERS{$field},$val;
- return bless \%retval, $BLESSEDMEMBERS{$field};
- }
- return $val;
-}
-
-sub STORE {
- my ($self,$field,$newval) = @_;
- my $member_func = "vectorc::Vector_${field}_set";
- if (exists $BLESSEDMEMBERS{$field}) {
- &amp;$member_func($self,tied(%{$newval}));
- } else {
- &amp;$member_func($self,$newval);
- }
-}
-</pre></blockquote>
-<p>
-Each structure or class is mapped into a Perl package of the same name. The C++ constructors and destructors are mapped into constructors and destructors for the package and are always named "new" and "DESTROY". The constructor always returns a tied hash table. This hash table is used to access the member variables of a structure in addition to being able to invoke member functions. The <tt>%OWNER</tt> and <tt>%BLESSEDMEMBERS</tt> hash tables are used internally and described shortly. <p>
-<p>
-To use our new shadow class we can simply do the following:<p>
-<p>
-<blockquote><pre># Perl code using Vector class
-$v = new Vector(2,3,4);
-$w = Vector-&gt;new(-1,-2,-3);
-
-# Assignment of a single member
-$v-&gt;{x} = 7.5;
-
-# Assignment of all members
-%$v = ( x=&gt;3,
- y=&gt;9,
- z=&gt;-2);
-
-# Reading members
-$x = $v-&gt;{x};
-
-# Destruction
-$v-&gt;DESTROY();
-
-</pre></blockquote>
-<a name="n51"></a><h3> Object Ownership</h3>
-In order for shadow classes to work properly, it is necessary for Perl to manage some mechanism of object ownership. Here's the crux of the problem---suppose you had a function like this :<p>
-<p>
-<blockquote><pre>Vector *Vector_get(Vector *v, int index) {
- return &amp;v[i];
-}
-
-</pre></blockquote>
-This function takes a Vector pointer and returns a pointer to another Vector. Such a function might be used to manage arrays or lists of vectors (in C). Now contrast this function with the constructor for a Vector object :<p>
-<p>
-<blockquote><pre>Vector *new_Vector(double x, double y, double z) {
- Vector *v;
- v = new Vector(x,y,z); // Call C++ constructor
- return v;
-}
-
-</pre></blockquote>
-Both functions return a Vector, but the constructor is returning a brand-new Vector while the other function is returning a Vector that was already created (hopefully). In Perl, both vectors will be indistinguishable---clearly a problem considering that we would probably like the newly created Vector to be destroyed when we are done with it.<p>
-<p>
-To manage these problems, each class contains two methods that access an internal hash table called <tt>%OWNER</tt>. This hash keeps a list of all of the objects that Perl knows that it has created. This happens in two cases: (1) when the constructor has been called, and (2) when a function implicitly creates a new object (as is done when SWIG needs to return a complex datatype by value). When the destructor is invoked, the Perl shadow class module checks the <tt>%OWNER</tt> hash to see if Perl created the object. If so, the C/C++ destructor is invoked. If not, we simply destroy the Perl object and leave the underlying C object alone (under the assumption that someone else must have created it).<p>
-<p>
-This scheme works remarkably well in practice but it isn't foolproof. In fact, it will fail if you create a new C object in Perl, pass it on to a C function that remembers the object, and then destroy the corresponding Perl object (this situation turns out to come up frequently when constructing objects like linked lists and trees). When C takes possession of an object, you can change Perl's owership by simply deleting the object from the <tt>%OWNER</tt> hash. This is done using the <tt>DISOWN </tt>method.<p>
-<p>
-<blockquote><pre># Perl code to change ownership of an object
-$v = new Vector(x,y,z);
-$v-&gt;DISOWN();
-</pre></blockquote>
-<p>
-To acquire ownership of an object, the <tt>ACQUIRE</tt> method can be used.<p>
-<p>
-<blockquote><pre># Given Perl ownership of a file
-$u = Vector_get($v);
-$u-&gt;ACQUIRE();
-
-</pre></blockquote>
-As always, a little care is in order. SWIG does not provide reference counting, garbage collection, or advanced features one might find in sophisticated languages.<p>
-<a name="n52"></a><h3> Nested Objects</h3>
-Suppose that we have a new object that looks like this :<p>
-<p>
-<blockquote><pre>struct Particle {
- Vector r;
- Vector v;
- Vector f;
- int type;
-}
-
-</pre></blockquote>
-In this case, the members of the structure are complex objects that have already been encapsulated in a Perl shadow class. To handle these correctly, we use the <tt>%BLESSEDMEMBERS</tt> hash which would look like this (along with some supporting code) :<p>
-<p>
-<blockquote><pre>package Particle;
-...
-%BLESSEDMEMBERS = (
- r =&gt; `Vector',
- v =&gt; `Vector',
- f =&gt; `Vector',
-);
-
-</pre></blockquote>
-When fetching members from the structure, <tt>%BLESSEDMEMBERS</tt> is checked. If the requested field is present, we create a tied-hash table and return it. If not, we just return the corresponding member unmodified.<p>
-<p>
-This implementation allows us to operate on nested structures as follows :<p>
-<blockquote><pre>
-# Perl access of nested structure
-$p = new Particle();
-$p-&gt;{f}-&gt;{x} = 0.0;
-%${$p-&gt;{v}} = ( x=&gt;0, y=&gt;0, z=&gt;0);
-</pre></blockquote>
-<p>
-<a name="n53"></a><h3> Shadow Functions</h3>
-When functions take arguments involving a complex object, it is sometimes necessary to write a shadow function. For example :<p>
-<p>
-<blockquote><pre>double dot_product(Vector *v1, Vector *v2);
-
-</pre></blockquote>
-Since Vector is an object already wrapped into a shadow class, we need to modify this function to accept arguments that are given in the form of tied hash tables. This is done by creating a Perl function like this :<p>
-<p>
-<blockquote><pre>sub dot_product {
- my @args = @_;
- $args[0] = tied(%{$args[0]}); # Get the real pointer values
- $args[1] = tied(%{$args[1]});
- my $result = vectorc::dot_product(@args);
- return $result;
-}
-</pre></blockquote>
-<p>
-This function replaces the original function, but operates in an identical manner.<p>
-<a name="n54"></a><h3> Inheritance</h3>
-Simple C++ inheritance is handled using the Perl <tt>@ISA</tt> array in each class package. For example, if you have the following interface file :<p>
-<p>
-<blockquote><pre>// shapes.i
-// SWIG interface file for shapes class
-%module shapes
-%{
-#include "shapes.h"
-%}
-
-class Shape {
-public:
- virtual double area() = 0;
- virtual double perimeter() = 0;
- void set_location(double x, double y);
-};
-class Circle : public Shape {
-public:
- Circle(double radius);
- ~Circle();
- double area();
- double perimeter();
-};
-class Square : public Shape {
-public:
- Square(double size);
- ~Square();
- double area();
- double perimeter();
-}
-
-</pre></blockquote>
-The resulting, Perl wrapper class will create the following code :<p>
-<blockquote><pre>Package Shape;
-@ISA = (shapes);
-...
-Package Circle;
-@ISA = (shapes Shape);
-...
-Package Square;
-@ISA = (shapes Shape);
-
-</pre></blockquote>
-The <tt>@ISA</tt> array determines where to look for methods of a particular class. In this case, both the <tt>Circle</tt> and <tt>Square</tt> classes inherit functions from <tt>Shape</tt> so we'll want to look in the <tt>Shape</tt> base class for them. All classes also inherit from the top-level module <tt>shapes</tt>. This is because certain common operations needed to implement shadow classes are implemented only once and reused in the wrapper code for various classes and structures.<p>
-<p>
-Since SWIG shadow classes are implemented in Perl, it is easy to subclass from any SWIG generated class. To do this, simply put the name of a SWIG class in the <tt>@ISA</tt> array for your new class. However, be forewarned that this is not a trivial problem. In particular, inheritance of data members is extremely tricky (and I'm not even sure if it really works). <p>
-<a name="n55"></a><h3> Iterators</h3>
-With each class or structure, SWIG also generates a pair of functions to support Perl iterators. This makes it possible to use the <tt>keys</tt> and <tt>each</tt> functions on a C/C++ object. Iterators are implemented using code like this :<p>
-<p>
-<blockquote><pre>sub FIRSTKEY {
- my $self = shift;
- @ITERATORS{$self} = [`x','y','z', ];
- my $first = shift @{$ITERATORS{$self}};
- return $first;
-}
-
-sub NEXTKEY {
- my $self = shift;
- $nelem = scalar @{$ITERATORS{$self}};
- if ($nelem &gt; 0) {
- my $member = shift @{$ITERATORS{$self}};
- return $member;
- } else {
- @ITERATORS{$self} = [`x','y','z', ];
- return ();
- }
-}
-</pre></blockquote>
-The <tt>%ITERATORS</tt> hash table maintains the state of each object for which the <tt>keys</tt> or <tt>each</tt> function has been applied to. The state is maintained by keeping a list of the member names.<p>
-<p>
-While iterators may be of limited use when working with C/C++ code, it turns out they can be used to perform an element by element copy of an object.<p>
-<p>
-<blockquote><pre>$v = new Vector(1,2,3);
-$w = new Vector(0,0,0);
-%$w = %$v; # Copy contents of v into w
-
-</pre></blockquote>
-However, this is not a deep copy so they probably works better with C than with C++.<p>
-<a name="n16"></a><h2> Where to go from here?</h2>
-The SWIG Perl5 module is constantly improving to provide better integration with Perl and to be easier to use. The introduction of shadow classes and typemaps in this release are one more step in that direction. The SWIG <tt>Examples</tt> directory contains more simple examples of building Perl5 modules. As always, suggestions for improving the Perl5 implementation are welcome.<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:47:01 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Preface.html b/swigweb/Doc1.1/HTML/Preface.html
deleted file mode 100644
index 47207f9e7..000000000
--- a/swigweb/Doc1.1/HTML/Preface.html
+++ /dev/null
@@ -1,83 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Preface</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1> Preface</h1><p><ul>
-<li> <a href="#n1">Introduction</a>
-<li> <a href="#n2">SWIG resources</a>
-<li> <a href="#n3">About this manual</a>
-<li> <a href="#n4">Credits</a>
-<li> <a href="#n5">What's new?</a>
-<li> <a href="#n6">Bug reports</a>
-<li> <a href="#n7">SWIG is free</a>
-</ul>
-
-<a name="n1"></a><h2> Introduction</h2>
-SWIG is a tool for solving problems.<p>
-<p>
-More specifically, SWIG is a simple tool for building interactive C, C++, or Objective-C programs with common scripting languages such as Tcl, Perl, and Python. Of course, more importantly, SWIG is a tool for making C programming more enjoyable and promoting laziness (an essential feature). SWIG is not part of an overgrown software engineering project, an attempt to build some sort of monolithic programming environment, or an attempt to force everyone to rewrite all of their code (ie. code reuse). In fact, none of these things have ever been a priority.<p>
-<p>
-SWIG was originally developed in the Theoretical Physics Division at Los Alamos National Laboratory for building interfaces to large materials science research simulations being run on the Connection Machine 5 supercomputer. In this environment, we were faced with the problems of working with huge amounts of data, complicated machines, and constantly changing code. As scientists, we needed a mechanism for building interactive programs that was extremely easy to use, could keep pace with code that was constantly changing, and didn't get in the way of the real problems that were being solved. Mainly, we just wanted to "cut the crap" and work on the real problems at hand.<p>
-<p>
-While SWIG was originally developed for scientific applications, it has become a general purpose tool that is being used in an increasing variety of other computing applications--in fact almost anything where C programming is involved. Some of the application areas that I am aware of include scientific applications, visualization, databases, semiconductor CAD, remote sensing and distributed objects. Development has been pragmatic in nature--features have been added to address interesting problems as they arise. Most of the really cool stuff has been contributed or suggested by SWIG's users. There has never really been a "grand" design to SWIG other than the goal of creating a practical programming tool that could be used in other applications.<p>
-<a name="n2"></a><h2> SWIG resources</h2>
-The official location of SWIG related material is<p>
-<blockquote><pre>
-http://www.cs.utah.edu/~beazley/SWIG
-</pre></blockquote>
-<p>
-This site contains the latest version of the software, users guide, and information regarding bugs, installation problems, and implementation tricks. The latest version of the software and related files are also available via anonymous ftp at <p>
-<p>
-<blockquote><pre>ftp://ftp.cs.utah.edu/pub/beazley/SWIG
-</pre></blockquote>
-<p>
-You can also subscribe to the SWIG mailing list by sending a message with the text "subscribe swig" to <p>
-<p>
-<blockquote><pre>majordomo@cs.utah.edu
-</pre></blockquote>
-<p>
-The mailing list often discusses some of the more technical aspects of SWIG along with information about beta releases and future work.<p>
-<a name="n3"></a><h2> About this manual</h2>
-This manual has been written in parallel with the development of SWIG because I hate black boxes and I don't like using software that is poorly documented. This manual attempts to describe all aspects of SWIG and how it can be used to solve interesting problems. Don't let the size scare you, SWIG can be quite easy to use. However, covering automatic code generation for four different scripting languages takes abit of explanation. SWIG can do quite a few interesting things that might not be so obvious so I hope that the manual can shed some light on many of these issues. The manual also serves as a general reference describing many of SWIG's implementation issues (I use the manual quite regularly myself).<p>
-<a name="n8"></a><h3> Prerequisites</h3>
-This manual assumes that you are interested in writing interactive C programs and that you have at least heard of scripting languages such as Tcl, Python, and Perl. A detailed knowledge of these scripting languages is not required although some familiarity certainly won't hurt. No prior experience with building C extensions to these languages is required---after all, this is what SWIG allows you to do automatically. However, I do assume that you are reasonably familiar with the use of compilers, linkers, and makefiles since making scripting language extensions is somewhat more complicated than writing a normal C program (although not significantly more complex).<p>
-<a name="n9"></a><h3> Organization of this manual</h3>
-The first few chapters of this manual describe SWIG in general and provide an overview of its capabilities. The remaining chapters are devoted to specific SWIG language modules and are self contained. Thus, if you are using SWIG to build Python interfaces, you can skip right to that chapter and find just about everything you need to know. So, in a sense, you are really getting 3 or 4 manuals in one.<p>
-<a name="n10"></a><h3> How to avoid reading the manual</h3>
-If you hate reading manuals, glance at the "Introduction" which contains a few simple examples and the overall philosophy. These examples contain about 95% of everything you need to know to use SWIG. After that, simply use the language-specific chapters for reference. The SWIG distribution also comes with a large directory of examples that illustrate how to do most kinds of things. <p>
-<a name="n4"></a><h2> Credits</h2>
-This work would certainly not be possible without the support of many people. I would like to acknowledge Peter Lomdahl, Brad Holian, Shujia Zhou, Niels Jensen, and Tim Germann at Los Alamos National Laboratory for allowing me to pursue this project and for being the first users. Patrick Tullmann at the University of Utah suggested the idea of automatic documentation generation. John Schmidt and Kurtis Bleeker at the University of Utah tested out the early versions. I'd also like to acknowledge Chris Johnson and the Scientific Computing and Imaging Group at the University of Utah for their continued support. John Buckman, Larry Virden, and Tom Schwaller provided valuable input on the first releases and improving the portability of SWIG. David Fletcher and Gary Holt have provided a great deal of input on improving SWIG's Perl5 implementation. I'd also like to thank Kevin Butler for his valuable input and contribution of a Windows NT port. Finally, I'd like to acknowledge all of the users who have braved the first few releases and have been instrumental in suggesting way to make SWIG more fun to use than I ever imagined possible.<p>
-<a name="n5"></a><h2> What's new?</h2>
-The following significant features are new in version 1.1<p>
-<p>
-<ul>
-<li>Support for typemaps (a mechanism for customizing SWIG).
-<li>Multiple inheritance.
-<li>Default/optional arguments.
-<li>Perl5 shadow classes.
-<li>Tcl8.0 module (uses the native Tcl8 object interface).
-<li>An entirely new documentation system.
-<li>Limited support for nested structures.
-<li>New object oriented Tcl interface.
-<li>User defined exception handling.
-<li>New directives for better library support (%inline, %extern %import)
-<li>Objective-C support.
-<li>Support for Windows-NT and Macintosh.
-<li>Lots of minor bug fixes to almost everything.
-</ul>
-<p>
-This release should be backwards compatible with interface files generated for SWIG 1.0. However, many things have changed in the SWIG C++ API so special purpose SWIG C++ extensions written for 1.0 will need to be modified.<p>
-<a name="n6"></a><h2> Bug reports</h2>
-While every attempt has been made to make SWIG bug-free, occasionally bugs will arrise. To report a bug, send mail to the SWIG mailing list at <tt>swig@cs.utah.edu</tt>. In your message, be as specific as possible, including (if applicable), error messages, tracebacks (if a core dump occurred), corresponding portions of the SWIG interface file used, and any important pieces of the SWIG generated wrapper code. I attempt to respond to all bug reports, but I can only fix bugs if I know about them.<p>
-<a name="n7"></a><h2> SWIG is free</h2>
-SWIG is a completely free package that you can use in any manner that you wish, including modification, redistribution, and use in commercial products. The only restriction on its use is that redistributions of the SWIG compiler should reproduce the SWIG copyright notice in the supporting documentation. The code generated by SWIG can be redistributed in any manner. On a more personal note, if you've used SWIG to make something cool, I'd like to find out more about it so that I can make SWIG better (and to satisfy my curiosity).<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:46:49 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Python.html b/swigweb/Doc1.1/HTML/Python.html
deleted file mode 100644
index 357ab5343..000000000
--- a/swigweb/Doc1.1/HTML/Python.html
+++ /dev/null
@@ -1,2334 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>SWIG and Python</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>9 SWIG and Python</h1><p><ul>
-<li> <a href="#n1">Preliminaries</a>
-<li> <a href="#n2">Building Python Extensions under Windows 95/NT</a>
-<li> <a href="#n3">The low-level Python/C interface</a>
-<li> <a href="#n4">Python shadow classes</a>
-<li> <a href="#n5">About the Examples</a>
-<li> <a href="#n6">Solving a simple heat-equation</a>
-<li> <a href="#n7">Wrapping a C library</a>
-<li> <a href="#n8">Putting it all together</a>
-<li> <a href="#n9">Exception handling</a>
-<li> <a href="#n10">Remapping C datatypes with typemaps</a>
-<li> <a href="#n11">Implementing C callback functions in Python</a>
-<li> <a href="#n12">Other odds and ends</a>
-<li> <a href="#n13">The gory details of shadow classes</a>
-</ul>
-
-This chapter describes SWIG's support of Python. Many of the example presented here will have a scientific bias given Python's increasing use in scientific applications (this is how I primarily use Python), but the techniques are widely applicable to other areas.<p>
-<a name="n1"></a><h2> Preliminaries</h2>
-SWIG 1.1 works with Python 1.3 and Python 1.4. Given the choice, you should use the latest version of Python. You should also determine if your system supports shared libraries and dynamic loading. SWIG will work with or without dynamic loading, but the compilation process will vary.<p>
-<a name="n14"></a><h3> Running SWIG</h3>
-To build a Python module, run SWIG using the <tt>-python</tt> option :<p>
-<p>
-<blockquote><pre>%swig -python example.i
-</pre></blockquote>
-<p>
-This will produce 2 files. The file <tt>example_wrap.c</tt> contains all of the C code needed to build a Python module and a documentation file describes the resulting interface. To build a Python module, you will need to compile the file <tt>example_wrap.c</tt> and link it with the rest of your program (and possibly Python itself). When working with shadow classes, SWIG will also produce a <tt>.py</tt> file, but this is described later.<p>
-<a name="n15"></a><h3> Getting the right header files</h3>
-In order to compile, you need to locate the following directories that are part of the Python distribution :<p>
-<p>
-For Python 1.3 :<p>
-<p>
-<blockquote><pre>/usr/local/include/Py
-/usr/local/lib/python/lib
-</pre></blockquote>
-<p>
-For Python 1.4 :<p>
-<p>
-<blockquote><pre>/usr/local/include/python1.4
-/usr/local/lib/python1.4/config
-
-</pre></blockquote>
-The exact location may vary on your machine, but the above locations are typical. <p>
-<a name="n16"></a><h3> Compiling a dynamic module</h3>
-To build a shared object file, you need to compile your module in a manner similar to the following (shown for Irix):<p>
-<p>
-<blockquote><pre>% swig -python example.i
-% gcc -c example.c
-% gcc -c example_wrap.c -DHAVE_CONFIG_H -I/usr/local/include/python1.4 \
- -I/usr/local/lib/python1.4/config
-% ld -shared example.o example_wrap.o -o examplemodule.so
-
-</pre></blockquote>
-Unfortunately, the process of building a shared object file varies on every single machine so you may need to read up on the man pages for your C compiler and linker.<p>
-<p>
-When building a dynamic module, the name of the output file is important. If the name of your SWIG module is "<tt>example</tt>", the name of the corresponding object file should be "<tt>examplemodule.so</tt>" (or equivalent depending on your machine). The name of the module is specified using the <tt>%module</tt> directive or<tt> -module</tt> command line option.<p>
-<p>
-While dynamic loading is the preferred method for making SWIG modules, it is not foolproof and not supported on all machines. In these cases, you can rebuild the Python interpreter with your extensions added.<p>
-<a name="n17"></a><h3> Rebuilding the Python interpreter (aka. static linking)</h3>
-The normal procedure for adding a new module to Python involves finding the Python source, adding an entry to the <tt>Modules/Setup</tt> file, and rebuilding the interpreter using the Python Makefile. While it's possible to simplify the process by using the VPATH feature of `make', I've always found the process to be a little too complicated. <p>
-<p>
-SWIG provides an extremely easy, although somewhat unconventional, mechanism for rebuilding Python using SWIG's library feature. When you want to build a static version of Python, simply make an interface file like this :<p>
-<p>
-<blockquote><pre>%module example
-
-extern int fact(int);
-extern int mod(int, int);
-extern double My_variable;
-
-%include embed.i // Include code for a static version of Python
-
-</pre></blockquote>
-The <tt>embed.i</tt> library file includes supporting code that contains everything needed to rebuild Python. To build your module, simply do the following :<p>
-<p>
-<blockquote><pre>% swig -python example.i
-% gcc example.c example_wrap.c -DHAVE_CONFIG_H -I/usr/local/include/python1.4 \
- -I/usr/local/lib/python1.4/config \
- -L/usr/local/lib/python1.4/config -lModules -lPython -lObjects -lParser -lm \
- -o mypython
-
-</pre></blockquote>
-On some machines, you may need need to supply additional libraries on the link line. In particular, you may need to supply <tt>-lsocket</tt>,<tt> -lnsl</tt>, and <tt>-ldl</tt>. <p>
-<p>
-It is also possible to add the embed.i library to an existing interface by running SWIG as follows :<p>
-<p>
-<blockquote><pre>% swig -python -lembed.i example.i
-
-</pre></blockquote>
-The <tt>embed.i</tt> file uses all of the modules that are currently being used in your installed version of Python. Thus, your new version of Python will be identical to the old one except with your new module added. If you have configured Python to use modules such as <tt>tkinter,</tt> you may need to supply linkage to the Tcl/Tk libraries and X11 libraries.<p>
-<p>
-Python's <tt>main()</tt> program is rather unfriendly towards C++ code, but SWIG's <tt>embed.i</tt> module provides a replacement that can be compiled with the C++ compiler--making it easy to build C++ Python extensions.<p>
-<p>
-The <tt>embed.i</tt> library should only be used with Python 1.4. If you are using Python 1.3, you should use the file <tt>embed13.i</tt> instead (this can be done by making a symbolic link in the SWIG library) or simply using the <tt>-l</tt> option.<p>
-<a name="n18"></a><h3> Using your module</h3>
-To use your module in Python, simply use Python's import command. The process is identical regardless of whether or not you used dynamic loading or rebuilt the Python interpreter :<p>
-<p>
-<blockquote><pre>% python
-&gt;&gt;&gt; import example
-&gt;&gt;&gt; example.fact(4)
-24
-&gt;&gt;&gt;
-
-</pre></blockquote>
-<a name="n19"></a><h3> Compilation problems and compiling with C++</h3>
-For the most part, compiling a Python module is straightforward, but there are a number of potential problems :<p>
-<p>
-<ul>
-<li>Dynamic loading is not supported on all machines. If you can't get a module to build, you might try building a new version of Python using static linking instead.
-<li>In order to build C++ modules, you may need to link with the C++ compile using a command like `<tt>c++ -shared example_wrap.o example.o -o examplemodule.so</tt>'
-<li>If building a dynamic C++ module using g++, you may also need to link against <tt>libgcc.a</tt>, <tt>libg++.a</tt>, and <tt>libstc++.a</tt> libraries.
-<li>Make sure you are using the correct header files and libraries. A module compiled with Python 1.3 headers probably won't work with Python 1.4.
-</ul>
-<a name="n2"></a><h2> Building Python Extensions under Windows 95/NT</h2>
-Building a SWIG extension to Python under Windows 95/NT is roughly similar to the process used with Unix. Normally, you will want to produce a DLL that can be loaded into the Python interpreter. This section covers the process of using SWIG with Microsoft Visual C++ 4.x although the procedure may be similar with other compilers. SWIG currently supports both the basic Python release and Pythonwin. In order to build extensions, you will need to download the source distribution to these packages as you will need the Python header files.<p>
-<a name="n20"></a><h3> Running SWIG from Developer Studio</h3>
-If you are developing your application within Microsoft developer studio, SWIG can be invoked as a custom build option. The process roughly follows these steps :<p>
-<p>
-<ul>
-<li>Open up a new workspace and use the AppWizard to select a DLL project.
-<li>Add both the SWIG interface file (the .i file), any supporting C files, and the name of the wrapper file that will be created by SWIG (ie. <tt>example_wrap.c</tt>). Note : If using C++, choose a different suffix for the wrapper file such as <tt>example_wrap.cxx</tt>. Don't worry if the wrapper file doesn't exist yet--Developer Studio will keep a reference to it around.
-<li>Select the SWIG interface file and go to the settings menu. Under settings, select the "Custom Build" option.
-<li>Enter "SWIG" in the description field.
-<li>Enter "<tt>swig -python -o $(ProjDir)\$(InputName)_wrap.c $(InputPath)</tt>" in the "Build command(s) field"
-<li>Enter "<tt>$(ProjDir)\$(InputName)_wrap.c</tt>" in the "Output files(s) field".
-<li>Next, select the settings for the entire project and go to "C++:Preprocessor". Add the include directories for your Python installation under "Additional include directories".
-<li>Define the symbol __WIN32__ under preprocessor options.
-<li>Finally, select the settings for the entire project and go to "Link Options". Add the Python library file to your link libraries. For example "python14.lib". Also, set the name of the output file to match the name of your Python module (ie. example.dll).
-<li>Build your project.
-</ul>
-<p>
-Now, assuming all went well, SWIG will be automatically invoked when you build your project. Any changes made to the interface file will result in SWIG being automatically invoked to produce a new version of the wrapper file. To run your new Python extension, simply run Python and use the <tt>import</tt> command as normal. For example :<p>
-<p>
-<blockquote><pre>
-MSDOS &gt; python
-&gt;&gt;&gt; import example
-&gt;&gt;&gt; print example.fact(4)
-24
-&gt;&gt;&gt;
-</pre></blockquote>
-<a name="n21"></a><h3> Using NMAKE</h3>
-Alternatively, SWIG extensions can be built by writing a Makefile for NMAKE. Make sure the environment variables for MSVC++ are available and the MSVC++ tools are in your path. Now, just write a short Makefile like this :<p>
-<p>
-<blockquote><pre># Makefile for building a Python extension
-
-SRCS = example.c
-IFILE = example
-INTERFACE = $(IFILE).i
-WRAPFILE = $(IFILE)_wrap.c
-
-# Location of the Visual C++ tools (32 bit assumed)
-
-TOOLS = c:\msdev
-TARGET = example.dll
-CC = $(TOOLS)\bin\cl.exe
-LINK = $(TOOLS)\bin\link.exe
-INCLUDE32 = -I$(TOOLS)\include
-MACHINE = IX86
-
-# C Library needed to build a DLL
-
-DLLIBC = msvcrt.lib oldnames.lib
-
-# Windows libraries that are apparently needed
-WINLIB = kernel32.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib
-winspool.lib
-
-# Libraries common to all DLLs
-LIBS = $(DLLIBC) $(WINLIB)
-
-# Linker options
-LOPT = -debug:full -debugtype:cv /NODEFAULTLIB /RELEASE /NOLOGO \
- /MACHINE:$(MACHINE) -entry:_DllMainCRTStartup@12 -dll
-
-# C compiler flags
-
-CFLAGS = /Z7 /Od /c /nologo
-PY_INCLUDE = -Id:\python-1.4\Include -Id:\python-1.4 -Id:\python-1.4\Pc
-PY_LIB = d:\python-1.4\vc40\python14.lib
-PY_FLAGS = /D__WIN32__
-
-python::
- swig -python -o $(WRAPFILE) $(INTERFACE)
- $(CC) $(CFLAGS) $(PY_FLAGS) $(PY_INCLUDE) $(SRCS) $(WRAPFILE)
- set LIB=$(TOOLS)\lib
- $(LINK) $(LOPT) -out:example.dll $(LIBS) $(PY_LIB) example.obj example_wrap.obj
-
-
-</pre></blockquote>
-<p>
-To build the extension, run NMAKE (you may need to run <tt>vcvars32</tt> first). This is a pretty simplistic Makefile, but hopefully its enough to get you started. <p>
-<a name="n3"></a><h2> The low-level Python/C interface</h2>
-The SWIG Python module is based upon a basic low-level interface that provides access to C functions, variables, constants, and C++ classes. This low-level interface is often used to create more sophisticated interfaces (such as shadow classes) so it may be hidden in practice.<p>
-<a name="n22"></a><h3> Modules</h3>
-The SWIG <tt>%module</tt> directive specifies the name of the Python module. If you specified `<tt>%module example</tt>', then everything found in a SWIG interface file will be contained within the Python `<tt>example</tt>' module. Make sure you don't use the same name as a built-in Python command or standard module or your results may be unpredictable. <p>
-<a name="n23"></a><h3> Functions</h3>
-C/C++ functions are mapped directly into a matching Python function. For example :<p>
-<p>
-<blockquote><pre>%module example
-extern int fact(int n);
-
-</pre></blockquote>
-gets turned into the Python function <tt>example.fact(n)</tt> :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; import example
-&gt;&gt;&gt; print example.fact(4)
-24
-&gt;&gt;&gt;
-</pre></blockquote>
-<a name="n24"></a><h3> Variable Linking</h3>
-SWIG provides access to C/C++ global variables, but the mechanism is slightly different than one might expect due to the object model used in Python. When you type the following in Python :<p>
-<p>
-<blockquote><pre>a = 3.4
-
-</pre></blockquote>
-"a" becomes a name for an object containing the value 3.4. If you later type<p>
-<p>
-<blockquote><pre>b = a
-
-</pre></blockquote>
-Then "a" and "b" are both names for the object containing the value 3.4. In other words, there is only one object containing 3.4 and "a" and "b" are both names that refer to it. This is a very different model than that used in C. For this reason, there is no mechanism for mapping "assignment" in Python onto C global variables (because assignment is Python is really a naming operation).<p>
-<p>
-To provide access to C global variables, SWIG creates a special Python object called `<tt>cvar</tt>' that is added to each SWIG generated module. This object is used to access global variables as follows :<p>
-<blockquote><pre>
-// SWIG interface file with global variables
-%module example
-...
-extern int My_variable;
-extern double density;
-...
-</pre></blockquote>
-<p>
-Now in Python :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; import example
-&gt;&gt;&gt; # Print out value of a C global variable
-&gt;&gt;&gt; print example.cvar.My_variable
-4
-&gt;&gt;&gt; # Set the value of a C global variable
-&gt;&gt;&gt; example.cvar.density = 0.8442
-&gt;&gt;&gt; # Use in a math operation
-&gt;&gt;&gt; example.cvar.density = example.cvar.density*1.10
-</pre></blockquote>
-<p>
-Just remember, all C globals need to be prefixed with a "<tt>cvar.</tt>" and you will be set. If you would like to use a name other than "<tt>cvar</tt>", it can be changed using the <tt>-globals</tt> option :<p>
-<p>
-<blockquote><pre>% swig -python -globals myvar example.i
-
-</pre></blockquote>
-Some care is in order when importing multiple SWIG modules. If you use the "<tt>from &lt;file&gt; import *</tt>" style of importing, you will get a name clash on the variable `<tt>cvar</tt>' and will only be able to access global variables from the last module loaded. SWIG does not create <tt>cvar</tt> if there are no global variables in a module.<p>
-<a name="n25"></a><h3> Constants</h3>
-C/C++ constants are installed as new Python objects containing the appropriate value. These constants are given the same name as the corresponding C constant. "Constants" are not guaranteed to be constants in Python---in other words, you are free to change them and suffer the consequences!<p>
-<a name="n26"></a><h3> Pointers</h3>
-Pointers to C/C++ objects are represented as character strings such as the following :<p>
-<p>
-<blockquote><pre>_100f8e2_Vector_p
-
-</pre></blockquote>
-A NULL pointer is represented by the string "NULL". You can also explicitly create a NULL pointer consisting of the value 0 and a type such as :<p>
-<p>
-<blockquote><pre>_0_Vector_p
-
-</pre></blockquote>
-To some Python users, the idea of representing pointers as strings may seem strange, but keep in mind that pointers are meant to be opaque objects. In practice, you may never notice that pointers are character strings. There is also a certain efficiency in using this representation as it is easy to pass pointers around between modules and it is unnecessary to rely on a new Python datatype. Eventually, pointers may be represented as special Python objects, but the string representation works remarkably well so there has been little need to replace it.<p>
-<a name="n27"></a><h3> Structures </h3>
-The low-level SWIG interface only provides a simple interface to C structures. For example :<p>
-<p>
-<blockquote><pre>struct Vector {
- double x,y,z;
-};
-
-</pre></blockquote>
-gets mapped into the following collection of C functions :<p>
-<p>
-<blockquote><pre>double Vector_x_get(Vector *obj)
-double Vector_x_set(Vector *obj, double x)
-double Vector_y_get(Vector *obj)
-double Vector_y_set(Vector *obj, double y)
-double Vector_z_get(Vector *obj)
-double Vector_z_set(Vector *obj, double z)
-
-</pre></blockquote>
-These functions are then used in the resulting Python interface. For example :<p>
-<p>
-<blockquote><pre># v is a Vector that got created somehow
-&gt;&gt;&gt; Vector_x_get(v)
-3.5
-&gt;&gt;&gt; Vector_x_set(v,7.8) # Change x component
-&gt;&gt;&gt; print Vector_x_get(v), Vector_y_get(v), Vector_z_get(v)
-7.8 -4.5 0.0
-&gt;&gt;&gt;
-</pre></blockquote>
-<p>
-Similar access is provided for unions and the data members of C++ classes.<p>
-<a name="n28"></a><h3> C++ Classes</h3>
-C++ classes are handled by building a set of low level accessor functions. Consider the following class :<p>
-<p>
-<blockquote><pre>class List {
-public:
- List();
- ~List();
- int search(char *item);
- void insert(char *item);
- void remove(char *item);
- char *get(int n);
- int length;
-static void print(List *l);
-};
-</pre></blockquote>
-<p>
-When wrapped by SWIG, the following functions will be created :<p>
-<p>
-<blockquote><pre>List *new_List();
-void delete_List(List *l);
-int List_search(List *l, char *item);
-void List_insert(List *l, char *item);
-void List_remove(List *l, char *item);
-char *List_get(List *l, int n);
-int List_length_get(List *l);
-int List_length_set(List *l, int n);
-void List_print(List *l);
-
-</pre></blockquote>
-Within Python, these functions used to access the C++ class :<p>
-<blockquote><pre>
-&gt;&gt;&gt; l = new_List()
-&gt;&gt;&gt; List_insert(l,"Ale")
-&gt;&gt;&gt; List_insert(l,"Stout")
-&gt;&gt;&gt; List_insert(l,"Lager")
-&gt;&gt;&gt; List_print(l)
-Lager
-Stout
-Ale
-&gt;&gt;&gt; print List_length_get(l)
-3
-&gt;&gt;&gt; print l
-_1008560_List_p
-&gt;&gt;&gt;
-
-</pre></blockquote>
-C++ objects are really just pointers. Member functions and data are accessed by simply passing a pointer into a collection of accessor functions that take the pointer as the first argument.<p>
-<p>
-While somewhat primitive, the low-level SWIG interface provides direct and flexible access to C++ objects. As it turns out, a more elegant method of accessing structures and classes is available using shadow classes.<p>
-<a name="n4"></a><h2> Python shadow classes</h2>
-The low-level interface generated by SWIG provides access to C structures and C++ classes, but it doesn't look much like a class that might be created in Python. However, it is possible to use the low-level C interface to write a Python class that looks like the original C++ class. In this case, the Python class is said to "shadow" the C++ class. That is, it behaves like the original class, but is really just a wrapper around a C++ class.<p>
-<a name="n29"></a><h3> A simple example</h3>
-For our earlier List class, a Python shadow class could be written by hand like this :<p>
-<p>
-<blockquote><pre>class List:
- def __init__(self):
- self.this = new_List()
- def __del__(self):
- delete_List(self.this)
- def search(self,item):
- return List_search(self.this,item)
- def insert(self,item):
- List_insert(self.this,item)
- def remove(self,item):
- List_remove(self.this,item)
- def get(self,n):
- return List_get(self.this,n)
- def __getattr__(self,name):
- if name == "length" : return List_length_get(self.this))
- else : return self.__dict__[name]
- def __setattr__(self,name,value):
- if name == "length": List_length_set(self.this,value)
- else : self.__dict__[name] = value
-</pre></blockquote>
-<p>
-When used in a Python script, we can use the class as follows :<p>
-<blockquote><pre>
-
-&gt;&gt;&gt; l = List()
-&gt;&gt;&gt; l.insert("Ale")
-&gt;&gt;&gt; l.insert("Stout")
-&gt;&gt;&gt; l.insert("Lager")
-&gt;&gt;&gt; List_print(l.this)
-Lager
-Stout
-Ale
-&gt;&gt;&gt; l.length
-3
-</pre></blockquote>
-<p>
-Obviously, this is a much nicer interface than before--and it only required a small amount of Python coding.<p>
-<a name="n30"></a><h3> Why write shadow classes in Python?</h3>
-While one could wrap C/C++ objects directly into Python as new Python types, this approach has a number of problems. First, as the C/C++ code gets complicated, the resulting wrapper code starts to become extremely ugly. It also becomes hard to handle inheritance and more advanced language features. A second, and more serious problem, is that Python "types" created in C can not be subclassed or used in the same way as one might use a real Python class. As a result, it is not possible to do interesting things like create Python classes that inherit from C++ classes. <p>
-<p>
-By writing shadow classes in Python instead of C, the classes become real Python classes that can be used as base-classes in an inheritance hierarchy or for other applications. Writing the shadow classes in Python also greatly simplies coding complexity as writing in Python is much easier than trying to accomplish the same thing in C. Finally, by writing shadow classes in Python, they are easy to modify and can be changed without ever recompiling any of the C code. The downside to this approach is worse performance--a concern for some users.<p>
-<p>
-The problems of combining C++ and Python have been of great interest to the Python community. SWIG is primarily concerned with accessing C++ from Python. Readers who are interested in more than this (and the idea of accessing Python classes from C++) are encouraged to look into the MESS extension which aims to provide a tighter integration between C++ and Python. The recently announced GRAD package also shows much promise and provides very comprehensive C++/Python interface.<p>
-<a name="n31"></a><h3> Automated shadow class generation</h3>
-SWIG can automatically generate shadow classes if you use the <tt>-shadow</tt> option :<p>
-<p>
-<blockquote><pre>swig -python -shadow interface.i
-
-</pre></blockquote>
-This will create the following two files :<p>
-<p>
-<blockquote><pre>interface_wrap.c
-module.py
-</pre></blockquote>
-<p>
-The file <tt>interface_wrap.c</tt> contains the normal SWIG C/C++ wrappers. The file <tt>module.py</tt> contains the Python code corresponding to shadow classes. The name of this file will be the same as specified by the <tt>%module</tt> directive in the SWIG interface file.<p>
-<p>
-Associated with the two files are TWO Python modules. The C module `<tt>modulec</tt>' contains the low-level C interface that would have been created without the <tt>-shadow</tt> option. The Python module `<tt>module</tt>' contains the Python shadow classes that have been built around the low-level interface. To use the module, simply use `<tt>import module</tt>'. For all practical purposes, the `<tt>modulec</tt>' module is completely hidden although you can certainly use it if you want to.<p>
-<a name="n32"></a><h3> Compiling modules with shadow classes</h3>
-To compile a module involving shadow classes, you can use the same procedure as before except that the module name now has an extra `<tt>c</tt>' appended to the name. Thus, an interface file like this <p>
-<p>
-<blockquote><pre>%module example
-... a bunch of declarations ...
-
-</pre></blockquote>
-might be compiled as follows :<p>
-<p>
-<blockquote><pre>% swig -python -shadow example.i
-% gcc -c example.c example_wrap.c -I/usr/local/include/python1.4 \
- -I/usr/local/lib/python1.4/config -DHAVE_CONFIG_H
-% ld -shared example.o example_wrap.o -o examplecmodule.so
-
-</pre></blockquote>
-Notice the naming of `<tt>examplecmodule.so</tt>' as opposed to `<tt>examplemodule.so</tt>' that would have been created without shadow classes.<p>
-<p>
-When using static linking, no changes need to be made to the compilation process.<p>
-<a name="n33"></a><h3> Where to go for more information</h3>
-Shadow classes turn out to be so useful that they are used almost all of the time with SWIG. All of the examples presented here will assume that shadow classes have been enabled. The precise implementation of shadow classes is described at the end of this chapter and is not necessary to effectively use SWIG.<p>
-<a name="n5"></a><h2> About the Examples</h2>
-The next few sections will go through a series of Python examples of varying complexity. These examples are designed to illustrate how SWIG can be used to integrate C/C++ and Python in a variety of ways. Some of the things that will be covered include :<p>
-<p>
-<ul>
-<li>Controlling a simple C++ program with Python
-<li>Wrapping a C library.
-<li>Adding Python methods to existing C++ classes
-<li>Accessing arrays and other common data structures.
-<li>Building reusable components.
-<li>Writing C/C++ callback functions in Python.
-</ul>
-<a name="n6"></a><h2> Solving a simple heat-equation</h2>
-In this example, we will show how Python can be used to control a simple physics application--in this case, some C++ code for solving a 2D heat equation. This example is probably overly simplistic, but hopefully it's enough to give you some ideas.<p>
-<a name="n34"></a><h3> The C++ code </h3>
-Our simple application consists of the following two files :<p>
-<blockquote><pre>
-// File : pde.h
-// Header file for Heat equation solver
-
-#include &lt;math.h&gt;
-#include &lt;stdio.h&gt;
-
-// A simple 2D Grid structure
-
-// A simple structure for holding a 2D grid of values
-struct Grid2d {
- Grid2d(int ni, int nj);
- ~Grid2d();
- double **data;
- int xpoints;
- int ypoints;
-};
-
-// Simple class for solving a heat equation */
-class Heat2d {
-private:
- Grid2d *work; // Temporary grid, needed for solver
- double h,k; // Grid spacing
-public:
- Heat2d(int ni, int nj);
- ~Heat2d();
- Grid2d *grid; // Data
- double dt; // Timestep
- double time; // Elapsed time
- void solve(int nsteps); // Run for nsteps
- void set_temp(double temp); // Set temperature
-};
-</pre></blockquote>
-<p>
-The supporting C++ code implements a simple partial differential equation solver and some operations on the grid data structure. The precise implementation isn't important here, but all of the code can be found in the "<tt>Examples/python/manual" </tt>directory of the SWIG distribution. <p>
-<a name="n35"></a><h3> Making a quick and dirty Python module</h3>
-Given our simple application, making a Python module is easy. Simply use the following SWIG interface file :<p>
-<p>
-<blockquote><pre>// File : pde.i
-%module pde
-%{
-#include "pde.h"
-%}
-
-%include pde.h
-
-</pre></blockquote>
-Since <tt>pde.h</tt> is fairly simple, we can simply include it directly into our interface file using <tt>%include</tt>. However, we also need to make sure we also include it in the <tt>%{,%}</tt> block--otherwise we'll get a huge number of compiler errors when we compile the resulting wrapper file. <p>
-<p>
-To build the module simply run SWIG with the following options<p>
-<p>
-<blockquote><pre>swig -python -shadow pde.i
-</pre></blockquote>
-<p>
-and compile using the techniques described in the beginning of this chapter.<p>
-<a name="n36"></a><h3> Using our new module</h3>
-We are now ready to use our new module. To do this, we can simply write a Python script like this :<p>
-<p>
-<blockquote><pre># A fairly uninteresting example
-
-from pde import *
-
-h = Heat2d(50,50) # Creates a new "problem"
-
-h.set_temp(1.0)
-print "Dt = ", h.dt
-
-# Solve something
-
-for i in range(0,25):
- h.solve(100)
- print "time = ", h.time
-
-</pre></blockquote>
-<p>
-When run, we get rather exciting output such as the following :<p>
-<blockquote><pre>
-Dt = 2.5e-05
-time = 0.0025
-time = 0.005
-time = 0.0075
-...
-time = 0.06
-time = 0.0625
-
-</pre></blockquote>
-(okay, it's not that exciting--well, maybe it is if you don't get out much).<p>
-<p>
-While this has only been a simple example it is important to note that we could have just as easily written the same thing in C++. For example :<p>
-<p>
-<blockquote><pre>// Python example written in C++
-
-#include "pde.h"
-#include &lt;stdio.h&gt;
-
-int main(int argc, char **argv) {
-
- Heat2d *h;
-
- h = new Heat2d(50,50);
- printf("Dt = %g\n", h-&gt;dt);
-
- h-&gt;set_temp(1.0);
-
- for (int i = 0; i &lt; 25; i++) {
- h-&gt;solve(100);
- printf("time = %g\n", h-&gt;time);
- }
-}
-
-</pre></blockquote>
-For the most part, the code looks identical (although the Python version is simpler). As for performance, the Python version runs less than 1% slower than the C++ version on my machine. Given that most of the computational work is written in C++, there is very little performance penalty for writing the outer loop of our calculation in Python in this case.<p>
-<p>
-Unfortunately, our Python version suffers a number of drawbacks. Most notably, there is no way for us to access any of the grid data (which is easily accomplished in C++). However, there are ways to fix this :<p>
-<a name="n37"></a><h3> Accessing array data</h3>
-Let's modify our heat equation problem so that we can access grid data directly from Python. This can be done by modifying our interface file as follows :<p>
-<blockquote><pre>
-%module pde
-%{
-#include "pde.h"
-%}
-
-%include pde.h
-
-// Add a few "helper" functions to extract grid data
-%inline %{
-double Grid2d_get(Grid2d *g, int i, int j) {
- return g-&gt;data[i][j];
-}
-void Grid2d_set(Grid2d *g, int i, int j, double val) {
- g-&gt;data[i][j] = val;
-}
-%}
-
-</pre></blockquote>
-Rather than modifying our C++ code, it is easy enough to supply a few accessor functions directly in our interface file. These function may only be used from Python so this approach makes sense and it helps us keep our C++ code free from unnecessary clutter. The <tt>%inline</tt> directive is a convenient method for adding helper functions since the functions you declare show up in the interface automatically.<p>
-<p>
-We can now use our accessor functions to write a more sophisticated Python script :<p>
-<p>
-<blockquote><pre># An example using our set/get functions
-
-from pde import *
-
-# Set up an initial condition
-def initcond(h):
- h.set_temp(0.0)
- nx = h.grid.xpoints
- for i in range(0,nx):
- Grid2d_set(h.grid,i,0,1.0) # Set grid values
-
-# Dump out to a file
-def dump(h,filename):
- f = open(filename,"w")
- nx = h.grid.xpoints
- ny = h.grid.ypoints
- for i in range(0,nx):
- for j in range(0,ny):
- f.write(str(Grid2d_get(h.grid,i,j))+"\n") # Get grid value
- f.close()
-
-# Set up a problem and run it
-
-h = Heat2d(50,50)
-initcond(h)
-fileno = 1
-for i in range(0,25):
- h.solve(100)
- dump(h,"Dat"+str(fileno))
- print "time = ", h.time
- fileno = fileno+1
-
-</pre></blockquote>
-<p>
-We now have a Python script that can create a grid, set up an initial condition, run a simulation, and dump a collection of datafiles. So, with just a little supporting code in our interface file, we can start to do useful work from Python. <p>
-<a name="n38"></a><h3> Use Python for control, C for performance</h3>
-Now that it is possible to access grid data from Python, it is possible to quickly write code for all sorts of operations. However, Python may not provide enough performance for certain operations. For example, the <tt>dump()</tt> function in the previous example may become quite slow as problem sizes increase. Thus, we might consider writing it in C++ such as the follows:<p>
-<p>
-<blockquote><pre>void dump(Heat2d *h, char *filename) {
- FILE *f;
- int i,j;
-
- f = fopen(filename,"w");
- for (i = 0; i &lt; h-&gt;grid-&gt;xpoints; i++)
- for (j = 0; j &lt; h-&gt;grid-&gt;ypoints; j++)
- fprintf(f,"%0.17f\n",h-&gt;grid-&gt;data[i][j]);
- fclose(f);
-}
-</pre></blockquote>
-<p>
-To use this new function, simple put its declaration in the SWIG interface file and get rid of the old Python version. The Python script won't know that you changed the implementation.<p>
-<a name="n39"></a><h3> Getting even more serious about array access</h3>
-We have provided access to grid data using a pair of get/set functions. However, using these functions is a little clumsy because they always have to be called as a separate function like this :<p>
-<p>
-<blockquote><pre>Grid2d_set(grid,i,j,1.0)
-</pre></blockquote>
-<p>
-It might make more sense to make the get/set functions appear like member functions of the <tt>Grid2D</tt> class. That way we could use them like this :<p>
-<p>
-<blockquote><pre>grid.set(i,j,1.0)
-grid.get(i,j)
-
-</pre></blockquote>
-SWIG provides a simple technique for doing this as illustrated in the following interface file :<p>
-<p>
-<blockquote><pre>%module pde
-%{
-#include "pde.h"
-%}
-%include pde.h
-
-// Add a few "helper" functions to extract grid data
-%{
- double Grid2d_get(Grid2d *g, int i, int j) {
- return g-&gt;data[i][j];
- }
- void Grid2d_set(Grid2d *g, int i, int j, double val) {
- g-&gt;data[i][j] = val;
- }
-%}
-
-// Now add these helper functions as methods of Grid2d
-
-%addmethods Grid2d {
- double get(int i, int j); // Gets expanded to Grid2d_get()
- void set(int i, int j, double val); // Gets expanded to Grid2d_set()
-}
-</pre></blockquote>
-<p>
-The <tt>%addmethods</tt> directive tells SWIG that you want to add new functions to an existing C++ class or C structure for the purposes of building an interface. In reality, SWIG leaves the original C++ class unchanged, but the resulting Python interface will have some new functions that appear to be class members.<p>
-<p>
-SWIG uses a naming convention for adding methods to a class. If you have a class <tt>Foo</tt> and you add a member function <tt>bar(args),</tt> SWIG will look for a function called <tt>Foo_bar(this,args)</tt> that implements the desired functionality. You can write this function yourself, as in the previous interface file, but you can also just supply the code immediately after a declaration like this :<p>
-<blockquote><pre>
-%module pde
-%{
-#include "pde.h"
-%}
-%include pde.h
-
-// Add some new accessor methods to the Grid2D class
-%addmethods Grid2d {
- double get(int i, int j) {
- return self-&gt;data[i][j];
- };
- void set(int i, int j, double val) {
- self-&gt;data[i][j] = val;
- };
-};
-
-</pre></blockquote>
-<p>
-In this case, SWIG will take the supplied code, and automatically generate a function for the method. The special variable "<tt>self</tt>" is used to hold a pointer to the corresponding object. The <tt>self </tt>pointer is exactly like the C++ "<tt>this</tt>" pointer, except that the name has been changed in order to remind you that you aren't really writing a real class member function. (Actually, the real reason we can't use "this" is because the C++ compiler will start complaining!)<p>
-<p>
- Finally, it is worth noting that the <tt>%addmethods</tt> directive may also be used inside a class definition like this :<p>
-<p>
-<blockquote><pre>struct Grid2d {
- Grid2d(int ni, int nj);
- ~Grid2d();
- double **data;
- int xpoints;
- int ypoints;
- %addmethods {
- double get(int i, int j);
- void set(int i, int j, double value);
- }
-};
-
-</pre></blockquote>
-This latter case is really only useful if the C++ class definition is included in the SWIG interface file itself. If you are pulling the class definition out of a separate file or a C++ header file, using a separate <tt>%addmethods</tt> directive is preferable. It doesn't matter if the <tt>%addmethods</tt> directive appears before or after the real class definition--SWIG will correctly associate the two definitions.<p>
-<p>
-Okay, enough talk. By adding the set/get functions as methods, we can now change our Python script to look like this (changes are underlined) :<p>
-<p>
-<blockquote><pre># An example using our new set/get functions
-
-from pde import *
-
-# Set up an initial condition
-
-def initcond(h):
- h.set_temp(0.0)
- nx = h.grid.xpoints
- for i in range(0,nx):
- h.grid.set(i,0,1.0) # Note changed interface
-
-# Dump out to a file
-def dump(h,filename):
- f = open(filename,"w")
- nx = h.grid.xpoints
- ny = h.grid.ypoints
- for i in range(0,nx):
- for j in range(0,ny):
- f.write(str(h.grid.get(i,j))+"\n")
- f.close()
-
-# Set up a problem and run it
-
-h = Heat2d(50,50)
-initcond(h)
-fileno = 1
-
-for i in range(0,25):
- h.solve(100)
- h.dump("Dat"+str(fileno))
- print "time = ", h.time
- fileno = fileno+1
-
-</pre></blockquote>
-<p>
-Now it's starting to look a little better, but we can do even better...<p>
-<a name="n40"></a><h3> Implementing special Python methods in C</h3>
-Now that you're getting into the spirit of things, let's make it so that we can access our <tt>Grid2D</tt> data like a Python array. As it turns out, we can do this with a little trickery in the SWIG interface file. Don't forget to put on your Python wizard cap...<p>
-<p>
-<blockquote><pre>// SWIG interface file with Python array methods added
-%module pde
-%{
-#include "pde.h"
-%}
-
-%include pde.h
-
-%inline %{
- // Define a new Grid2d row class
- struct Grid2dRow {
- Grid2d *g; // Grid
- int row; // Row number
- // These functions are used by Python to access sequence types (lists, tuples, ...)
- double __getitem__(int i) {
- return g-&gt;data[row][i];
- };
- void __setitem__(int i, double val) {
- g-&gt;data[row][i] = val;
- };
- };
-%}
-
-// Now add a __getitem__ method to Grid2D to return a row
-%addmethods Grid2d {
- Grid2dRow __getitem__(int i) {
- Grid2dRow r;
- r.g = self;
- r.row = i;
- return r;
- };
-};
-</pre></blockquote>
-<p>
-We have now replaced our get/set functions with<tt> the __getitem__</tt> and <tt>__setitem__</tt> functions that Python needs to access arrays. We have also added a special <tt>Grid2dRow</tt> class. This is needed to allow us to make a funny kind of "multidimensional" array in Python (this may take a few minutes of thought to figure out). Using this new interface file, we can now write a Python script like this :<p>
-<p>
-<blockquote><pre># An example script using our array access functions
-
-from pde import *
-
-# Set up an initial condition
-
-def initcond(h):
- h.set_temp(0.0)
- nx = h.grid.xpoints
- for i in range(0,nx):
- h.grid[i][0] = 1.0 # Note nice array access
-
-# Set up a problem and run it
-
-h = Heat2d(50,50)
-initcond(h)
-fileno = 1
-
-for i in range(0,25):
- h.solve(100)
- h.dump("Dat"+str(fileno))
- print "time = ", h.time
- fileno = fileno+1
-
-# Calculate average temperature over the region
-
-sum = 0.0
-for i in range(0,h.grid.xpoints):
- for j in range(0,h.grid.ypoints):
- sum = sum + h.grid[i][j] # Note nice array access
-
-avg = sum/(h.grid.xpoints*h.grid.ypoints)
-
-print "Avg temperature = ",avg
-</pre></blockquote>
-<a name="n41"></a><h3> Summary (so far)</h3>
-In our first example, we have taken a very simple C++ problem and wrapped it into a Python module. With a little extra work, we have been able to provide array type access to our C++ data from Python and to write some computationally intensive operations in C++. At this point, it would easy to write all sorts of Python scripts to set up problems, run simulations, look at the data, and to debug new operations implemented in C++. <p>
-<a name="n7"></a><h2> Wrapping a C library</h2>
-In this next example, we focus on wrapping the gd-1.2 library. gd is public domain library for fast GIF image creation written by Thomas Boutell and available on the internet. gd-1.2 is copyright 1994,1995, Quest Protein Database Center, Cold Spring Harbor Labs. This example assumes that you have gd-1.2 available, but you can use the ideas here to wrap other kinds of C libraries.<p>
-<a name="n42"></a><h3> Preparing a module</h3>
-Wrapping a C library into a Python module usually involves working with the C header files associated with a particular library. In some cases, a header file can be used directly (without modification) with SWIG. Other times, it may be necessary to copy the header file into a SWIG interface file and make a few touch-ups and modifications. In either case, it's usually not too difficult.<p>
-<p>
-To make a module, you can use the following checklist :<p>
-<p>
-<ul>
-<li>Locate the header files associated with a package
-<li>Look at the contents of the header files to see if SWIG can handle them. In particular, SWIG can not handle excessive use of C preprocessor macros, or non-ANSI C syntax. The best way to identify problems is to simply run SWIG on the file and see what errors (if any) get reported.
-<li>Make a SWIG interface file for your module specifying the name of the module, the appropriate header files, and any supporting documentation that you would like to provide.
-<li>If the header file is clean, simply use SWIG's <tt>%include</tt> directive. If not, paste the header file into your interface file and edit it until SWIG can handle it.
-<li>Clean up the interface by possibly adding supporting code, deleting unnecessary functions, and eliminating clutter.
-<li>Run SWIG and compile.
-</ul>
-<p>
-In the case of the gd library, we can simply use the following SWIG interface file :<p>
-<p>
-<blockquote><pre>%module gd
-%{
-#include "gd.h"
-%}
-
-%section "gd-1.2",ignore
-%include "gd.h"
-
-// These will come in handy later
-FILE *fopen(char *, char *);
-void fclose(FILE *f);
-
-</pre></blockquote>
-<p>
-In this file, we first tell SWIG to put all of the gd functions in a separate documentation section and to ignore all comments. This usually helps clean up the documentation when working with raw header files. Next, we simply include the contents of "gd.h" directly. Finally, we provide wrappers to <tt>fopen()</tt> and <tt>fclose()</tt> since these will come in handy in our Python interface.<p>
-<p>
-If we give this interface file to SWIG, we will get the following output :<p>
-<p>
-<blockquote><pre>% swig -python -shadow -I/usr/local/include gd.i
-Generating wrappers for Python
-/usr/local/include/gd.h : Line 32. Arrays not currently supported (ignored).
-/usr/local/include/gd.h : Line 33. Arrays not currently supported (ignored).
-/usr/local/include/gd.h : Line 34. Arrays not currently supported (ignored).
-/usr/local/include/gd.h : Line 35. Arrays not currently supported (ignored).
-/usr/local/include/gd.h : Line 41. Arrays not currently supported (ignored).
-/usr/local/include/gd.h : Line 42. Arrays not currently supported (ignored).
-%
-
-</pre></blockquote>
-While SWIG was able to handle most of the header file, it also ran into a few unsupported declarations---in this case, a few data structures with array members. However, the warning messages also tell us that these declarations have simply been ignored. Thus, we can choose to continue and build our interface anyways. As it turns out in this case, the ignored declarations are of little or no consequence so we can ignore the warnings.<p>
-<p>
-If SWIG is unable to process a raw header file or if you would like to eliminate the warning messages, you can structure your interface file as follows :<p>
-<p>
-<blockquote><pre>%module gd
-%{
-#include "gd.h"
-%}
-
-%section "gd-1.2",ignore
-
-... paste the contents of gd.h here and remove problems ...
-
-// A few extra support functions
-
-FILE *fopen(char *, char *);
-void fclose(FILE *f);
-
-</pre></blockquote>
-This latter option requires a little more work (since you need to paste the contents of gd.h into the file and edit it), but is otherwise not much more difficult to do. For highly complex C libraries or header files that go overboard with the C preprocessor, you may need to do this more often. <p>
-<a name="n43"></a><h3> Using the gd module</h3>
-Now, that we have created a module from the gd library, we can use it in Python scripts. The following script makes a simple image of a black background with a white line drawn on it. Notice how we have used our wrapped versions of <tt>fopen()</tt> and <tt>fclose()</tt> to create a FILE handle for use in the gd library (there are also ways to use Python file objects, but this is described later).<p>
-<p>
-<blockquote><pre># Simple gd program
-
-from gd import *
-
-im = gdImageCreate(64,64)
-black = gdImageColorAllocate(im,0,0,0)
-white = gdImageColorAllocate(im,255,255,255)
-gdImageLine(im,0,0,63,63,white)
-out = fopen("test.gif","w")
-gdImageGif(im,out)
-fclose(out)
-gdImageDestroy(im)
-
-</pre></blockquote>
-<p>
-That was simple enough--and it only required about 5 minutes of work. Unfortunately, our gd module still has a few problems...<p>
-<a name="n44"></a><h3> Extending and fixing the gd module</h3>
-While our first attempt at wrapping gd works for simple functions, there are a number of problems. For example, the gd-1.2 library contains the following function for drawing polygons :<p>
-<p>
-<blockquote><pre>void gdImagePolygon(gdImagePtr im, gdPointPtr points, int pointsTotal, int color);
-
-</pre></blockquote>
-The <tt>gdImagePtr</tt> type is created by another function in our module and the parameters <tt>pointsTotal</tt> and <tt>color</tt> are simple integers. However, the 2nd argument is a pointer to an array of points as defined by the following data structure in the gd-1.2 header file :<p>
-<p>
-<blockquote><pre>typedef struct {
- int x, y;
-} gdPoint, *gdPointPtr;
-
-</pre></blockquote>
-Unfortunately, there is no way to create a gdPoint in Python and consequently no way to call the gdImagePolygon function. A temporary setback, but one that is not difficult to solve using the <tt>%addmethods</tt> directive as follows :<p>
-<blockquote><pre>
-%module gd
-%{
-#include "gd.h"
-%}
-
-%include "gd.h"
-
-// Fix up the gdPoint structure a little bit
-%addmethods gdPoint {
- // Constructor to make an array of "Points"
- gdPoint(int npoints) {
- return (gdPoint *) malloc(npoints*sizeof(gdPoint));
- };
- // Destructor to destroy this array
- ~gdPoint() {
- free(self);
- };
- // Python method for array access
- gdPoint *__getitem__(int i) {
- return self+i;
- };
-};
-
-FILE *fopen(char *, char *);
-void fclose(FILE *f);
-
-</pre></blockquote>
-With these simple additions, we can now create arrays of points and use the polygon function as follows :<p>
-<p>
-<blockquote><pre># Simple gd program
-
-from gd import *
-
-im = gdImageCreate(64,64)
-black = gdImageColorAllocate(im,0,0,0)
-white = gdImageColorAllocate(im,255,255,255)
-
-pts = gdPoint(3); # Create an array of Points
-pts[0].x,pts[0].y = (5,5) # Assign a set of points
-pts[1].x,pts[1].y = (60,25)
-pts[2].x,pts[2].y = (16,60)
-
-gdImagePolygon(im,pts,3,white) # Draw a polygon from our array of points
-out = fopen("test.gif","w")
-gdImageGif(im,out)
-fclose(out)
-gdImageDestroy(im)
-
-</pre></blockquote>
-<a name="n45"></a><h3> Building a simple 2D imaging class</h3>
-Now it's time to get down to business. Using our gd-1.2 module, we can write a simple 2D imaging class that hides alot of the underlying details and provides scaling, translations, and a host of other operations. (It's a fair amount code, but an interesting example of how one can take a simple C library and turn it into something that looks completely different).<p>
-<p>
-<p>
-<blockquote><pre># image.py
-# Generic 2D Image Class
-#
-# Built using the 'gd-1.2' library by Thomas Boutell
-#
-
-import gd
-
-class Image:
- def __init__(self,width,height,xmin=0.0,ymin=0.0,xmax=1.0,ymax=1.0):
- self.im = gd.gdImageCreate(width,height)
- self.xmin = xmin
- self.ymin = ymin
- self.xmax = xmax
- self.ymax = ymax
- self.width = width
- self.height = height
- self.dx = 1.0*(xmax-xmin)
- self.dy = 1.0*(ymax-ymin)
- self.xtick = self.dx/10.0
- self.ytick = self.dy/10.0
- self.ticklen= 3
- self.name = "image.gif"
- gd.gdImageColorAllocate(self.im,0,0,0) # Black
- gd.gdImageColorAllocate(self.im,255,255,255) # White
- gd.gdImageColorAllocate(self.im,255,0,0) # Red
- gd.gdImageColorAllocate(self.im,0,255,0) # Green
- gd.gdImageColorAllocate(self.im,0,0,255) # Blue
-
- def __del__(self):
- print "Deleting"
- gd.gdImageDestroy(self.im)
-
- # Dump out this image to a file
- def write(self,name="NONE"):
- if name == "NONE":
- name = self.name
- f = gd.fopen(name,"w")
- gd.gdImageGif(self.im,f)
- gd.fclose(f)
- self.name = name
-
- # Virtual method that derived classes define
- def draw(self):
- print "No drawing method specified."
-
- # A combination of write and draw
- def show(self,filename="NONE"):
- self.draw()
- self.write(filename)
-
- # Load up a colormap from a Python array of (R,G,B) tuples
- def colormap(self, cmap):
- for i in range(0,255):
- gd.gdImageColorDeallocate(self.im,i)
- for c in cmap:
- gd.gdImageColorAllocate(self.im,c[0],c[1],c[2])
-
- # Change viewing region
- def region(self,xmin,ymin,xmax,ymax):
- self.xmin = xmin
- self.ymin = ymin
- self.xmax = xmax
- self.ymax = ymax
- self.dx = 1.0*(xmax-xmin)
- self.dy = 1.0*(ymax-ymin)
-
- # Transforms a 2D point into screen coordinates
- def transform(self,x,y):
- npt = []
- ix = (x-self.xmin)/self.dx*self.width + 0.5
- iy = (self.ymax-y)/self.dy*self.height + 0.5
- return (ix,iy)
-
- # A few graphics primitives
- def clear(self,color):
- gd.gdImageFilledRectangle(self.im,0,0,self.width,self.height,color)
-
- def plot(self,x,y,color):
- ix,iy = self.transform(x,y)
- gd.gdImageSetPixel(self.im,ix,iy,color)
-
- def line(self,x1,y1,x2,y2,color):
- ix1,iy1 = self.transform(x1,y1)
- ix2,iy2 = self.transform(x2,y2)
- gd.gdImageLine(self.im,ix1,iy1,ix2,iy2,color)
-
- def box(self,x1,y1,x2,y2,color):
- ix1,iy1 = self.transform(x1,y1)
- ix2,iy2 = self.transform(x2,y2)
- gd.gdImageRectangle(self.im,ix1,iy1,ix2,iy2,color)
-
- def solidbox(self,x1,y1,x2,y2,color):
- ix1,iy1 = self.transform(x1,y1)
- ix2,iy2 = self.transform(x2,y2)
- gd.gdImageFilledRectangle(self.im,ix1,iy1,ix2,iy2,color)
-
- def arc(self,cx,cy,w,h,s,e,color):
- ix,iy = self.transform(cx,cy)
- iw = (x - self.xmin)/self.dx * self.width
- ih = (y - self.ymin)/self.dy * self.height
- gd.gdImageArc(self.im,ix,iy,iw,ih,s,e,color)
-
- def fill(self,x,y,color):
- ix,iy = self.transform(x,y)
- gd.gdImageFill(self,ix,iy,color)
-
- def axis(self,color):
- self.line(self.xmin,0,self.xmax,0,color)
- self.line(0,self.ymin,0,self.ymax,color)
- x = -self.xtick*(int(-self.xmin/self.xtick)+1)
- while x &lt;= self.xmax:
- ix,iy = self.transform(x,0)
- gd.gdImageLine(self.im,ix,iy-self.ticklen,ix,iy+self.ticklen,color)
- x = x + self.xtick
- y = -self.ytick*(int(-self.ymin/self.ytick)+1)
- while y &lt;= self.ymax:
- ix,iy = self.transform(0,y)
- gd.gdImageLine(self.im,ix-self.ticklen,iy,ix+self.ticklen,iy,color)
- y = y + self.ytick
-
- # scalex(s). Scales the x-axis. s is given as a scaling factor
- def scalex(self,s):
- xc = self.xmin + self.dx/2.0
- dx = self.dx*s
- xmin = xc - dx/2.0
- xmax = xc + dx/2.0
- self.region(xmin,self.ymin,xmax,self.ymax)
-
- # scaley(s). Scales the y-axis.
- def scaley(self,s):
- yc = self.ymin + self.dy/2.0
- dy = self.dy*s
- ymin = yc - dy/2.0
- ymax = yc + dy/2.0
- self.region(self.xmin,ymin,self.xmax,ymax)
-
- # Zooms a current image. s is given as a percent
- def zoom(self,s):
- s = 100.0/s
- self.scalex(s)
- self.scaley(s)
-
- # Move image left. s is given in range 0,100. 100 moves a full screen left
- def left(self,s):
- dx = self.dx*s/100.0
- xmin = self.xmin + dx
- xmax = self.xmax + dx
- self.region(xmin,self.ymin,xmax,self.ymax)
-
- # Move image right. s is given in range 0,100. 100 moves a full screen right
- def right(self,s):
- self.left(-s)
-
- # Move image down. s is given in range 0,100. 100 moves a full screen down
- def down(self,s):
- dy = self.dy*s/100.0
- ymin = self.ymin + dy
- ymax = self.ymax + dy
- self.region(self.xmin,ymin,self.xmax,ymax)
-
- # Move image up. s is given in range 0,100. 100 moves a full screen up
- def up(self,s):
- self.down(-s)
-
- # Center image
- def center(self,x,y):
- self.right(50-x)
- self.up(50-y)
-
-
-</pre></blockquote>
-Our image class provides a number of methods for creating images, plotting points, making lines, and other graphical objects. We have also provided some methods for moving and scaling the image. Now, let's use this image class to do some interesting things :<p>
-<p>
-<a name="n46"></a><h3> A mathematical function plotter </h3>
-Here's a simple class that can be used to plot mathematical functions :<p>
-<p>
-<blockquote><pre># funcplot.py
-
-from image import *
-
-class PlotFunc(Image):
- def __init__(self,func,xmin,ymin,xmax,ymax,width=500,height=500):
- Image.__init__(self,width,height,xmin,ymin,xmax,ymax)
- self.func = func # The function being plotted
- self.npoints = 100 # Number of samples
- self.color = 1
- def draw(self):
- self.clear(0)
- lastx = self.xmin
- lasty = self.func(lastx)
- dx = 1.0*(self.xmax-self.xmin)/self.npoints
- x = lastx+dx
- for i in range(0,self.npoints):
- y = self.func(x)
- self.line(lastx,lasty,x,y,self.color)
- lastx = x
- lasty = y
- x = x + dx
- self.axis(1)
-
-</pre></blockquote>
-Most of the functionality is implemented in our base image class so this is pretty simple. However, if we wanted to make a GIF image of a mathematical function, we could just do this :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; from funcplot import *
-&gt;&gt;&gt; import math
-&gt;&gt;&gt; p = PlotFunc(lambda x: 0.5*math.sin(x)+0.75*math.sin(2*x)-0.6*math.sin(3*x),
- -10,-2,10,2)
-&gt;&gt;&gt; p.show("plot.gif")
-
-</pre></blockquote>
-Which would produce the following GIF image :<p>
-<p><center><img src="ch9.1.png"></center><p>
-<p>
-<p>
-<a name="n47"></a><h3> Plotting an unstructured mesh</h3>
-Of course, perhaps we want to plot something a little more complicated like a mesh. Recently, a colleague came to me with some unstructured mesh data contained in a pair of ASCII formatted files. These files contained a collection of points, and a list of connectivities defining a mesh on these points. Reading and plotting this data in Python turned out to be relatively easy using the following script and our image base class :<p>
-<p>
-<blockquote><pre># plotmesh.py
-# Plots an unstructured mesh stored as an ASCII file
-from image import *
-import string
-
-class PlotMesh(Image):
- def __init__(self,filename,xmin,ymin,xmax,ymax,width=500,height=500):
- Image.__init__(self,width,height,xmin,ymin,xmax,ymax)
- # read in a mesh file in pieces
- pts = []
- # Read in data points
- atoi = string.atoi
- atof = string.atof
- f = open(filename+".pts","r")
- npoints = atoi(f.readline())
- for i in range(0,npoints):
- l = string.split(f.readline())
- pts.append((atof(l[0]),atof(l[1])))
- f.close()
-
- # Read in mesh data
- f = open(filename+".tris","r")
- ntris = string.atoi(f.readline())
- tris = [ ]
- for i in range(0,ntris):
- l = string.split(f.readline())
- tris.append((atoi(l[0])-1,atoi(l[1])-1,atoi(l[2])-1,atoi(l[3])))
- f.close()
-
- # Set up local attributes
- self.pts = pts
- self.npoints = npoints
- self.tris = tris
- self.ntris = ntris
-
- # Draw mesh
- def draw(self):
- self.clear(0);
- i = 0
- while i &lt; self.ntris:
- tri = self.tris[i]
- pt1 = self.pts[tri[0]]
- pt2 = self.pts[tri[1]]
- pt3 = self.pts[tri[2]]
- # Now draw the mesh
- self.triangle(pt1[0],pt1[1],pt2[0],pt2[1],pt3[0],pt3[1],tri[3]);
- i = i + 1
-
- # Draw a triangle
- def triangle(self,x1,y1,x2,y2,x3,y3,color):
- self.line(x1,y1,x2,y2,color)
- self.line(x2,y2,x3,y3,color)
- self.line(x3,y3,x1,y1,color)
-
-</pre></blockquote>
-This class simply reads the data into a few Python lists, has a drawing function for making a plot, and adds a special method for making triangles. Making a plot is now easy, just do this :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; from plotmesh.py import *
-&gt;&gt;&gt; mesh = PlotMesh("mesh",5,0,35,25)
-&gt;&gt;&gt; mesh.show("mesh.gif")
-
-</pre></blockquote>
-This produces the following GIF image :<p>
-<p><center><img src="ch9.2.png"></center><p>
-<p>
-<p>
-When run interactively, we can also use simple commands to zoom in and move the image around. For example :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; mesh = PlotMesh("mesh",5,0,35,25)
-&gt;&gt;&gt; mesh.zoom(200) # Enlarge by 200%
-&gt;&gt;&gt; mesh.left(50) # Move image half a screen to left
-&gt;&gt;&gt; mesh.show()
-&gt;&gt;&gt;
-</pre></blockquote>
-<p>
-While a Python-only implementation would be unsuitable for huge datasets, performance critical operations could be moved to C and used in conjunction with our Image base class. <p>
-<a name="n48"></a><h3> From C to SWIG to Python</h3>
-This example illustrates a number of things that are possible with SWIG and Python. First, it is usually relatively easy to build a Python interface to an existing C library. With a little extra work, it is possible to improve the interface by adding a few support functions such as our Point extensions. Finally, once in Python, it is possible to encapsulate C libraries in new kinds of Python objects and classes. We built a simple Image base class and used it to plot mathematical functions and unstructured 2D mesh data---two entirely different tasks, yet easily accomplished with a small amount of Python code. If we later decided to use a different C library such as OpenGL, we could wrap it in SWIG, change the Image base class appropriately , and use the function and mesh plotting examples without modification. I think this is pretty cool.<p>
-<a name="n8"></a><h2> Putting it all together</h2>
-Finally, let's combine our heat equation solver and graphics module into a single application. To do this, we first need to know how to combine two different SWIG generated modules. When different SWIG modules need to be combined, there are a number of things you can do.<p>
-<a name="n49"></a><h3> Merging modules</h3>
-Two SWIG modules can be combined into a single module if you make an interface file like this :<p>
-<p>
-<blockquote><pre>%module package
-%include pde.i
-%include gd.i
-</pre></blockquote>
-<p>
-This will combine everything in both interface files into a single super-module called "package". The advantage to this approach is that it is extremely quick and easy. The disadvantage is that the module names of "pde" and "gd" will be lost. If you had a bunch of scripts that relied on those names, they would no longer work. Thus, combining modules in this way is probably only a good idea if the modules are closely related.<p>
-<a name="n50"></a><h3> Using dynamic loading</h3>
-If your system supports dynamic loading, you can build each SWIG module into a separate dynamically loadable module and load each one individually into Python. This is the preferred approach if it is supported on your system. SWIG wrapper files declare virtually everything as "static" so using dynamic loading with multiple SWIG generated modules will not usually cause any namespace clashes. <p>
-<a name="n51"></a><h3> Use static linking</h3>
-As an alternative to dynamic loading, you can use a special form of the <tt>%module</tt> directive as follows :<p>
-<p>
-<blockquote><pre>%module package, pdec, gdc
-%include embed.i
-
-</pre></blockquote>
-This will build a static version of Python with 3 C extension modules added (<tt>package</tt>, <tt>pdec</tt>, and <tt>gdc</tt>). When using this technique, the names of the modules refer to the low-level SWIG generated C/C++ modules. Since shadow classes are being used, these modules must have an extra `c' appended to the name (thus, "pdec" and "gdc" instead of "pde" and "gd"). The extra modules specified with the <tt>%modules</tt> directive do not necessarily have to be SWIG-generated modules. In practice, almost any kind of Python module can be listed here. It should also be noted that extra modules names are completely ignored if the <tt>embed.i </tt>library file is not used.<p>
-<a name="n52"></a><h3> Building large multi-module systems</h3>
-By default, SWIG includes the C code for the SWIG type-checker and variable linking into every module. However, when, building systems involving large numbers of SWIG modules, common code such as the SWIG pointer type-checker and variable linking extensions can be shared if you run SWIG with the <tt>-c</tt> option. For example :<p>
-<p>
-<blockquote><pre>% swig -c -python graphics.i
-% swig -c -python network.i
-% swig -c -python analysis.i
-% swig -c -python math.i
-% gcc -c graphics_wrap.c network_wrap.c analysis_wrap.c math_wrap.c
-% ld -shared graphics_wrap.o -lswigpy -o graphicsmodule.so
-% ld -shared network_wrap.o -lswigpy -o networkmodule.so
-% ld -shared analysis_wrap.o -lswigpy -o analysismodule.so
-% ld -shared math_wrap.o -o -lswigpy mymathmodule.so
-
-</pre></blockquote>
-<tt>swigpy</tt> is a special purpose library that contains the SWIG pointer type checker and other support code (see the <tt>Misc</tt> subdirectory of the SWIG distribution). When used in this manner, the same support code will be used for all of the modules. The <tt>swigpy</tt> library can also be applied when static linking is being used. See the Advanced Topics chapter for more information about using SWIG with multiple modules.<p>
-<a name="n53"></a><h3> A complete application</h3>
-The following Python script shows an application that combines our C++ heat equation solver, our gd library, and our Image base class that we developed. <p>
-<p>
-<blockquote><pre># Solve the heat equation.
-# Make a series of data files
-# Make a movie of GIF images
-
-from pde import *
-from image import *
-import string
-
-# Image class
-class HeatImg(Image):
- def __init__(self,h,width=300,height=300):
- Image.__init__(self,width,height,0.0,0.0,1.0,1.0)
- self.h = h
- # Create a greyscale colormap
- cmap = []
- for i in range(0,255):
- cmap.append((i,i,i))
- self.colormap(cmap)
- self.cmin = 0.0
- self.cmax = 1.0
- self.imgno = 1
- def draw(self):
- self.clear(0)
- dx = 1.0/(self.h.grid.xpoints-2)
- dy = 1.0/(self.h.grid.ypoints-2)
- i = 1
- x = 0.0
- while i &lt; self.h.grid.xpoints:
- j = 1;
- y = 0.0
- while j &lt; self.h.grid.ypoints:
- c = int((self.h.grid[i][j]-self.cmin)/(self.cmax-
- self.cmin)*255)
- self.solidbox(x,y+dy,x+dx,y,c)
- j = j + 1
- y = y + dy
- i = i + 1
- x = x + dx
- self.name = "image"+string.zfill(self.imgno,4)+".gif"
- self.imgno = self.imgno+1
-
-# Set up an initial condition
-def initcond(h):
- h.set_temp(0.0)
- nx = h.grid.xpoints
- for i in range(0,nx):
- h.grid[i][0] = 1.0
-
-# Set up a problem and run it
-h = Heat2d(50,50)
-
-# Make an image object
-img = HeatImg(h)
-
-initcond(h)
-fileno = 1
-
-# Run it
-for i in range(0,25):
- h.solve(100)
- h.dump("Dat"+str(fileno))
- img.show()
- print "time = ", h.time
- fileno = fileno+1
-
-# Calculate average temperature and exit
-sum = 0.0
-for i in range(0,h.grid.xpoints):
- for j in range(0,h.grid.ypoints):
- sum = sum + h.grid[i][j]
-avg = sum/(h.grid.xpoints*h.grid.ypoints)
-print "Avg temperature = ",avg
-</pre></blockquote>
-<p>
-When run, we now get a collection of datafiles and series of images like this :<p>
-<p><center><img src="ch9.3.png"></center><p>
-<p>
-<p>
-Thus, we have a simple physics application that only takes about 1 page of Python code, runs a simulation, creates data files, and a movie of images. We can easily change any aspect of the simulation, interactively query variables and examine data. New procedures can be written and tested in Python and later implemented in C++ if needed. More importantly, we have an application that is actually fun to use and modify (well, at least I think so).<p>
-<a name="n9"></a><h2> Exception handling </h2>
-The SWIG <tt>%except</tt> directive can be used to create a user-definable exception handler in charge of converting exceptions in your C/C++ program into Python exceptions. The chapter on exception handling contains more details, but suppose you have a C++ class like the following :<p>
-<blockquote><pre>
-class RangeError {}; // Used for an exception
-
-class DoubleArray {
- private:
- int n;
- double *ptr;
- public:
- // Create a new array of fixed size
- DoubleArray(int size) {
- ptr = new double[size];
- n = size;
- }
- // Destroy an array
- ~DoubleArray() {
- delete ptr;
- }
- // Return the length of the array
- int length() {
- return n;
- }
-
- // Get an item from the array and perform bounds checking.
- double getitem(int i) {
- if ((i &gt;= 0) &amp;&amp; (i &lt; n))
- return ptr[i];
- else
- throw RangeError();
- }
-
- // Set an item in the array and perform bounds checking.
- void setitem(int i, double val) {
- if ((i &gt;= 0) &amp;&amp; (i &lt; n))
- ptr[i] = val;
- else {
- throw RangeError();
- }
- }
- };
-</pre></blockquote>
-<p>
-The functions associated with this class can throw a range exception for an out-of-bounds array access. We can catch this in our Python extension by specifying the following in an interface file :<p>
-<p>
-<blockquote><pre>%except(python) {
- try {
- $function
- }
- catch (RangeError) {
- PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
- return NULL;
- }
-}
-
-</pre></blockquote>
-When the C++ class throws a RangeError exception, our wrapper functions will catch it, turn it into a Python exception, and allow a graceful death as opposed to just having some sort of mysterious program crash. Since SWIG's exception handling is user-definable, we are not limited to C++ exception handling. Please see the chapter on exception handling for more details and using the <tt>exception.i</tt> library for writing language-independent exception handlers.<p>
-<p>
-Python exceptions can be raised using the <tt>PyErr_SetString()</tt> function as shown above. The following table provides a list of the different Python exceptions available.<p>
-<center><img src="ch9.table.1.png"></center><p>
-<p>
-<a name="n10"></a><h2> Remapping C datatypes with typemaps</h2>
-This section describes how SWIG's treatment of various C/C++ datatypes can be remapped using the SWIG <tt>%typemap</tt> directive. While not required, this section assumes some familiarity with Python's C API. The reader is advised to consult the Python reference manual or one of the books on Python. A glance at the chapter on SWIG typemaps will also be useful. <p>
-<a name="n54"></a><h3> What is a typemap?</h3>
-A typemap is mechanism by which SWIG's processing of a particular C datatype can be overridden. A simple typemap might look like this :<p>
-<p>
-<blockquote><pre>%module example
-
-%typemap(python,in) int {
- $target = (int) PyLong_AsLong($source);
- printf("Received an integer : %d\n",$target);
-}
-extern int fact(int n);
-</pre></blockquote>
-<p>
-Typemaps require a language name, method name, datatype, and conversion code. For Python, "python" should be used as the language name. The "in" method in this example refers to an input argument of a function. The datatype `int' tells SWIG that we are remapping integers. The supplied code is used to convert from a <tt>PyObject *</tt> to the corresponding C datatype. Within the supporting C code, the variable <tt>$source</tt> contains the source data (the <tt>PyObject</tt> in this case) and <tt>$target</tt> contains the destination of a conversion. <p>
-<p>
-When this example is compiled into a Python module, it will operate as follows :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; from example import *
-&gt;&gt;&gt; fact(6)
-Received an integer : 6
-720
-</pre></blockquote>
-<p>
-A full discussion of typemaps can be found in the main SWIG users reference. We will primarily be concerned with Python typemaps here.<p>
-<a name="n55"></a><h3> Python typemaps</h3>
-The following typemap methods are available to Python modules :<p>
-<p>
-<tt>%typemap(python,in) </tt>Converts Python objects to input function arguments<p>
-<tt>%typemap(python,out)</tt> Converts return value of a C function to a Python object<p>
-<tt>%typemap(python,varin) </tt>Assigns a global variable from a Python object<p>
-<tt>%typemap(python,varout)</tt> Returns a global variable as a Python object<p>
-<tt>%typemap(python,freearg)</tt> Cleans up a function argument (if necessary)<p>
-<tt>%typemap(python,argout)</tt> Output argument processing<p>
-<tt>%typemap(python,ret)</tt> Cleanup of function return values<p>
-<tt>%typemap(python,const)</tt> Creation of Python constants<p>
-<tt>%typemap(memberin)</tt> Setting of C++ member data<p>
-<tt>%typemap(memberout)</tt> Return of C++ member data<p>
-<tt>%typemap(python,check)</tt> Checks function input values.<p>
-<a name="n56"></a><h3> Typemap variables</h3>
-The following variables may be used within the C code used in a typemap:<p>
-<p>
-<tt>$source</tt> Source value of a conversion<p>
-<tt>$target</tt> Target of conversion (where the result should be stored)<p>
-<tt>$type</tt> C datatype being remapped<p>
-<tt>$mangle</tt> Mangled version of data (used for pointer type-checking)<p>
-<tt>$value</tt> Value of a constant (const typemap only)<p>
-<a name="n57"></a><h3> Name based type conversion</h3>
-Typemaps are based both on the datatype and an optional name attached to a datatype. For example :<p>
-<p>
-<blockquote><pre>%module foo
-
-// This typemap will be applied to all char ** function arguments
-%typemap(python,in) char ** { ... }
-
-// This typemap is applied only to char ** arguments named `argv'
-%typemap(python,in) char **argv { ... }
-
-</pre></blockquote>
-In this example, two typemaps are applied to the <tt>char **</tt> datatype. However, the second typemap will only be applied to arguments named `<tt>argv</tt>'. A named typemap will always override an unnamed typemap.<p>
-<p>
-Due to the name-based nature of typemaps, it is important to note that typemaps are independent of typedef declarations. For example :<p>
-<p>
-<blockquote><pre>%typemap(python, in) double {
- ... get a double ...
-}
-void foo(double); // Uses the above typemap
-typedef double Real;
-void bar(Real); // Does not use the above typemap (double != Real)
-
-</pre></blockquote>
-To get around this problem, the <tt>%apply</tt> directive can be used as follows :<p>
-<blockquote><pre>
-%typemap(python,in) double {
- ... get a double ...
-}
-void foo(double);
-
-typedef double Real; // Uses typemap
-%apply double { Real }; // Applies all "double" typemaps to Real.
-void bar(Real); // Now uses the same typemap.
-</pre></blockquote>
-<a name="n58"></a><h3> Converting Python list to a char ** </h3>
-A common problem in many C programs is the processing of command line arguments, which are usually passed in an array of NULL terminated strings. The following SWIG interface file allows a Python list object to be used as a <tt>char **</tt> object.<p>
-<p>
-<blockquote><pre>%module argv
-
-// This tells SWIG to treat char ** as a special case
-%typemap(python,in) char ** {
- /* Check if is a list */
- if (PyList_Check($source)) {
- int size = PyList_Size($source);
- int i = 0;
- $target = (char **) malloc((size+1)*sizeof(char *));
- for (i = 0; i &lt; size; i++) {
- PyObject *o = PyList_GetItem($source,i);
- if (PyString_Check(o))
- $target[i] = PyString_AsString(PyList_GetItem($source,i));
- else {
- PyErr_SetString(PyExc_TypeError,"list must contain strings");
- free($target);
- return NULL;
- }
- }
- $target[i] = 0;
- } else {
- PyErr_SetString(PyExc_TypeError,"not a list");
- return NULL;
- }
-}
-
-// This cleans up the char ** array we malloc'd before the function call
-%typemap(python,freearg) char ** {
- free((char *) $source);
-}
-
-// This allows a C function to return a char ** as a Python list
-%typemap(python,out) char ** {
- int len,i;
- len = 0;
- while ($source[len]) len++;
- $target = PyList_New(len);
- for (i = 0; i &lt; len; i++) {
- PyList_SetItem($target,i,PyString_FromString($source[i]));
- }
-}
-
-// Now a few test functions
-%inline %{
-int print_args(char **argv) {
- int i = 0;
- while (argv[i]) {
- printf("argv[%d] = %s\n", i,argv[i]);
- i++;
- }
- return i;
-}
-
-// Returns a char ** list
-
-char **get_args() {
- static char *values[] = { "Dave", "Mike", "Susan", "John", "Michelle", 0};
- return &amp;values[0];
-}
-%}
-
-</pre></blockquote>
-When this module is compiled, our wrapped C functions now operate as follows :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; from argv import *
-&gt;&gt;&gt; print_args(["Dave","Mike","Mary","Jane","John"])
-argv[0] = Dave
-argv[1] = Mike
-argv[2] = Mary
-argv[3] = Jane
-argv[4] = John
-5
-&gt;&gt;&gt; get_args()
-[`Dave', `Mike', `Susan', `John', `Michelle']
-&gt;&gt;&gt;
-
-</pre></blockquote>
-Our type-mapping makes the Python interface to these functions more natural and easy to use. <p>
-<a name="n59"></a><h3> Converting a Python file object to a FILE *</h3>
-In our previous example involving gd-1.2, we had to write wrappers around <tt>fopen()</tt> and <tt>fclose()</tt> so that we could provide gd with a <tt>FILE *</tt> pointer. However, we could have used a typemap like this instead :<p>
-<p>
-<blockquote><pre>// Type mapping for grabbing a FILE * from Python
-
-%typemap(python,in) FILE * {
- if (!PyFile_Check($source)) {
- PyErr_SetString(PyExc_TypeError, "Need a file!");
- return NULL;
- }
- $target = PyFile_AsFile($source);
-}
-</pre></blockquote>
-<p>
-Now, we can rewrite one of our earlier examples like this :<p>
-<p>
-<blockquote><pre># Simple gd program
-
-from gd import *
-
-im = gdImageCreate(64,64)
-black = gdImageColorAllocate(im,0,0,0)
-white = gdImageColorAllocate(im,255,255,255)
-gdImageLine(im,0,0,63,63,white)
-f = open("test.gif","w") # Create a Python file object
-gdImageGif(im,f) # Pass to a C function as FILE *
-f.close()
-gdImageDestroy(im)
-</pre></blockquote>
-<a name="n60"></a><h3> Using typemaps to return arguments</h3>
-A common problem in some C programs is that values may be returned in arguments rather than in the return value of a function. For example :<p>
-<p>
-<blockquote><pre>/* Returns a status value and two values in out1 and out2 */
-int spam(double a, double b, double *out1, double *out2) {
- ... Do a bunch of stuff ...
- *out1 = result1;
- *out2 = result2;
- return status;
-};
-
-</pre></blockquote>
-A named typemap can be used to handle this case as follows :<p>
-<p>
-<blockquote><pre>%module outarg
-
-// This tells SWIG to treat an double * argument with name 'OutValue' as
-// an output value. We'll append the value to the current result which
-// is guaranteed to be a List object by SWIG.
-
-%typemap(python,argout) double *OutValue {
- PyObject *o;
- o = PyFloat_FromDouble(*$source);
- if ((!$target) || ($target == Py_None)) {
- $target = o;
- } else {
- if (!PyList_Check($target)) {
- PyObject *o2 = $target;
- $target = PyList_New(0);
- PyList_Append($target,o2);
- Py_XDECREF(o2);
- }
- PyList_Append($target,o);
- Py_XDECREF(o);
- }
-}
-int spam(double a, double b, double *OutValue, double *OutValue);
-
-</pre></blockquote>
-With this typemap, we first check to see if any result exists. If so, we turn it into a list and append our new output value to it. If this is the only result, we simply return it normally. For our sample function, there are three output values so the function will return a list of 3 elements. As written, our function needs to take 4 arguments, the last two being pointers to doubles. We may not want to pass anything into these arguments if they are only used to hold output values so we could change this as follows :<p>
-<blockquote><pre>
-%typemap(python,ignore) double *OutValue(double temp) {
- $target = &amp;temp; /* Assign the pointer to a local variable */
-}
-
-</pre></blockquote>
-Now, in a Python script, we could do this :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; a = spam(4,5)
-&gt;&gt;&gt; print a
-[0, 2.45, 5.0]
-&gt;&gt;&gt;
-</pre></blockquote>
-<a name="n61"></a><h3> Mapping Python tuples into small arrays</h3>
-In some applications, it is sometimes desirable to pass small arrays of numbers as arguments. For example :<p>
-<p>
-<blockquote><pre>extern void set_direction(double a[4]); // Set direction vector
-</pre></blockquote>
-<p>
-This too, can be handled used typemaps as follows :<p>
-<p>
-<blockquote><pre>// Grab a 4 element array as a Python 4-tuple
-%typemap(python,in) double[4](double temp[4]) { // temp[4] becomes a local variable
- int i;
- if (PyTuple_Check($source)) {
- if (!PyArg_ParseTuple($source,"dddd",temp,temp+1,temp+2,temp+3)) {
- PyErr_SetString(PyExc_TypeError,"tuple must have 4 elements");
- return NULL;
- }
- $target = &amp;temp[0];
- } else {
- PyErr_SetString(PyExc_TypeError,"expected a tuple.");
- return NULL;
- }
-}
-
-</pre></blockquote>
-This allows our <tt>set_direction</tt> function to be called from Python as follows :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; set_direction((0.5,0.0,1.0,-0.25))
-
-</pre></blockquote>
-Since our mapping copies the contents of a Python tuple into a C array, such an approach would not be recommended for huge arrays, but for small structures, this kind of scheme works fine.<p>
-<a name="n62"></a><h3> Accessing array structure members</h3>
-Consider the following data structure :<p>
-<p>
-<blockquote><pre>#define NAMELEN 32
-typedef struct {
- char name[NAMELEN];
- ...
-} Person;
-
-</pre></blockquote>
-By default, SWIG doesn't know how to the handle the name structure since it's an array, not a pointer. In this case, SWIG will make the array member readonly. However, member typemaps can be used to make this member writable from Python as follows :<p>
-<p>
-<blockquote><pre>%typemap(memberin) char[NAMELEN] {
- /* Copy at most NAMELEN characters into $target */
- strncpy($target,$source,NAMELEN);
-}
-
-</pre></blockquote>
-Whenever a <tt>char[NAMELEN]</tt> type is encountered in a structure or class, this typemap provides a safe mechanism for setting its value. An alternative implementation might choose to print an error message if the name was too long to fit into the field.<p>
-<p>
-It should be noted that the <tt>[NAMELEN]</tt> array size is attached to the typemap. A datatype involving some other kind of array would not be affected. However, you can write a typemap to match any sized array using the <tt>ANY</tt> keyword as follows :<p>
-<p>
-<blockquote><pre>%typemap(memberin) char [ANY] {
- strncpy($target,$source,$dim0);
-}
-</pre></blockquote>
-<p>
-During code generation, <tt>$dim0</tt> will be filled in with the real array dimension. <p>
-<a name="n63"></a><h3> Useful Functions</h3>
-When writing typemaps, it is often necessary to work directly with Python objects instead of using the conventional <tt>PyArg_ParseTuple()</tt> function that is usually used when writing Python extensions. However, there are a number of useful Python functions available for you to use.<p>
-<center>
-<img src="ch9.table.2.png"><br>
-<img src="ch9.table.3.png"><br>
-<img src="ch9.table.4.png"><br>
-<img src="ch9.table.5.png"><br>
-<img src="ch9.table.6.png"><br>
-<img src="ch9.table.7.png"><br>
-</center><p>
-<p>
-<a name="n64"></a><h3> Standard typemaps</h3>
-The following typemaps show how to convert a few common kinds of objects between Python and C (and to give a better idea of how typemaps work)<p>
-<center>
-<img src="ch9.table.8.png"><br>
-<img src="ch9.table.9.png"><br>
-</center><p>
-<p>
-<a name="n65"></a><h3> Pointer handling</h3>
-SWIG pointers are mapped into Python strings containing the hexadecimal value and type. The following functions can be used to create and read pointer values.<p>
-<center>
-<img src="ch9.table.10.png">
-</center><p>
-<p>
-These functions can be used in typemaps. For example, the following typemap makes an argument of "<tt>char *buffer</tt>" accept a pointer instead of a NULL-terminated ASCII string.<p>
-<p>
-<blockquote><pre>%typemap(python,in) char *buffer {
- PyObject *o;
- char *str;
- if (!PyString_Check(o)) {
- PyErr_SetString(PyExc_TypeError,"not a string");
- return NULL;
- }
- str = PyString_AsString(o);
- if (SWIG_GetPtr(str, (void **) &amp;$target, "$mangle")) {
- PyErr_SetString(PyExc_TypeError,"not a pointer");
- return NULL;
- }
-}
-
-</pre></blockquote>
-Note that the <tt>$mangle</tt> variable generates the type string associated with the datatype used in the typemap.<p>
-<p>
-By now you hopefully have the idea that typemaps are a powerful mechanism for building more specialized applications. While writing typemaps can be technical, many have already been written for you. See the Typemaps chapter for more information about using library files.<p>
-<a name="n11"></a><h2> Implementing C callback functions in Python</h2>
-Now that you're an expert, we will implement simple C callback functions in Python and use them in a C++ code.<p>
-<p>
-Let's say that we wanted to write a simple C++ 2D plotting widget layered on top of the gd-1.2 library. A class definition might look like this :<p>
-<p>
-<blockquote><pre>// --------------------------------------------------------------------
-// Create a C++ plotting "widget" using the gd-1.2 library by Thomas Boutell
-//
-// This example primarily illustrates how callback functions can be
-// implemented in Python.
-// --------------------------------------------------------------------
-
-#include &lt;stdio.h&gt;
-extern "C" {
-#include "gd.h"
-}
-
-typedef double (*PLOTFUNC)(double, void *);
-
-class PlotWidget {
-private:
- double xmin,ymin,xmax,ymax; // Plotting range
- PLOTFUNC callback; // Callback function
- void *clientdata; // Client data for callback
- int npoints; // Number of points to plot
- int width; // Image width
- int height; // Image height
- int black,white; // Some colors
- gdImagePtr im; // Image pointer
- void transform(double,double,int&amp;,int&amp;);
-public:
- PlotWidget(int w, int h,double,double,double,double);
- ~PlotWidget();
- void set_method(PLOTFUNC func, void *clientdata); // Set callback method
- void set_range(double,double,double,double); // Set plot range
- void set_points(int np) {npoints = np;} // Set number of points
- void plot(); // Make a plot
- void save(FILE *f); // Save a plot to disk
-};
-
-</pre></blockquote>
-The widget class hides all of the underlying implementation details so this could have just as easily been implemented on top of OpenGL, X11 or some other kind of library. When used in C++, the widget works like this :<p>
-<p>
-<blockquote><pre>// Simple main program to test out our widget
-#include &lt;stdio.h&gt;
-#include "widget.h"
-#include &lt;math.h&gt;
-
-// Callback function
-double my_func(double a, void *clientdata) {
- return sin(a);
-}
-
-int main(int argc, char **argv) {
- PlotWidget *w;
- FILE *f;
-
- w = new PlotWidget(500,500,-6.3,-1.5,6.3,1.5);
- w-&gt;set_method(my_func,0); // Set callback function
- w-&gt;plot(); // Make plot
- f = fopen("plot.gif","w");
- w-&gt;save(f);
- fclose(f);
- printf("wrote plot.gif\n");
-}
-
-</pre></blockquote>
-Now suppose that we wanted to use our widget interactively from Python. While possible, it is going to be difficult because we would really like to implement the callback function in Python, not C++. We also don't want to go in and hack or C++ code to support this. Fortunately, you can do it with SWIG using the following interface file :<p>
-<p>
-<blockquote><pre>// SWIG interface to our PlotWidget
-%module plotwidget
-%{
-#include "widget.h"
-%}
-
-// Grab a Python function object as a Python object.
-%typemap(python,in) PyObject *pyfunc {
- if (!PyCallable_Check($source)) {
- PyErr_SetString(PyExc_TypeError, "Need a callable object!");
- return NULL;
- }
- $target = $source;
-}
-
-// Type mapping for grabbing a FILE * from Python
-%typemap(python,in) FILE * {
- if (!PyFile_Check($source)) {
- PyErr_SetString(PyExc_TypeError, "Need a file!");
- return NULL;
- }
- $target = PyFile_AsFile($source);
-}
-
-// Grab the class definition
-%include widget.h
-
-%{
-/* This function matches the prototype of the normal C callback
- function for our widget. However, we use the clientdata pointer
- for holding a reference to a Python callable object. */
-
-static double PythonCallBack(double a, void *clientdata)
-{
- PyObject *func, *arglist;
- PyObject *result;
- double dres = 0;
-
- func = (PyObject *) clientdata; // Get Python function
- arglist = Py_BuildValue("(d)",a); // Build argument list
- result = PyEval_CallObject(func,arglist); // Call Python
- Py_DECREF(arglist); // Trash arglist
- if (result) { // If no errors, return double
- dres = PyFloat_AsDouble(result);
- }
- Py_XDECREF(result);
- return dres;
-}
-%}
-
-// Attach a new method to our plot widget for adding Python functions
-%addmethods PlotWidget {
- // Set a Python function object as a callback function
- // Note : PyObject *pyfunc is remapped with a typempap
- void set_pymethod(PyObject *pyfunc) {
- self-&gt;set_method(PythonCallBack, (void *) pyfunc);
- Py_INCREF(pyfunc);
- }
-}
-
-</pre></blockquote>
-While this is certainly not a trivial SWIG interface file, the results are quite cool. Let's try out our new Python module :<p>
-<p>
-<blockquote><pre># Now use our plotting widget in variety of ways
-
-from plotwidget import *
-from math import *
-
-# Make a plot using a normal Python function as a callback
-def func1(x):
- return 0.5*sin(x)+0.25*sin(2*x)+0.125*cos(4*x)
-
-print "Making plot1.gif..."
-# Make a widget and set callback
-w = PlotWidget(500,500,-10,-2,10,2)
-w.set_pymethod(func1) # Register our Python function
-w.plot()
-f = open("plot1.gif","w")
-w.save(f)
-f.close()
-
-# Make a plot using an anonymous function
-
-print "Making plot2.gif..."
-w1 = PlotWidget(500,500,-4,-1,4,16)
-w1.set_pymethod(lambda x: x*x) # Register x^2 as a callback
-w1.plot()
-f = open("plot2.gif","w")
-w1.save(f)
-f.close()
-
-# Make another plot using a built-in function
-
-print "Making plot3.gif..."
-w2 = PlotWidget(500,500,-7,-1.5,7,1.5)
-w2.set_pymethod(sin) # Register sin(x) as a callback
-w2.plot()
-f = open("plot3.gif","w")
-w2.save(f)
-f.close()
-</pre></blockquote>
-<p>
-<p>
-The "plot" method for each widget is written entirely in C++ and assumes that it is calling a callback function written in C/C++. Little does it know that we have actually implemented this function in Python. With a little more work, we can even write a simple function plotting tool :<p>
-<p>
-<blockquote><pre># Plot a function and spawn xv
-
-import posix
-import sys
-import string
-from plotwidget import *
-from math import *
-
-line = raw_input("Enter a function of x : ")
-ranges = string.split(raw_input("Enter xmin,ymin,xmax,ymax :"),",")
-
-print "Making a plot..."
-w = PlotWidget(500,500,string.atof(ranges[0]),string.atof(ranges[1]),
- string.atof(ranges[2]),string.atof(ranges[3]))
-
-# Turn user input into a Python function
-code = "def func(x): return " + line
-exec(code)
-
-w.set_pymethod(func)
-w.plot()
-f = open("plot.gif","w")
-w.save(f)
-f.close()
-posix.system("xv plot.gif &amp;")
-
-</pre></blockquote>
-<a name="n12"></a><h2> Other odds and ends</h2>
-<a name="n66"></a><h3> Adding native Python functions to a SWIG module</h3>
-Sometimes it is desirable to add a native Python method to a SWIG wrapper file. Suppose you have the following Python/C function :<p>
-<p>
-<blockquote><pre>PyObject *spam_system(PyObject *self, PyObject *args) {
- char *command;
- int sts;
- if (!PyArg_ParseTuple(args,"s",&amp;command))
- return NULL;
- sts = system(command);
- return Py_BuildValue("i",sts);
-}
-
-</pre></blockquote>
-This function can be added to a SWIG module using the following declaration :<p>
-<p>
-<blockquote><pre>%native(system) spam_system; // Create a command called `system'
-
-</pre></blockquote>
-Alternatively, you can use the full function declaration like this <p>
-<p>
-<blockquote><pre>%native(system) PyObject *spam_system(PyObject *self, PyObject *args);
-</pre></blockquote>
-<p>
-or<p>
-<p>
-<blockquote><pre>%native(system) extern PyObject *spam_system(PyObject *self, PyObject *args);
-</pre></blockquote>
-<a name="n13"></a><h2> The gory details of shadow classes</h2>
-This section describes the process by which SWIG creates shadow classes and some of the more subtle aspects of using them.<p>
-<a name="n67"></a><h3> A simple shadow class</h3>
-Consider the following declaration from our previous example :<p>
-<p>
-<blockquote><pre>%module pde
-struct Grid2d {
- Grid2d(int ni, int nj);
- ~Grid2d();
- double **data;
- int xpoints;
- int ypoints;
-};
-</pre></blockquote>
-<p>
-The SWIG generated class for this structure looks like the following :<p>
-<p>
-<blockquote><pre># This file was created automatically by SWIG.
-import pdec
-class Grid2dPtr :
- def __init__(self,this):
- self.this = this
- self.thisown = 0
- def __del__(self):
- if self.thisown == 1 :
- pdec.delete_Grid2d(self.this)
- def __setattr__(self,name,value):
- if name == "data" :
- pdec.Grid2d_data_set(self.this,value)
- return
- if name == "xpoints" :
- pdec.Grid2d_xpoints_set(self.this,value)
- return
- if name == "ypoints" :
- pdec.Grid2d_ypoints_set(self.this,value)
- return
- self.__dict__[name] = value
- def __getattr__(self,name):
- if name == "data" :
- return pdec.Grid2d_data_get(self.this)
- if name == "xpoints" :
- return pdec.Grid2d_xpoints_get(self.this)
- if name == "ypoints" :
- return pdec.Grid2d_ypoints_get(self.this)
- return self.__dict__[name]
- def __repr__(self):
- return "&lt;C Grid2d instance&gt;"
-class Grid2d(Grid2dPtr):
- def __init__(self,arg0,arg1) :
- self.this = pdec.new_Grid2d(arg0,arg1)
- self.thisown = 1
-
-</pre></blockquote>
-<a name="n68"></a><h3> Module names</h3>
-Shadow classes are built using the low-level SWIG generated C interface. This interface is named "modulec" where "module" is the name of the module specified in a SWIG interface file. The Python code for the shadow classes is created in a file "module.py". This is the file that should be loaded when a user wants to use the module.<p>
-<a name="n69"></a><h3> Two classes</h3>
-For each structure or class found in an interface file, SWIG creates two Python classes. If a class is named "<tt>Grid2d</tt>", one of these classes will be named "<tt>Grid2dPtr</tt>" and the other named "<tt>Grid2d</tt>". The <tt>Grid2dPtr</tt> class is used to turn wrap a Python class around an already preexisting <tt>Grid2d</tt> pointer. For example :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; gptr = create_grid2d() # Returns a Grid2d from somewhere
-&gt;&gt;&gt; g = Grid2dPtr(gptr) # Turn it into a Python class
-&gt;&gt;&gt; g.xpoints
-50
-&gt;&gt;&gt;
-
-</pre></blockquote>
-The <tt>Grid2d</tt> class, on the other hand, is used when you want to create a new <tt>Grid2d</tt> object from Python. In reality, it inherits all of the attributes of a <tt>Grid2dPtr</tt>, except that its constructor calls the corresponding C++ constructor to create a new object. Thus, in Python, this would look something like the following :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; g = Grid2d(50,50) # Create a new Grid2d
-&gt;&gt;&gt; g.xpoints
-50
-&gt;&gt;&gt;
-
-</pre></blockquote>
-This two class model is a tradeoff. In order to support C/C++ properly, it is necessary to be able to create Python objects from both pre-existing C++ objects and to create entirely new C++ objects in Python. While this might be accomplished using a single class, it would complicate the handling of constructors considerably. The two class model, on the other hand, works, is consistent, and is relatively easy to use. In practice, you probably won't even be aware that there are two classes working behind the scenes.<p>
-<a name="n70"></a><h3> The this pointer</h3>
-Within each shadow class, the member "<tt>this</tt>" contains the actual C/C++ pointer to the object. You can check this out yourself by typing something like this :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; g = Grid2d(50,50)
-&gt;&gt;&gt; print g.this
-_1008fe8_Grid2d_p
-&gt;&gt;&gt;
-</pre></blockquote>
-<p>
-Direct manipulation of the "<tt>this</tt>" pointer is generally discouraged. In fact forget that you read this.<p>
-<a name="n71"></a><h3> Object ownership</h3>
-Ownership is a critical issue when mixing C++ and Python. For example, suppose I create a new object in C++, but later use it to create a Python object. If that object is being used elsewhere in the C++ code, we clearly don't want Python to delete the C++ object when the Python object is deleted. Similarly, what if I create a new object in Python, but C++ saves a pointer to it and starts using it repeatedly. Clearly, we need some notion of who owns what. Since sorting out all of the possibilities is probably impossible, SWIG shadow classes always have an attribute "<tt>thisown</tt>" that indicates whether or not Python owns an object. Whenever an object is created in Python, Python will be given ownership by setting <tt>thisown </tt> to <tt> 1</tt>. When a Python class is created from a pre-existing C/C++ pointer, ownership is assumed to belong to the C/C++ code and <tt>thisown</tt> will be set to 0.<p>
-<p>
-Ownership of an object can be changed as necessary by changing the value of <tt>thisown</tt>. When set, Python will call the C/C++ destructor when the object is deleted. If it is zero, Python will never call the C/C++ destructor.<p>
-<a name="n72"></a><h3> Constructors and Destructors</h3>
-C++ constructors and destructors will be mapped into Python's <tt>__init__</tt> and <tt>__del__</tt> methods respectively. Shadow classes always contain these methods even if no constructors or destructors were available in the SWIG interface file. The Python destructor will only call a C/C++ destructor if <tt>self.thisown</tt> is set.<p>
-<a name="n73"></a><h3> Member data</h3>
-Member data of an object is accessed through Python's <tt>__getattr__</tt> and <tt>__setattr__</tt> methods.<p>
-<a name="n74"></a><h3> Printing</h3>
-SWIG automatically creates a Python<tt> __repr__</tt> method for each class. This forces the class to be relatively well-behaved when printing or being used interactively in the Python interpreter.<p>
-<a name="n75"></a><h3> Shadow Functions</h3>
-Suppose you have the following declarations in an interface file :<p>
-<p>
-<blockquote><pre>%module vector
-struct Vector {
- Vector();
- ~Vector();
- double x,y,z;
-};
-
-Vector addv(Vector a, Vector b);
-
-</pre></blockquote>
-By default, the function <tt>addv</tt> will operate on <tt>Vector</tt> pointers, not Python classes. However, the SWIG Python module is smart enough to know that <tt>Vector</tt> has been wrapped into a Python class so it will create the following replacement for the <tt>addv()</tt> function.<p>
-<p>
-<blockquote><pre>def addv(a,b):
- result = VectorPtr(vectorc.addv(a.this,b.this))
- result.thisown = 1
- return result
-
-</pre></blockquote>
-Function arguments are modified to use the "this" pointer of a Python Vector object. The result is a pointer to the result which has been allocated by malloc or new (this behavior is described in the chapter on SWIG basics), so we simply create a new VectorPtr with the return value. Since the result involved an implicit malloc, we set the ownership to 1 indicating that the result is to be owned by Python and that it should be deleted when the Python object is deleted. As a result, operations like this are perfectly legal and result in no memory leaks :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; v = add(add(add(add(a,b),c),d),e)
-
-</pre></blockquote>
-Substitution of complex datatypes occurs for all functions and member functions involving structure or class definitions. It is rarely necessary to use the low-level C interface when working with shadow classes.<p>
-<a name="n76"></a><h3> Nested objects</h3>
-SWIG shadow classes support nesting of complex objects. For example, suppose you had the following interface file :<p>
-<p>
-<blockquote><pre>%module particle
-
-typedef struct {
- Vector();
- double x,y,z;
-} Vector;
-
-typedef struct {
- Particle();
- ~Particle();
- Vector r;
- Vector v;
- Vector f;
- int type;
-} Particle;
-
-</pre></blockquote>
-<p>
-In this case you will be able to access members as follows :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; p = Particle()
-&gt;&gt;&gt; p.r.x = 0.0
-&gt;&gt;&gt; p.r.y = -1.5
-&gt;&gt;&gt; p.r.z = 2.0
-&gt;&gt;&gt; p.v = addv(v1,v2)
-&gt;&gt;&gt; ...
-
-</pre></blockquote>
-Nesting of objects is implemented using Python's<tt> __setattr__</tt> and <tt>__getattr__</tt> functions. In this case, they would look like this :<p>
-<p>
-<blockquote><pre>class ParticlePtr:
- ...
- def __getattr__(self,name):
- if name == "r":
- return particlec.VectorPtr(Particle_r_get(self.this))
- elif name == "v":
- return particlec.VectorPtr(Particle_v_get(self.this))
- ...
-
- def __setattr__(self,name,value):
- if name == "r":
- particlec.Particle_r_set(self.this,value.this)
- elif name == "v":
- particlec.Particle_v_set(self.this,value.this)
- ...
-
-</pre></blockquote>
-The attributes of any given object are only converted into a Python object when referenced. This approach is more memory efficient, faster if you have a large collection of objects that aren't examined very often, and works with recursive structure definitions such as :<p>
-<p>
-<blockquote><pre>struct Node {
- char *name;
- struct Node *next;
-};
-</pre></blockquote>
-<p>
-Nested structures such as the following are also supported by SWIG. These types of structures tend to arise frequently in database and information processing applications.<p>
-<p>
-<blockquote><pre>typedef struct {
- unsigned int dataType;
- union {
- int intval;
- double doubleval;
- char *charval;
- void *ptrvalue;
- long longval;
- struct {
- int i;
- double f;
- void *v;
- char name[32];
- } v;
- } u;
-} ValueStruct;
-
-</pre></blockquote>
-Access is provided in an entirely natural manner,<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; v = new_ValueStruct() # Create a ValueStruct somehow
-&gt;&gt;&gt; v.dataType
-1
-&gt;&gt;&gt; v.u.intval
-45
-&gt;&gt;&gt; v.u.longval
-45
-&gt;&gt;&gt; v.u.v.v = _0_void_p
-&gt;&gt;&gt;
-
-</pre></blockquote>
-To support the embedded structure definitions, SWIG has to extract the internal structure definitions and use them to create new Python classes. In this example, the following shadow classes are created :<p>
-<p>
-<blockquote><pre># Class corresponding to union u member
-class ValueStruct_u :
- ...
-# Class corresponding to struct v member of union u
-class ValueStruct_u_v :
- ...
-</pre></blockquote>
-<p>
-The names of the new classes are formed by appending the member names of each embedded structure.<p>
-<a name="n77"></a><h3> Inheritance and shadow classes</h3>
-Since shadow classes are implemented in Python, you can use any of the automatically generated classes as a base class for more Python classes. However, you need to be extremely careful when using multiple inheritance. When multiple inheritance is used, at most ONE SWIG generated shadow class can be involved. If multiple SWIG generated classes are used in a multiple inheritance hierarchy, you will get name clashes on the <tt>this</tt> pointer, the <tt>__getattr__</tt> and <tt>__setattr__</tt> functions won't work properly and the whole thing will probably crash and burn. Perhaps it's best to think of multiple inheritance as a big hammer that can be used to solve alot of problems, but it hurts quite alot if you accidently drop it on your foot.... <p>
-<a name="n78"></a><h3> Methods that return new objects</h3>
-By default SWIG assumes that constructors are the only functions returning new objects to Python. However, you may have other functions that return new objects as well. For example :<p>
-<blockquote><pre>
-Vector *cross_product(Vector *v1, Vector *v2) {
- Vector *result = new Vector();
- result = ... compute cross product ...
- return result;
-}
-
-</pre></blockquote>
-When the value is returned to Python, we want Python to assume ownership. The brute force way to do this is to simply change the value of thisown. For example :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; v = cross_product(a,b)
-&gt;&gt;&gt; v.thisown = 1 # Now Python owns it
-
-</pre></blockquote>
-Unfortunately, this is ugly and it doesn't work if we use the result as a temporary value :<p>
-<p>
-<blockquote><pre>w = vector_add(cross_product(a,b),c) # Results in a memory leak
-</pre></blockquote>
-<p>
-However, you can provide a hint to SWIG when working with such a function as shown :<p>
-<p>
-<blockquote><pre>// C Function returning a new object
-%new Vector *cross_product(Vector *v1, Vector *v2);
-
-</pre></blockquote>
-The <tt>%new</tt> directive only provides a hint that the function is returning a new object. The Python module will assign proper ownership of the object when this is used.<p>
-<a name="n79"></a><h3> Performance concerns and hints</h3>
-Shadow classing is primarily intended to be a convenient way of accessing C/C++ objects from Python. However, if you're directly manipulating huge arrays of complex objects from Python, performance may suffer greatly. In these cases, you should consider implementing the functions in C or thinking of ways to optimize the problem.<p>
-<p>
-There are a number of ways to optimize programs that use shadow classes. Consider the following two code fragments involving the <tt>Particle</tt> data structure in a previous example :<p>
-<p>
-<blockquote><pre>def force1(p1,p2):
- dx = p2.r.x - p1.r.x
- dy = p2.r.y - p1.r.y
- dz = p2.r.z - p1.r.z
- r2 = dx*dx + dy*dy + dz*dz
- f = 1.0/(r2*math.sqrt(r2))
- p1.f.x = p1.f.x + f*dx
- p2.f.x = p2.f.x - f*dx
- p1.f.y = p1.f.y + f*dy
- p2.f.y = p2.f.y - f*dy
- p1.f.z = p1.f.z + f*dz
- p2.f.z = p2.f.z - f*dz
-
-def force2(p1,p2):
- r1 = p1.r
- r2 = p2.r
- dx = r2.x - r1.x
- dy = r2.y - r1.y
- dz = r2.z - r1.z
- r2 = dx*dx + dy*dy + dz*dz
- f = 1.0/(r2*math.sqrt(r2))
- f1 = p1.f
- f2 = p2.f
- f1.x = f1.x + f*dx
- f2.x = f2.x - f*dx
- f1.y = f1.y + f*dy
- f2.y = f2.y - f*dy
- f1.z = f1.z + f*dz
- f2.z = f2.z - f*dz
-
-</pre></blockquote>
-The first calculation simply works with each Particle structure directly. Unfortunately, it performs alot of dereferencing of objects. If the calculation is restructured to use temporary variables as shown in force2, it will run significantly faster--in fact, on my machine, the second code fragment runs more than twice as fast as the first one.<p>
-<p>
-If performance is even more critical you can use the low-level C interface which eliminates all of the overhead of going through Python's class mechanism (at the expense of coding simplicity). When Python shadow classes are used, the low level C interface can still be used by importing the `modulec' module where `module' is the name of the module you used in the SWIG interface file.<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:47:07 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/SWIG.html b/swigweb/Doc1.1/HTML/SWIG.html
deleted file mode 100644
index 64eb6da9a..000000000
--- a/swigweb/Doc1.1/HTML/SWIG.html
+++ /dev/null
@@ -1,1586 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>SWIG Basics</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>3 SWIG Basics</h1><p><ul>
-<li> <a href="#n1">Running SWIG</a>
-<li> <a href="#n2">Simple C functions, variables, and constants</a>
-<li> <a href="#n3">Pointers and complex objects</a>
-<li> <a href="#n4">Getting down to business</a>
-<li> <a href="#n5">Structures, unions, and object oriented C programming</a>
-<li> <a href="#n6">C++ support</a>
-<li> <a href="#n7">Objective-C</a>
-<li> <a href="#n8">Conditional compilation</a>
-<li> <a href="#n9">Code Insertion</a>
-<li> <a href="#n10">A general interface building strategy</a>
-</ul>
-
-<a name="n1"></a><h2> Running SWIG</h2>
-SWIG is invoked by the <tt>swig</tt> command. This command has a number of options including:<p>
-<p>
-<blockquote><pre>swig &lt;options&gt; filename
-
--tcl Generate Tcl wrappers
--tcl8 Generate Tcl 8.0 wrappers
--perl Generate Perl5 wrappers
--python Generate Python wrappers
--perl4 Generate Perl4 wrappers
--guile Generate Guile wrappers
--dascii ASCII documentation
--dlatex LaTeX documentation
--dhtml HTML documentation
--dnone No documentation
--c++ Enable C++ handling
--objc Enable Objective-C handling.
--Idir Set SWIG include directory
--lfile Include a SWIG library file.
--c Generate raw wrapper code (omit supporting code)
--v Verbose mode (perhaps overly verbose)
--o outfile Name of output file
--d docfile Set name of documentation file (without suffix)
--module name Set name of SWIG module
--Dsymbol Define a symbol
--version Show SWIG's version number
--help Display all options
-
-</pre></blockquote>
-This is only a partial list of options. A full listing of options can be obtained by invoking "<tt>swig -help</tt>". Each target language may have additional options which can be displayed using "<tt>swig -lang -help</tt>" where <tt>-lang</tt> is one of the target languages above.<p>
-<a name="n11"></a><h3> Input format</h3>
-As input, SWIG takes a file containing ANSI C/C++ declarations. This file may be a special "interface file" (usually given a .i suffix), a C header file or a C source file. The most common method of using SWIG is with a special interface file. These files contain ANSI C declarations like a header file, but also contain SWIG directives and documentation. Interface files usually have the following format :<p>
-<p>
-<p>
-<blockquote><pre>%module mymodule
-%{
-#include "myheader.h"
-%}
-// Now list ANSI C variable and function declarations
-
-</pre></blockquote>
-The name of the module (if supplied) must always appear before the first C declaration or be supplied on the SWIG command line using the <tt>-module</tt> option (When the module name is specified on the command line, it will override any module name present in a file). Everything inside the <tt>%{,%</tt>} block is copied verbatim into the resulting output file. The <tt>%{,%}</tt> block is optional, but most interface files use one to include the proper header files.<p>
-<a name="n12"></a><h3> SWIG Output</h3>
-By default an interface file with the name <tt>myfile.i</tt> will be transformed into a file called <tt>myfile_wrap.c</tt>. The name of the output file can be changed using the <tt>-o</tt> option. When working with some C++ compilers, the <tt>-o</tt> option can be used to give the output file a proper C++ suffix. The output file usually contains everything that is needed to build a working module for the target scripting language. Compile it along with your C program, link it, and you should be ready to run.<p>
-<a name="n13"></a><h3> Comments</h3>
-C and C++ style comments may be placed in interface files, but these are used to support the automatic documentation system. Please see the documentation section for more details on this. Otherwise, SWIG throws out all comments so you can use a C++ style comment even if the resulting wrapper file is compiled with the C compiler. <p>
-<a name="n14"></a><h3> C Preprocessor directives</h3>
-SWIG does not run the C preprocessor. If your input file makes extensive use of the C preprocessor, SWIG will probably hate it. However, SWIG does recognize a few C preprocessor constructs that are quite common in C code :<p>
-<p>
-<ul>
-<li><tt>#define</tt>. Used to create constants
-<li><tt>#ifdef,#ifndef,#else,#endif</tt>, <tt>#if, #elif</tt>. Used for conditional compilation
-</ul>
-<p>
-All other C preprocessor directives are ignored by SWIG (including macros created using <tt>#define</tt>). <p>
-<a name="n15"></a><h3> SWIG Directives</h3>
-SWIG directives are always preceded by a "<tt>%</tt>" to distinguish them from normal C directives and declarations. There are about two dozen different directives that can be used to give SWIG hints, provide annotation, and change SWIG's behavior in some way or another. <p>
-<a name="n16"></a><h3> Limitations in the Parser (and various things to keep in mind)</h3>
-It was never my intent to write a full C/C++ parser. Therefore SWIG has a number of limitations to keep in mind.<p>
-<p>
-<ul>
-<li>Functions with variable length arguments (ie. "...") are not supported.
-<li>Complex declarations such as function pointers and arrays are problematic. You may need to remove these from the SWIG interface file or hide them with a typedef.
-<li>C++ source code (what would appear in a .C file) is especially problematic. Running SWIG on C++ source code is highly discouraged.
-<li>More sophisticated features of C++ such as templates and operator overloading are not supported. Please see the section on using SWIG with C++ for more details. When encountered, SWIG may issue a warning message or a syntax error if it can't figure out you are trying to do.
-</ul>
-<p>
-Many of these limitations may be eliminated in future releases. It is worth noting that many of the problems associated with complex declarations can sometimes be fixed by clever use of <tt>typedef</tt>.<p>
-<p>
-If you are not sure whether SWIG can handle a particular declaration, the best thing to do is try it and see. SWIG will complain loudly if it can't figure out what's going on. When errors occur, you can either remove the offending declaration, conditionally compile it out (SWIG defines a symbol <tt>SWIG</tt> that can be used for this), or write a helper function to work around the problem. <p>
-<a name="n2"></a><h2> Simple C functions, variables, and constants</h2>
-SWIG supports just about any C function, variable, or constant involving built-in C datatypes. For example :<p>
-<p>
-<blockquote><pre>%module example
-
-extern double sin(double x);
-extern int strcmp(const char *, const char *);
-extern int My_variable;
-#define STATUS 50
-const char *VERSION="1.1";
-
-</pre></blockquote>
-will create two commands called "<tt>sin</tt>" and "<tt>strcmp</tt>", a global variable "<tt>My_variable</tt>", and two constants "<tt>STATUS</tt>" and "<tt>VERSION</tt>". Things work about like you would expect. For example, in Tcl :<p>
-<p>
-<blockquote><pre>% sin 3
-5.2335956
-% strcmp Dave Mike
--1
-% puts $My_variable
-42
-% puts $STATUS
-50
-% puts $VERSION
-1.1
-
-</pre></blockquote>
-The main concern when working with simple functions is SWIG's treatment of basic datatypes. This is described next.<p>
-<a name="n17"></a><h3> Integers</h3>
-SWIG maps the following C datatypes into integers in the target scripting language. <p>
-<p>
-<blockquote><pre>int
-short
-long
-unsigned
-signed
-unsigned short
-unsigned long
-unsigned char
-signed char
-bool
-</pre></blockquote>
-<p>
-Scripting languages usually only support a single integer type that corresponds to either the <tt>int</tt> or <tt>long</tt> datatype in C. When converting from C, all of the above datatypes are cast into the representation used by the target scripting language. Thus, a 16 bit short in C may be converted to a 32 bit integer. When integers are converted from the scripting language back into C, the value will be cast into the appropriate type. The value will be truncated if it is too large to fit into the corresponding C datatype. This truncation is not currently checked.<p>
-<p>
-The <tt>unsigned char</tt> and <tt>signed char</tt> datatypes are special cases that are treated as integers by SWIG. Normally, the <tt>char</tt> datatype is mapped as an ASCII string. <p>
-<p>
-The <tt>bool</tt> datatype is cast to and from an integer value of 0 and 1.<p>
-<p>
-Some care is in order for large integer values. Most scripting language use 32 bit integers so mapping a 64 bit long integer may lead to truncation errors. Similar problems may arise with 32 bit unsigned integers that may show up as negative numbers. As a rule of thumb, the <tt>int</tt> datatype and all variations of <tt>char</tt> and <tt>short</tt> datatypes are safe to use. For <tt>unsigned int</tt> and <tt>long</tt> datatypes, you should verify the correct operation of your program after wrapping it with SWIG.<p>
-<a name="n18"></a><h3> Floating Point</h3>
-SWIG recognizes the following floating point types :<p>
-<blockquote><pre>
-float
-double
-</pre></blockquote>
-<p>
-Floating point numbers are mapped to and from the natural representation of floats in the target language. This is almost always a <tt>double</tt> except in Tcl 7.x which uses character strings. The rarely used datatype of "long double" is not supported by SWIG.<p>
-<a name="n19"></a><h3> Character Strings</h3>
-The <tt>char</tt> datatype is mapped into a NULL terminated ASCII string with a single character. When used in a scripting language it will show up as a tiny string containing the character value. When converting the value back into C, SWIG will take a character string from the scripting language and strip off the first character as the char value. Thus if you try to assigned the value "foo" to a <tt>char</tt> datatype, it will get the value `f'.<p>
-<p>
-The <tt>char *</tt> datatype is assumed to be a NULL-terminated ASCII string. SWIG maps this into a character string in the target language. SWIG converts character strings in the target language to NULL terminated strings before passing them into C/C++. It is illegal for these strings to have embedded NULL bytes although there are ways to work around this problem.<p>
-<p>
-The <tt>signed char</tt> and <tt>unsigned char</tt> datatypes are mapped into integer values. The following example illustrates the mapping of <tt>char</tt> datatypes.<p>
-<tt></tt><p>
-<blockquote><pre><tt>%{
-#include &lt;stdio.h&gt;
-#include &lt;ctype.h&gt;
-#include &lt;string.h&gt;
-signed char sum(signed char a, signed char b) { return a+b;}
-%}
-
-int strcmp(char *, char *);
-char toupper(char);
-signed char sum(signed char a, signed char b);
-</tt></pre></blockquote>
-<p>
-A Tcl script using these functions (and the resulting output) might be as follows.<p>
-<p>
-<blockquote><pre>tclsh &gt; strcmp Mike John
-1
-tclsh &gt; toupper g
-G
-tclsh &gt; sum 17 -8
-9
-</pre></blockquote>
-<a name="n20"></a><h3> Variables</h3>
-SWIG attempts to map C/C++ global variables into scripting language variables. For example:<p>
-<p>
-<blockquote><pre>%module example
-
-double foo;
-
-</pre></blockquote>
-will result in a scripting language variable that can be used as follows :<p>
-<p>
-<blockquote><pre># Tcl
-set foo [3.5] ;# Set foo to 3.5
-puts $foo ;# Print the value of foo
-
-# Python
-cvar.foo = 3.5 ;# Set foo to 3.5
-print cvar.foo ;# Print value of foo
-
-# Perl
-$foo = 3.5; ;# Set foo to 3.5
-print $foo,"\n"; ;# Print value of foo
-
-</pre></blockquote>
-Whenever this "special" variable is used, the underlying C global variable will be accessed. As it turns out, working with global variables is one of the most tricky aspects of SWIG. Whenever possible, you should try to avoid the use of globals. Fortunately, most modular programs make limited (or no) use of globals.<p>
-<a name="n21"></a><h3> Constants</h3>
-Constants can be created using <tt>#define</tt>, <tt>const</tt>, or enumerations. Constant expressions are also allowed. The following interface file shows a few valid constant declarations :<p>
-<p>
-<blockquote><pre>#define I_CONST 5 // An integer constant
-#define F_CONST 3.14159 // A Floating point constant
-#define S_CONST "hello world" // A string constant
-#define NEWLINE '\n' // Character constant
-#define MODE DEBUG // Sets MODE to DEBUG.
- // DEBUG is assumed to be an
- // int unless declared earlier
-enum boolean {NO=0, YES=1};
-enum months {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG,
- SEP, OCT, NOV, DEC};
-const double PI 3.141592654;
-#define F_CONST (double) 5 // A floating pointer constant with cast
-#define PI_4 PI/4
-#define FLAGS 0x04 | 0x08 | 0x40
-
-</pre></blockquote>
-In <tt>#define</tt> declarations, the type of a constant is inferred by syntax or can be explicitly set using a cast. For example, a number with a decimal point is assumed to be floating point. When no explicit value is available for a constant, SWIG will use the value assigned by the C compiler. For example, no values are given to the <tt>months</tt> enumeration, but this is no problem---SWIG will use whatever the C compiler picks. <p>
-<p>
-The use of constant expressions is allowed, but SWIG does not evaluate them. Rather, it passes them through to the output file and lets the C compiler perform the final evaluation (SWIG does perform a limited form of type-checking however).<p>
-<p>
-For enumerations, it is critical that the original enum definition be included somewhere in the interface file (either in a header file or in the <tt>%{,%}</tt> block). SWIG only translates the enumeration into code needed to add the constants to a scripting language. It needs the original enumeration declaration to retrieve the correct enum values.<p>
-<a name="n3"></a><h2> Pointers and complex objects</h2>
-As we all know, most C programs have much more than just integers, floating point numbers, and character strings. There may be pointers, arrays, structures, and other objects floating around. Fortunately, this is usually not a problem for SWIG.<p>
-<a name="n22"></a><h3> Simple pointers</h3>
-Pointers to basic C datatypes such as <p>
-<p>
-<blockquote><pre>int *
-double ***
-char **
-</pre></blockquote>
-<p>
-can be used freely in an interface file. SWIG encodes pointers into a representation containing the actual value of the pointer and a string representing the datatype. Thus, the SWIG representation of the above pointers (in Tcl), might look like the following :<p>
-<p>
-<blockquote><pre>_10081012_int_p
-_1008e124_double_ppp
-_f8ac_char_pp
-</pre></blockquote>
-<p>
-A NULL pointer is represented by the string "NULL" or the value 0 encoded with type information.<p>
-<p>
-All pointers are treated as opaque objects by SWIG. A pointer may be returned by a function and passed around to other C functions as needed. For all practical purposes, the scripting language interface works in exactly the same way as you would write a C program (well, with a few limitations).<p>
-<p>
-The scripting language representation of a pointer should never be manipulated directly (although nothing prevents this). SWIG does not normally map pointers into high-level objects such as associative arrays or lists (for example, it might be desirable to convert an <tt>int *</tt> into an list of integers). There are several reasons for this :<p>
-<p>
-<ul>
-<li>Adding special cases would make SWIG more complicated and difficult to maintain.
-<li>There is not enough information in a C declaration to properly map pointers into higher level constructs. For example, an <tt>int *</tt> may indeed be an array of integers, but if it contains one million elements, converting it into a Tcl, Perl, or Python list would probably be an extremely bad idea.
-<li>By treating all pointers equally, it is easy to know what you're going to get when you create an interface (pointers are treated in a consistent manner).
-</ul>
-<p>
-As it turns out, you can remap any C datatype to behave in new ways so these rules are not set in stone. Interested readers should look at the chapter on typemaps.<p>
-<a name="n23"></a><h3> Run time pointer type checking</h3>
-By allowing pointers to be manipulated interactively in a scripting language, we have effectively bypassed the type-checker in the C/C++ compiler. By encoding pointer values with a datatype, SWIG is able to perform run-time type-checking in order to prevent mysterious system crashes and other anomalies. By default, SWIG uses a strict-type checking model that checks the datatype of all pointers before passing them to C/C++. However, you can change the handling of pointers using the <tt>-strict</tt> option:<p>
-<p>
-<blockquote><pre>-strict 0 No type-checking (living on the edge)
--strict 1 Generate warning messages (somewhat annoying)
--strict 2 Strict type checking (the default)
-
-</pre></blockquote>
-Strict type checking is the recommended default since is the most reliable and most closely follows the type checking rules of C. In fact, at this time, the other two modes should be considered to be outdated SWIG features that are supported, but no longer necessary.<p>
-<p>
-By default, SWIG allows "NULL" pointers to be passed to C/C++. This has the potential to crash code and cause other problems if you are not careful. Checks can be placed on certain values to prevent this but this requires the use of typemaps (described in later chapters).<p>
-<blockquote><pre>
-</pre></blockquote>
-Like C, it should also be noted that functions involving <tt>void</tt> pointers can accept any kind of pointer object.<p>
-<a name="n24"></a><h3> Derived types, structs, and classes</h3>
-For everything else (structs, classes, arrays, etc...) SWIG applies a very simple rule :<p>
-<p>
-All complex datatypes are pointers<p>
-<p>
-In other words, SWIG manipulates everything else by reference. This model makes sense because most C/C++ programs make heavy use of pointers and we can use the type-checked pointer mechanism already present for handling pointers to basic datatypes.<p>
-<p>
-While all of this probably sounds complicated, it's really quite simple. Suppose you have an interface file like this :<p>
-<p>
-<blockquote><pre>%module fileio
-FILE *fopen(char *, char *);
-int fclose(FILE *);
-unsigned fread(void *ptr, unsigned size, unsigned nobj, FILE *);
-unsigned fwrite(void *ptr, unsigned size, unsigned nobj, FILE *);
-void *malloc(int nbytes);
-void free(void *);
-
-</pre></blockquote>
-In this file, SWIG doesn't know what a <tt>FILE</tt> is, but it's used as a pointer, so it doesn't really matter what it is. If you wrapped this module into Python, you could use the functions just like you would expect :<p>
-<p>
-<blockquote><pre># Copy a file
-def filecopy(source,target):
- f1 = fopen(source,"r")
- f2 = fopen(target,"w")
- buffer = malloc(8192)
- nbytes = fread(buffer,8192,1,f1)
- while (nbytes &gt; 0):
- fwrite(buffer,8192,1,f2)
- nbytes = fread(buffer,8192,1,f1)
- free(buffer)
-
-</pre></blockquote>
-In this case <tt>f1</tt>,<tt> f2</tt>, and <tt>buffer</tt> are all opaque objects containing C pointers. It doesn't matter what value they contain--our program works just fine without this knowledge.<p>
-<a name="n25"></a><h3> What happens when SWIG encounters an unknown datatype?</h3>
-When SWIG encounters an unknown datatype, it automatically assumes that it is some sort of complex datatype. For example, suppose the following function appeared in a SWIG input file:<p>
-<p>
-<blockquote><pre>void matrix_multiply(Matrix *a, Matrix *b, Matrix *c);
-</pre></blockquote>
-<p>
-SWIG has no idea what a "<tt>Matrix</tt>" is so it will assume that you know what you are doing and map it into a pointer. This makes perfect sense because the underlying C function is using pointers in the first place. Unlike C or C++, SWIG does not actually care whether <tt>Matrix</tt> has been previously defined in the interface file or not. While this may sound strange, it makes it possible for SWIG to generate interfaces from only partial information. In many cases, you may not care what a <tt>Matrix</tt> really is as long as you can pass references to one around in the scripting language interface. The downside to this relaxed approach is that typos may go completely undetected by SWIG. You can also end up shooting yourself in the foot, but presumably you've passed your programming safety course if you've made it this far.<p>
-<p>
-As a debugging tool, SWIG will report a list of used, but undefined datatypes, if you run it with the <tt>-stat</tt> option.<p>
-<p>
-<blockquote><pre>[beazley@guinness SWIG1.1b6]$ swig -stat matrix.i
-Making wrappers for Tcl
-Wrapped 1 functions
-Wrapped 0 variables
-Wrapped 0 constants
-The following datatypes were used, but undefined.
- Matrix
-[beazley@guinness SWIG1.1b6]$
-</pre></blockquote>
-<a name="n26"></a><h3> Typedef</h3>
-<tt>typedef</tt> can be used to remap datatypes within SWIG. For example :<p>
-<p>
-<blockquote><pre>typedef unsigned int size_t;
-
-</pre></blockquote>
-This makes SWIG treat <tt>size_t</tt> like an unsigned int. Use of <tt>typedef</tt> is fairly critical in most applications. Without it, SWIG would consider <tt>size_t</tt> to be a complex object (which would be incorrectly converted into a pointer).<p>
-<a name="n4"></a><h2> Getting down to business</h2>
-So far, you know just about everything you need to know to use SWIG to build interfaces. In fact, using nothing but basic datatypes and opaque pointers it is possible to build scripting language interfaces to most kinds of C/C++ packages. However, as the novelty wears off, you will want to do more. This section describes SWIG's treatment of more sophsticated issues.<p>
-<a name="n27"></a><h3> Passing complex datatypes by value</h3>
-Unfortunately, not all C programs manipulate complex objects by reference. When encountered, SWIG will transform the corresponding C/C++ declaration to use references instead. For example, suppose you had the following function :<p>
-<p>
-<blockquote><pre>double dot_product(Vector a, Vector b);
-</pre></blockquote>
-<p>
-SWIG will transform this function call into the equivalent of the following :<p>
-<p>
-<blockquote><pre>double wrap_dot_product(Vector *a, Vector *b) {
- return dot_product(*a,*b);
-}
-</pre></blockquote>
-<p>
-In the scripting language<tt>, dot_product</tt> will now take references to Vectors instead of Vectors, although you may not notice the change. <p>
-<a name="n28"></a><h3> Return by value</h3>
-C functions that return complex datatypes by value are more difficult to handle. Consider the following function:<p>
-<p>
-<blockquote><pre>Vector cross(Vector v1, Vector v2);
-
-</pre></blockquote>
-This function is returning a complex object, yet SWIG only likes to work with references. Clearly, something must be done with the return result, or it will be lost forever. As a result, SWIG transforms this function into the following code :<p>
-<p>
-<blockquote><pre>Vector *wrap_cross(Vector *v1, Vector *v2) {
- Vector *result;
- result = (Vector *) malloc(sizeof(Vector));
- *(result) = cross(*v1,*v2);
- return result;
-}
-</pre></blockquote>
-<p>
-or if using C++ :<p>
-<p>
-<blockquote><pre>Vector *wrap_cross(Vector *v1, Vector *v2) {
- Vector *result = new Vector(cross(*v1,*v2)); // Uses default copy constructor
- return result;
-}
-</pre></blockquote>
-<p>
-SWIG is forced to create a new object and return a reference to it. It is up to the user to delete the returned object when it is no longer in use. When used improperly, this can lead to memory leaks and other problems. Personally, I'd rather live with a potential memory leak than forbid the use of such a function. Needless to say, some care is probably in order (you need to be aware of this behavior in any case). <p>
-<a name="n29"></a><h3> Linking to complex variables</h3>
-When global variables or class members involving complex datatypes are encountered, SWIG converts them into references. For example, a global variable like this :<p>
-<blockquote><pre>
-Vector unit_i;
-</pre></blockquote>
-<p>
-gets mapped to a pair of set/get functions like this :<p>
-<p>
-<blockquote><pre>Vector *unit_i_get() {
- return &amp;unit_i;
-}
-Vector *unit_i_set(Vector *value) {
- unit_i = *value;
- return &amp;unit_i;
-}
-</pre></blockquote>
-<p>
-Returning a reference to the variable makes it accessible like any other object of this type. When setting the value, we simply make a copy of some other Vector reference. Again some caution is in order. A global variable created in this manner will show up as a reference in the target scripting language. It would be an extremely bad idea to free or destroy such a reference. Similarly, one can run into problems when copying complex C++ objects in this manner. Fortunately, in well-written modular code, excessive use (or abuse) of global variables is rare.<p>
-<a name="n30"></a><h3> Arrays</h3>
-The use of arrays in the current version of SWIG is supported, but with caution. If simple arrays appear, they will be mapped into a pointer representation. Thus, the following declarations :<p>
-<p>
-<blockquote><pre>int foobar(int a[40]);
-void grok(char *argv[]);
-void transpose(double a[20][20]);
-</pre></blockquote>
-<p>
-will be processed as if they were declared like this:<p>
-<p>
-<blockquote><pre>int foobar(int *a);
-void grok(char **argv);
-void transpose(double (*a)[20]);
-</pre></blockquote>
-<p>
-Multi-dimensional arrays are transformed into a single pointer since <tt>a[][]</tt> and <tt>**a</tt> are not the same thing (even though they can be used in similar ways). Rather, <tt>a[][]</tt> is mapped to *a, where <tt>*a</tt> is the equivalent of <tt>&amp;a[0][0]</tt>. The reader is encouraged to dust off their C book and look at the section on arrays before using them with SWIG.<p>
-<p>
-Be aware that use of arrays may cause compiler warnings or errors when compiling SWIG generated modules. While every attempt has been made to eliminate these problems, handling of arrays can be somewhat problematic due to the subtle differences between an array and a pointer.<p>
-<a name="n31"></a><h3> Creating read-only variables</h3>
-A read-only variable can be created by using the <tt>%readonly</tt> directive as shown :<p>
-<blockquote><pre>
-// File : interface.i
-
-int a; // Can read/write
-%readonly
-int b,c,d // Read only variables
-%readwrite
-double x,y // read/write
-</pre></blockquote>
-<p>
-The <tt>%readonly</tt> directive enables read-only mode until it is explicitly disabled using the <tt>%readwrite</tt> directive.<p>
-<a name="n32"></a><h3> Renaming declarations</h3>
-Normally, the name of a C function is used as the name of the command added to the target scripting language. Unfortunately, this name may conflict with a keyword or already existing function in the scripting language. Naming conflicts can be resolved using the <tt>%name</tt> directive as shown :<p>
-<p>
-<blockquote><pre>// interface.i
-
-%name(my_print) extern void print(char *);
-%name(foo) extern int a_really_long_and_annoying_name;
-
-</pre></blockquote>
-SWIG still calls the correct C functions, but in this case the function <tt>print()</tt> will really be called "<tt>my_print()</tt>" in the scripting language. <p>
-<p>
-A more powerful renaming operation can be performed with the<tt> %renam</tt>e directive as follows :<p>
-<p>
-<blockquote><pre>%rename oldname newname;
-
-</pre></blockquote>
-<tt>%rename </tt>applies a renaming operation to all future occurrences of a name. The renaming applies to functions, variables, class and structure names, member functions, and member data. For example, if you had two-dozen C++ classes, all with a member function named `print' (which is a keyword in Python), you could rename them all to `output' by specifying :<p>
-<p>
-<blockquote><pre>%rename print output; // Rename all `print' functions to `output'
-</pre></blockquote>
-<p>
-SWIG does not perform any checks to see if the functions it adds are already defined in the target scripting language. However, if you are careful about namespaces and your use of modules, you can usually avoid these problems.<p>
-<a name="n33"></a><h3> Overriding call by reference</h3>
-SWIG is quite literal in its interpretation of datatypes. If you give it a pointer, it will use pointers. For example, if you're trying to call a function in a Fortran library (through its C interface) all function parameters will have to be passed by reference. Similarly, some C functions may use pointers in unusual ways. The <tt>%val</tt> directive can be used to change the calling mechanism for a C function. For example :<p>
-<p>
-<blockquote><pre>// interface.i
-%{
-#include &lt;time.h&gt;
-%}
-
-typedef long time_t;
-time_t time(time_t *t);
-struct tm *localtime(%val time_t *t);
-char *asctime(struct tm *);
-
-</pre></blockquote>
-The <tt>localtime()</tt> function takes a pointer to a <tt>time_t</tt> value, but we have forced it to take a value instead in order to match up nicely with the return value of the <tt>time()</tt> function. When used in Perl, this allows us to do something like this :<p>
-<blockquote><pre>
-$t = time(0);
-$tm = localtime($t); # Note passing $t by value here
-print $asctime($tm);
-
-</pre></blockquote>
-Internally, the <tt>%val</tt> directive creates a temporary variable. The argument value is stored in this variable and a function call is made using a pointer to the temporary variable. Of course, if the function returns a value in this temporary variable, it will be lost forever. <p>
-<a name="n34"></a><h3> Default/optional arguments</h3>
-SWIG allows default arguments to be used in both C/C++ code as follows :<p>
-<p>
-<blockquote><pre>int plot(double x, double y, int color=WHITE);
-
-</pre></blockquote>
-To specify a default argument, simply specify it the function prototype as shown. SWIG will generate wrapper code in which the default arguments are optional. For example, this function could be used in Tcl as follows :<p>
-<p>
-<blockquote><pre>% plot -3.4 7.5 # Use default value
-% plot -3.4 7.5 10 # set color to 10 instead
-
-</pre></blockquote>
-While the ANSI C standard does not specify default arguments, default arguments used in a SWIG generated interface work with both C and C++.<p>
-<a name="n35"></a><h3> Pointers to functions</h3>
-At the moment, the SWIG parser has difficulty handling pointers to functions (a deficiency that is being corrected). However, having function pointers is useful for managing C callback functions and other things. To properly handle function pointers, it is currently necessary to use <tt>typedef.</tt> For example, the function <p>
-<blockquote><pre>
-void do_operation(double (*op)(double,double), double a, double b);
-</pre></blockquote>
-<p>
-should be handled as follows :<p>
-<blockquote><pre>
-typedef double (*OP_FUNC)(double,double);
-void do_operation(OP_FUNC op, double a, double b);
-
-</pre></blockquote>
-SWIG understands both the typedef declaration and the later function call. It will treat <tt>OP_FUNC</tt> just like any other complex datatype. In order for this approach to work, it is necessary that the typedef declaration be present in the original C code--otherwise, the C compiler will complain. If you are building a separate interface file to an existing C program and do not want to make changes to the C source, you can also do the following :<p>
-<blockquote><pre>
-// File : interface.i
-%typedef double (*OP_FUNC)(double,double);
-double do_operation(OP_FUNC op, double a, double b);
-</pre></blockquote>
-<p>
-<tt>%typedef</tt> forces SWIG to generate a <tt>typedef</tt> in the C output code for you. This would allow the interface file shown to work with the original unmodified C function declaration.<p>
-<p>
-Constants containing the addresses of C functions can also be created. For example, suppose you have the following callback functions :<p>
-<p>
-<blockquote><pre>extern double op_add(double a, double b);
-extern double op_sub(double a, double b);
-extern double op_mul(double a, double b);
-
-</pre></blockquote>
-The addresses of these functions could be installed as scripting language constants as follows :<p>
-<p>
-<blockquote><pre>// interface.i
-typedef double (*OP_FUNC)(double,double);
-...
-const OP_FUNC ADD = op_add;
-const OP_FUNC SUB = op_sub;
-const OP_FUNC MUL = op_mul;
-...
-
-</pre></blockquote>
-When wrapped, this would create the constants <tt>ADD</tt>,<tt>SUB</tt>, and <tt>MUL</tt> containing the addresses of C callback functions. We could then pass these to other C functions expecting such function pointers as arguments as shown (for Tcl) :<p>
-<p>
-<blockquote><pre>%do_operation $ADD 3 4
-7
-%
-</pre></blockquote>
-<a name="n5"></a><h2> Structures, unions, and object oriented C programming</h2>
-If SWIG encounters the definition of a structure or union, it will create a set of accessor functions for you. While SWIG does not need structure definitions to build an interface, providing definitions make it possible to access structure members. The accessor functions generated by SWIG simply take a pointer to an object and allow access to an individual member. For example, the declaration :<p>
-<p>
-<blockquote><pre>struct Vector {
- double x,y,z;
-}
-
-</pre></blockquote>
-gets mapped into the following set of accessor functions :<p>
-<p>
-<blockquote><pre>double Vector_x_get(Vector *obj) {
- return obj-&gt;x;
-}
-double Vector_y_get(Vector *obj) {
- return obj-&gt;y;
-}
-double Vector_z_get(Vector *obj) {
- return obj-&gt;z;
-}
-double Vector_x_set(Vector *obj, double value) {
- obj-&gt;x = value;
- return value;
-}
-double Vector_y_set(Vector *obj, double value) {
- obj-&gt;y = value;
- return value;
-}
-double Vector_z_set(Vector *obj, double value) {
- obj-&gt;z = value;
- return value;
-}
-</pre></blockquote>
-<a name="n36"></a><h3> Typedef and structures</h3>
-SWIG supports the following construct which is quite common in C programs :<p>
-<p>
-<blockquote><pre>typedef struct {
- double x,y,z;
-} Vector;
-
-</pre></blockquote>
-When encountered, SWIG will assume that the name of the object is `Vector' and create accessor functions like before. If two different names are used like this :<p>
-<p>
-<blockquote><pre>typedef struct vector_struct {
- double x,y,z;
-} Vector;
-
-</pre></blockquote>
-the name `Vector' will still be used instead of "vector_struct".<p>
-<a name="n37"></a><h3> Character strings and structures</h3>
-Structures involving character strings require some care. SWIG assumes that all members of type <tt>char *</tt> have been dynamically allocated using <tt>malloc()</tt> and that they are NULL-terminated ASCII strings. When such a member is modified, the previously contents will be released, and the new contents allocated. For example :<p>
-<p>
-<blockquote><pre>%module mymodule
-...
-struct Foo {
- char *name;
- ...
-}
-
-</pre></blockquote>
-This results in the following accessor functions :<p>
-<p>
-<blockquote><pre>char *Foo_name_get(Foo *obj) {
- return Foo-&gt;name;
-}
-
-char *Foo_name_set(Foo *obj, char *c) {
- if (obj-&gt;name) free(obj-&gt;name);
- obj-&gt;name = (char *) malloc(strlen(c)+1);
- strcpy(obj-&gt;name,c);
- return obj-&gt;name;
-}
-</pre></blockquote>
-<p>
-This seems to work most of the time, but occasionally it's not always what you want. Typemaps can be used to change this behavior if necessary.<p>
-<a name="n38"></a><h3> Array members</h3>
-Arrays may appear as the members of structures, but they will be read-only. SWIG will write an accessor function that returns the pointer to the first element of the array, but will not write a function to change the array itself. This restriction is due to the fact that C won't let us change the "value" of an array. When this situation is detected, SWIG generates a warning message such as the following :<p>
-<p>
-<blockquote><pre>interface.i : Line 116. Warning. Array member will be read-only
-
-</pre></blockquote>
-To eliminate the warning message, typemaps can be used, but this is discussed in a later chapter (and best reserved for experienced users). Otherwise, if you get this warning, it may be harmless.<p>
-<a name="n39"></a><h3> C constructors and destructors </h3>
-While not part of the C language, it is usually useful to have some mechanism for creating and destroying an object. You can, of course, do this yourself by making an appropriate call to <tt>malloc()</tt>, but SWIG can make such functions for you automatically if you use C++ syntax like this :<p>
-<p>
-<blockquote><pre>%module mymodule
-...
-struct Vector {
- Vector(); // Tell SWIG to create a C constructor
- ~Vector(); // Tell SWIG to create a C destructor
- double x,y,z;
-}
-
-</pre></blockquote>
-When used with C code, SWIG will create two additional functions like this :<p>
-<p>
-<blockquote><pre>Vector *new_Vector() {
- return (Vector *) malloc(sizeof(Vector));
-}
-
-void delete_Vector(Vector *v) {
- free(v);
-}
-
-</pre></blockquote>
-While C knows nothing about constructors and destructors, SWIG does---and it can automatically create some for you if you want. This only applies to C code--handling of C++ is handled differently.<p>
-<p>
-As an alternative to explicitly defining constructors and destructors, SWIG can also automatically generate them using either a command line option or a pragma. For example :<p>
-<p>
-<blockquote><pre>swig -make_default example.i
-
-</pre></blockquote>
-or<p>
-<p>
-<blockquote><pre>%module foo
-...
-%pragma make_default // Make default constructors
-... declarations ...
-%pragma no_default // Disable default constructors
-
-</pre></blockquote>
-This works with both C and C++.<p>
-<a name="n40"></a><h3> Adding member functions to C structures</h3>
-Many scripting languages provide a mechanism for creating classes and supporting object oriented programming. From a C standpoint, object oriented programming really just boils down to the process of attaching functions to structures. These functions typically operate on the structure (or object) in some way or another. While there is a natural mapping of C++ to such a scheme, there is no direct mechanism for utilizing it with C code. However, SWIG provides a special <tt>%addmethods</tt> directive that makes it possible to attach methods to C structures for purposes of building an object oriented scripting language interface. Suppose you have a C header file with the following declaration :<p>
-<p>
-<blockquote><pre>/* file : vector.h */
-...
-typedef struct {
- double x,y,z;
-} Vector;
-
-</pre></blockquote>
-You can make a Vector look alot like a class by doing the following in an interface file :<p>
-<p>
-<blockquote><pre>// file : vector.i
-%module mymodule
-%{
-#include "vector.h"
-%}
-
-%include vector.h // Just grab original C header file
-%addmethods Vector { // Attach these functions to struct Vector
- Vector(double x, double y, double z) {
- Vector *v;
- v = (Vector *v) malloc(sizeof(Vector));
- v-&gt;x = x;
- v-&gt;y = y;
- v-&gt;z = z;
- return v;
- }
- ~Vector() {
- free(self);
- }
- double magnitude() {
- return sqrt(self-&gt;x*self-&gt;x+self-&gt;y*self-&gt;y+self-&gt;z*self-&gt;z);
- }
- void print() {
- printf("Vector [%g, %g, %g]\n", self-&gt;x,self-&gt;y,self-&gt;z);
- }
-};
-
-</pre></blockquote>
-Now, when used with shadow classes in Python, you can do things like this :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; v = Vector(3,4,0) # Create a new vector
-&gt;&gt;&gt; print v.magnitude() # Print magnitude
-5.0
-&gt;&gt;&gt; v.print() # Print it out
-[ 3, 4, 0 ]
-&gt;&gt;&gt; del v # Destroy it
-</pre></blockquote>
-<p>
-The <tt>%addmethods</tt> directive can also be used in the definition of the Vector structure. For example:<p>
-<blockquote><pre>// file : vector.i
-%module mymodule
-%{
-#include "vector.h"
-%}
-
-typedef struct {
- double x,y,z;
- %addmethods {
- Vector(double x, double y, double z) { ... }
- ~Vector() { ... }
- ...
- }
-} Vector;
-</pre></blockquote>
-<p>
-Finally, <tt>%addmethods</tt> can be used to access externally written functions provided they follow the naming convention used in this example :<p>
-<p>
-<blockquote><pre>/* File : vector.c */
-/* Vector methods */
-#include "vector.h"
-Vector *new_Vector(double x, double y, double z) {
- Vector *v;
- v = (Vector *) malloc(sizeof(Vector));
- v-&gt;x = x;
- v-&gt;y = y;
- v-&gt;z = z;
- return v;
-}
-void delete_Vector(Vector *v) {
- free(v);
-}
-
-double Vector_magnitude(Vector *v) {
- return sqrt(v-&gt;x*v-&gt;x+v-&gt;y*v-&gt;y+v-&gt;z*v-&gt;z);
-}
-
-// File : vector.i
-// Interface file
-%module mymodule
-%{
-#include "vector.h"
-%}
-
-typedef struct {
- double x,y,z;
- %addmethods {
- double magnitude(); // This will call Vector_magnitude
- ...
- }
-} Vector;
-
-</pre></blockquote>
-So why bother with all of this <tt>%addmethods</tt> business? In short, you can use it to make some pretty cool `object oriented' scripting language interfaces to C programs without having to rewrite anything in C++. <p>
-<a name="n41"></a><h3> Nested structures</h3>
-Occasionally, a C program will involve structures like this :<p>
-<p>
-<blockquote><pre>typedef struct Object {
- int objtype;
- union {
- int ivalue;
- double dvalue;
- char *strvalue;
- void *ptrvalue;
- } intRep;
-} Object;
-
-</pre></blockquote>
-When SWIG encounters this, it performs a structure splitting operation that transforms the declaration into the equivalent of the following:<p>
-<p>
-<blockquote><pre>typedef union {
- int ivalue;
- double dvalue;
- char *strvalue;
- void *ptrvalue;
-} Object_intRep;
-
-typedef struct Object {
- int objType;
- Object_intRep intRep;
-} Object;
-
-</pre></blockquote>
-SWIG will create an <tt>Object_intRep</tt> structure for use inside the interface file. Accessor functions will be created for both structures. In this case, functions like this would be created :<p>
-<p>
-<blockquote><pre>Object_intRep *Object_intRep_get(Object *o) {
- return (Object_intRep *) &amp;o-&gt;intRep;
-}
-int Object_intRep_ivalue_get(Object_intRep *o) {
- return o-&gt;ivalue;
-}
-int Object_intRep_ivalue_set(Object_intRep *o, int value) {
- return (o-&gt;ivalue = value);
-}
-double Object_intRep_dvalue_get(Object_intRep *o) {
- return o-&gt;dvalue;
-}
-... etc ...
-
-</pre></blockquote>
-Is it hairy? You bet. Does it work? Well, surprisingly yes. When used with Python and Perl5 shadow classes, it's even possible to access the nested members just like you expect :<p>
-<p>
-<blockquote><pre># Perl5 script for accessing nested member
-$o = CreateObject(); # Create an object somehow
-$o-&gt;{intRep}-&gt;{ivalue} = 7 # Change value of o.intRep.ivalue
-</pre></blockquote>
-<p>
-If you've got a bunch of nested structure declarations, it is certainly advisable to check them out after running SWIG. However, there is a good chance that they will work. If not, you can always remove the nested structure declaration and write your own set of accessor functions.<p>
-<a name="n42"></a><h3> Other things to note about structures</h3>
-SWIG doesn't care if the definition of a structure exactly matches that used in the underlying C code (except in the case of nested structures). For this reason, there are no problems omitting problematic members or simply omitting the structure definition altogether. If you are happy simply passing pointers around, this can be done without ever giving SWIG a structure definition.<p>
-<p>
-It is also important to note that most language modules may choose to build a more advanced interface. You may never use the low-level interface described here, although most of SWIG's language modules use it in some way or another.<p>
-<a name="n6"></a><h2> C++ support</h2>
-SWIG's support for C++ is an extension of the support for C functions, variables, and structures. However, SWIG only supports a subset of the C++ language. It has never been my goal to write a full C++ compiler or to turn scripting languages into some sort of weird pseudo C++ interpreter (considering how hard it is to write a C++ compiler, I'm not sure this would even be feasible anyways). <p>
-<p>
-This section describes SWIG's low-level access to C++ declarations. In many instances, this low-level interface may be hidden by shadow classes or an alternative calling mechanism (this is usually language dependent and is described in detail in later chapters).<p>
-<a name="n43"></a><h3> Supported C++ features</h3>
-SWIG supports the following C++ features :<p>
-<p>
-<ul>
-<li>Simple class definitions
-<li>Constructors and destructors
-<li>Virtual functions
-<li>Public inheritance (including multiple inheritance)
-<li>Static functions
-<li>References
-</ul>
-<p>
-The following C++ features are not currently supported :<p>
-<p>
-<ul>
-<li>Operator overloading
-<li>Function overloading (without renaming)
-<li>Templates (anything that would be defined using the `<tt>template</tt>' keyword).
-<li>Friends
-<li>Nested classes
-<li>Namespaces
-<li>Pointers to member functions.
-</ul>
-<p>
-Since SWIG's C++ support is a "work in progress", many of these limitations may be lifted in future releases. In particular, function overloading and nested classes, may be supported in the future. Operator overloading and templates are unlikely to be supported anytime in the near future, but I'm not going to rule out the possibility in later releases.<p>
-<a name="n44"></a><h3> C++ example</h3>
-The following code shows a SWIG interface file for a simple C++ class.<p>
-<p>
-<blockquote><pre>%module list
-%{
-#include "list.h"
-%}
-
-// Very simple C++ example for linked list
-
-class List {
-public:
- List();
- ~List();
- int search(char *value);
- void insert(char *);
- void remove(char *);
- char *get(int n);
- int length;
-static void print(List *l);
-};
-</pre></blockquote>
-<p>
-When compiling C++ code, it is critical that SWIG be called with the `<tt>-c++</tt>' option. This changes the way a number of critical features are handled with respect to differences between C and C++. It also enables the detection of C++ keywords. Without the <tt>-c++</tt> flag, SWIG will either issue a warning or a large number of syntax errors if it encounters any C++ code in an interface file.<p>
-<a name="n45"></a><h3> Constructors and destructors</h3>
-C++ constructors and destructors are translated into accessor functions like the following :<p>
-<p>
-<blockquote><pre>List * new_List(void) {
- return new List;
-}
-void delete_List(List *l) {
- delete l;
-}
-
-</pre></blockquote>
-If the original C++ class does not have any constructors or destructors, putting constructors and destructors in the SWIG interface file will cause SWIG to generate wrappers for the default constructor and destructor of an object.<p>
-<a name="n46"></a><h3> Member functions</h3>
-Member functions are translated into accessor functions like this :<p>
-<p>
-<blockquote><pre>int List_search(List *obj, char *value) {
- return obj-&gt;search(value);
-}
-
-</pre></blockquote>
-Virtual member functions are treated in an identical manner since the C++ compiler takes care of this for us automatically.<p>
-<a name="n47"></a><h3> Static members</h3>
-Static member functions are called directly without making any additional C wrappers. For example, the static member function <tt>print(List *l)</tt> will simply be called as <tt>List::print(List *l)</tt> in the resulting wrapper code.<p>
-<a name="n48"></a><h3> Member data</h3>
-Member data is handled in exactly the same manner as used for C structures. A pair of accessor functions will be created. For example :<p>
-<p>
-<blockquote><pre>int List_length_get(List *obj) {
- return obj-&gt;length;
-}
-int List_length_set(List *obj, int value) {
- obj-&gt;length = value;
- return value;
-}
-
-</pre></blockquote>
-A read-only member can be created using the <tt>%readonly</tt> and <tt>%readwrite</tt> directives. For example, we probably wouldn't want the user to change the length of a list so we could do the following to make the value available, but read-only.<p>
-<p>
-<blockquote><pre>class List {
-public:
-...
-%readonly
- int length;
-%readwrite
-...
-};
-</pre></blockquote>
-<a name="n49"></a><h3> Protection</h3>
-SWIG can only wrap class members that are declared public. Anything specified in a private or protected section will simply be ignored. To simplify your interface file, you may want to consider eliminating all private and protected declarations (if you've copied a C++ header file for example).<p>
-<p>
-By default, members of a class definition are assumed to be private until you explicitly give a `<tt>public:</tt>' declaration (This is the same convention used by C++).<p>
-<a name="n50"></a><h3> Enums and constants</h3>
-Enumerations and constants placed in a class definition are mapped into constants with the classname as a prefix. For example :<p>
-<p>
-<blockquote><pre>class Swig {
-public:
- enum {ALE, LAGER, PORTER, STOUT};
-};
-
-</pre></blockquote>
-Generates the following set of constants in the target scripting language :<p>
-<p>
-<blockquote><pre>Swig_ALE = Swig::ALE
-Swig_LAGER = Swig::LAGER
-Swig_PORTER = Swig::PORTER
-Swig_STOUT = Swig::STOUT
-
-</pre></blockquote>
-Members declared as <tt>const</tt> are wrapped in a similar manner.<p>
-<a name="n51"></a><h3> References</h3>
-C++ references are supported, but SWIG will treat them as pointers. For example, a declaration like this :<p>
-<p>
-<blockquote><pre>class Foo {
-public:
- double bar(double &amp;a);
-}
-</pre></blockquote>
-<p>
-will be accessed using a function like this :<p>
-<p>
-<blockquote><pre>double Foo_bar(Foo *obj, double *a) {
- obj-&gt;bar(*a);
-}
-
-</pre></blockquote>
-Functions returning a reference will be mapped into functions returning pointers.<p>
-<a name="n52"></a><h3> Inheritance</h3>
-SWIG supports basic C++ public inheritance of classes and allows both single and multiple inheritance. The SWIG type-checker knows about the relationship between base and derived classes and will allow pointers to any object of a derived class to be used in functions of a base class. The type-checker properly casts pointer values and is safe to use with multiple inheritance.<p>
-SWIG does not support private or protected inheritance (it will be parsed, but ignored).<p>
-<p>
-The following example shows how SWIG handles inheritance. For clarity, the full C++ code has been omitted.<p>
-<p>
-<blockquote><pre>// shapes.i
-%module shapes
-%{
-#include "shapes.h"
-%}
-
-class Shape {
-public:
- virtual double area() = 0;
- virtual double perimeter() = 0;
- void set_location(double x, double y);
-};
-class Circle : public Shape {
-public:
- Circle(double radius);
- ~Circle();
- double area();
- double perimeter();
-};
-class Square : public Shape {
-public:
- Square(double size);
- ~Square();
- double area();
- double perimeter();
-}
-</pre></blockquote>
-<p>
-When wrapped into Perl5, we can now perform the following operations :<p>
-<p>
-<blockquote><pre>beazley@slack% perl5.003
-use shapes;
-$circle = shapes::new_Circle(7);
-$square = shapes::new_Square(10);
-print shapes::Circle_area($circle),"\n";
-# Notice use of base class below
-print shapes::Shape_area($circle),"\n";
-print shapes::Shape_area($square),"\n";
-shapes::Shape_set_location($square,2,-3);
-print shapes::Shape_perimeter($square),"\n";
-&lt;ctrl-d&gt;
-153.93804004599999757
-153.93804004599999757
-100.00000000000000000
-40.00000000000000000
-
-</pre></blockquote>
-In our example, we have created Circle and Square objects. We can call member functions on each object by making calls to <tt>Circle_area</tt>, <tt>Square_area</tt>, and so on. However, we can can accomplish the same thing by simply using the <tt>Shape_area</tt> function on either object.<p>
-<a name="n53"></a><h3> Templates</h3>
-SWIG does not support template definitions--that is, it does not support anything that would be declared in C++ using the `<tt>template</tt>' keyword. If a template definition is found, SWIG will issue a warning message and attempt to ignore the contents of the entire declaration. For example, a template class such as the following would be ignored by SWIG :<p>
-<p>
-<blockquote><pre>// File : list.h
-#define MAXITEMS 100
-template&lt;class T&gt; class List { // Entire class is ignored by SWIG
-private:
- T *data;
- int nitems;
-public:
- List() {
- data = new T [MAXITEMS];
- nitems = 0;
- }
- ~List() {
- delete [] data;
- };
- void append(T obj) {
- if (nitems &lt; MAXITEMS) {
- data[nitems++] = obj;
- }
- }
- int length() {
- return nitems;
- }
- T get(int n) {
- return data[n];
- }
-};
-
-</pre></blockquote>
-However, SWIG can support instantiations of a template and types involving templates. For example, the following interface file would be legal :<p>
-<p>
-<blockquote><pre>// SWIG interface involving a template
-%module example
-%{
-#include "list.h" // Get Template definition
-%}
-
-// Now a function involving templates
-extern void PrintData(List&lt;double&gt; &amp;l);
-
-</pre></blockquote>
-The type "<tt>List&lt;double</tt>&gt;" becomes the datatype for the function parameter. In, Python it might appear like this :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; print cl
-_80a2df8_List&lt;double&gt;_p
-&gt;&gt;&gt;
-
-</pre></blockquote>
-To create specific objects, you may need to supply helper functions such as the following :<p>
-<blockquote><pre>
-%inline %{
-// Helper function to create a List&lt;double&gt;
-List&lt;double&gt; *new_DoubleList() {
- return new List&lt;double&gt;;
-}
-%}
-</pre></blockquote>
-<p>
-Specific templates can also be wrapped in a clever way using <tt>typedef.</tt> For example, the following would also work :<p>
-<p>
-<blockquote><pre>%module example
-%{
-#include "list.h"
-typedef List&lt;double&gt; DoubleList;
-%}
-
-class DoubleList {
-public:
- DoubleList();
- ~DoubleList();
- void append(double);
- int length();
- double get(int n);
-};
-
-</pre></blockquote>
-In this case, SWIG thinks that there is a class "<tt>DoubleList</tt>" with the methods supplied. It generates the appropriate code and everything works like you would expect (of course, in reality there is no such class). When the SWIG module is compiled, all of the methods get supplied by the original template class. A key thing to keep in mind when working with templates is that SWIG can only handle particular instantiations of a template (such as a list of double). More general support is not yet provided (but may be added someday).<p>
-<a name="n54"></a><h3> Renaming</h3>
-C++ member functions and data can be renamed with the <tt>%name</tt> directive. The <tt>%name</tt> directive only replaces the member function name. For example :<p>
-<p>
-<blockquote><pre>class List {
-public:
- List();
-%name(ListSize) List(int maxsize);
- ~List();
- int search(char *value);
-%name(find) void insert(char *);
-%name(delete) void remove(char *);
- char *get(int n);
- int length;
-static void print(List *l);
-};
-
-</pre></blockquote>
-This will create the functions <tt>List_find</tt>, <tt>List_delete</tt>, and a function named <tt>new_ListSize</tt> for the overloaded constructor.<p>
-<p>
-The <tt>%name </tt>directive can be applied to all members including constructors, destructors, static functions, data members, and enumeration values.<p>
-<p>
-The class name prefix can be changed by specifying <p>
-<p>
-<blockquote><pre>%name(newname) class List {
-...
-}
-</pre></blockquote>
-<a name="n55"></a><h3> Adding new methods</h3>
-New methods can be added to a class using the <tt>%addmethods</tt> directive. This directive is primarily used in conjunction with shadow classes to add additional functionality to an existing class. For example :<p>
-<p>
-<blockquote><pre>%module vector
-%{
-#include "vector.h"
-%}
-
-class Vector {
-public:
- double x,y,z;
- Vector();
- ~Vector();
- ... bunch of C++ methods ...
- %addmethods {
- char *__str__() {
- static char temp[256];
- sprintf(temp,"[ %g, %g, %g ]", v-&gt;x,v-&gt;y,v-&gt;z);
- return &amp;temp[0];
- }
- }
-};
-</pre></blockquote>
-<p>
-This code adds a<tt> __str__</tt> method to our class for producing a string representation of the object. In Python, such a method would allow us to print the value of an object using the <tt>print</tt> command. <p>
-<p>
-<blockquote><pre>&gt;&gt;&gt;
-&gt;&gt;&gt; v = Vector();
-&gt;&gt;&gt; v.x = 3
-&gt;&gt;&gt; v.y = 4
-&gt;&gt;&gt; v.z = 0
-&gt;&gt;&gt; print(v)
-[ 3.0, 4.0, 0.0 ]
-&gt;&gt;&gt;
-
-</pre></blockquote>
-The<tt> %addmethods</tt> directive follows all of the same conventions as its use with C structures.<p>
-<a name="n56"></a><h3> Partial class definitions</h3>
-Since SWIG is still somewhat limited in its support of C++, it may be necessary to only use partial class information in an interface file. This should not present a problem as SWIG does not need the exact C++ specification. As a general rule, you should strip all classes of operator overloading, friends, and other declarations before giving them to SWIG (although SWIG will generate only warnings for most of these things).<p>
-<p>
-As a rule of thumb, running SWIG on raw C++ header or source files is currently discouraged. Given the complexity of C++ parsing and limitations in SWIG's parser it will still take some time for SWIG's parser to evolve to a point of being able to safely handle most raw C++ files.<p>
-<a name="n57"></a><h3> SWIG, C++, and the Legislation of Morality</h3>
-As languages go, C++ is quite possibly one of the most immense and complicated languages ever devised. It is certainly a far cry from the somewhat minimalistic nature of C. Many parts of C++ are designed to build large programs that are "safe" and "reliable." However, as a result, it is possible for developers to overload operators, implement smart pointers, and do all sorts of other insane things (like expression templates). As far as SWIG is concerned, the primary goal is attaching to such systems and providing a scripting language interface. There are many features of C++ that I would not have the slightest idea how to support in SWIG (most kinds of templates for example). There are other C++ idioms that may be unsafe to use with SWIG. For example, if one implements "smart" pointers, how would they actually interact with the pointer mechanism used by SWIG? <p>
-<p>
-Needless to say, handling all of the possible cases is probably impossible. SWIG is certainly not guaranteed to work with every conceivable type of C++ program (especially those that use C++ in a maximal manner). Nor is SWIG claiming to build C++ interfaces in a completely "safe" manner. The bottom line is that effective use of C++ with SWIG requires that you know what you're doing and that you have a certain level of "moral flexibility" when it comes to the issue of building a useful scripting language interface.<p>
-<a name="n58"></a><h3> The future of C++ and SWIG</h3>
-SWIG's support of C++ is best described as an ongoing project. It will probably remain evolutionary in nature for the foreseeable future. In the short term, work is already underway for supporting nested classes and function overloading. As always, these developments will take time. Feedback and contributions are always welcome.<p>
-<a name="n7"></a><h2> Objective-C</h2>
-One of SWIG's most recent additions is support for Objective-C parsing. This is currently an experimental feature that may be improved in future releases. <p>
-<p>
-Objective-C support is built using the same approach as used for C++ parsing. Objective-C interface definitions are converted into a collection of ANSI C accessor functions. These accessor functions are then wrapped by SWIG and turned into an interface.<p>
-<p>
-To enable Objective-C parsing, SWIG should be given the <tt>-objc</tt> option (this option may be used in conjunction with the <tt>-c++</tt> option if using Objective-C++). It may also be helpful to use the -o option to give the output file the .m suffix needed by many Objective-C compilers. For example :<p>
-<p>
-<blockquote><pre>% swig -objc -o example_wrap.m example.i
-
-</pre></blockquote>
-Objective-C interfaces should also include the file `<tt>objc.i</tt>' as this contains important definitions that are common to most Objective-C programs. <p>
-<a name="n59"></a><h3> Objective-C Example</h3>
-The following code shows a SWIG interface file for a simple Objective-C class :<p>
-<p>
-<blockquote><pre>%module list
-%{
-#import "list.h"
-%}
-%include objc.i
-// Very simple list class
-@interface List : Object {
- int nitems; // Number of items in the list
- int maxitems; // Maximum number of items
- id *items; // Array holding the items
-}
-//------------------------- List methods --------------------------
-
-// Create a new list
-+ new;
-
-// Destroy the list
-- free;
-
-// Copy a list
-- copy;
-
-// Append a new item to the list
-- (void) append: (id) item;
-
-// Insert an item in the list
-- (void) insert: (id) item : (int) pos;
-
-// Delete an item from the list
-- remove: (int) pos;
-
-// Get an item from the list
-- get: (int) i;
-
-// Find an item in the list and return its index
-- (int) index: obj;
-
-// Get length of the list
-- (int) len;
-
-// Print out a list (Class method)
-+ (void) print: (List *) l;
-
-@end
-
-</pre></blockquote>
-<a name="n60"></a><h3> Constructors and destructors</h3>
-By default, SWIG assumes that the methods "new" and "free" correspond to constructors and destructors. These functions are translated into the following accessor functions :<p>
-<p>
-<blockquote><pre>List *new_List(void) {
- return (List *) [List new];
-}
-void delete_List(List *l) {
- [l free];
-}
-
-</pre></blockquote>
-If the original Objective-C class does not have any constructors or destructors, putting them in the interface file will cause SWIG to generate wrappers for a default constructor and destructor (assumed to be defined in the object's base-class).<p>
-<p>
-If your Objective-C program uses a different naming scheme for constructors and destructors, you can tell SWIG about it using the following directive :<p>
-<p>
-<blockquote><pre>%pragma objc_new = "create" // Change constructor to `create'
-%pragma objc_delete = "destroy" // Change destructor to `destroy'
-</pre></blockquote>
-<a name="n61"></a><h3> Instance methods</h3>
-Instance methods are converted into accessor functions like this :<p>
-<p>
-<blockquote><pre>void List_append(List *l, id item) {
- [l append : item];
-}
-</pre></blockquote>
-<a name="n62"></a><h3> Class methods</h3>
-Class methods are translated into the following access function :<p>
-<blockquote><pre>
-void List_print(List *l) {
- [List print : l];
-}
-</pre></blockquote>
-<a name="n63"></a><h3> Member data</h3>
-Member data is handled in the same manner as for C++ with accessor functions being produced for getting and setting the value. By default, all data members of an Objective-C object are private unless explicitly declared <tt>@public</tt>. <p>
-<a name="n64"></a><h3> Protection</h3>
-SWIG can only wrap data members that are declared @public. Other protection levels are ignored.<p>
-<a name="n65"></a><h3> The use of id</h3>
-The datatype `<tt>id</tt>' assumes the same role in SWIG as it does with Objective-C. A function operating on an `id' will accept any Object type (works kind of like <tt>void *</tt>). All methods with no explicit return value are also assumed to return an `id'. <p>
-<a name="n66"></a><h3> Inheritance</h3>
-Essentially all Objective-C classes will inherit from a baseclass <tt>Object</tt>. If undefined, SWIG will generate a warning, but other function properly. A missing baseclass has no effect on the wrapper code or the operation of the resulting module. Really, the only side effect of a missing base class is that you will not be able to execute base-class methods from the scripting interface. Objective-C does not support multiple inheritance.<p>
-<a name="n67"></a><h3> Referring to other classes</h3>
-The<tt> @class</tt> declaration can be used to refer to other classes. SWIG uses this in certain instances to make sure wrapper code is generated correctly.<p>
-<a name="n68"></a><h3> Categories</h3>
-Categories provide a mechanism for adding new methods to existing Objective-C classes. SWIG correctly parses categories and attaches the methods to the wrappers created for the original class. For example :<p>
-<p>
-<blockquote><pre>%module example
-%{
-#import "foo.h"
-%}
-
-// Sample use of a category in an interface
-@interface Foo (CategoryName)
-// Method declarations
--bar : (id) i;
-@end
-
-</pre></blockquote>
-<a name="n69"></a><h3> Implementations and Protocols</h3>
-SWIG currently ignores all declarations found inside an <tt>@implementation</tt> or <tt>@protocol</tt> section. Support for this may be added in future releases.<p>
-<p>
-Although SWIG ignores protocols, protocol type-specifiers may be used. For example, these are legal declarations :<p>
-<p>
-<blockquote><pre>%module example
-
-%interface Foo : Object &lt;proto1, proto2&gt; {
-
-}
-// Methods
-- Bar : (id &lt;proto1,proto2&gt;) i;
-@end
-
-</pre></blockquote>
-SWIG will carry the protocol lists through the code generation process so the resulting wrapper code compiles without warnings.<p>
-<a name="n70"></a><h3> Renaming</h3>
-Objective-C members can be renamed using the <tt>%name()</tt> directive as in :<p>
-<p>
-<blockquote><pre>@interface List : Object {
-@public
-%name(size) int length; // Rename length to size
-}
-
-+ new;
-- free;
-%name(add) -(void) append: (id) item; // Rename append to add
-@end
-
-</pre></blockquote>
-<a name="n71"></a><h3> Adding new methods</h3>
-New methods can be added to a class using the <tt>%addmethods</tt> directive. This is primarily used with shadow classes to add additional functionality to a class. For example :<p>
-<p>
-<blockquote><pre>@interface List : Object {
-}
-... bunch of Objective-C methods ...
-%addmethods {
- - (void) output {
- ... code to output a list ...
- }
-}
-@end
-</pre></blockquote>
-<p>
-<tt>%addmethods </tt>works in exactly the same manner as it does for C and C++ (except that Objective-C syntax is allowed). Consult those sections for more details.<p>
-<a name="n72"></a><h3> Other issues</h3>
-Objective-C is dynamically typed while SWIG tends to enforce a type-checking model on all of its pointer values. This mismatch could create operational problems with Objective-C code in the form of SWIG type errors. One solution to this (although perhaps not a good one) is to use the SWIG pointer library in conjunction with Objective-C. The pointer library provides simple functions for casting pointer types and manipulating values. <p>
-<p>
-Certain aspects of Objective-C are not currently supported (protocols for instance). These limitations may be lifted in future releases.<p>
-<a name="n8"></a><h2> Conditional compilation</h2>
-SWIG does not run the C preprocessor, but it does support conditional compilation of interface files in a manner similar to the C preprocessor. This can be done by placed <tt>#ifdef</tt>, <tt>#ifndef</tt>, <tt>#if</tt>, <tt>#else</tt>, <tt>#elif</tt>, and <tt>#endif</tt> directives in your interface file. These directives can be safely nested. This allows one to conditionally compile out troublesome C/C++ code if necessary. For example, the following file can serve as both a C header file and a SWIG interface file :<p>
-<p>
-<blockquote><pre>#ifdef SWIG
-%module mymodule
-%{
-#include "header.h"
-%}
-
-%include wish.i
-#endif
-
-... normal C declarations here ...
-
-</pre></blockquote>
-<p>
-Similarly, conditional compilation can be used to customize an interface. The following interface file can be used to build a Perl5 module that works with either static or dynamic linking :<p>
-<p>
-<blockquote><pre>
-%module mymodule
-%{
-#include "header.h"
-%}
-
-... Declarations ...
-
-#ifdef STATIC
-%include perlmain.i // Include code for static linking
-#endif
-
-</pre></blockquote>
-However, it is not safe to use conditional compilation in the middle of a declaration. For example :<p>
-<p>
-<blockquote><pre>double foo(
-#ifdef ANSI_ARGS
-double a, double b
-#endif
-);
-
-</pre></blockquote>
-This fails because the SWIG parser is not equipped to handle conditional compilation directives in an arbitrary location (like the C preprocessor). For files that make heavy use of the C preprocessor like this, it may be better to run the header file through the C preprocessor and use the output as the input to SWIG.<p>
-<a name="n73"></a><h3> Defining symbols</h3>
-To define symbols, you can use the <tt>-D</tt> option as in :<p>
-<blockquote><pre>
-swig -perl5 -static -DSTATIC interface.i
-
-</pre></blockquote>
-Symbols can also be defined using <tt>#define</tt> with no arguments. For example :<p>
-<p>
-<blockquote><pre>%module mymodule
-#define STATIC
-
-... etc ...
-</pre></blockquote>
-<p>
-For the purposes of conditional compilation, one should not assign values to symbols. If this is done, SWIG interprets the #define as providing the definition of a scripting language constant. <p>
-<a name="n74"></a><h3> The #if directive</h3>
-The <tt>#if</tt> directive can only be used in the following context :<p>
-<blockquote><pre>
-#if defined(SYMBOL)
-...
-#elif !defined(OTHERSYMBOL)
-...
-#endif
-</pre></blockquote>
-<p>
-The C preprocessor version supports any constant integral expression as an argument to <tt>#if</tt>, but SWIG does not yet contain an expression evaluator so this is not currently supported. As a result, declarations such as the following don't yet work :<p>
-<p>
-<blockquote><pre>#if (defined(foo) || defined(bar))
-...
-#endif
-
-</pre></blockquote>
-<a name="n75"></a><h3> Predefined Symbols</h3>
-One or more of the following symbols will be defined by SWIG when it is processing an interface file :<p>
-<p>
-<blockquote><pre>SWIG Always defined when SWIG is processing a file
-SWIGTCL Defined when using Tcl
-SWIGTCL8 Defined when using Tcl8.0
-SWIGPERL Defined when using Perl
-SWIGPERL4 Defined when using Perl4
-SWIGPERL5 Defined when using Perl5
-SWIGPYTHON Defined when using Python
-SWIGGUILE Defined when using Guile
-SWIGWIN Defined when running SWIG under Windows
-SWIGMAC Defined when running SWIG on the Macintosh
-
-</pre></blockquote>
-Interface files can look at these symbols as necessary to change the way in which an interface is generated or to mix SWIG directives with C code. These symbols are also defined within the C code generated by SWIG (except for the symbol `<tt>SWIG</tt>' which is only defined within the SWIG compiler).<p>
-<a name="n9"></a><h2> Code Insertion</h2>
-Sometimes it is necessary to insert special code into the resulting wrapper file generated by SWIG. For example, you may want to include additional C code to perform initialization or other operations. There are four ways to insert code, but it's useful to know how the output of SWIG is structured first.<p>
-<a name="n76"></a><h3> The output of SWIG</h3>
-SWIG creates a single C source file containing wrapper functions, initialization code, and support code. The structure of this file is as follows :<p>
-<center><img src="ch3.1.png"></center>
-
-<p>
-<p>
-The headers portion typically contains header files, supporting code, helper functions, and forward declarations. If you look at it, you'll usually find a hideous mess since this also contains the SWIG run-time pointer type-checker and internal functions used by the wrapper functions. The "wrapper" portion of the output contains all of the wrapper functions. Finally, the initialization function is a single C function that is created to initialize your module when it is loaded.<p>
-<a name="n77"></a><h3> Code blocks</h3>
-A code block is enclosed by a <tt>%{, %}</tt> and is used to insert code into the header portion of the resulting wrapper file. Everything in the block is copied verbatim into the output file and will appear before any generated wrapper functions. Most SWIG input files have at least one code block that is normally used to include header files and supporting C code. Additional code blocks may be placed anywhere in a SWIG file as needed. <p>
-<blockquote><pre>
-%module mymodule
-%{
-#include "my_header.h"
-%}
-
-... Declare functions here
-%{
-
-... Include Tcl_AppInit() function here ...
-
-%}
-</pre></blockquote>
-<p>
-Code blocks are also typically used to write "helper" functions. These are functions that are used specifically for the purpose of building an interface and are generally not visible to the normal C program. For example :<p>
-<p>
-<blockquote><pre>%{
-
-/* Create a new vector */
-static Vector *new_Vector() {
- return (Vector *) malloc(sizeof(Vector));
-}
-
-%}
-
-// Now wrap it
-Vector *new_Vector();
-
-</pre></blockquote>
-<a name="n78"></a><h3> Inlined code blocks</h3>
-Because the process of writing helper functions is fairly common, there is a special inlined form of code block that is used as follows :<p>
-<p>
-<blockquote><pre>%inline %{
-/* Create a new vector */
-Vector *new_Vector() {
- return (Vector *) malloc(sizeof(Vector));
-}
-%}
-
-</pre></blockquote>
-The <tt>%inline</tt> directive inserts all of the code that follows verbatim into the header portion of an interface file. The code is then fed into the SWIG parser and turned into an interface. Thus, the above example creates a new command <tt>new_Vector</tt> using only one declaration. Since the code inside an <tt>%inline %{ ... %}</tt> block is given to both the C compiler and SWIG, it is illegal to include any SWIG directives inside the <tt>%{ ... %}</tt> block.<p>
-<a name="n79"></a><h3> Initialization blocks</h3>
-Code may also be inserted using an initialization block, as shown below :<p>
-<p>
-<blockquote><pre>%init %{
-
- init_variables();
-%}
-</pre></blockquote>
-<p>
-This code is inserted directly into SWIG's initialization function. You can use it to perform additional initialization and operations. Since this code is inserted directly into another function, it should not declare functions or include header files. Primarily this can be used to add callouts to widgets and other packages that might also need to be initialized when your extension is loaded.<p>
-<a name="n80"></a><h3> Wrapper code blocks</h3>
-Code may be inserted in the wrapper code section of an output file using the <tt>%wrapper</tt> directive as shown :<p>
-<p>
-<blockquote><pre>%wrapper %{
- ... a bunch of code ...
-%}
-
-</pre></blockquote>
-This directive, for almost all practical purposes, is identical to just using a <tt>%{,%}</tt> block, but may be required for more sophisticated applications. It is mainly only used for advanced features in the SWIG library. As a general rule, you should avoid using this directive unless you absolutely know what you are doing.<p>
-<a name="n10"></a><h2> A general interface building strategy</h2>
-This section describes the general approach for building interface with SWIG. The specifics related to a particular scripting language are found in later chapters.<p>
-<a name="n81"></a><h3> Preparing a C program for SWIG</h3>
-SWIG doesn't require modifications to your C code, but if you feed it a collection of raw C header files or source code, the results might not be what you expect---in fact, they might be awful. Here's a series of steps you can follow to make an interface for a C program :<p>
-<p>
-<ul>
-<li>Identify the functions that you want to wrap. It's probably not necessary to access every single function in a C program--thus, a little forethought can dramatically simplify the resulting scripting language interface. C header files are particularly good source for finding things to wrap.
-<li>Create a new interface file to describe the scripting language interface to your program.
-<li>Copy the appropriate declarations into the interface file or use SWIG's <tt>%include</tt> directive to process an entire C source/header file. Either way, this step is fairly easy.
-<li>Make sure everything in the interface file uses ANSI C/C++syntax.
-<li>Check to make sure there aren't any functions involving function pointers, or variable length arguments since SWIG doesn't like these very much.
-<li>Eliminate unnecessary C preprocessor directives. SWIG will probably remove most of them, but better safe than sorry. Remember, SWIG does not run the C preprocessor.
-<li>Make sure all necessary `<tt>typedef</tt>' declarations and type-information is available in the interface file.
-<li>If your program has a main() function, you may need to rename it (read on).
-<li>Run SWIG and compile.
-</ul>
-<p>
-While this may sound complicated, the process turns out to be relatively easy in practice--for example, making an interface to the entire OpenGL library only takes about 5-10 minutes.<p>
-<p>
-In the process of building an interface, you are encouraged to use SWIG to find problematic declarations and specifications. SWIG will report syntax errors and other problems along with the associated file and line number. <p>
-<a name="n82"></a><h3> The SWIG interface file</h3>
-The preferred method of using SWIG is to generate separate interface file. Suppose you have the following C header file :<p>
-<blockquote><pre>
-/* File : header.h */
-
-#include &lt;stdio.h&gt;
-#include &lt;math.h&gt;
-
-extern int foo(double);
-extern double bar(int, int);
-extern void dump(FILE *f);
-
-</pre></blockquote>
-A typical SWIG interface file for this header file would look like the following :<p>
-<blockquote><pre>
-/* File : interface.i */
-%module mymodule
-%{
-#include "header.h"
-%}
-extern int foo(double);
-extern double bar(int, int);
-extern void dump(FILE *f);
-
-</pre></blockquote>
-Of course, in this case, our header file is pretty simple so we could have made an interface file like this as well:<p>
-<p>
-<blockquote><pre>/* File : interface.i */
-%module mymodule
-%include header.h
-</pre></blockquote>
-<p>
-Naturally, your mileage may vary.<p>
-<a name="n83"></a><h3> Why use separate interface files?</h3>
-While SWIG can parse many header files, it is more common to write a special <tt>.i</tt> file defining the interface to a package. There are several reasons for doing this :<p>
-<p>
-<ul>
-<li>It is rarely necessary to access every single function in a large package. Many C functions might have little or no use in a scripted environment. Therfore, why wrap them?
-<li>Separate interface files provide an opportunity to provide more precise rules about how an interface is to be constructed.
-<li>Interface files can provide structure and organization. For example , you can break the interface up into sections, provide documentation, and do other things that you might not normally do with an ordinary .h file.
-<li>SWIG can't parse certain definitions that appear in header files. Having a separate file allows you to eliminate or work around these problems.
-<li>Interface files provide a precise definition of what the interface is. Users wanting to extend the system can go to the interface file and immediately see what is available without having to dig it out of header files.
-</ul>
-<a name="n84"></a><h3> Getting the right header files</h3>
-Sometimes, it is necessary to use certain header files in order for the code generated by SWIG to compile properly. You can have SWIG include certain header files by using a <tt>%{,%}</tt> block as follows :<p>
-<blockquote><pre>
-%module graphics
-%{
-#include &lt;GL/gl.h&gt;
-#include &lt;GL/glu.h&gt;
-%}
-
-// Put rest of declarations here
-...
-</pre></blockquote>
-<a name="n85"></a><h3> What to do with main()</h3>
-If your program defines a <tt>main()</tt> function, you may need to get rid of it or rename it in order to use a scripting language. Most scripting languages define their own <tt>main()</tt> procedure that must be called instead. <tt>main()</tt> also makes no sense when working with dynamic loading. There are a few approaches to solving the <tt>main()</tt> conflict :<p>
-<p>
-<ul>
-<li>Get rid of <tt>main()</tt> entirely. This is the brute force approach.
-<li>Rename <tt>main()</tt> to something else. You can do this by compiling your C program with an option like <tt>-Dmain=oldmain</tt>.
-<li>Use conditional compilation to only include <tt>main()</tt> when not using a scripting language.
-</ul>
-<p>
-Getting rid of <tt>main()</tt> may cause potential initialization problems of a program. To handle this problem, you may consider writing a special function called <tt>program_init()</tt> that initializes your program upon startup. This function could then be called either from the scripting language as the first operation, or when the SWIG generated module is loaded.<p>
-<p>
-As a general note, many C programs only use the <tt>main()</tt> function to parse command line options and to set parameters. However, by using a scripting language, you are probably trying to create a program that is more interactive. In many cases, the old <tt>main()</tt> program can be completely replaced by a Perl, Python, or Tcl script.<p>
-<a name="n86"></a><h3> Working with the C preprocessor</h3>
-If you have a header file that makes heavy use of macros and C preprocessor directives, it may be useful to run it through the C preprocessor first. This can usually be done by running the C compiler with the -E option. The output will be completely hideous, but macros and other preprocessor directives should now be expanded as needed. If you want to wrap a C preprocessor macro with SWIG, this can be done by giving a function declaration with the same name and usage as the macro. When writing the macro as a function declaration, you are providing SWIG with type-information--without that, SWIG would be unable to produce any sort of wrapper code. <p>
-<a name="n87"></a><h3> How to cope with C++</h3>
-Given the complexity of C++, it will almost always be necessary to build a special interface file containing suitably edited C++ declarations. If you are working with a system involving 400 header files, this process will not be trivial. Perhaps the best word of advice is to think hard about what you want this interface to be. Also, is it absolutely critical to wrap every single function in a C++ program? SWIG's support of C++ will improve with time, but I'll be the first to admit that SWIG works much better with pure ANSI C code when it comes to large packages.<p>
-<a name="n88"></a><h3> How to avoid creating the interface from hell</h3>
-SWIG makes it pretty easy to build a big interface really fast. In fact, if you apply it to a large enough package, you'll find yourself with a rather large chunk of code being produced in the resulting wrapper file. To give you an idea, wrapping a 1000 line C header file with a large number of structure declarations may result in a wrapper file containing 20,000-30,000 lines of code. I can only imagine what wrapping a huge C++ class hierarchy would generate. Here's a few rules of thumb for making smaller interfaces :<p>
-<p>
-<ul>
-<li>Ask yourself if you really need to access particular functions. It is usually not necessary to wrap every single function in a package. In fact, you probably only need a relatively small subset.
-<li>SWIG does not require structure definitions to operate. If you are never going to access the members of a structure, don't wrap the structure definition.
-<li>Eliminate unneeded members of C++ classes.
-<li>Think about the problem at hand. If you are only using a subset of some library, there is no need to wrap the whole thing.
-<li>Write support or helper functions to simplify common operations. Some C functions may not be easy to use in a scripting language environment. You might consider writing an alternative version and wrapping that instead.
-</ul>
-<p>
-Writing a nice interface to a package requires work. Just because you use SWIG it doesn't mean that you're going to end up with a good interface. SWIG is primarily designed to eliminate the tedious task of writing wrapper functions. It does not eliminate the need for proper planning and design when it comes to building a useful application. In short, a little forethought can go a long way.<p>
-<p>
-Of course,if you're primarily interested in just slapping something together for the purpose of debugging, rapid application development, and prototyping, SWIG will gladly do it for you (in fact, I use SWIG alot for this when developing other C/C++ applications).<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:46:53 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Scripting.html b/swigweb/Doc1.1/HTML/Scripting.html
deleted file mode 100644
index db7881246..000000000
--- a/swigweb/Doc1.1/HTML/Scripting.html
+++ /dev/null
@@ -1,255 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Scripting Languages</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>2 Scripting Languages</h1><p><ul>
-<li> <a href="#n1">The two language view of the world</a>
-<li> <a href="#n2">How does a scripting language talk to C?</a>
-<li> <a href="#n3">Building scripting language extensions</a>
-<li> <a href="#n4">Shared libraries and dynamic loading</a>
-</ul>
-
-SWIG is all about using scripting languages with C/C++ to make flexible applications. This chapter provides a brief overview of several concepts and important aspects of this interface. Many of SWIG's potential users may not have considered using a scripting language before, so I hope that this chapter can provide a little motivation.<p>
-<a name="n1"></a><h2> The two language view of the world</h2>
-By developing SWIG, I am trying to build systems that are loosely structured as follows :<p>
-<p><center><img src="ch2.1.png"></center><p>
-<p>
-<p>
-A real application might look more like this :<p>
-<p><center><img src="ch2.2.png"></center><p>
-<p>
-In either case, we are interested in controlling a C/C++ program with a scripting language interface. Our interface may be for a small group of functions or a large collection of C libraries for performing a variety of tasks. In this model, C functions are turned into commands. To control the program, the user now types these commands or writes scripts to perform a particular operation. If you have used commercial packages such as MATLAB or IDL, it is a very similar model--you execute commands and write scripts, yet most of the underlying functionality is still written in C or Fortran for performance.<p>
-<p>
-The two-language model of computing is extremely powerful because it exploits the strengths of each language. C/C++ can be used for maximal performance and complicated systems programming tasks. Scripting languages can be used for rapid prototyping, interactive debugging, scripting, and access to high-level data structures such as lists, arrays, and hash tables.<p>
-<a name="n5"></a><h3> Will scripting languages make my C program inefficient?</h3>
-One of the criticisms of scripting languages is that they are interpreted and slow. No doubt about it, a scripting language will always run much slower than C. However, if you are using a scripting language to control a big C program, most of your functionality is still written in C and still fast. Thus, there is really no difference between writing the following in C <p>
-<p>
-<blockquote><pre>for (i = 0; i &lt; 1000; i++) {
- call a bunch of C functions to do something
-}
-</pre></blockquote>
-<p>
-or writing the same thing in Python :<p>
-<p>
-<blockquote><pre>for i in range(0,1000):
- call a bunch of C functions to do something
-
-</pre></blockquote>
-Most of the time is still spent in the underlying C functions. Of course, you wouldn't want to write the inner loop of a matrix multiply in a scripting language, but you already knew this. It is also worth noting that reimplementing certain operations in C might not lead to better performance. For example, Perl is highly optimized for text-processing operations. Most of these operations are already implemented in C (underneath the hood) so in certain cases, using a scripting language may actually be faster than an equivalent implementation in C. <p>
-<a name="n6"></a><h3> Will adding a scripting language to my C program make it unmanagable?</h3>
-A fear among some users is that by adding a second language, you will end up with a package that is hard to maintain and use. I believe that there are two answers to this question. If you find yourself modifying the C code to fit it into a specific scripting language, then it will be difficult to maintain. By doing this, you will lock yourself into a particular language. If that language changes or disappears off the face of the earth, then you will be left with serious maintenance problems. On the flip side of the coin, a non-invasive tool like SWIG can build interfaces without requiring language-specific modifications to the underlying C code. If the scripting language changes, it is easy to update the resulting interface. If you decide that you want to scrap the whole interface scheme and try something else, you still have a clean set of C libraries<p>
-<p>
-My personal experience has been that adding a scripting language to a C program makes the C program more managable! You are encouraged to think about how your C program is structured and how you want things to work. In every program in which I have added a scripting interface, the C code has actually decreased in size, improved in reliability, become easier to maintain, while becoming more functional and flexible than before.<p>
-<a name="n2"></a><h2> How does a scripting language talk to C?</h2>
-Scripting languages are built around a small parser that reads and executes statements on the fly as your program runs. Within the parser, there is a mechanism for executing commands or accessing variables. However, in order to access C functions and variables, it is necessary to tell the parser additional information such as the name of the function, what kind of arguments does it take, and what to do when it is called. Unfortunately, this process can be extremely tedious and technical. SWIG automates the process and allows you to forget about it. In any case, it's probably a good idea to know what's going on under the hood.<p>
-<a name="n7"></a><h3> Wrapper functions</h3>
-Suppose you have an ordinary C function like this :<p>
-<p>
-<blockquote><pre>int fact(int n) {
- if (n &lt;= 1) return 1;
- else return n*fact(n-1);
-}
-</pre></blockquote>
-<p>
-In order to access this function from a scripting language, it is necessary to write a special "wrapper" function that serves as the glue between the scripting language and the underlying C function. A wrapper function must do three things :<p>
-<p>
-<ul>
-<li>Gather function arguments and make sure they are valid.
-<li>Call the C function.
-<li>Convert the return value into a form recognized by the scripting language.
-</ul>
-<p>
-As an example, the Tcl wrapper function for the <tt>fact()</tt> function above example might look like the following : <p>
-<blockquote><pre>
-int wrap_fact(ClientData clientData, Tcl_Interp *interp,
- int argc, char *argv[]) {
- int _result;
- int _arg0;
- if (argc != 2) {
- interp-&gt;result = "wrong # args";
- return TCL_ERROR;
- }
- _arg0 = atoi(argv[1]);
- _result = fact(_arg0);
- sprintf(interp-&gt;result,"%d", _result);
- return TCL_OK;
-}
-
-</pre></blockquote>
-Once we have created a wrapper function, the final step is to tell the scripting language about our new function. This is usually done in an initialization function called by the language when our module is loaded. For example, adding the above function to the Tcl interpreter would require code like the following :<p>
-<p>
-<blockquote><pre>int Wrap_Init(Tcl_Interp *interp) {
- Tcl_CreateCommand(interp, "fact", wrap_fact, (ClientData) NULL,
- (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
-</pre></blockquote>
-<p>
-When executed, Tcl will now have a new command called "<tt>fact</tt>" that you can use like any other Tcl command.<p>
-<p>
-While the process of adding a new function to Tcl has been illustrated, the procedure is almost identical for Perl and Python. Both require special wrappers to be written and both need additional initialization code. Only the specific details are different.<p>
-<a name="n8"></a><h3> Variable linking</h3>
-Variable linking is a slightly more difficult problem. The idea here is to map a C/C++ global variable into a variable in the scripting language (we are "linking" a variable in the scripting language to a C variable). For example, if you have the following variable:<p>
-<p>
-<blockquote><pre>double My_variable = 3.5;
-</pre></blockquote>
-<p>
-It would be nice to be able to access it from a script as follows (shown for Perl):<p>
-<p>
-<blockquote><pre>$a = $My_variable * 2.3;
-</pre></blockquote>
-<p>
-Unfortunately, the process of linking variables is somewhat problematic and not supported equally in all scripting languages. There are two primary methods for approaching this problem:<p>
-<p>
-<ul>
-<li>Direct access. Tcl provides a mechanism for directly accessing C <tt>int</tt>, <tt>double</tt>, and <tt>char</tt> * datatypes as Tcl variables. Whenever these variables are used in a Tcl script, the interpreter will directly access the corresponding C variable. In order for this to work, one must first "register" the C variables with the Tcl interpreter. While this approach is easy to support it is also somewhat problematic. Not all C datatypes are supported, and having Tcl directly manipulate your variables in its native representation could be potentially dangerous.
-<li>Access through function calls. Languages such as Perl and Python can access global variables using a function call mechanism. Rather than allowing direct access, the idea is to provide a pair of set/get functions that set or get the value of a particular variable. In many cases, this mechanism may be completely hidden. For example, it is possible to create a magical Perl variable that looks and feels just like a normal Perl variable, but is really mapped into a C variable via a pair of set/get functions. The advantage of this approach is that it is possible to support almost all C datatypes. The disadvantage is that it introduces alot of complexity to the wrapper code as it is now necessary to write a pair of C functions for every single global variable.
-</ul>
-<p>
-SWIG supports both styles of variable linking although the latter is more common. In some cases, a hybrid approach is taken (for example, the Tcl module will create a pair of set/get functions if it encounters a datatype that Tcl can't support). Fortunately, global variables are relatively rare when working with modular code.<p>
-<a name="n9"></a><h3> Constants</h3>
-Constants can easily be created by simply creating a new variable in the target language with the appropriate value. Unfortunately, this can have the undesirable side-effect of making the constant non-constant. As a result, a somewhat better (although perhaps inefficient) method of creating constants is to install them as read-only variables. SWIG tends to prefer this approach.<p>
-<a name="n10"></a><h3> Structures and classes</h3>
-Most scripting languages have trouble directly dealing with C structures and C++ classes. This is because the use of structures is inherently C dependent and it doesn't always map well into a scripting language environment. Many of these problems are simply due to data representation issues and differences in the way C and a scripting language might represent integers, floats, strings, and so on. Other times, the problem is deeper than that--for example, what does it mean (if anything) to try and use C++ inheritance from Perl?<p>
-<p>
-Dealing with objects is a tough problem that many people are looking at. Packages such as CORBA and ILU are primarily concerned with the representation of objects in a portable manner. This allows objects to be used in distributed systems, used with different languages and so on. SWIG is not concerned with the representation problem, but rather the problem of accessing and using C/C++ objects from a scripting language (in fact SWIG has even been used in conjunction with CORBA-based systems).<p>
-<p>
-To provide access, the simplist approach is to transform a structure into a collection of accessor functions. For example :<p>
-<p>
-<blockquote><pre>struct Vector {
- Vector();
- ~Vector();
- double x,y,z;
-};
-
-</pre></blockquote>
-can be transformed into the following set of functions :<p>
-<p>
-<blockquote><pre>Vector *new_Vector();
-void delete_Vector(Vector *v);
-double Vector_x_get(Vector *v);
-double Vector_y_get(Vector *v);
-double Vector_y_get(Vector *v);
-void Vector_x_set(Vector *v, double x);
-void Vector_y_set(Vector *v, double y);
-void Vector_z_set(Vector *v, double z);
-
-</pre></blockquote>
-When accessed in Tcl, the functions could be used as follows :<p>
-<p>
-<blockquote><pre>% set v [new_Vector]
-% Vector_x_set $v 3.5
-% Vector_y_get $v
-% delete_Vector $v
-% ...
-</pre></blockquote>
-<p>
-The accessor functions provide a mechanism for accessing a real C/C++ object. Since all access occurs though these function calls, Tcl does not need to know anything about the actual representation of a <tt>Vector</tt>. This simplifies matters considerably and steps around many of the problems associated with objects--in fact, it lets the C/C++ compiler do most of the work.<p>
-<a name="n11"></a><h3> Shadow classes</h3>
-As it turns out, it is possible to use the low-level accessor functions above to create something known as a "shadow" class. In a nutshell, a "shadow class" is a funny kind of object that gets created in a scripting language to access a C/C++ class (or struct) in a way that looks like the original structure (that is, it "shadows" the real C++ class). Of course, in reality, it's just a slick way of accessing objects that is more natural to most programmers. For example, if you have the following C definition :<p>
-<blockquote><pre>
-class Vector {
-public:
- Vector();
- ~Vector();
- double x,y,z;
-};
-</pre></blockquote>
-<p>
-A shadow classing mechanism would allow you to access the structure in a natural manner. For example, in Python, you might do the following,<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; v = Vector()
-&gt;&gt;&gt; v.x = 3
-&gt;&gt;&gt; v.y = 4
-&gt;&gt;&gt; v.z = -13
-&gt;&gt;&gt; ...
-&gt;&gt;&gt; del v
-</pre></blockquote>
-<p>
-while in Perl5, it might look like this :<p>
-<blockquote><pre>
-$v = new Vector;
-$v-&gt;{x} = 3;
-$v-&gt;{y} = 4;
-$v-&gt;{z} = -13;
-
-</pre></blockquote>
-and in Tcl :<p>
-<blockquote><pre>
-Vector v
-v configure -x 3 -y 4 -z 13
-
-</pre></blockquote>
-When shadow classes are used, two objects are at really work--one in the scripting language, and an underlying C/C++ object. Operations affect both objects equally and for all practical purposes, it appears as if you are simply manipulating a C/C++ object. However, the introduction of additional "objects" can also produce excessive overhead if working with huge numbers of objects in this manner. Despite this, shadow classes turn out to be extremely useful. The actual implementation is covered later.<p>
-<a name="n3"></a><h2> Building scripting language extensions</h2>
-The final step in using a scripting language with your C/C++ application is adding your extensions to the scripting language itself. Unfortunately, this almost always seems to be the most difficult part. There are two fundamental approaches for doing this. First, you can build an entirely new version of the scripting language interpreter with your extensions built into it. Alternatively, you can build a shared library and dynamically load it into the scripting language as needed. Both approachs are described below :<p>
-<a name="n12"></a><h3> Static linking</h3>
-With static linking you rebuild the scripting language interpreter with extensions. The process usually involves compiling a short main program that adds your customized commands to the language and starts the interpreter. You then link your program with a library to produce a new executable. When using static linking, SWIG will provide a <tt>main()</tt> program for you so you usually just have to compile as follows (shown for Tcl) :<p>
-<p>
-<blockquote><pre>unix &gt; swig -tcl -ltclsh.i example.i
-Generating wrappers for Tcl.
-unix &gt; gcc example.c example_wrap.c -I/usr/local/include \
- -L/usr/local/lib -ltcl -lm -o my_tclsh
-
-</pre></blockquote>
-<tt>my_tclsh</tt> is a new executable containing the Tcl intepreter. <tt>my_tclsh</tt> will be exactly the same as tclsh except with your new commands added to it. When invoking SWIG, the <tt>-ltclsh.i</tt> option includes support code needed to rebuild the <tt>tclsh</tt> application. <p>
-<p>
-Virtually all machines support static linking and in some cases, it may be the only way to build an extension. The downside to static linking is that you can end up with a large executable. In a very large system, the size of the executable may be prohibitively large.<p>
-<a name="n4"></a><h2> Shared libraries and dynamic loading</h2>
-An alternative to static linking is to build a shared library. With this approach, you build a shared object file containing only the code related to your module (on Windows, this is the same as building a DLL). Unfortunately the process of building these modules varies on every single machine, but the procedure for a few common machines is show below :<p>
-<p>
-<blockquote><pre># Build a shared library for Solaris
-gcc -c example.c example_wrap.c -I/usr/local/include
-ld -G example.o example_wrap.o -o example.so
-
-# Build a shared library for Irix
-gcc -c example.c example_wrap.c -I/usr/local/include
-ld -shared example.o example_wrap.o -o example.so
-
-# Build a shared library for Linux
-gcc -fpic -c example.c example_wrap.c -I/usr/local/include
-gcc -shared example.o example_wrap.o -o example.so
-
-</pre></blockquote>
-To use your shared library, you simply use the corresponding command in the scripting language (load, import, use, etc...). This will import your module and allow you to start using it. <p>
-<p>
-When working with C++ codes, the process of building shared libraries is more difficult--primarily due to the fact that C++ modules may need additional code in order to operate correctly. On most machines, you can build a shared C++ module by following the above procedures, but changing the link line to the following :<p>
-<p>
-<blockquote><pre>c++ -shared example.o example_wrap.o -o example.so
-</pre></blockquote>
-<p>
-The advantages to dynamic loading is that you can use modules as they are needed and they can be loaded on the fly. The disadvantage is that dynamic loading is not supported on all machines (although support is improving). The compilation process also tends to be more complicated than what might be used for a typical C/C++ program.<p>
-<a name="n13"></a><h3> Linking with shared libraries</h3>
-When building extensions as shared libraries, it is not uncommon for your extension to rely upon other shared libraries on your machine. In order for the extension to work, it needs to be able to find all of these libraries at run-time. Otherwise, you may get an error such as the following :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; import graph
-Traceback (innermost last):
- File "&lt;stdin&gt;", line 1, in ?
- File "/home/sci/data1/beazley/graph/graph.py", line 2, in ?
- import graphc
-ImportError: 1101:/home/sci/data1/beazley/bin/python: rld: Fatal Error: cannot
-successfully map soname 'libgraph.so' under any of the filenames /usr/lib/libgraph.so:/
-lib/libgraph.so:/lib/cmplrs/cc/libgraph.so:/usr/lib/cmplrs/cc/libgraph.so:
-&gt;&gt;&gt;
-</pre></blockquote>
-<p>
-What this error means is that the extension module created by SWIG depends upon a shared library called "<tt>libgraph.so</tt>" that the system was unable to locate. To fix this problem, there are a few approaches you can take.<p>
-<p>
-<ul>
-<li>Set the UNIX environment variable <tt>LD_LIBRARY_PATH</tt> to the directory where shared libraries are located before running Python.
-<li>Link your extension and explicitly tell the linker where the required libraries are located. Often times, this can be done with a special linker flag such as <tt>-R</tt>, <tt>-rpath</tt>, etc... This is not implemented in a standard manner so read the man pages for your linker to find out more about how to set the search path for shared libraries.
-<li>Put shared libraries in the same directory as the executable. This technique is sometimes required for correct operation on non-Unix platforms.
-</ul>
-<p>
-With a little patience and after some playing around, you can usually get things to work. Afterwards, building extensions becomes alot easier.<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:46:50 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Tcl.html b/swigweb/Doc1.1/HTML/Tcl.html
deleted file mode 100644
index a9c31737a..000000000
--- a/swigweb/Doc1.1/HTML/Tcl.html
+++ /dev/null
@@ -1,2048 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>SWIG and Tcl</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>10 SWIG and Tcl</h1><p><ul>
-<li> <a href="#n1">Preliminaries</a>
-<li> <a href="#n2">Building Tcl/Tk Extensions under Windows 95/NT</a>
-<li> <a href="#n3">Basic Tcl Interface</a>
-<li> <a href="#n4">The object oriented interface</a>
-<li> <a href="#n5">About the examples</a>
-<li> <a href="#n6">Binary trees in Tcl</a>
-<li> <a href="#n7">Building C/C++ data structures with Tk</a>
-<li> <a href="#n8">Accessing arrays</a>
-<li> <a href="#n9">Building a simple OpenGL module</a>
-<li> <a href="#n10">Exception handling</a>
-<li> <a href="#n11">Typemaps</a>
-<li> <a href="#n12">Configuration management with SWIG</a>
-<li> <a href="#n13">Building new kinds of Tcl interfaces (in Tcl)</a>
-<li> <a href="#n14">Extending the Tcl Netscape Plugin</a>
-<li> <a href="#n15">Tcl8.0 features</a>
-</ul>
-
-This chapter discusses SWIG's support of Tcl. SWIG supports Tcl versions 7.3 and newer, including Tcl 8.0. Tk 3.6 and newer can also be used. However, for the best results you should consider using Tcl 7.5/Tk4.1 or later.<p>
-<a name="n1"></a><h2> Preliminaries</h2>
-You will need to install Tcl/Tk on your system if you haven't done so already. If you are using Tcl 7.5 or newer, you should also determine if your system supports dynamic loading and shared libraries. SWIG will work with or without this, but the compilation process varies.<p>
-<a name="n16"></a><h3> Running SWIG</h3>
-To build a Tcl module, run swig using the <tt>-tcl</tt> option as follows :<p>
-<p>
-<blockquote><pre>swig -tcl example.i
-
-</pre></blockquote>
-This will produce 2 files. The first file, <tt>example_wrap.c, </tt>contains all of the C code needed to build your Tcl module. The second file contains supporting documentation and may be named <tt>example_wrap.doc</tt>, <tt>example_wrap.html</tt>, <tt>example_wrap.tex</tt>, etc... To build a Tcl extension you will need to compile the <tt>example_wrap.c</tt> file and link it with the rest of your program (and possibly Tcl itself).<p>
-<a name="n17"></a><h3> Additional SWIG options</h3>
-The following options are also available with the Tcl module :<p>
-<p>
-<blockquote><pre>-tcl8 Produce Tcl8.0 native wrappers (use in place of -tcl).
--module Set the module name.
--namespace Use [incr Tcl] namespaces.
--prefix pkg Set a package prefix of `pkg'. This prefix will be
- attached to each function.
--htcl tcl.h Set name of Tcl header file.
--htk tk.h Set name of Tk header file.
--plugin Generate additional code for the netscape plugin.
--noobject Omit object oriented extensions (compatibility with SWIG 1.0)
-</pre></blockquote>
-<p>
-Many of these options will be described later.<p>
-<a name="n18"></a><h3> Getting the right header files and libraries</h3>
-In order to compile Tcl/Tk extensions, you will need to locate the "<tt>tcl.h</tt>" and "<tt>tk.h</tt>" header files. These are usually located in <tt>/usr/local/include</tt>. You will also need to locate the Tcl/Tk libraries <tt>libtcl.a</tt> and <tt>libtk.a</tt>. These are usually located in <tt>/usr/local/lib</tt>.<p>
-When locating the right header and libraries files, double check to make sure the files are the correct version and form a matching pair. SWIG works with the following Tcl/Tk releases.<p>
-<p>
-<blockquote><pre>Tcl 7.3, Tk 3.6
-Tcl 7.4, Tk 4.0
-Tcl 7.5, Tk 4.1
-Tcl 7.6, Tk 4.2
-Tcl 8.0a2, Tk 8.0a2
-</pre></blockquote>
-<p>
-Do not mix versions. Although the code might compile if you do, it will usually core dump mysteriously. By default, SWIG looks for the header files "<tt>tcl.h</tt>" and "<tt>tk.h</tt>", but your installed version of Tcl/Tk may use slightly different names such as "<tt>tcl7.5.h</tt>" and "<tt>tk4.1.h</tt>". If you need to use different header files, you can use the <tt>-htcl</tt> and <tt>-htk</tt> options as in :<p>
-<p>
-<blockquote><pre>swig -tcl -htcl tcl7.5.h -htk tk4.1.h example.i
-
-</pre></blockquote>
-If you are installing Tcl/Tk yourself, it is often easier to set up a symbolic links between <tt>tcl.h</tt> and the header files for the latest installed version. You might also be able to make symbolic links to the correct files in your working directory.<p>
-<a name="n19"></a><h3> Compiling a dynamic module (Unix)</h3>
-To compile a dynamically loadable module, you will need to compile your SWIG extension into a shared library. This usually looks something like the following (shown for Linux).<p>
-<p>
-<blockquote><pre>unix &gt; swig -tcl example.i
-unix &gt; gcc -fpic example_wrap.c example.c -I/usr/local/include
-unix &gt; gcc -shared example.o example_wrap.o -o example.so # Linux
-
-</pre></blockquote>
-Unfortunately, the process of building of building shared libraries varies on every single machine. SWIG will try to guess when you run configure, but it isn't always successful. It's always a good idea to read the man pages on the compiler/linker to find out more information.<p>
-<a name="n20"></a><h3> Using a dynamic module</h3>
-To use a dynamic module, you will need to load it using the Tcl load command as follows :<p>
-<p>
-<blockquote><pre>load ./example.so example
-
-</pre></blockquote>
-The first argument is the name of the shared library while the second argument is the name of the module (the same as what you specified with the <tt>%module</tt> directive). As alternative, you can turn your module into a Tcl package. See the section on configuration management at the end of this chapter for details.<p>
-<a name="n21"></a><h3> Static linking</h3>
-If your machine does not support dynamic loading or you've tried to use it without success, you can build new versions of <tt>tclsh</tt> (the Tcl shell) or <tt>wish</tt> (Tcl/Tk shell) with your extensions added. To do this, use SWIG's <tt>%include</tt> directive as follows :<p>
-<p>
-<blockquote><pre>%module mymodule
-... declarations ...
-
-%include tclsh.i // Support code for rebuilding tclsh
-</pre></blockquote>
-<p>
-To rebuild tclsh, you will need to compile as follows :<p>
-<p>
-<blockquote><pre>unix &gt; swig -tcl example.i
-unix &gt; gcc example_wrap.c example.c -I/usr/local/include -L/usr/local/lib -ltcl -ldl \
- -lm -o my_tclsh
-
-</pre></blockquote>
-Alternatively, you can use SWIG's <tt>-l</tt> option to add the tclsh.i library file without modifying the interface file. For example :<p>
-<p>
-<blockquote><pre>unix &gt; swig -tcl -ltclsh.i example.i
-unix &gt; gcc example_wrap.c example.c -I/usr/local/include -L/usr/local/lib -ltcl -ldl \
- -lm -o my_tclsh
-
-</pre></blockquote>
-The <tt>-ldl</tt> option will be required if your Tcl/Tk supports dynamic loading. On some machines (most notably Solaris),it will also be necessary to add <tt>-lsocket -lnsl</tt> to the compile line. This will produce a new version of <tt>tclsh</tt> that is identical to the old one, but with your extensions added.<p>
-<p>
-If you are using Tk, you will want to rebuild the <tt>wish</tt> executable instead. This can be done as follows :<p>
-<p>
-<blockquote><pre>%module mymodule
-... declarations ...
-
-%include wish.i // Support code for rebuilding wish
-
-</pre></blockquote>
-The compilation process is similar as before, but now looks like this :<p>
-<p>
-<blockquote><pre>unix &gt; swig -tcl example.i
-unix &gt; gcc example_wrap.c example.c -I/usr/local/include -L/usr/local/lib -ltk -ltcl \
- -lX11 -ldl -lm -o my_wish
-
-</pre></blockquote>
-In this case you will end up with a new version of the <tt>wish</tt> executable with your extensions added. Make sure you include <tt>-ltk</tt>, <tt>-ltcl</tt>, and <tt>-lX11</tt> in the order shown.<p>
-<a name="n22"></a><h3> Compilation problems</h3>
-Tcl is one of the easiest languages to compile extensions for. The Tcl header files should work without problems under C and C++. Perhaps the only tricky task is that of compiling dynamically loadable modules for C++. If your C++ code has static constructors, it is unlikely to work at all. In this case, you will need to build new versions of the <tt>tclsh</tt> or <tt>wish</tt> executables instead. You may also need to link against the <tt>libgcc.a</tt>, <tt>libg++.a</tt>, and l<tt>ibstdc++.a</tt> libraries (assuming g++).<p>
-<a name="n23"></a><h3> Setting a package prefix</h3>
-To avoid namespace problems, you can instruct SWIG to append a package prefix to all of your functions and variables. This is done using the -prefix option as follows :<p>
-<p>
-<blockquote><pre>swig -tcl -prefix Foo example.i
-
-</pre></blockquote>
-If you have a function "<tt>bar</tt>" in the SWIG file, the prefix option will append the prefix to the name when creating a command and call it "<tt>Foo_bar</tt>". <p>
-<a name="n24"></a><h3> Using [incr Tcl] namespaces</h3>
-Alternatively, you can have SWIG install your module into an [incr Tcl] namespace by specifying the <tt>-namespace</tt> option :<p>
-<p>
-<blockquote><pre>swig -tcl -namespace example.i
-
-</pre></blockquote>
-By default, the name of the namespace will be the same as the module name, but you can override it using the <tt>-prefix</tt> option.<p>
-<p>
-When the<tt> -namespace</tt> option is used, the resulting wrapper code can be compiled under both Tcl and [incr Tcl]. When compiling under Tcl, the namespace will turn into a package prefix such as in <tt>Foo_bar</tt>. When running under [incr Tcl], it will be something like <tt>Foo::bar.</tt><p>
-<a name="n2"></a><h2> Building Tcl/Tk Extensions under Windows 95/NT</h2>
-Building a SWIG extension to Tcl/Tk under Windows 95/NT is roughly similar to the process used with Unix. Normally, you will want to produce a DLL that can be loaded into tclsh or wish. This section covers the process of using SWIG with Microsoft Visual C++ 4.x although the procedure may be similar with other compilers.<p>
-<a name="n25"></a><h3> Running SWIG from Developer Studio</h3>
-If you are developing your application within Microsoft developer studio, SWIG can be invoked as a custom build option. The process roughly follows these steps :<p>
-<p>
-<ul>
-<li>Open up a new workspace and use the AppWizard to select a DLL project.
-<li>Add both the SWIG interface file (the .i file), any supporting C files, and the name of the wrapper file that will be created by SWIG (ie. <tt>example_wrap.c</tt>). Note : If using C++, choose a different suffix for the wrapper file such as <tt>example_wrap.cxx</tt>. Don't worry if the wrapper file doesn't exist yet--Developer studio will keep a reference to it around.
-<li>Select the SWIG interface file and go to the settings menu. Under settings, select the "Custom Build" option.
-<li>Enter "SWIG" in the description field.
-<li>Enter "<tt>swig -tcl -o $(ProjDir)\$(InputName)_wrap.c $(InputPath)</tt>" in the "Build command(s) field"
-<li>Enter "<tt>$(ProjDir)\$(InputName)_wrap.c</tt>" in the "Output files(s) field".
-<li>Next, select the settings for the entire project and go to "C++:Preprocessor". Add the include directories for your Tcl installation under "Additional include directories".
-<li>Finally, select the settings for the entire project and go to "Link Options". Add the Tcl library file to your link libraries. For example "<tt>tcl80.lib</tt>". Also, set the name of the output file to match the name of your Tcl module (ie. example.dll).
-<li>Build your project.
-</ul>
-<p>
-Now, assuming all went well, SWIG will be automatically invoked when you build your project. Any changes made to the interface file will result in SWIG being automatically invoked to produce a new version of the wrapper file. To run your new Tcl extension, simply run <tt>tclsh</tt> or <tt>wish</tt> and use the <tt>load</tt> command. For example :<p>
-<p>
-<blockquote><pre>
-
-MSDOS &gt; tclsh80
-% load example.dll
-% fact 4
-24
-%
-</pre></blockquote>
-<a name="n26"></a><h3> Using NMAKE</h3>
-Alternatively, SWIG extensions can be built by writing a Makefile for NMAKE. To do this, make sure the environment variables for MSVC++ are available and the MSVC++ tools are in your path. Now, just write a short Makefile like this :<p>
-<p>
-<blockquote><pre># Makefile for building various SWIG generated extensions
-
-SRCS = example.c
-IFILE = example
-INTERFACE = $(IFILE).i
-WRAPFILE = $(IFILE)_wrap.c
-
-# Location of the Visual C++ tools (32 bit assumed)
-
-TOOLS = c:\msdev
-TARGET = example.dll
-CC = $(TOOLS)\bin\cl.exe
-LINK = $(TOOLS)\bin\link.exe
-INCLUDE32 = -I$(TOOLS)\include
-MACHINE = IX86
-
-# C Library needed to build a DLL
-
-DLLIBC = msvcrt.lib oldnames.lib
-
-# Windows libraries that are apparently needed
-WINLIB = kernel32.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib
-winspool.lib
-
-# Libraries common to all DLLs
-LIBS = $(DLLIBC) $(WINLIB)
-
-# Linker options
-LOPT = -debug:full -debugtype:cv /NODEFAULTLIB /RELEASE /NOLOGO /
-MACHINE:$(MACHINE) -entry:_DllMainCRTStartup@12 -dll
-
-# C compiler flags
-
-CFLAGS = /Z7 /Od /c /nologo
-TCL_INCLUDES = -Id:\tcl8.0a2\generic -Id:\tcl8.0a2\win
-TCLLIB = d:\tcl8.0a2\win\tcl80.lib
-
-tcl::
- ..\..\swig -tcl -o $(WRAPFILE) $(INTERFACE)
- $(CC) $(CFLAGS) $(TCL_INCLUDES) $(SRCS) $(WRAPFILE)
- set LIB=$(TOOLS)\lib
- $(LINK) $(LOPT) -out:example.dll $(LIBS) $(TCLLIB) example.obj example_wrap.obj
-
-</pre></blockquote>
-To build the extension, run NMAKE (you may need to run vcvars32 first). This is a pretty minimal Makefile, but hopefully its enough to get you started. With a little practice, you'll be making lots of Tcl extensions.<p>
-<a name="n3"></a><h2> Basic Tcl Interface</h2>
-<a name="n27"></a><h3> Functions</h3>
-C functions are turned into new Tcl commands with the same usage as the C function. Default/optional arguments are also allowed. An interface file like this :<p>
-<p>
-<blockquote><pre>%module example
-int foo(int a);
-double bar (double, double b = 3.0);
-...
-
-</pre></blockquote>
-Will be used in Tcl like this :<p>
-<p>
-<blockquote><pre>set a [foo 2]
-set b [bar 3.5 -1.5]
-set b [bar 3.5] # Note : default argument is used
-
-</pre></blockquote>
-There isn't much more to say...this is pretty straightforward.<p>
-<a name="n28"></a><h3> Global variables</h3>
-For global variables, things are a little more complicated. For the following C datatypes, SWIG will use Tcl's variable linking mechanism to provide direct access :<p>
-<p>
-<blockquote><pre>int, unsigned int,
-double,
-char *,
-
-</pre></blockquote>
-When used in an interface file and script, it will operate as follows :<p>
-<p>
-<blockquote><pre>// example.i
-%module example
-...
-double My_variable;
-...
-
-# Tcl script
-puts $My_variable # Output value of C global variable
-set My_variable 5.5 # Change the value
-
-</pre></blockquote>
-For all other C datatypes, SWIG will generate a pair of set/get functions. For example :<p>
-<p>
-<blockquote><pre>// example.i
-short My_short;
-</pre></blockquote>
-<p>
-will be accessed in Tcl as follows :<p>
-<p>
-<blockquote><pre>puts [My_short_get] # Get value of global variable
-My_short_set 5.5 # Set value of global variable
-
-</pre></blockquote>
-While not the most elegant solution, this is the only solution for now. Tcl's normal variable linking mechanism operates directly on a variables and would not work correctly on datatypes other than the 3 basic datatypes supported by Tcl (<tt>int</tt>, <tt>double</tt>, and <tt>char *</tt>).<p>
-<a name="n29"></a><h3> Constants</h3>
-Constants are created as read-only variables. For odd datatypes (not supported by the variable linking mechanism), SWIG generates a string representation of the constant and use it instead (you shouldn't notice this however since everything is already a string in Tcl). It is never necessary to use a special "get" function with constants. Unlike Tcl variables, constants can contain pointers, structure addresses, function pointers, etc...<p>
-<a name="n30"></a><h3> Pointers</h3>
-Pointers to C/C++ objects are represented as character strings such as the following :<p>
-<p>
-<blockquote><pre>_100f8e2_Vector_p
-
-</pre></blockquote>
-A NULL pointer is represented by the string "NULL". NULL pointers can also be explicitly created as follows :<p>
-<p>
-<blockquote><pre>_0_Vector_p
-
-</pre></blockquote>
-In Tcl 8.0, pointers are represented using a new type of Tcl object, but the string representation is the same (and is interchangable). As a general, direct manipulation of pointer values is discouraged. <p>
-<a name="n31"></a><h3> Structures </h3>
-SWIG generates a basic low-level interface to C structures. For example :<p>
-<p>
-<blockquote><pre>struct Vector {
- double x,y,z;
-};
-
-</pre></blockquote>
-gets mapped into the following collection of C functions :<p>
-<p>
-<blockquote><pre>double Vector_x_get(Vector *obj)
-double Vector_x_set(Vector *obj, double x)
-double Vector_y_get(Vector *obj)
-double Vector_y_set(Vector *obj, double y)
-double Vector_z_get(Vector *obj)
-double Vector_z_set(Vector *obj, double z)
-
-</pre></blockquote>
-These functions are then used in the resulting Tcl interface. For example :<p>
-<p>
-<blockquote><pre># v is a Vector that got created somehow
-% Vector_x_get $v
-3.5
-% Vector_x_set $v 7.8 # Change x component
-</pre></blockquote>
-<p>
-Similar access is provided for unions and the data members of C++ classes.<p>
-<a name="n32"></a><h3> C++ Classes</h3>
-C++ classes are handled by building a set of low level accessor functions. Consider the following class :<p>
-<p>
-<blockquote><pre>
-class List {
-public:
- List();
- ~List();
- int search(char *item);
- void insert(char *item);
- void remove(char *item);
- char *get(int n);
- int length;
-static void print(List *l);
-};
-</pre></blockquote>
-<p>
-When wrapped by SWIG, the following functions are created :<p>
-<p>
-<blockquote><pre>List *new_List();
-void delete_List(List *l);
-int List_search(List *l, char *item);
-void List_insert(List *l, char *item);
-void List_remove(List *l, char *item);
-char *List_get(List *l, int n);
-int List_length_get(List *l);
-int List_length_set(List *l, int n);
-void List_print(List *l);
-
-</pre></blockquote>
-Within Tcl, we can use the functions as follows :<p>
-<blockquote><pre>
-% set l [new_List]
-% List_insert $l Ale
-% List_insert $l Stout
-% List_insert $l Lager
-% List_print $l
-Lager
-Stout
-Ale
-% puts [List_length_get $l]
-3
-% puts $l
-_1008560_List_p
-%
-
-</pre></blockquote>
-C++ objects are really just pointers (which are represented as strings). Member functions and data are accessed by simply passing a pointer into a collection of accessor functions that take the pointer as the first argument.<p>
-<p>
-While somewhat primitive, the low-level SWIG interface provides direct and flexible access to almost any C++ object. As it turns out, it is possible to do some rather amazing things with this interface as will be shown in some of the later examples. SWIG 1.1 also generates an object oriented interface that can be used in addition to the basic interface just described here.<p>
-<a name="n4"></a><h2> The object oriented interface</h2>
-With SWIG 1.1, a new object oriented interface to C structures and C++ classes is supported. This interface supplements the low-level SWIG interface already defined--in fact, both can be used simultaneously. To illustrate this interface, consider our previous <tt>List</tt> class :<p>
-<p>
-<blockquote><pre>class List {
-public:
- List();
- ~List();
- int search(char *item);
- void insert(char *item);
- void remove(char *item);
- char *get(int n);
- int length;
-static void print(List *l);
-};
-
-</pre></blockquote>
-Using the object oriented interface requires no additional modifications or recompilation of the SWIG module (the functions are just used differently).<p>
-<a name="n33"></a><h3> Creating new objects</h3>
-The name of the class becomes a new command for creating an object. There are 5 methods for creating an object (<tt>MyObject </tt>is the name of the corresponding C++ class) <p>
-<p>
-<blockquote><pre>MyObject o # Creates a new object `o'
-
-MyObject o -this $objptr # Turn a pointer to an existing C++ object into a
- # Tcl object `o'
-
-MyObject -this $objptr # Turn the pointer $objptr into a Tcl "object"
-
-MyObject -args args # Create a new object and pick a name for it. A handle
- # will be returned and is the same as the pointer value.
-
-MyObject # The same as MyObject -args, but for constructors that
- # take no arguments.
-</pre></blockquote>
-<p>
-Thus, for our List class, we can create new List objects as follows :<p>
-<p>
-<blockquote><pre>List l # Create a new list l
-
-set listptr [new_List] # Create a new List using low level interface
-List l2 -this $listptr # Turn it into a List object named `l2'
-
-set l3 [List] # Create a new list. The name of the list is in $l3
-
-List -this $listptr # Turn $listptr into a Tcl object of the same name
-</pre></blockquote>
-<p>
-Now assuming you're not completely confused at this point, the best way to think of this is that there are really two different ways of representing an object. One approach is to simply use the pointer value as the name of an object. For example :<p>
-<p>
-<blockquote><pre>_100e8f8_List_p
-
-</pre></blockquote>
-The second approach is to allow you to pick a name for an object such as "foo". The different types of constructors are really just mechanism for using either approach.<p>
-<a name="n34"></a><h3> Invoking member functions</h3>
-Member functions are invoked using the name of the object followed by the method name and any arguments. For example :<p>
-<p>
-<blockquote><pre>% List l
-% l insert "Bob"
-% l insert "Mary"
-% l search "Dave"
-0
-% ...
-
-</pre></blockquote>
-Or if you let SWIG generate the name of the object... (this is the pointer model)<p>
-<p>
-<blockquote><pre>% set l [List]
-% $l insert "Bob" # Note $l contains the name of the object
-% $l insert "Mary"
-% $l search "Dave"
-0
-%
-</pre></blockquote>
-<a name="n35"></a><h3> Deleting objects</h3>
-Since objects are created by adding new Tcl commands, they can be deleted by simply renaming them. For example :<p>
-<p>
-<blockquote><pre>% rename l "" # Destroy list object `l'
-
-</pre></blockquote>
-SWIG will automatically call the corresponding C/C++ destructor, with one caveat--SWIG will not destroy an object if you created it from an already existing pointer (if you called the constructor using the -this option). Since the pointer already existed when you created the Tcl object, Tcl doesn't own the object so it would probably be a bad idea to destroy it.<p>
-<a name="n36"></a><h3> Accessing member data</h3>
-Member data of an object can be accessed using the <tt>cget</tt> method. The approach is quite similar to that used in [incr Tcl] and other Tcl extensions. For example :<p>
-<p>
-<blockquote><pre>% l cget -length # Get the length of the list
-13
-
-</pre></blockquote>
-The <tt>cget</tt> method currently only allows retrieval of one member at a time. Extracting multiple members will require repeated calls.<p>
-<p>
-The member <tt>-this</tt> contains the pointer to the object that is compatible with other SWIG functions. Thus, the following call would be legal<p>
-<p>
-<blockquote><pre>
-% List l # Create a new list object
-% l insert Mike
-% List_print [l cget -this] # Print it out using low-level function
-</pre></blockquote>
-<a name="n37"></a><h3> Changing member data</h3>
-To change the value of member data, the <tt>configure</tt> method can be used. For example :<p>
-<p>
-<blockquote><pre>% l configure -length 10 # Change length to 10 (probably not a good idea, but
- # possible).
-
-</pre></blockquote>
-In a structure such as the following :<p>
-<blockquote><pre>
-struct Vector {
- double x, y, z;
-};
-
-</pre></blockquote>
-you can change the value of all or some of the members as follows :<p>
-<p>
-<blockquote><pre>% v configure -x 3.5 -y 2 -z -1.0
-</pre></blockquote>
-<p>
-The order of attributes does not matter. <p>
-<a name="n38"></a><h3> Relationship with pointers</h3>
-The object oriented interface is mostly compatible with all of the functions that accept pointer values as arguments. Here are a couple of things to keep in mind :<p>
-<p>
-<ul>
-<li>If you explicitly gave a name to an object, the pointer value can be retrieved using the `<tt>cget -this</tt>' method. The pointer value is what you should give to other SWIG generated functions if necessary.
-<li>If you let SWIG generate the name of an object for you, then the name of the object is the same as the pointer value. This is the preferred approach.
-<li>If you have a pointer value but it's not a Tcl object, you can turn it into one by calling the constructor with the `<tt>-this</tt>' option.
-</ul>
-<p>
-Here is a script that illustrates how these things work :<p>
-<p>
-<blockquote><pre># Example 1 : Using a named object
-
-List l # Create a new list
-l insert Dave # Call some methods
-l insert Jane
-l insert Pat
-List_print [l cget -this] # Call a static method (which requires the pointer value)
-
-# Example 2: Let SWIG pick a name
-
-set l [List] # Create a new list
-$l insert Dave # Call some methods
-$l insert Jane
-$l insert Pat
-List_print $l # Call static method (name of object is same as pointer)
-
-# Example 3: Already existing object
-set l [new_List] # Create a raw object using low-level interface
-List_insert $l Dave # Call some methods (using low-level functions)
-List -this $l # Turn it into a Tcl object instead
-$l insert Jane
-$l insert Part
-List_print $l # Call static method (uses pointer value as before).
-</pre></blockquote>
-<p>
-<a name="n39"></a><h3> Performance concerns and disabling the object oriented interface</h3>
-The object oriented interface is mainly provided for ease of programming at the expense of introducing more overhead and increased code size (C code that is). If you are concerned about these issues use the basic SWIG interface instead. It provides direct access and is much faster. As it turns out, it is possible to build an object oriented interface directly in Tcl as well--an example we'll return to a little later.<p>
-<p>
-To disable the object oriented interface, run SWIG with the <tt>-noobject</tt> option. This will strip out all of the extra code and produce only the low-level interface.<p>
-<a name="n5"></a><h2> About the examples</h2>
-The next few sections cover Tcl examples of varying complexity. These are primarily designed to illustrate how SWIG can be used to integrate C/C++ and Tcl in a variety of ways. Some of the things that will be covered are :<p>
-<p>
-<ul>
-<li>Controlling C programs with Tcl
-<li>Building C data structures in Tcl.
-<li>Use of C objects with Tk
-<li>Wrapping a C library (OpenGL in this case)
-<li>Accessing arrays and other common data structures
-<li>Using Tcl to build new Tcl interfaces to C programs.
-<li>Modifying SWIG's handling of datatypes.
-<li>And a bunch of other cool stuff.
-</ul>
-<a name="n6"></a><h2> Binary trees in Tcl</h2>
-In this example, we show Tcl can be used to manipulate binary trees implemented in C. This will involve accessing C data structures and functions.<p>
-<a name="n40"></a><h3> C files</h3>
-We will build trees using the following C header file :<p>
-<p>
-<blockquote><pre>/* tree.h */
-typedef struct Node Node;
-struct Node {
- char *key;
- char *value;
- Node *left;
- Node *right;
-};
-
-typedef struct Tree {
- Node *head; /* Starting node */
- Node *z; /* Ending node (at leaves) */
-} Tree;
-
-extern Node *new_Node(char *key, char *value);
-extern Tree *new_Tree();
-</pre></blockquote>
-<p>
-The C functions to create new nodes and trees are as follows :<p>
-<p>
-<blockquote><pre>/* File : tree.c */
-#include &lt;string.h&gt;
-#include "tree.h"
-Node *new_Node(char *key, char *value) {
- Node *n;
- n = (Node *) malloc(sizeof(Node));
- n-&gt;key = (char *) malloc(strlen(key)+1);
- n-&gt;value = (char *) malloc(strlen(value)+1);
- strcpy(n-&gt;key,key);
- strcpy(n-&gt;value,value);
- n-&gt;left = 0;
- n-&gt;right = 0;
- return n;
-};
-Tree *new_Tree() {
- Tree *t;
- t = (Tree *) malloc(sizeof(Tree));
- t-&gt;head = new_Node("","__head__");
- t-&gt;z = new_Node("__end__","__end__");
- t-&gt;head-&gt;right = t-&gt;z;
- t-&gt;z-&gt;left = t-&gt;z;
- t-&gt;z-&gt;right = t-&gt;z;
- return t;
-}
-</pre></blockquote>
-<a name="n41"></a><h3> Making a quick a dirty Tcl module</h3>
-To make a quick Tcl module with these functions, we can do the following :<p>
-<p>
-<blockquote><pre>// file : tree.i
-%module tree
-%{
-#include "tree.h"
-%}
-%include tree.h // Just grab header file since it's fairly simple
-
-</pre></blockquote>
-To build the module, run SWIG as follows and compile the resulting output :<p>
-<p>
-<blockquote><pre>% swig -tcl -ltclsh.i tree.i
-% gcc tree.c tree_wrap.c -I/usr/local/include -L/usr/local/lib -ltcl -lm -o my_tclsh
-</pre></blockquote>
-<p>
-We can now try out the module interactively by just running the new `<tt>my_tclsh</tt>' executable.<p>
-<p>
-<blockquote><pre>unix &gt; my_tclsh
-% set t [new_Tree] # Create a new tree
-_8053198_Tree_p
-% set n [Tree_head_get $t] # Get first node
-_80531a8_Node_p
-% puts [Node_value_get $n] # Get its value
-__head__
-% Node -this $n
-% $n cget -value # Altenative method for getting value
-__head__
-</pre></blockquote>
-<a name="n42"></a><h3> Building a C data structure in Tcl</h3>
-Given our simple Tcl interface, it is easy to write Tcl functions for building up a C binary tree. For example :<p>
-<p>
-<blockquote><pre># Insert an item into a tree
-proc insert_tree {tree key value} {
- set tree_head [Tree_head_get $tree]
- set tree_z [Tree_z_get $tree]
- set p $tree_head
- set x [Node_right_get $tree_head]
- while {[Node_key_get $x] != "__end__"} {
- set p $x
- if {$key &lt; [Node_key_get $x]} {
- set x [Node_left_get $x]
- } {
- set x [Node_right_get $x]
- }
- }
- set x [new_Node $key $value]
- if {$key &lt; [Node_key_get $p]} {
- Node_left_set $p $x
- } {
- Node_right_set $p $x
- }
- Node_left_set $x $tree_z
- Node_right_set $x $tree_z
-}
-
-# Search tree and return all matches
-proc search_tree {tree key} {
- set tree_head [Tree_head_get $tree]
- set tree_z [Tree_z_get $tree]
- set found {}
- set x [Node_right_get $tree_head]
- while {[Node_key_get $x] != "__end__"} {
- if {[Node_key_get $x] == $key} {
- lappend found [Node_value_get $x]
- }
- if {$key &lt; [Node_key_get $x]} {
- set x [Node_left_get $x]
- } {
- set x [Node_right_get $x]
- }
- }
- return $found
-}
-
-</pre></blockquote>
-While written in Tcl, these functions are building up a real C binary tree data structure that could be passed into other C function. For example, we could write a function that globs an entire directory and builds a tree structure as follows :<p>
-<p>
-<blockquote><pre># Insert all of the files in pathname into a binary tree
-
-proc build_dir_tree {tree pathname} {
- set error [catch {set filelist [glob -nocomplain $pathname/*]}]
- if {$error == 0} {
- foreach f $filelist {
- if {[file isdirectory $f] == 1} {
- insert_tree $tree [file tail $f] $f
- if {[file type $f] != "link"} {build_dir_tree $tree $f}
- } {
- insert_tree $tree [file tail $f] $f
- }
- }
- }
-}
-
-</pre></blockquote>
-We can test out our function interactively as follows :<p>
-<p>
-<blockquote><pre>% source tree.tcl
-% set t [new_Tree] # Create a new tree
-_80533c8_Tree_p
-% build_dir_tree $t /home/beazley/SWIG/SWIG1.1
-% search_tree $t tcl
-/home/beazley/SWIG/SWIG1.1/Examples/tcl /home/beazley/SWIG/SWIG1.1/swig_lib/tcl
-%
-</pre></blockquote>
-<a name="n43"></a><h3> Implementing methods in C</h3>
-While our Tcl methods may be fine for small problems, it may be faster to reimplement the insert and search methods in C :<p>
-<p>
-<blockquote><pre>void insert_tree(Tree *t, char *key, char *value) {
- Node *p;
- Node *x;
-
- p = t-&gt;head;
- x = t-&gt;head-&gt;right;
- while (x != t-&gt;z) {
- p = x;
- if (strcmp(key,x-&gt;key) &lt; 0)
- x = x-&gt;left;
- else
- x = x-&gt;right;
- }
- x = new_Node(key,value);
- if (strcmp(key,p-&gt;key) &lt; 0)
- p-&gt;left = x;
- else
- p-&gt;right = x;
- x-&gt;left = t-&gt;z;
- x-&gt;right = t-&gt;z;
-}
-
-</pre></blockquote>
-To use this function in Tcl, simply put a declaration into the file <tt>tree.h</tt> or <tt>tree.i</tt>.<p>
-<p>
-When reimplemented in C, the underlying Tcl script may not notice the difference. For example, our directory subroutine would not care if <tt>insert_tree</tt> had been written in Tcl or C. Of course, by writing this function C, we will get significantly better performance. <p>
-<a name="n44"></a><h3> Building an object oriented C interface</h3>
-So far our tree example has been using the basic SWIG interface. With a little work in the interface file, we can improve the interface a little bit.<p>
-<p>
-<blockquote><pre>%module tree
-%{
-#include "tree.h"
-%}
-
-%include tree.h
-%{
-
- /* Function to count up Nodes */
- static int count_nodes(Node *n, Node *end) {
- if (n == end) return 0;
- return 1+count_nodes(n-&gt;left,end)+count_nodes(n-&gt;right,end);
- }
-
-%}
-
-// Attach some new methods to the Tree structure
-
-%addmethods Tree {
- void insert(char *key, char *value) {
- insert_tree(self,key,value);
- }
- char *search(char *key) {
- return search_tree(self,key);
- }
- char *findnext(char *key) {
- return find_next(self,key);
- }
- int count() {
- return count_nodes(self-&gt;head-&gt;right,self-&gt;z);
- }
- Tree(); // This is just another name for new_Tree
-}
-
-</pre></blockquote>
-The <tt>%addmethods</tt> directive can be used to attach methods to existing structures and classes. In this case, we are attaching some methods to the <tt>Tree</tt> structure. Each of the methods are simply various C functions we have written for accessing trees. This type of interface file comes in particularly handy when using the Tcl object oriented interface. For example, we can rewrite our directory globber as follows :<p>
-<p>
-<blockquote><pre>proc build_dir_tree {tree pathname} {
- set error [catch {set filelist [glob -nocomplain $pathname/*]}]
- if {$error == 0} {
- foreach f $filelist {
- if {[file isdirectory $f] == 1} {
- $tree insert [file tail $f] $f # Note new calling method
- if {[file type $f] != "link"} {build_dir_tree $tree $f}
- } {
- $tree insert [file tail $f] $f
- }
- }
- }
-}
-
-</pre></blockquote>
-Now using it :<p>
-<blockquote><pre>% source tree.tcl
-% Tree t # Create a new Tree object
-_8054610_Tree_p
-% build_dir_tree t /home/beazley/SWIG/SWIG1.1
-% t count
-1770
-% t search glaux.i
-/home/beazley/SWIG/SWIG1.1/Examples/OpenGL/glaux.i
-% t search typemaps
-/home/beazley/SWIG/SWIG1.1/Examples/perl5/typemaps
-% t findnext typemaps
-/home/beazley/SWIG/SWIG1.1/Examples/python/typemaps
-% t findnext typemaps
-/home/beazley/SWIG/SWIG1.1/Examples/tcl/typemaps
-% t findnext typemaps
-None
-%
-</pre></blockquote>
-<p>
-With a little extra work, we've managed to turn an ordinary C structure into a class-like object in Tcl. <p>
-<a name="n7"></a><h2> Building C/C++ data structures with Tk</h2>
-Given the direct access to C/C++ objects provided by SWIG, it can be possible to use Tk to interactively build a variety of interesting data structures. To do this, it is usually useful to maintain a mapping between canvas items and an underlying C data structure. This is done using associative arrays to map C pointers to canvas items and canvas items back to pointers.<p>
-<p>
-Suppose that we have a C program for manipulating directed graphs and that we wanted to provide a Tk interface for building graphs using a ball-and-stick model such as the following :<p>
-<p><center><img src="ch10.1.png"></center><p>
-<p>
-<p>
-The SWIG interface file for this might look something like this :<p>
-<p>
-<blockquote><pre>%module graph
-%{
-#include "graph.h"
-%}
-
-/* Get a node's number */
-int GetNum(Node *n); /* Get a node's number */
-AdjList *GetAdj(Node *n); /* Get a node's adjacency list */
-AdjList *GetNext(AdjList *l); /* Get next node in adj. list */
-Node *GetNode(AdjList *l); /* Get node from adj. list */
-Node *new_node(); /* Make a new node */
-void AddLink(Node *v1, Node *v2); /* Add an edge */
-... etc ...
-
-</pre></blockquote>
-The interface file manipulates <tt>Node</tt> and <tt>AdjList</tt> structures. The precise implementation of these doesn't matter here--in fact SWIG doesn't even need it. Within a Tcl/Tk script however, we can keep track of these objects as follows :<p>
-<p>
-<blockquote><pre># Make a new node and put it on the canvas
-proc mkNode {x y} {
- global nodeX nodeY nodeP nodeMap nodeList edgeFirst edgeSecond
- set new [.c create oval [expr $x-15] [expr $y-15] \
- [expr $x+15] [expr $y+15] -outline black \
- -fill white -tags node]
- set newnode [new_node] ;# Make a new C Node
- set nnum [GetNum $newnode] ;# Get our node's number
- set id [.c create text [expr $x-4] [expr $y+10] \
- -text $nnum -anchor sw -tags nodeid]
- set nodeX($new) $x ;# Save coords of canvas item
- set nodeY($new) $y
- set nodeP($new) $newnode ;# Save C pointer
- set nodeMap($newnode) $new ;# Map pointer to Tk widget
- set edgeFirst($new) {}
- set edgeSecond($new) {}
- lappend nodeList $new ;# Keep a list of all C
- ;# Pointers we've made
-}
-
-# Make a new edge between two nodes and put an arrow on the canvas
-proc mkEdge {first second new} {
- global nodeP edgeFirst edgeSecond
- set edge [mkArrow $first $second] ;# Make an arrow
- lappend edgeFirst($first) $edge ;# Save information
- lappend edgeSecond($second) $edge
- if {$new == 1} {
-# Now add an edge within our C data structure
- AddLink $nodeP($first) $nodeP($second) ;# Add link to C structure
- }
-}
-</pre></blockquote>
-<p>
-In these functions, the array <tt>nodeP()</tt> allows us to associate a particular canvas item with a C object. When manipulating the graph, this makes it easy to move from the Tcl world to C. A second array, <tt>nodeMap()</tt> allows us to go the other way--mapping C pointers to canvas items. A list <tt>nodeList</tt> keeps track of all of the nodes we've created just in case we want to examine all of the nodes. For example, suppose a C function added more edges to the graph. To reflect the new state of the graph, we would want to add more edges to the Tk canvas. This might be accomplished as follows :<p>
-<p>
-<blockquote><pre># Look at the C data structure and update the canvas
-proc mkEdges {} {
- global nodeX nodeY nodeP nodeMap nodeList edgeFirst edgeSecond
- unset edgeFirst
- unset edgeSecond
- .c delete arc # Edges have been tagged with arc (not shown)
-
- foreach node $nodeList { ;# clear old lists
- set edgeFirst($node) {}
- set edgeSecond($node) {}
- }
- foreach node $nodeList { ;# Go through all of the nodes
- set v $nodeP($node) ;# Get the node pointer
- set v1 [GetAdj $v] ;# Get its adjacency list
- while {$v1 != "NULL"} {
- set v2 [GetNode $v1] ;# Get node pointer
- set w $nodeMap($v2) ;# Get canvas item
- mkEdge $node $w 0 ;# Make an edge between them
- set v1 [GetNext $v1] ;# Get next node
- }
- }
-}
-
-</pre></blockquote>
-<p>
-This function merely scans through all of the nodes and walks down the adjacency list of each one. The <tt>nodeMap()</tt> array maps C pointers onto the corresponding canvas items. We use this to construct edges on the canvas using the <tt>mkEdge</tt> function.<p>
-<a name="n8"></a><h2> Accessing arrays</h2>
-In some cases, C functions may involve arrays and other objects. In these instances, you may have to write helper functions to provide access. For example, suppose you have a C function like this :<p>
-<p>
-<blockquote><pre>// Add vector a+b -&gt; c
-void vector_add(double *a, double *b, double *c, int size);
-
-</pre></blockquote>
-SWIG is quite literal in its interpretation of <tt>double *</tt>--it is a pointer to a <tt>double</tt>. To provide access, a few helper functions can be written such as the following :<p>
-<p>
-<blockquote><pre>// SWIG helper functions for double arrays
-%inline %{
-double *new_double(int size) {
- return (double *) malloc(size*sizeof(double));
-}
-void delete_double(double *a) {
- free a;
-}
-double get_double(double *a, int index) {
- return a[index];
-}
-void set_double(double *a, int index, double val) {
- a[index] = val;
-}
-%}
-</pre></blockquote>
-<p>
-Using our C functions might work like this :<p>
-<p>
-<blockquote><pre># Tcl code to create some arrays and add them
-
-set a [new_double 200]
-set b [new_double 200]
-set c [new_double 200]
-
-# Fill a and b with some values
-for {set i 0} {$i &lt; 200} {incr i 1} {
- set_double $a $i 0.0
- set_double $b $i $i
-}
-
-# Add them and store result in c
-vector_add $a $b $c 200
-
-</pre></blockquote>
-The functions <tt>get_double</tt> and <tt>set_double</tt> can be used to access individual elements of an array. To convert from Tcl lists to C arrays, one could write a few functions in Tcl such as the following :<p>
-<p>
-<blockquote><pre># Tcl Procedure to turn a list into a C array
-proc Tcl2Array {l} {
- set len [llength $l]
- set a [new_double $len]
- set i 0
- foreach item $l {
- set_double $a $i $item
- incr i 1
- }
- return $a
-}
-
-# Tcl Procedure to turn a C array into a Tcl List
-proc Array2Tcl {a size} {
- set l {}
- for {set i 0} {$i &lt; size} {incr i 1} {
- lappend $l [get_double $a $i]
- }
- return $l
-}
-
-</pre></blockquote>
-While not optimal, one could use these to turn a Tcl list into a C representation. The C representation could be used repeatedly in a variety of C functions without having to repeatedly convert from strings (Of course, if the Tcl list changed one would want to update the C version). Likewise, it is relatively simple to go back from C into Tcl. This is not the only way to manage arrays--typemaps can be used as well. The SWIG library file `<tt>array.i</tt>' also contains a variety of pre-written helper functions for managing different kinds of arrays.<p>
-<a name="n9"></a><h2> Building a simple OpenGL module</h2>
-In this example, we consider building a SWIG module out of the OpenGL graphics library. The OpenGL library consists of several hundred functions for building complex 3D images. By wrapping this library, we will be able to play with it interactively from a Tcl interpreter.<p>
-<a name="n45"></a><h3> Required files</h3>
-To build an OpenGL module, you will need to have some variant of OpenGL installed on your machine. If unavailable, the Mesa graphics library is an OpenGL clone that runs on most machines that support X11. We will use the "GL/gl.h", "GL/glu.h", and the GL Auxilliary libraries.<p>
-<a name="n46"></a><h3> Wrapping gl.h</h3>
-The first step is to build an interface from the gl.h file. To do this, follow these steps :<p>
-<p>
-<ul>
-<li>Copy the file <tt>gl.h</tt> to a file <tt>gl.i</tt> which will become the interface.
-<li>Edit the <tt>gl.i</tt> file by taking out unneeded C preprocessor directives and any other clutter that you find.
-<li>Put the following code at the beginning of the<tt> gl.i</tt> file
-<blockquote><pre>
-// gl.i : SWIG file for OpenGL
-%module gl
-%{
-#include &lt;GL/gl.h&gt;
-%}
-
-... Rest of edited gl.h file here ...
-
-</pre></blockquote>
-</ul>
-<p>
-A critical part of this first step is making sure you have the proper set of typedefs in the <tt>gl.i</tt> file. The first part of the file should include definitions such as the following :<p>
-<blockquote><pre>
-typedef unsigned int GLenum;
-typedef unsigned char GLboolean;
-typedef unsigned int GLbitfield;
-typedef signed char GLbyte;
-typedef short GLshort;
-typedef int GLint;
-typedef int GLsizei;
-typedef unsigned char GLubyte;
-typedef unsigned short GLushort;
-typedef unsigned int GLuint;
-typedef float GLfloat;
-typedef float GLclampf;
-typedef double GLdouble;
-typedef double GLclampd;
-typedef void GLvoid;
-</pre></blockquote>
-<a name="n47"></a><h3> Wrapping glu.h</h3>
-Next we write a module for the glu library. The procedure is essentially identical to <tt>gl.h</tt>--that is, we'll copy the header file and edit it slightly. In this case, <tt>glu.h</tt> contains a few functions involving function pointers and arrays. These may generate errors or warnings. As a result, we can simply edit those declarations out. Fortunately, there aren't many declarations like this. If access is required later, the problem can often be fixed with typemaps and helper functions. The final <tt>glu.i</tt> file will look something like this :<p>
-<p>
-<blockquote><pre>%module glu
-%{
-#include &lt;GL/glu.h&gt;
-%}
-
-... rest of edited glu.h file here ...
-
-</pre></blockquote>
-Given these two files, we have a fairly complete OpenGL package. Unfortunately, we still don't have any mechanism for opening a GL window and creating images. To to this, we can wrap the OpenGL auxilliary library which contains functions to open windows and draw various kinds of objects (while not the most powerful approach, it is the simplest to implement and works on most machines).<p>
-<a name="n48"></a><h3> Wrapping the aux library</h3>
-Wrapping the aux library follows exactly the same procedure as before. You will create a file <tt>glaux.i</tt> such as the following :<p>
-<p>
-<blockquote><pre>// File :glaux.i
-%module glaux
-%{
-#include "glaux.h"
-%}
-
-... Rest of edited glaux.h file ...
-
-</pre></blockquote>
-<a name="n49"></a><h3> A few helper functions</h3>
-Finally, to make our library a little easier to use, we need to have a few functions to handle arrays since quite a few OpenGL calls use them as arguments. Small 4 element arrays are particularly useful so we'll create a few helper functions in a file called <tt>help.i.</tt><p>
-<p>
-<blockquote><pre>// help.i : OpenGL helper functions
-
-%inline %{
-GLfloat *newfv4(GLfloat a,GLfloat b,GLfloat c,GLfloat d) {
- GLfloat *f;
- f = (GLfloat *) malloc(4*sizeof(GLfloat));
- f[0] = a; f[1] = b; f[2] = c; f[3] = d;
- return f;
-}
-void setfv4(GLfloat *fv, GLfloat a, GLfloat b, GLfloat c, GLfloat d) {
- fv[0] = a; fv[1] = b; fv[2] = c; fv[3] = d;
-}
-%}
-%name(delfv4) void free(void *);
-</pre></blockquote>
-<a name="n50"></a><h3> An OpenGL package</h3>
-Whew, we're almost done now. The last thing to do is to package up all of our interface files into a single file called <tt>opengl.i</tt>. <p>
-<p>
-<blockquote><pre>
-//
-// opengl.i. SWIG Interface file for OpenGL
-%module opengl
-
-%include gl.i // The main GL functions
-%include glu.i // The GLU library
-%include glaux.i // The aux library
-%include help.i // Our helper functions
-
-</pre></blockquote>
-To build the module, we can simply run SWIG as follows :<p>
-<blockquote><pre>
-unix &gt; swig -tcl opengl.i # Build a dynamicly loaded extension
-
-</pre></blockquote>
-or<p>
-<p>
-<blockquote><pre>unix &gt; swig -tcl -lwish.i opengl.i # Build a statically linked wish executable
-
-</pre></blockquote>
-Compile the file <tt>opengl_wrap.c</tt> with your C compiler and link with Tcl, Tk, and OpenGL to create the final module.<p>
-<a name="n51"></a><h3> Using the OpenGL module</h3>
-The module is now used by writing a Tcl script such as the following :<p>
-<p>
-<blockquote><pre>load ./opengl.so
-auxInitDisplayMode [expr {$AUX_SINGLE | $AUX_RGBA | $AUX_DEPTH}]
-auxInitPosition 0 0 500 500
-auxInitWindow "Lit-Sphere"
-
-# set up material properties
-set mat_specular [newfv4 1.0 1.0 1.0 1.0]
-set mat_shininess [newfv4 50.0 0 0 0]
-set light_position [newfv4 1.0 1.0 1.0 0.0]
-
-glMaterialfv $GL_FRONT $GL_SPECULAR $mat_specular
-glMaterialfv $GL_FRONT $GL_SHININESS $mat_shininess
-glLightfv $GL_LIGHT0 $GL_POSITION $light_position
-glEnable $GL_LIGHTING
-glEnable $GL_LIGHT0
-glDepthFunc $GL_LEQUAL
-glEnable $GL_DEPTH_TEST
-
-# Set up view
-glClearColor 0 0 0 0
-glColor3f 1.0 1.0 1.0
-glMatrixMode $GL_PROJECTION
-glLoadIdentity
-glOrtho -1 1 -1 1 -1 1
-glMatrixMode $GL_MODELVIEW
-glLoadIdentity
-
-# Draw it
-glClear $GL_COLOR_BUFFER_BIT
-glClear $GL_DEPTH_BUFFER_BIT
-auxSolidSphere 0.5
-
-# Clean up
-delfv4 $mat_specular
-delfv4 $mat_shininess
-delfv4 $light_position
-</pre></blockquote>
-<p>
-In our interpreted interface, it is possible to interactively change parameters and see the effects of various OpenGL functions. This a great way to figure out what various functions do and to try different things without having to recompile and run after each change.<p>
-<a name="n52"></a><h3> Problems with the OpenGL interface</h3>
-While the OpenGL interface we have generated is fully usable, it is not without problems.<p>
-<p>
-<ul>
-<li>OpenGL constants are installed as global variables. As a result, it is necessary to use the global keyword when writing Tcl subroutines. For example :
-<blockquote><pre>
-proc clear_screan { } {
- global GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT
- glClear $GL_COLOR_BUFFER_BIT
- glClear $GL_DEPTH_BUFFER_BIT
-}
-
-</pre></blockquote>
-<li>Arrays need to be accessed via helper functions such as our <tt>newfv4</tt>() function. This approach certainly works and its easy enough to implement, but it may be preferable to call certain OpenGL functions with a Tcl list instead. For example :
-<blockquote><pre>
-glMaterialfv $GL_FRONT $GL_SPECULAR {1.0 1.0 1.0 1.0}
-</pre></blockquote>
-</ul>
-<p>
-While these are only minor annoyances, it turns out that you can address both problems using SWIG typemaps (which are discussed shortly).<p>
-<a name="n10"></a><h2> Exception handling </h2>
-The <tt>%except</tt> directive can be used to create a user-definable exception handler in charge of converting exceptions in your C/C++ program into Tcl exceptions. The chapter on exception handling contains more details, but suppose you extended the array example into a C++ class like the following :<p>
-<blockquote><pre>
-class RangeError {}; // Used for an exception
-
-class DoubleArray {
- private:
- int n;
- double *ptr;
- public:
- // Create a new array of fixed size
- DoubleArray(int size) {
- ptr = new double[size];
- n = size;
- }
- // Destroy an array
- ~DoubleArray() {
- delete ptr;
- }
- // Return the length of the array
- int length() {
- return n;
- }
-
- // Get an item from the array and perform bounds checking.
- double getitem(int i) {
- if ((i &gt;= 0) &amp;&amp; (i &lt; n))
- return ptr[i];
- else
- throw RangeError();
- }
-
- // Set an item in the array and perform bounds checking.
- void setitem(int i, double val) {
- if ((i &gt;= 0) &amp;&amp; (i &lt; n))
- ptr[i] = val;
- else {
- throw RangeError();
- }
- }
- };
-</pre></blockquote>
-<p>
-The functions associated with this class can throw a C++ range exception for an out-of-bounds array access. We can catch this in our Tcl extension by specifying the following in an interface file :<p>
-<p>
-<blockquote><pre>%except(tcl) {
- try {
- $function // Gets substituted by actual function call
- }
- catch (RangeError) {
- interp-&gt;result = "Array index out-of-bounds";
- return TCL_ERROR;
- }
-}
-
-</pre></blockquote>
-or in Tcl 8.0<p>
-<p>
-<blockquote><pre>%except(tcl8) {
- try {
- $function // Gets substituted by actual function call
- }
- catch (RangeError) {
- Tcl_SetStringObj(tcl_result,"Array index out-of-bounds");
- return TCL_ERROR;
- }
-}
-
-</pre></blockquote>
-When the C++ class throws a <tt>RangeError</tt> exception, our wrapper functions will catch it, turn it into a Tcl exception, and allow a graceful death as opposed to just having some sort of mysterious program crash. We are not limited to C++ exception handling. Please see the chapter on exception handling for more details on other possibilities, including a method for language-independent exception handling..<p>
-<a name="n11"></a><h2> Typemaps</h2>
-This section describes how SWIG's treatment of various C/C++ datatypes can be remapped using the <tt>%typemap</tt> directive. While not required, this section assumes some familiarity with Tcl's C API. The reader is advised to consult a Tcl book. A glance at the chapter on SWIG typemaps will also be useful. <p>
-<a name="n53"></a><h3> What is a typemap?</h3>
-A typemap is mechanism by which SWIG's processing of a particular C datatype can be changed. A simple typemap might look like this :<p>
-<p>
-<blockquote><pre>%module example
-
-%typemap(tcl,in) int {
- $target = (int) atoi($source);
- printf("Received an integer : %d\n",$target);
-}
-...
-extern int fact(int n);
-</pre></blockquote>
-<p>
-Typemaps require a language name, method name, datatype, and conversion code. For Tcl, "tcl" should be used as the language name. For Tcl 8.0, "tcl8" should be used if you are using the native object interface. The "in" method in this example refers to an input argument of a function. The datatype `int' tells SWIG that we are remapping integers. The supplied code is used to convert from a Tcl string to the corresponding C datatype. Within the supporting C code, the variable <tt>$source</tt> contains the source data (a string in this case) and <tt>$target</tt> contains the destination of a conversion (a C local variable). <p>
-<p>
-When the example is compiled into a Tcl module, it will operate as follows :<p>
-<p>
-<blockquote><pre>% fact 6
-Received an integer : 6
-720
-%
-</pre></blockquote>
-<p>
-A full discussion of typemaps can be found in the main SWIG users reference. We will primarily be concerned with Tcl typemaps here.<p>
-<a name="n54"></a><h3> Tcl typemaps</h3>
-The following typemap methods are available to Tcl modules :<p>
-<p>
-<tt>%typemap(tcl,in)</tt> Converts a string to input function arguments<p>
-<tt>%typemap(tcl,out)</tt> Converts return value of a C function to a string<p>
-<tt>%typemap(tcl,freearg)</tt> Cleans up a function argument (if necessary)<p>
-<tt>%typemap(tcl,argout)</tt> Output argument processing<p>
-<tt>%typemap(tcl,ret)</tt> Cleanup of function return values<p>
-<tt>%typemap(tcl,const)</tt> Creation of Tcl constants<p>
-<tt>%typemap(memberin)</tt> Setting of C++ member data<p>
-<tt>%typemap(memberout)</tt> Return of C++ member data<p>
-<tt>%typemap(tcl, check)</tt> Check value of function arguments.<p>
-<a name="n55"></a><h3> Typemap variables</h3>
-The following variables may be used within the C code used in a typemap:<p>
-<p>
-<tt>$source</tt> Source value of a conversion<p>
-<tt>$target</tt> Target of conversion (where the result should be stored)<p>
-<tt>$type</tt> C datatype being remapped<p>
-<tt>$mangle</tt> Mangled version of data (used for pointer type-checking)<p>
-<tt>$value</tt> Value of a constant (const typemap only)<p>
-<tt>$arg</tt> Original function argument (usually a string)<p>
-<a name="n56"></a><h3> Name based type conversion</h3>
-Typemaps are based both on the datatype and an optional name attached to a datatype. For example :<p>
-<p>
-<blockquote><pre>%module foo
-
-// This typemap will be applied to all char ** function arguments
-%typemap(tcl,in) char ** { ... }
-
-// This typemap is applied only to char ** arguments named `argv'
-%typemap(tcl,in) char **argv { ... }
-
-</pre></blockquote>
-In this example, two typemaps are applied to the <tt>char **</tt> datatype. However, the second typemap will only be applied to arguments named `<tt>argv</tt>'. A named typemap will always override an unnamed typemap.<p>
-<p>
-Due to the name-based nature of typemaps, it is important to note that typemaps are independent of typedef declarations. For example :<p>
-<p>
-<blockquote><pre>%typemap(tcl, in) double {
- ... get a double ...
-}
-void foo(double); // Uses the above typemap
-typedef double Real;
-void bar(Real); // Does not use the above typemap (double != Real)
-
-</pre></blockquote>
-To get around this problem, the <tt>%apply</tt> directive can be used as follows :<p>
-<blockquote><pre>
-%typemap(tcl,in) double {
- ... get a double ...
-}
-void foo(double);
-
-typedef double Real; // Uses typemap
-%apply double { Real }; // Applies all "double" typemaps to Real.
-void bar(Real); // Now uses the same typemap.
-</pre></blockquote>
-<a name="n57"></a><h3> Converting a Tcl list to a char ** </h3>
-A common problem in many C programs is the processing of command line arguments, which are usually passed in an array of NULL terminated strings. The following SWIG interface file allows a Tcl list to be used as a <tt>char **</tt> object.<p>
-<p>
-<blockquote><pre>%module argv
-
-// This tells SWIG to treat char ** as a special case
-%typemap(tcl,in) char ** {
- int tempc;
- if (Tcl_SplitList(interp,$source,&amp;tempc,&amp;$target) == TCL_ERROR)
- return TCL_ERROR;
-}
-
-// This gives SWIG some cleanup code that will get called after the function call
-%typemap(tcl,freearg) char ** {
- free((char *) $source);
-}
-
-// Return a char ** as a Tcl list
-%typemap(tcl,out) char ** {
- int i = 0;
- while ($source[i]) {
- Tcl_AppendElement(interp,$source[i]);
- i++;
- }
-}
-
-// Now a few test functions
-%inline %{
-int print_args(char **argv) {
- int i = 0;
- while (argv[i]) {
- printf("argv[%d] = %s\n", i,argv[i]);
- i++;
- }
- return i;
-}
-
-
-// Returns a char ** list
-char **get_args() {
- static char *values[] = { "Dave", "Mike", "Susan", "John", "Michelle", 0};
- return &amp;values[0];
-}
-
-// A global variable
-char *args[] = { "123", "54", "-2", "0", "NULL", 0 };
-
-%}
-%include tclsh.i
-
-</pre></blockquote>
-When compiled, we can use our functions as follows :<p>
-<p>
-<blockquote><pre>% print_args {John Guido Larry}
-argv[0] = John
-argv[1] = Guido
-argv[2] = Larry
-3
-% puts [get_args]
-Dave Mike Susan John Michelle
-% puts [args_get]
-123 54 -2 0 NULL
-%
-</pre></blockquote>
-<p>
-Perhaps the only tricky part of this example is the implicit memory allocation that is performed by the <tt>Tcl_SplitList</tt> function. To prevent a memory leak, we can use the SWIG "freearg" typemap to clean up the argument value after the function call is made. In this case, we simply free up the memory that <tt>Tcl_SplitList</tt> allocated for us.<p>
-<a name="n58"></a><h3> Remapping constants</h3>
-By default, SWIG installs C constants as Tcl read-only variables. Unfortunately, this has the undesirable side effect that constants need to be declared as "global" when used in subroutines. For example :<p>
-<p>
-<blockquote><pre>proc clearscreen { } {
- global GL_COLOR_BUFFER_BIT
- glClear $GL_COLOR_BUFFER_BIT
-}
-
-</pre></blockquote>
-If you have hundreds of functions however, this quickly gets annoying. Here's a fix using hash tables and SWIG typemaps :<p>
-<p>
-<blockquote><pre>// Declare some Tcl hash table variables
-%{
-static Tcl_HashTable constTable; /* Hash table */
-static int *swigconst; /* Temporary variable */
-static Tcl_HashEntry *entryPtr; /* Hash entry */
-static int dummy; /* dummy value */
-%}
-
-// Initialize the hash table (This goes in the initialization function)
-
-%init %{
- Tcl_InitHashTable(&amp;constTable,TCL_STRING_KEYS);
-%}
-
-// A Typemap for creating constant values
-// $source = the value of the constant
-// $target = the name of the constant
-
-%typemap(tcl,const) int, unsigned int, long, unsigned long {
- entryPtr = Tcl_CreateHashEntry(&amp;constTable,"$target",&amp;dummy);
- swigconst = (int *) malloc(sizeof(int));
- *swigconst = $source;
- Tcl_SetHashValue(entryPtr, swigconst);
- /* Make it so constants can also be used as variables */
- Tcl_LinkVar(interp,"$target", (char *) swigconst, TCL_LINK_INT | TCL_LINK_READ_ONLY);
-};
-
-// Now change integer handling to look for names in addition to values
-%typemap(tcl,in) int, unsigned int, long, unsigned long {
- Tcl_HashEntry *entryPtr;
- entryPtr = Tcl_FindHashEntry(&amp;constTable,$source);
- if (entryPtr) {
- $target = ($type) (*((int *) Tcl_GetHashValue(entryPtr)));
- } else {
- $target = ($type) atoi($source);
- }
-}
-
-</pre></blockquote>
-In our Tcl code, we can now access constants by name without using the "global" keyword as follows :<p>
-<p>
-<blockquote><pre>proc clearscreen { } {
- glClear GL_COLOR_BUFFER_BIT
-}
-
-</pre></blockquote>
-<a name="n59"></a><h3> Returning values in arguments</h3>
-The "argout" typemap can be used to return a value originating from a function argument. For example :<p>
-<p>
-<blockquote><pre>// A typemap defining how to return an argument by appending it to the result
-%typemap(tcl,argout) double *outvalue {
- char dtemp[TCL_DOUBLE_SPACE];
- Tcl_PrintDouble(interp,*($source),dtemp);
- Tcl_AppendElement(interp, dtemp);
-}
-
-// A typemap telling SWIG to ignore an argument for input
-// However, we still need to pass a pointer to the C function
-%typemap(tcl,ignore) double *outvalue {
- static double temp; /* A temporary holding place */
- $target = &amp;temp;
-}
-
-// Now a function returning two values
-int mypow(double a, double b, double *outvalue) {
- if ((a &lt; 0) || (b &lt; 0)) return -1;
- *outvalue = pow(a,b);
- return 0;
-};
-
-</pre></blockquote>
-When wrapped, SWIG matches the <tt>argout</tt> typemap to the "<tt>double *outvalue</tt>" argument. The "ignore" typemap tells SWIG to simply ignore this argument when generating wrapper code. As a result, a Tcl function using these typemaps will work like this :<p>
-<p>
-<blockquote><pre>% mypow 2 3 # Returns two values, a status value and the result
-0 8
-%
-</pre></blockquote>
-<p>
-An alternative approach to this is to return values in a Tcl variable as follows :<p>
-<p>
-<blockquote><pre>%typemap(tcl,argout) double *outvalue {
- char temp[TCL_DOUBLE_SPACE];
- Tcl_PrintDouble(interp,*($source),dtemp);
- Tcl_SetVar(interp,$arg,temp,0);
-}
-%typemap(tcl,in) double *outvalue {
- static double temp;
- $target = &amp;temp;
-}
-
-</pre></blockquote>
-Our Tcl script can now do the following :<p>
-<p>
-<blockquote><pre>% set status [mypow 2 3 a]
-% puts $status
-0
-% puts $a
-8.0
-%
-</pre></blockquote>
-Here, we have passed the name of a Tcl variable to our C wrapper function which then places the return value in that variable. This is now very close to the way in which a C function calling this function would work.<p>
-<a name="n60"></a><h3> Mapping C structures into Tcl Lists</h3>
-Suppose you have a C structure like this :<p>
-<p>
-<blockquote><pre>typedef struct {
- char login[16]; /* Login ID */
- int uid; /* User ID */
- int gid; /* Group ID */
- char name[32]; /* User name */
- char home[256]; /* Home directory */
-} User;
-
-</pre></blockquote>
-By default, SWIG will simply treat all occurrences of "<tt>User</tt>" as a pointer. Thus, functions like this :<p>
-<p>
-<blockquote><pre>extern void add_user(User u);
-extern User *lookup_user(char *name);
-
-</pre></blockquote>
-will work, but they will be weird. In fact, they may not work at all unless you write helper functions to create users and extract data. A typemap can be used to fix this problem however. For example :<p>
-<p>
-<blockquote><pre>// This works for both "User" and "User *"
-%typemap(tcl,in) User * {
- int tempc;
- char **tempa;
- static User temp;
- if (Tcl_SplitList(interp,$source,&amp;tempc,&amp;tempa) == TCL_ERROR) return TCL_ERROR;
- if (tempc != 5) {
- free((char *) tempa);
- interp-&gt;result = "Not a valid User record";
- return TCL_ERROR;
- }
- /* Split out the different fields */
- strncpy(temp.login,tempa[0],16);
- temp.uid = atoi(tempa[1]);
- temp.gid = atoi(tempa[2]);
- strncpy(temp.name,tempa[3],32);
- strncpy(temp.home,tempa[4],256);
- $target = &amp;temp;
- free((char *) tempa);
-}
-
-// Describe how we want to return a user record
-%typemap(tcl,out) User * {
- char temp[20];
- if ($source) {
- Tcl_AppendElement(interp,$source-&gt;login);
- sprintf(temp,"%d",$source-&gt;uid);
- Tcl_AppendElement(interp,temp);
- sprintf(temp,"%d",$source-&gt;gid);
- Tcl_AppendElement(interp,temp);
- Tcl_AppendElement(interp,$source-&gt;name);
- Tcl_AppendElement(interp,$source-&gt;home);
- }
-}
-</pre></blockquote>
-<p>
-These function marshall Tcl lists to and from our <tt>User</tt> data structure. This allows a more natural implementation that we can use as follows :<p>
-<p>
-<blockquote><pre>% add_user {beazley 500 500 "Dave Beazley" "/home/beazley"}
-% lookup_user beazley
-beazley 500 500 {Dave Beazley} /home/beazley
-
-</pre></blockquote>
-This is a much cleaner interface (although at the cost of some performance). The only caution I offer is that the pointer view of the world is pervasive throughout SWIG. Remapping complex datatypes like this will usually work, but every now and then you might find that it breaks. For example, if we needed to manipulate arrays of Users (also mapped as a "<tt>User *</tt>"), the typemaps defined here would break down and something else would be needed. Changing the representation in this manner may also break the object-oriented interface. <p>
-<a name="n61"></a><h3> Useful functions</h3>
-The following tables provide some functions that may be useful in writing Tcl typemaps. Both Tcl 7.x and Tcl 8.x are covered. For Tcl 7.x, everything is a string so the interface is relatively simple. For Tcl 8, everything is now a Tcl object so a more precise set of functions is required. Given the alpha-release status of Tcl 8, the functions described here may change in future releases.<p>
-<center>
-<img src="ch10.table.1.png"><br>
-<img src="ch10.table.2.png"><br>
-<img src="ch10.table.3.png"><br>
-<img src="ch10.table.4.png"><br>
-<img src="ch10.table.5.png"><br>
-<img src="ch10.table.6.png"><br>
-<img src="ch10.table.7.png">
-</center><p>
-<p>
-<a name="n62"></a><h3> Standard typemaps</h3>
-The following typemaps show how to convert a few common kinds of objects between Tcl and C (and to give a better idea of how typemaps work)<p>
-<center>
-<img src="ch10.table.8.png"><br>
-<img src="ch10.table.9.png"><br>
-<img src="ch10.table.10.png"><br>
-<img src="ch10.table.11.png">
-</center><p>
-<p>
-<a name="n63"></a><h3> Pointer handling</h3>
-SWIG pointers are mapped into Python strings containing the hexadecimal value and type. The following functions can be used to create and read pointer values.<p>
-<center><img src="ch10.table.12.png"></center><p>
-<p>
-These functions can be used in typemaps as well. For example, the following typemap makes an argument of "<tt>char *buffer</tt>" accept a pointer instead of a NULL-terminated ASCII string.<p>
-<p>
-<blockquote><pre>%typemap(tcl,in) char *buffer {
- if (SWIG_GetPtr($source, (void **) &amp;$target, "$mangle")) {
- Tcl_SetResult(interp,"Type error. Not a pointer", TCL_STATIC);
- return TCL_ERROR;
- }
-}
-
-</pre></blockquote>
-Note that the <tt>$mangle</tt> variable generates the type string associated with the datatype used in the typemap.<p>
-<p>
-By now you hopefully have the idea that typemaps are a powerful mechanism for building more specialized applications. While writing typemaps can be technical, many have already been written for you. See the SWIG library reference for more information.<p>
-<a name="n12"></a><h2> Configuration management with SWIG</h2>
-After you start to work with Tcl for awhile, you suddenly realize that there are an unimaginable number of extensions, tools, and other packages. To make matters worse, there are about 20 billion different versions of Tcl, not all of which are compatible with each extension (this is to make life interesting of course).<p>
-<p>
-While SWIG is certainly not a magical solution to the configuration management problem, it can help out alot in a number of key areas :<p>
-<p>
-<ul>
-<li>SWIG generated code can be used with all versions of Tcl/Tk newer than 7.3/3.6. This includes the Tcl Netscape Plugin and Tcl 8.0a2.
-<li>The SWIG library mechanism can be used to manage various code fragments and initialization functions.
-<li>SWIG generated code usually requires no modification so it is relatively easy to switch between different Tcl versions as necessary or upgrade to a newer version when the time comes (of course, the Sun Tcl/Tk team might have changed other things to keep you occupied)
-</ul>
-<a name="n64"></a><h3> Writing a main program and Tcl_AppInit()</h3>
-The traditional method of creating a new Tcl extension required a programmer to write a special function called <tt>Tcl_AppInit()</tt> that would initialize your extension and start the Tcl interpreter. A typical <tt>Tcl_AppInit()</tt> function looks like the following :<p>
-<p>
-<blockquote><pre>/* main.c */
-#include &lt;tcl.h&gt;
-
-main(int argc, char *argv[]) {
- Tcl_Main(argc,argv);
- exit(0);
-}
-
-int Tcl_AppInit(Tcl_Interp *interp) {
- if (Tcl_Init(interp) == TCL_ERROR) {
- return TCL_ERROR;
- }
-
- /* Initialize your extension */
- if (Your_Init(interp) == TCL_ERROR) {
- return TCL_ERROR;
- }
-
- tcl_RcFileName = "~/.myapp.tcl";
- return TCL_OK;
-}
-
-</pre></blockquote>
-While relatively simple to write, there are tons of problems with doing this. First, each extension that you use typically has their own <tt>Tcl_AppInit()</tt> function. This forces you to write a special one to initialize everything by hand. Secondly, the process of writing a main program and initializing the interpreter varies between different versions of Tcl and different platforms. For example, in Tcl 7.4, the variable "<tt>tcl_RcFileName</tt>" is a C variable while in Tcl7.5 and newer versions its a Tcl variable instead. Similarly, the <tt>Tcl_AppInit</tt> function written for a Unix machine might not compile correctly on a Mac or Windows machine.<p>
-<p>
-In SWIG, it is almost never necessary to write a <tt>Tcl_AppInit()</tt> function because this is now done by SWIG library files such as <tt>tclsh.i</tt> or <tt>wish.i</tt>. To give a better idea of what these files do, here's the code from the SWIG <tt>tclsh.i</tt> file which is roughly comparable to the above code<p>
-<blockquote><pre>
-// tclsh.i : SWIG library file for rebuilding tclsh
-%{
-
-/* A TCL_AppInit() function that lets you build a new copy
- * of tclsh.
- *
- * The macro SWIG_init contains the name of the initialization
- * function in the wrapper file.
- */
-
-#ifndef SWIG_RcFileName
-char *SWIG_RcFileName = "~/.myapprc";
-#endif
-
-int Tcl_AppInit(Tcl_Interp *interp){
-
- if (Tcl_Init(interp) == TCL_ERROR)
- return TCL_ERROR;
-
- /* Now initialize our functions */
- if (SWIG_init(interp) == TCL_ERROR)
- return TCL_ERROR;
-
-#if TCL_MAJOR_VERSION &gt; 7 || TCL_MAJOR_VERSION == 7 &amp;&amp; TCL_MINOR_VERSION &gt;= 5
- Tcl_SetVar(interp,"tcl_rcFileName",SWIG_RcFileName,TCL_GLOBAL_ONLY);
-#else
- tcl_RcFileName = SWIG_RcFileName;
-#endif
- return TCL_OK;
-}
-
-#if TCL_MAJOR_VERSION &gt; 7 || TCL_MAJOR_VERSION == 7 &amp;&amp; TCL_MINOR_VERSION &gt;= 4
-int main(int argc, char **argv) {
- Tcl_Main(argc, argv, Tcl_AppInit);
- return(0);
-
-}
-#else
-extern int main();
-#endif
-
-%}
-</pre></blockquote>
-<p>
-This file is essentially the same as a normal <tt>Tcl_AppInit()</tt> function except that it supports a variety of Tcl versions. When included into an interface file, the symbol <tt>SWIG_init</tt> contains the actual name of the initialization function (This symbol is defined by SWIG when it creates the wrapper code). Similarly, a startup file can be defined by simply defining the symbol <tt>SWIG_RcFileName</tt>. Thus, a typical interface file might look like this :<p>
-<p>
-<blockquote><pre>%module graph
-%{
-#include "graph.h"
-#define SWIG_RcFileName "graph.tcl"
-%}
-
-%include tclsh.i
-
-... declarations ...
-
-
-</pre></blockquote>
-By including the <tt>tclsh.i</tt>, you automatically get a <tt>Tcl_AppInit()</tt> function. A variety of library files are also available. <tt>wish.i</tt> can be used to build a new wish executable, <tt>expect.i</tt> contains the main program for Expect, and <tt>ish.i</tt>, <tt>itclsh.i</tt>, <tt>iwish.i</tt>, and <tt>itkwish.i</tt> contain initializations for various incarnations of [incr Tcl].<p>
-<a name="n65"></a><h3> Creating a new package initialization library</h3>
-If a particular Tcl extension requires special initialization, you can create a special SWIG library file to initialize it. For example, a library file to extend Expect looks like the following :<p>
-<p>
-<blockquote><pre>
-// expect.i : SWIG Library file for Expect
-%{
-
-/* main.c - main() and some logging routines for expect
-
-Written by: Don Libes, NIST, 2/6/90
-
-Design and implementation of this program was paid for by U.S. tax
-dollars. Therefore it is public domain. However, the author and NIST
-would appreciate credit if this program or parts of it are used.
-*/
-
-#include "expect_cf.h"
-#include &lt;stdio.h&gt;
-#include INCLUDE_TCL
-#include "expect_tcl.h"
-
-void
-main(argc, argv)
-int argc;
-char *argv[];
-{
- int rc = 0;
- Tcl_Interp *interp = Tcl_CreateInterp();
- int SWIG_init(Tcl_Interp *);
-
- if (Tcl_Init(interp) == TCL_ERROR) {
- fprintf(stderr,"Tcl_Init failed: %s\n",interp-&gt;result);
- exit(1);
- }
- if (Exp_Init(interp) == TCL_ERROR) {
- fprintf(stderr,"Exp_Init failed: %s\n",interp-&gt;result);
- exit(1);
- }
-
- /* SWIG initialization. --- 2/11/96 */
- if (SWIG_init(interp) == TCL_ERROR) {
- fprintf(stderr,"SWIG initialization failed: %s\n", interp-&gt;result);
- exit(1);
- }
-
- exp_parse_argv(interp,argc,argv);
- /* become interactive if requested or "nothing to do" */
- if (exp_interactive)
- (void) exp_interpreter(interp);
- else if (exp_cmdfile)
- rc = exp_interpret_cmdfile(interp,exp_cmdfile);
- else if (exp_cmdfilename)
- rc = exp_interpret_cmdfilename(interp,exp_cmdfilename);
-
- /* assert(exp_cmdlinecmds != 0) */
- exp_exit(interp,rc);
- /*NOTREACHED*/
-}
-%}
-</pre></blockquote>
-<p>
-In the event that you need to write a new library file such as this, the process usually isn't too difficult. Start by grabbing the original <tt>Tcl_AppInit()</tt> function for the package. Enclose it in a <tt>%{,%}</tt> block. Now add a line that makes a call to <tt>SWIG_init()</tt>. This will automatically resolve to the real initialization function when compiled.<p>
-<a name="n66"></a><h3> Combining Tcl/Tk Extensions</h3>
-A slightly different problem concerns the mixing of various extensions. Most extensions don't require any special initialization other than calling their initialization function. To do this, we also use SWIG library mechanism. For example :<p>
-<p>
-<blockquote><pre>// blt.i : SWIG library file for initializing the BLT extension
-%{
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern int Blt_Init(Tcl_Interp *);
-#ifdef __cplusplus
-}
-#endif
-%}
-%init %{
- if (Blt_Init(interp) == TCL_ERROR) {
- return TCL_ERROR;
- }
-%}
-
-
-// tix.i : SWIG library file for initializing the Tix extension
-%{
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern int Tix_Init(Tcl_Interp *);
-#ifdef __cplusplus
-}
-#endif
-%}
-%init %{
- if (Tix_Init(interp) == TCL_ERROR) {
- return TCL_ERROR;
- }
-%}
-
-</pre></blockquote>
-Both files declare the proper initialization function (to be C++ friendly, this should be done using <tt>extern "C"</tt>). A call to the initialization function is then placed inside a <tt>%init %{ ... %}</tt> block. <p>
-<p>
-To use our library files and build a new version of wish, we might now do the following :<p>
-<p>
-<blockquote><pre>// mywish.i : wish with a bunch of stuff added to it
-%include wish.i
-%include blt.i
-%include tix.i
-
-... additional declarations ...
-
-</pre></blockquote>
-Of course, the really cool part about all of this is that the file `<tt>mywish.i</tt>' can itself, serve as a library file. Thus, when building various versions of Tcl, we can place everything we want to use a special file and use it in all of our other interface files :<p>
-<p>
-<blockquote><pre>// interface.i
-%module mymodule
-
-%include mywish.i // Build our version of Tcl with extensions
-
-... C declarations ...
-
-</pre></blockquote>
-or we can grab it on the command line :<p>
-<p>
-<blockquote><pre>unix &gt; swig -tcl -lmywish.i interface.i
-
-</pre></blockquote>
-<a name="n67"></a><h3> Limitations to this approach</h3>
-This interface generation approach is limited by the compatibility of each extension you use. If any one extension is incompatible with the version of Tcl you are using, you may be out of luck. It is also critical to pay careful attention to libraries and include files. An extension library compiled against an older version of Tcl may fail when linked with a newer version. <p>
-<a name="n68"></a><h3> Dynamic loading </h3>
-Newer versions of Tcl support dynamic loading. With dynamic loading, you compile each extension into a separate module that can be loaded at run time. This simplifies a number of compilation and extension building problems at the expense of creating new ones. Most notably, the dynamic loading process varies widely between machines and is not even supported in some cases. It also does not work well with C++ programs that use static constructors. Modules linked with older versions of Tcl may not work with newer versions as well (although SWIG only really uses the basic Tcl C interface). As a result, I usually find myself using both dynamic and static linking as appropriate. <p>
-<a name="n69"></a><h3> Turning a SWIG module into a Tcl Package.</h3>
-Tcl 7.4 introduced the idea of an extension package. By default, SWIG does not create "packages", but it is relatively easy to do. To make a C extension into a Tcl package, you need to provide a call to <tt>Tcl_PkgProvide() </tt>in the module initialization function<tt>.</tt> This can be done in an interface file as follows :<p>
-<p>
-<blockquote><pre>%init %{
- Tcl_PkgProvide(interp,"example","0.0");
-%}
-</pre></blockquote>
-<p>
-Where "example" is the name of the package and "0.0" is the version of the package. <p>
-<p>
-Next, after building the SWIG generated module, you need to execute the "<tt>pkg_mkIndex</tt>" command inside tclsh. For example :<p>
-<blockquote><pre>
-unix &gt; tclsh
-% pkg_mkIndex . example.so
-% exit
-
-</pre></blockquote>
-This creates a file "<tt>pkgIndex.tcl</tt>" with information about the package. To use your<p>
-package, you now need to move it to its own subdirectory which has the same name as the package. For example :<p>
-<p>
-<blockquote><pre>./example/
- pkgIndex.tcl # The file created by pkg_mkIndex
- example.so # The SWIG generated module
-
-</pre></blockquote>
-<p>
-Finally, assuming that you're not entirely confused at this point, make sure that the example subdirectory is visible from the directories contained in either the <tt>tcl_library</tt> or <tt>auto_path</tt> variables. At this point you're ready to use the package as follows :<p>
-<blockquote><pre>
-unix &gt; tclsh
-% package require example
-% fact 4
-24
-%
-</pre></blockquote>
-<p>
-If you're working with an example in the current directory and this doesn't work, do this instead :<p>
-<p>
-<blockquote><pre>unix &gt; tclsh
-% lappend auto_path .
-% package require example
-% fact 4
-24
-
-</pre></blockquote>
-<p>
-As a final note, most SWIG examples do not yet use the <tt>package</tt> commands. For simple extensions it may be easier just to use the <tt>load</tt> command instead.<p>
-<a name="n13"></a><h2> Building new kinds of Tcl interfaces (in Tcl)</h2>
-One of the most interesting aspects of Tcl and SWIG is that you can create entirely new kinds of Tcl interfaces in Tcl using the low-level SWIG accessor functions. For example, suppose you had a library of helper functions to access arrays :<p>
-<p>
-<blockquote><pre>/* File : array.i */
-%module array
-
-%inline %{
-double *new_double(int size) {
- return (double *) malloc(size*sizeof(double));
-}
-void delete_double(double *a) {
- free(a);
-}
-double get_double(double *a, int index) {
- return a[index];
-}
-void set_double(double *a, int index, double val) {
- a[index] = val;
-}
-int *new_int(int size) {
- return (int *) malloc(size*sizeof(int));
-}
-void delete_int(int *a) {
- free(a);
-}
-int get_int(int *a, int index) {
- return a[index];
-}
-int set_int(int *a, int index, int val) {
- a[index] = val;
-}
-%}
-
-</pre></blockquote>
-While these could be called directly, we could also write a Tcl script like this :<p>
-<p>
-<blockquote><pre>proc Array {type size} {
- set ptr [new_$type $size]
- set code {
- set method [lindex $args 0]
- set parms [concat $ptr [lrange $args 1 end]]
- switch $method {
- get {return [eval "get_$type $parms"]}
- set {return [eval "set_$type $parms"]}
- delete {eval "delete_$type $ptr; rename $ptr {}"}
- }
- }
- # Create a procedure
- uplevel "proc $ptr args {set ptr $ptr; set type $type;$code}"
- return $ptr
-}
-</pre></blockquote>
-<p>
-Our script allows easy array access as follows :<p>
-<p>
-<blockquote><pre>set a [Array double 100] ;# Create a double [100]
-for {set i 0} {$i &lt; 100} {incr i 1} { ;# Clear the array
- $a set $i 0.0
-}
-$a set 3 3.1455 ;# Set an individual element
-set b [$a get 10] ;# Retrieve an element
-
-set ia [Array int 50] ;# Create an int[50]
-for {set i 0} {$i &lt; 50} {incr i 1} { ;# Clear it
- $ia set $i 0
-}
-$ia set 3 7 ;# Set an individual element
-set ib [$ia get 10] ;# Get an individual element
-
-$a delete ;# Destroy a
-$ia delete ;# Destroy ia
-</pre></blockquote>
-<p>
-The cool thing about this approach is that it makes a common interface for two different types of arrays. In fact, if we were to add more C datatypes to our wrapper file, the Tcl code would work with those as well--without modification. If an unsupported datatype was requested, the Tcl code would simply return with an error so there is very little danger of blowing something up (although it is easily accomplished with an out of bounds array access).<p>
-<a name="n70"></a><h3> Shadow classes</h3>
-A similar approach can be applied to shadow classes. The following example is provided by Erik Bierwagen and Paul Saxe. To use it, run SWIG with the <tt>-noobject</tt> option (which disables the builtin object oriented interface). When running Tcl, simply source this file. Now, objects can be used in a more or less natural fashion.<p>
-<p>
-<blockquote><pre># swig_c++.tcl
-# Provides a simple object oriented interface using
-# SWIG's low level interface.
-#
-
-proc new {objectType handle_r args} {
- # Creates a new SWIG object of the given type,
- # returning a handle in the variable "handle_r".
- #
- # Also creates a procedure for the object and a trace on
- # the handle variable that deletes the object when the
- # handle varibale is overwritten or unset
- upvar $handle_r handle
- #
- # Create the new object
- #
- eval set handle \[new_$objectType $args\]
- #
- # Set up the object procedure
- #
- proc $handle {cmd args} "eval ${objectType}_\$cmd $handle \$args"
- #
- # And the trace ...
- #
- uplevel trace variable $handle_r uw "{deleteObject $objectType $handle}"
- #
- # Return the handle so that 'new' can be used as an argument to a procedure
- #
- return $handle
-}
-
-proc deleteObject {objectType handle name element op} {
- #
- # Check that the object handle has a reasonable form
- #
- if {![regexp {_[0-9a-f]*_(.+)_p} $handle]} {
- error "deleteObject: not a valid object handle: $handle"
- }
- #
- # Remove the object procedure
- #
- catch {rename $handle {}}
- #
- # Delete the object
- #
- delete_$objectType $handle
-}
-
-proc delete {handle_r} {
- #
- # A synonym for unset that is more familiar to C++ programmers
- #
- uplevel unset $handle_r
-}
-</pre></blockquote>
-<p>
-To use this file, we simply source it and execute commands such as "new" and "delete" to manipulate objects. For example :<p>
-<p>
-<blockquote><pre>// list.i
-%module List
-%{
-#include "list.h"
-%}
-
-// Very simple C++ example
-
-class List {
-public:
- List(); // Create a new list
- ~List(); // Destroy a list
- int search(char *value);
- void insert(char *); // Insert a new item into the list
- void remove(char *); // Remove item from list
- char *get(int n); // Get the nth item in the list
- int length; // The current length of the list
-static void print(List *l); // Print out the contents of the list
-};
-</pre></blockquote>
-<p>
-Now a Tcl script using the interface...<p>
-<p>
-<blockquote><pre>load ./list.so list ; # Load the module
-source swig_c++.tcl ; # Source the object file
-
-new List l
-$l insert Dave
-$l insert John
-$l insert Guido
-$l remove Dave
-puts $l length_get
-
-delete l
-
-</pre></blockquote>
-The cool thing about this example is that it works with any C++ object wrapped by SWIG and requires no special compilation. Proof that a short, but clever Tcl script can be combined with SWIG to do many interesting things.<p>
-<a name="n14"></a><h2> Extending the Tcl Netscape Plugin</h2>
-SWIG can be used to extend the Tcl Netscape plugin with C functions. As of this writing it has only been tested with version 1.0 of the plugin on Solaris and Irix 6.2. It may work on other machines as well. However, first a word of caution --- doing this might result in serious injury as you can add just about any C function you want. Furthermore, it's not portable (hey, we're talking C code here). It seems like the best application of this would be creating a browser interface to a highly specialized application. Any scripts that you would write would not work on other machines unless they also installed the C extension code as well. Perhaps we should call this a plugin-plugin...<p>
-<p>
-To use the plugin, use the <tt>-plugin</tt> option :<p>
-<p>
-<blockquote><pre>swig -tcl -plugin interface.i
-
-</pre></blockquote>
-This adds a "safe" initialization function compatible with the plugin (in reality, it just calls the function SWIG already creates). You also need to put the following symbol in your interface file for it to work :<p>
-<p>
-<blockquote><pre>%{
-#define SAFE_SWIG
-%}
-
-</pre></blockquote>
-The folks at Sun are quite concerned about the security implications of this sort of extension and originally wanted the user to modify the wrapper code by hand to "remind" them that they were installing functions into a safe interpreter. However, having seen alot of SWIG generated wrapper code, I hated that idea (okay, so the output of SWIG is just a little messy). This is compromise--you need to put that <tt>#define</tt> into your C file someplace. You can also just make it a compiler option if you would like.<p>
-<a name="n71"></a><h3> The step-by-step process for making a plugin extension.</h3>
-Making a plugin extension is relatively straightforward but you need to follow these steps :<p>
-<p>
-<ul>
-<li>Make sure you have Tcl7.6/Tk4.2 installed on your machine. We're going to need the header files into order to compile the extension.
-<li>Make sure you have the Netscape plugin properly installed.
-<li>Run SWIG using the `<tt>-tcl -plugin</tt>' options.
-<li>Compile the extension using the Tcl 7.6/Tk4.2 header files, but linking against the plugin itself. For example :
-<blockquote><pre>
-unix &gt; gcc -I/usr/local/include -c example.o interface_wrap.c
-unix &gt; ld -shared example.o interface_wrap.o \
- -L/home/beazley/.netscape/plugins/libtclplugin.so -o example.so
-
-</pre></blockquote>
-<li>Copy the shared object file to the <tt>~/.tclplug/tcl7.7</tt> directory.
-</ul>
-<a name="n72"></a><h3> Using the plugin</h3>
-To use the plugin, place the following line in your Tcl scripts :<p>
-<p>
-<blockquote><pre>load $tcl_library/example.so example
-
-</pre></blockquote>
-With luck, you will now be ready to run (at least that's the theory).<p>
-<a name="n15"></a><h2> Tcl8.0 features</h2>
-SWIG 1.1 now supports Tcl 8.0. However, considering the beta release nature of Tcl 8.0, anything presented here is subject to change. Currently only Tcl 8.0b1 is supported. None of the alpha releases are supported due to a change in the C API. <p>
-<p>
-The Tcl 8.0 module uses the new Tcl 8.0 object interface whenever possible. Instead of using strings, the object interface provides more direct access to objects in their native representation. As a result, the performance is significantly better. The older Tcl SWIG module is also compatible with Tcl 8.0, but since it uses strings it will be much slower than the new version.<p>
-<p>
-In addition to using native Tcl objects, the Tcl8.0 manipulates pointers directly in in a special Tcl object. On the surface it still looks like a string, but internally its represented a (value,type) pair. This too, should offer somewhat better performance.<p>
-<p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:47:12 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/Typemaps.html b/swigweb/Doc1.1/HTML/Typemaps.html
deleted file mode 100644
index 615a2cb4f..000000000
--- a/swigweb/Doc1.1/HTML/Typemaps.html
+++ /dev/null
@@ -1,733 +0,0 @@
-<!-- Published by Quadralay WebWorks HTML Lite 1.5.1 -->
-<!-- And munged by Dave's special Python script -->
-<html>
-<head>
-<title>Pointers, Constraints, and Typemaps</title>
-</head>
-
-<body bgcolor="#ffffff">
-<a name="n0"></a><h1>6 Pointers, Constraints, and Typemaps</h1><p><ul>
-<li> <a href="#n1">Introduction</a>
-<li> <a href="#n2">The SWIG Pointer Library</a>
-<li> <a href="#n3">Introduction to typemaps</a>
-<li> <a href="#n4">Managing input and output parameters</a>
-<li> <a href="#n5">Applying constraints to input values</a>
-<li> <a href="#n6">Writing new typemaps</a>
-<li> <a href="#n7">Common typemap methods</a>
-<li> <a href="#n8">Writing typemap code</a>
-<li> <a href="#n9">Typemaps for handling arrays</a>
-<li> <a href="#n10">Typemaps and the SWIG Library</a>
-<li> <a href="#n11">Implementing constraints with typemaps</a>
-<li> <a href="#n12">Typemap examples</a>
-<li> <a href="#n13">How to break everything with a typemap</a>
-<li> <a href="#n14">Typemaps and the future</a>
-</ul>
-
-<a name="n1"></a><h2> Introduction</h2>
-For most applications, SWIG's treatment of basic datatypes and pointers is enough to build an interface. However, in certain cases, it is desirable to change SWIG's treatment of particular datatypes. For example, we may want a <tt>char ** </tt>to act like a list of strings instead of a pointer. In another instance, we may want to tell SWIG that <tt>double *result</tt> is the output value of a function. Similarly, we might want to map a datatype of <tt>float[4]</tt> into a 4 element tuple. This chapter describes advanced methods for managing pointers, arrays, and complex datatypes. It also describes how you can customize SWIG to handle new kinds of objects and datatypes.<p>
-<a name="n2"></a><h2> The SWIG Pointer Library</h2>
-If your interface involves C pointers, chances are you will need to work with these pointers in some way or another. The SWIG pointer library provides a collection of useful methods for manipulating pointers. To use the library, simply put the following declaration in your interface file :<p>
-<p>
-<blockquote><pre>%include pointer.i // Grab the SWIG pointer library
-
-</pre></blockquote>
-or run SWIG as follows :<p>
-<p>
-<blockquote><pre>swig -perl5 -lpointer.i interface.i
-
-</pre></blockquote>
-Doing so adds a collection of pointer manipulation functions that are described below. The functions are mainly designed to work with basic C datatypes, but can often be used with more complicated structures.<p>
-<a name="n15"></a><h3> Pointer Library Functions</h3>
-<b>ptrcreate(type,?value?,?nitems?)</b><p>
-<dl>
-<dt><dd>
-<dt><dd>Creates a new object and returns a pointer to it. <tt>type</tt> is a string containing the C datatype and may be one of "<tt>int</tt>","<tt>short</tt>","<tt>long</tt>","<tt>float</tt>","<tt>double</tt>","<tt>char</tt>","<tt>char *</tt>", or "<tt>void</tt>". <tt>value</tt> is the optional initial value to be assigned to the object. <tt>nitems</tt> is an optional parameter containing the number of objects to create. By default it is 1, but specifying another value allows you to create an array of values. This function is really just a wrapper around the C <tt>malloc()</tt> function.
-</dl>
-<b></b><p>
-<b>ptrfree(ptr)</b><p>
-<dl>
-<dt><dd>Destroys an object created by <tt>ptrcreate</tt>. It is generally unsafe to use this function on objects not created by <tt>ptrcreate</tt>. Calls the C <tt>free()</tt> function.
-</dl>
-<p>
-<b>ptrvalue(ptr,?index?,?type?)</b><p>
-<dl>
-<dt><dd>This dereferences a pointer and returns the value that it is pointing to. <tt>index</tt> is an optional parameter that allows array access by returning the value of <tt>ptr[index]</tt>. <tt>type</tt> is an optional parameter that explicitly specifies the datatype. Since SWIG pointers are encoded with type information, the type is usually unnecessary. The <tt>type</tt> parameter provides somewhat better performance and allows you to dereference a pointer of different type however.
-<dt><dd>
-</dl>
-<b>ptrset(ptr, value, ?index?, ?type?)</b><p>
-<dl>
-<dt><dd>Sets the value of the object a pointer is pointing to. <tt>value</tt> is the new value of the object. <tt>index </tt>is an optional parameter allowing array access by setting <tt>ptr[index] = value</tt>. <tt>type </tt>is an optional parameter that explicitly specifies the datatype as described above.
-<dt><dd>
-</dl>
-<b>ptrcast(ptr, newtype)</b><p>
-<dl>
-<dt><dd>Casts a pointer to a new datatype and returns the new value. <tt>newtype</tt> is a string containing the new datatype and may either be the "mangled" version used by SWIG (such as "<tt>_Vector_p</tt>") or the C version (such as "<tt>Vector *</tt>"). This function works with any kind of pointer value. In additional to pointers, <tt>ptr</tt> may also hold an integer value in which case the integer is turned into a pointer of given type.
-<dt><dd>
-</dl>
-<b>ptradd(ptr, offset)</b><p>
-<dl>
-<dt><dd>Adds an offset to a pointer and returns a new pointer. <tt>offset</tt> is specified as the number of objects except for unknown complex datatypes in which case it is the number of bytes. For example, is <tt>ptr</tt> is a "<tt>double *</tt>", <tt>ptradd(ptr,1)</tt> will return the next double. On the other hand, if if <tt>ptr</tt> is "<tt>Vector *</tt>", then <tt>ptradd(ptr,1)</tt> will update the pointer by 1 byte.
-<dt><dd>
-</dl>
-<b>ptrmap(type1,type2)</b><p>
-<dl>
-<dt><dd>This performs a "runtime typedef" and makes SWIG recognize pointers of <tt>type1</tt> and <tt>type2</tt> as equivalent. <tt>type1</tt> and <tt>type2</tt> are specified as strings. Not generally needed, but sometimes useful.
-</dl>
-<a name="n16"></a><h3> A simple example</h3>
-Suppose you have the following C function :<p>
-<blockquote><pre>
-void add(double a, double b, double *result) {
- *result = a + b;
-}
-
-</pre></blockquote>
-To manage the result output, we can write an interface file like this :<p>
-<p>
-<blockquote><pre>%module example
-%include pointer.i
-
-extern void add(double a, double b, double *result);
-
-</pre></blockquote>
-Now, let's use the pointer library (shown for a few languages) :<p>
-<blockquote><pre>
-# Tcl
-set result [ptrcreate double] ;# Create a double
-add 4.5 3 $result ;# Call our C function
-puts [ptrvalue $result] ;# Print out the result
-ptrfree $result ;# Destroy the double
-
-# Perl5
-use example;
-package example; # Functions are in example package
-$result = ptrcreate("double"); # Create a double
-add(4.5,3,$result); # Call C function
-print ptrvalue($result),"\n"; # Print the result
-ptrfree($result); # Destroy the double
-
-# Python
-import example
-result = example.ptrcreate("double") # Create a double
-example.add(4.5,3,result) # Call C function
-print example.ptrvalue(result) # Print the result
-example.ptrfree(result) # Destroy the double
-
-</pre></blockquote>
-In this case, the idea is simple--we create a pointer, pass it to our C function, and dereference it to get the result. It's essentially identical to how we would have done it in C (well, minus the function call to dereference the value).<p>
-<a name="n17"></a><h3> Creating arrays</h3>
-Now suppose you have a C function involving arrays :<p>
-<p>
-<blockquote><pre>void addv(double a[], double b[], double c[], int nitems) {
- int i;
- for (i = 0; i &lt; nitems; i++) {
- c[i] = a[i]+b[i];
- }
-}
-
-</pre></blockquote>
-This is also easily handled by our pointer library. For example (in Python) :<p>
-<p>
-<blockquote><pre># Python function to turn a list into an "array"
-def build_array(l):
- nitems = len(l)
- a = ptrcreate("double",0,nitems)
- i = 0
- for item in l:
- ptrset(a,item,i)
- i = i + 1
- return a
-
-# Python function to turn an array into list
-def build_list(a,nitems):
- l = []
- for i in range(0,nitems):
- l.append(ptrvalue(a,i))
- return l
-
-# Now use our functions
-a = listtoarray([0.0,-2.0,3.0,9.0])
-b = build_array([-2.0,3.5,10.0,22.0])
-c = ptrcreate("double",0,4) # For return result
-add(a,b,c,4) # Call our C function
-result = build_list(c) # Build a python list from the result
-print result
-ptrfree(a)
-ptrfree(b)
-ptrfree(c)
-
-</pre></blockquote>
-This example may look quite inefficient on the surface (due to the translation of Python lists to and from C arrays). However, if you're working with lots of C functions, it's possible to simply pass C pointers around between them without any translation. As a result, applications can run fast--even when controlled from a scripting language. It's also worth emphasizing that the <tt>ptrcreate()</tt> function created a real C array that can be interchanged with other arrays. The <tt>ptrvalue()</tt> function can also dereference a C pointer even if it wasn't created from Python. <p>
-<a name="n18"></a><h3> Packing a data structure</h3>
-The pointer library can even be used to pack simple kinds of data-structures, perhaps for sending across a network, or simply for changing the value. For example, suppose you had this data structure:<p>
-<p>
-<blockquote><pre>struct Point {
- double x,y;
- int color;
-};
-
-</pre></blockquote>
-<p>
-You could write a Tcl function to set the fields of the structure as follows :<p>
-<p>
-<blockquote><pre>proc set_point { ptr x y c } {
- set p [ptrcast $ptr "double *"] ;# Make a double *
- ptrset $p $x ;# Set x component
- set p [ptradd $p 1] ;# Update pointer
- ptrset $p $y ;# Set y component
- set p [ptrcast [ptradd $p 1] "int *"] ;# Update pointer and cast
- ptrset $p $c ;# Set color component
-}
-</pre></blockquote>
-<p>
-This function could be used even if you didn't tell SWIG anything about the "Point" structure above. <p>
-<a name="n3"></a><h2> Introduction to typemaps</h2>
-Sometimes it's desirable to change SWIG behavior in some manner. For example, maybe you want to automatically translate C arrays to and from Perl lists. Or perhaps you would like a particular function argument to behave as an output parameter. Typemaps provide a mechanism for doing just this by modifying SWIG's code generator. Typemaps are new to SWIG 1.1, but it should be emphasized that they are not required to build an interface. <p>
-<a name="n19"></a><h3> The idea (in a nutshell)</h3>
-The idea behind typemaps is relatively simple--given the occurrence of a particular C datatype, we want to apply rules for special processing. For example, suppose we have a C function like this :<p>
-<p>
-<blockquote><pre>void add(double a, double b, double *result) {
- *result = a + b;
-}
-</pre></blockquote>
-<p>
-It is clear to us that the result of the function is being returned in the <tt>result</tt> parameter. Unfortunately, SWIG isn't this smart--after all "result" is just like any other pointer. However, with a typemap, we can make SWIG recognize "<tt>double *result</tt>" as a special datatype and change the handling to do exactly what we want.<p>
-<p>
-So, despite being a common topic of discussion on the SWIG mailing list, a typemap is really just a special processing rule that is applied to a particular datatype. Each typemap relies on two essential attributes--a datatype and a name (which is optional). When trying to match parameters, SWIG looks at both attributes. Thus, special processing applied to a parameter of "<tt>double *result</tt>" will not be applied to "<tt>double *input</tt>". On the other hand, special processing defined for a datatype of "<tt>double *</tt>" could be applied to both (since it is more general). <p>
-<a name="n20"></a><h3> Using some typemaps</h3>
-It is easy to start using some typemaps right away. To wrap the above function, simply use the <tt>typemaps.i</tt> library file (which is part of the SWIG library) as follows :<p>
-<p>
-<blockquote><pre>// Simple example using typemaps
-%module example
-%include typemaps.i // Grab the standard typemap library
-
-%apply double *OUTPUT { double *result };
-extern void add(double a, double b, double *result);
-
-</pre></blockquote>
-The <tt>%apply</tt> directive tells SWIG that we are going to apply special processing to a datatype. The "<tt>double *OUTPUT</tt>" is the name of a rule describing how to return an output value from a "<tt>double *</tt>" (this rule is defined in the file <tt>typemaps.i</tt>). The rule gets applied to all of the datatypes listed in curly braces-- in this case "<tt>double *result</tt>".<p>
-<p>
-While it may sound complicated, when you compile the module and use it, you get a function that works as follows :<p>
-<p>
-<blockquote><pre># Perl code to call our add function
-
-$a = add(3,4);
-print $a,"\n";
-7
-
-</pre></blockquote>
-Our function is much easier to use and it is no longer necessary to create a special double * object and pass it to the function. Typemaps took care of this automatically.<p>
-<a name="n4"></a><h2> Managing input and output parameters</h2>
-By default, when SWIG encounters a pointer, it makes no assumptions about what it is (well, other than the fact that it's a pointer). The <tt>typemaps.i</tt> library file contains a variety of methods for changing this behavior. The following methods are available in this file :<p>
-<a name="n21"></a><h3> Input Methods</h3>
-These methods tell SWIG that a pointer is a single input value. When used, functions will expect values instead of pointers.<p>
-<blockquote><pre>
-int *INPUT
-short *INPUT
-long *INPUT
-unsigned int *INPUT
-unsigned short *INPUT
-unsigned long *INPUT
-double *INPUT
-float *INPUT
-</pre></blockquote>
-<p>
-Suppose you had a C function like this :<p>
-<blockquote><pre>
-double add(double *a, double *b) {
- return *a+*b;
-}
-
-</pre></blockquote>
-You could wrap it with SWIG as follows :<p>
-<p>
-<blockquote><pre>%module example
-%include typemaps.i
-...
-extern double add(double *INPUT, double *INPUT);
-
-</pre></blockquote>
-Now, when you use your function ,it will work like this :<p>
-<p>
-<blockquote><pre>% set result [add 3 4]
-% puts $result
-7
-</pre></blockquote>
-<a name="n22"></a><h3> Output Methods</h3>
-These methods tell SWIG that pointer is the output value of a function. When used, you do not need to supply the argument when calling the function, but multiple return values can be returned.<p>
-<p>
-<blockquote><pre>int *OUTPUT
-short *OUTPUT
-long *OUTPUT
-unsigned int *OUTPUT
-unsigned short *OUTPUT
-unsigned long *OUTPUT
-double *OUTPUT
-float *OUTPUT
-
-</pre></blockquote>
-These methods can be used as shown in an earlier example. For example, if you have this C function :<p>
-<p>
-<blockquote><pre>void add(double a, double b, double *c) {
- *c = a+b;
-}
-</pre></blockquote>
-<p>
-A SWIG interface file might look like this :<p>
-<p>
-<blockquote><pre>%module example
-%include typemaps.i
-...
-extern void add(double a, double b, double *OUTPUT);
-
-</pre></blockquote>
-In this case, only a single output value is returned, but this is not a restriction. For example, suppose you had a function like this :<p>
-<p>
-<blockquote><pre>// Returns a status code and double
-int get_double(char *str, double *result);
-
-</pre></blockquote>
-When declared in SWIG as :<p>
-<p>
-<blockquote><pre>int get_double(char *str, double *OUTPUT);
-
-</pre></blockquote>
-The function would return a list of output values as shown for Python below :as follows :<p>
-<p>
-<blockquote><pre>&gt;&gt;&gt; get_double("3.1415926") # Returns both a status and value
-[0, 3.1415926]
-&gt;&gt;&gt;
-</pre></blockquote>
-<a name="n23"></a><h3> Input/Output Methods</h3>
-When a pointer serves as both an input and output value you can use the following methods :<p>
-<blockquote><pre>
-int *BOTH
-short *BOTH
-long *BOTH
-unsigned int *BOTH
-unsigned short *BOTH
-unsigned long *BOTH
-double *BOTH
-float *BOTH
-
-</pre></blockquote>
-A typical C function would be as follows :<p>
-<p>
-<blockquote><pre>void negate(double *x) {
- *x = -(*x);
-}
-
-</pre></blockquote>
-To make x function as both and input and output value, declare the function like this in an interface file :<p>
-<p>
-<blockquote><pre>%module example
-%include typemaps.i
-...
-extern void negate(double *BOTH);
-
-</pre></blockquote>
-Now within a script, you can simply call the function normally :<p>
-<p>
-<blockquote><pre>$a = negate(3); # a = -3 after calling this
-
-</pre></blockquote>
-<a name="n24"></a><h3> Using different names</h3>
-By explicitly using the parameter names of INPUT, OUTPUT, and BOTH in your declarations, SWIG performs different operations. If you would like to use different names, you can simply use the <tt>%apply</tt> directive. For example :<p>
-<p>
-<blockquote><pre>// Make double *result an output value
-%apply double *OUTPUT { double *result };
-
-// Make Int32 *in an input value
-%apply int *INPUT { Int32 *in };
-
-// Make long *x both
-%apply long *BOTH {long *x};
-
-</pre></blockquote>
-<tt>%apply</tt> only renames the different type handling rules. You can use it to match up with the naming scheme used in a header file and so forth. To later clear a naming rule, the <tt>%clear</tt> directive can be used :<p>
-<p>
-<blockquote><pre>%clear double *result;
-%clear Int32 *in, long *x;
-</pre></blockquote>
-<a name="n5"></a><h2> Applying constraints to input values</h2>
-In addition to changing the handling of various input values, it is also possible to apply constraints. For example, maybe you want to insure that a value is positive, or that a pointer is non-NULL. This can be accomplished including the <tt>constraints.i</tt> library file (which is also based on typemaps).<p>
-<a name="n25"></a><h3> Simple constraint example</h3>
-The constraints library is best illustrated by the following interface file :<p>
-<p>
-<blockquote><pre>// Interface file with constraints
-%module example
-%include constraints.i
-
-double exp(double x);
-double log(double POSITIVE); // Allow only positive values
-double sqrt(double NONNEGATIVE); // Non-negative values only
-double inv(double NONZERO); // Non-zero values
-
-void free(void *NONNULL); // Non-NULL pointers only
-
-</pre></blockquote>
-The behavior of this file is exactly as you would expect. If any of the arguments violate the constraint condition, a scripting language exception will be raised. As a result, it is possible to catch bad values, prevent mysterious program crashes and so on.<p>
-<a name="n26"></a><h3> Constraint methods</h3>
-The following constraints are currently available<p>
-<blockquote><pre>
-POSITIVE Any number &gt; 0 (not zero)
-NEGATIVE Any number &lt; 0 (not zero)
-NONNEGATIVE Any number &gt;= 0
-NONPOSITIVE Any number &lt;= 0
-NONZERO Nonzero number
-NONNULL Non-NULL pointer (pointers only).
-</pre></blockquote>
-<a name="n27"></a><h3> Applying constraints to new datatypes</h3>
-The constraints library only supports the built-in C datatypes, but it is easy to apply it to new datatypes using <tt>%apply</tt>. For example :<p>
-<p>
-<blockquote><pre>// Apply a constraint to a Real variable
-%apply Number POSITIVE { Real in };
-
-// Apply a constraint to a pointer type
-%apply Pointer NONNULL { Vector * };
-
-</pre></blockquote>
-The special types of "Number" and "Pointer" can be applied to any numeric and pointer variable type respectively. To later remove a constraint, the %clear directive can be used :<p>
-<p>
-<blockquote><pre>%clear Real in;
-%clear Vector *;
-</pre></blockquote>
-<a name="n6"></a><h2> Writing new typemaps</h2>
-So far, we have only seen a high-level picture of typemaps and have utilized pre-existing typemaps in the SWIG library. However, it is possible to do more if you're willing to get your hands dirty and dig into the internals of SWIG and your favorite scripting language.<p>
-<p>
-Before diving in, first ask yourself do I really need to change SWIG's default behavior? The basic pointer model works pretty well most of the time and I encourage you to use it--after all, I wanted SWIG to be easy enough to use so that you didn't need to worry about low level details. If, after contemplating this for awhile, you've decided that you really want to change something, a word of caution is in order. Writing a typemap from scratch usually requires a detailed knowledge of the internal workings of a particular scripting language. It is also quite easy to break all of the output code generated by SWIG if you don't know what you're doing. On the plus side, once a typemap has been written it can be reused over and over again by putting it in the SWIG library (as has already been demonstrated). This section describes the basics of typemaps. Language specific information (which can be quite technical) is contained in the later chapters.<p>
-<a name="n28"></a><h3> Motivations for using typemaps</h3>
-Suppose you have a few C functions such as the following :<p>
-<p>
-<blockquote><pre>void glLightfv(GLenum light, Glenum pname, GLfloat parms[4]);
-
-</pre></blockquote>
-In this case, the third argument takes a 4 element array. If you do nothing, SWIG will convert the last argument into a pointer. When used in the scripting language, you will need to pass a "<tt>GLfloat *</tt>" object to the function to make it work. <p>
-<a name="n29"></a><h3> Managing special data-types with helper functions</h3>
-Helper functions provide one mechanism for dealing with odd datatypes. With a helper function, you provide additional functionality for creating and destroying objects or converting values into a useful form. These functions are usually just placed into your interface file with the rest of the functions. For example, a few helper functions to work with 4 element arrays for the above function, might look like this :<p>
-<p>
-<blockquote><pre>%inline %{
-/* Create a new GLfloat [4] object */
-GLfloat *newfv4(double x, double y, double z, double w) {
- GLfloat *f = (GLfloat *) malloc(4*sizeof(GLfloat));
- f[0] = x;
- f[1] = y;
- f[2] = z;
- f[3] = w;
- return f;
-}
-
-/* Destroy a GLfloat [4] object */
-void delete_fv4(GLfloat *d) {
- free(d);
-}
-%}
-</pre></blockquote>
-<p>
-When wrapped, our helper functions will show up the interface and can be used as follows :<p>
-<p>
-<blockquote><pre>% set light [newfv4 0.0 0.0 0.0 1.0] # Creates a GLfloat *
-% glLightfv GL_LIGHT0 GL_AMBIENT $light # Pass it to the function
-...
-% delete_fv4 $light # Destroy it (When done)
-</pre></blockquote>
-<p>
-<p>
-While not the most elegant approach, helper functions provide a simple mechanism for working with more complex datatypes. In most cases, they can be written without diving into SWIG's internals. Before typemap support was added to SWIG, helper functions were the only method for handling these kinds of problems. The pointer.i library file described earlier is an example of just this sort of approach. As a rule of thumb, I recommend that you try to use this approach before jumping into typemaps. <p>
-<a name="n30"></a><h3> A Typemap Implementation</h3>
-As we have seen, a typemap can often eliminate the need for helper functions. Without diving into the details, a more sophisticated typemap implementation of the previous example can permit you to pass an array or list of values directly into the C function like this :<p>
-<p>
-<blockquote><pre>% glLightfv GL_LIGHT0 GL_AMBIENT {0.0 0.0 0.0 1.0}
-
-</pre></blockquote>
-This is a more natural implementation that replaces the low-level pointer method. Now we will look into how one actually specifies a typemap.<p>
-<a name="n31"></a><h3> What is a typemap?</h3>
-A typemap is specified using the <tt>%typemap</tt> directive in your interface file. A simple typemap might look liks this :<p>
-<p>
-<blockquote><pre>%module example
-%typemap(tcl,in) int {
- $target = atoi($source);
- printf("Received an integer : %d\n", $target);
-}
-
-int add(int a, int b);
-</pre></blockquote>
-<p>
-In this case, we changed the processing of integers as input arguments to functions. When used in a Tcl script, we would get the following debugging information:<p>
-<p>
-<blockquote><pre>% set a [add 7 13]
-Received an integer : 7
-Received an integer : 13
-
-</pre></blockquote>
-In the typemap specification, the symbols <tt>$source</tt> and <tt>$target</tt> are holding places for C variable names that SWIG is going to use when generating wrapper code. In this example, <tt>$source</tt> would contain a Tcl string containing the input value and <tt>$target</tt> would be the C integer value that is going to be passed into the "add" function.<p>
-<a name="n32"></a><h3> Creating a new typemap</h3>
-A new typemap can be created as follows :<p>
-<blockquote><pre>
-%typemap(lang,method) Datatype {
- ... Conversion code ...
-}
-
-</pre></blockquote>
-<tt>lang</tt> specifies the target language, <tt>method</tt> defines a particular conversion method, and <tt>Datatype</tt> gives the corresponding C datatype. The code corresponding to the typemap is enclosed in braces after the declaration. There are about a dozen different kinds of typemaps that are used within SWIG, but we will get to that shortly.<p>
-<p>
-A single conversion can be applied to multiple datatypes by giving a comma separated list of datatypes. For example :<p>
-<p>
-<blockquote><pre>%typemap(tcl,in) int, short, long, signed char {
- $target = ($type) atol($source);
-}
-
-</pre></blockquote>
-Here, <tt>$type</tt> will be expanded into the real datatype during code generation. Datatypes may also carry names as in<p>
-<p>
-<blockquote><pre>%typemap(perl5,in) char **argv {
- ... Turn a perl array into a char ** ...
-}
-
-</pre></blockquote>
-A "named"typemap will only apply to an object that matches both the C datatype and the name. Thus the <tt>char **argv</tt> typemap will only be applied to function arguments that exactly match "<tt>char **argv</tt>". In some cases, the name may correspond to a function name (as is the case for return values).<p>
-<p>
-Finally, there is a shortened form of the typemap directive :<p>
-<p>
-<blockquote><pre>%typemap(method) Datatype {
- ...
-}
-
-</pre></blockquote>
-When the language name is ommitted, the typemap will be applied to the current target language. This form is only recommended for typemap methods that are language independent (there are a few). It is not recommended if you are building interfaces for multiple languages.<p>
-<a name="n33"></a><h3> Deleting a typemap</h3>
-A typemap can be deleted by providing no conversion code. For example :<p>
-<p>
-<blockquote><pre>%typemap(lang,method) Datatype; // Deletes this typemap
-</pre></blockquote>
-<a name="n34"></a><h3> Copying a typemap</h3>
-A typemap can be copied using the following declaration :<p>
-<p>
-<blockquote><pre>%typemap(python,out) unsigned int = int; // Copies a typemap
-
-</pre></blockquote>
-This specifies that the typemap for "<tt>unsigned int</tt>" should be the same as the "<tt>int</tt>" typemap.<p>
-This is most commonly used when working with library files.<p>
-<a name="n35"></a><h3> Typemap matching rules</h3>
-When you specify a typemap, SWIG is going to try and match it with all future occurrences of the datatype you specify. The matching process is based upon the target language, typemap method, datatype, and optional name. Because of this, it is perfectly legal for multiple typemaps to exist for a single datatype at any given time. For example :<p>
-<p>
-<blockquote><pre>%typemap(tcl,in) int * {
- ... Convert an int * ...
-}
-%typemap(tcl,in) int [4] {
- ... Convert an int[4] ...
-}
-%typemap(tcl,in) int out[4] {
- ... Convert an out[4] ...
-}
-%typemap(tcl,in) int *status {
- ... Convert an int *status ...
-}
-
-</pre></blockquote>
-These typemaps all involve the "<tt>int *</tt>" datatype in one way or another, but are all considered to be distinct. There is an extra twist to typemaps regarding the similarity between C pointers and arrays. A typemap applied to a pointer will also work for any array of the same type. On the other hand, a typemap applied to an array will only work for arrays, not pointers. Assuming that you're not completely confused at this point, the following rules are applied in order to match pointers and arrays :<p>
-<p>
-<ul>
-<li>Named arrays
-<li>Unnamed arrays
-<li>Named datatypes
-<li>Unnamed datatypes
-</ul>
-<p>
-The following interface file shows how these rules are applied.<p>
-<p>
-<blockquote><pre>void foo1(int *); // Apply int * typemap
-void foo2(int a[4]); // Apply int[4] typemap
-void foo3(int out[4]); // Apply int out[4] typemap
-void foo4(int *status); // Apply int *status typemap
-void foo5(int a[20]); // Apply int * typemap (because int [20] is an int *)
-
-</pre></blockquote>
-Because SWIG uses a name-based approach, it is possible to attach special properties to named parameters. For example, we can make an argument of "<tt>int *OUTPUT</tt>" always be treated as an output value of a function or make a "<tt>char **argv</tt>" always accept a list of string values.<p>
-<a name="n7"></a><h2> Common typemap methods</h2>
-The following methods are supported by most SWIG language modules. Individual language may provide any number of other methods not listed here.<p>
-<center>
-<img src="ch6.table.1.png"><br>
-<img src="ch6.table.2.png"><br>
-</center>
-<p>
-Understanding how some of these methods are applied takes a little practice and better understanding of what SWIG does when it creates a wrapper function. The next few diagrams show the anatomy of a wrapper function and how the typemaps get applied. More detailed examples of typemaps can be found on the chapters for each target language.<p>
-<p>
-<center><img src="ch6.1.png">
-<p></center>
-<p>
-<center><img src="ch6.2.png">
-<p></center>
-<a name="n8"></a><h2> Writing typemap code</h2>
-The conversion code supplied to a typemap needs to follow a few conventions described here.<p>
-<a name="n36"></a><h3> Scope</h3>
-Typemap code is enclosed in braces when it is inserted into the resulting wrapper code (using C's block-scope). It is perfectly legal to declare local and static variables in a typemap. However, local variables will only exist in the tiny portion of code you supply. In other words, any local variables that you create in a typemap will disappear when the typemap has completed its execution.<p>
-<a name="n37"></a><h3> Creating local variables</h3>
-Sometimes it is necessary to declare a new local variable that exists in the scope of the entire wrapper function. This can be done by specifying a typemap with parameters as follows :<p>
-<p>
-<blockquote><pre>%typemap(tcl,in) int *INPUT(int temp) {
- temp = atoi($source);
- $target = &amp;temp;
-}
-
-</pre></blockquote>
-What happens here is that <tt>temp</tt> becomes a local variable in the scope of the entire wrapper function. When we set it to a value, that values persists for the duration of the wrapper function and gets cleaned up automatically on exit. This is particularly useful when working with pointers and temporary values.<p>
-<p>
-It is perfectly safe to use multiple typemaps involving local variables in the same function. For example, we could declare a function as :<p>
-<p>
-<blockquote><pre>void foo(int *INPUT, int *INPUT, int *INPUT);
-
-</pre></blockquote>
-When this occurs, SWIG will create three different local variables named `temp'. Of course, they don't all end up having the same name---SWIG automatically performs a variable renaming operation if it detects a name-clash like this.<p>
-<p>
-Some typemaps do not recognize local variables (or they may simply not apply). At this time, only the "in", "argout", "default", and "ignore" typemaps use local variables.<p>
-<a name="n38"></a><h3> Special variables</h3>
-The following special variables may be used within a typemap conversion code :<p>
-<center><img src="ch6.table.3.png"></center>
-<p>
-When found in the conversion code, these variables will be replaced with the correct values. Not all values are used in all typemaps. Please refer to the SWIG reference manual for the precise usage. <p>
-<a name="n9"></a><h2> Typemaps for handling arrays</h2>
-One of the most common uses of typemaps is providing some support for arrays. Due to the subtle differences between pointers and arrays in C, array support is somewhat limited unless you provide additional support. For example, consider the following structure appears in an interface file :<p>
-<p>
-<blockquote><pre>struct Person {
- char name[32];
- char address[64];
- int id;
-};
-
-</pre></blockquote>
-When SWIG is run, you will get the following warnings :<p>
-<p>
-<blockquote><pre>swig -python example.i
-Generating wrappers for Python
-example.i : Line 2. Warning. Array member will be read-only.
-example.i : Line 3. Warning. Array member will be read-only.
-</pre></blockquote>
-<p>
-These warning messages indicate that SWIG does not know how you want to set the name and address fields. As a result, you will only be able to query their value.<p>
-<p>
-To fix this, we could supply two typemaps in the file such as the following :<p>
-<blockquote><pre>
-
-%typemap(memberin) char [32] {
- strncpy($target,$source,32);
-}
-%typemap(memberin) char [64] {
- strncpy($target,$source,64);
-}
-
-</pre></blockquote>
-The "memberin" typemap is used to set members of structures and classes. When you run the new version through SWIG, the warnings will go away and you can now set each member. It is important to note that <tt>char[32]</tt> and <tt>char[64]</tt> are different datatypes as far as SWIG typemaps are concerned. However, both typemaps can be combined as follows :<p>
-<p>
-<blockquote><pre>// A better typemap for char arrays
-%typemap(memberin) char [ANY] {
- strncpy($target,$source,$dim0);
-}
-
-</pre></blockquote>
-The <tt>ANY</tt> keyword can be used in a typemap to match any array dimension. When used, the special variable <tt>$dim0</tt> will contain the real dimension of the array and can be used as shown above.<p>
-<p>
-Multidimensional arrays can also be handled by typemaps. For example :<p>
-<p>
-<blockquote><pre>// A typemap for handling any int [][] array
-%typemap(memberin) int [ANY][ANY] {
- int i,j;
- for (i = 0; i &lt; $dim0; i++)
- for (j = 0; j &lt; $dim1; j++) {
- $target[i][j] = *($source+$dim1*i+j);
- }
-}
-
-</pre></blockquote>
-When multi-dimensional arrays are used, the symbols <tt>$dim0,</tt> <tt>$dim1</tt>,<tt> $dim2</tt>, etc... get replaced by the actual array dimensions being used. <p>
-<p>
-The ANY keyword can be combined with any specific dimension. For example :<p>
-<p>
-<blockquote><pre>%typemap(python,in) int [ANY][4] {
- ...
-}
-</pre></blockquote>
-A typemap using a specific dimension always has precedence over a more general version. For example, <tt>[ANY][4]</tt> will be used before<tt>[ANY][ANY]</tt>.<p>
-<a name="n10"></a><h2> Typemaps and the SWIG Library</h2>
-Writing typemaps is a tricky business. For this reason, many common typemaps can be placed into a SWIG library file and reused in other modules without having to worry about nasty underlying details. To do this, you first write a file containing typemaps such as this :<p>
-<p>
-<blockquote><pre>// file : stdmap.i
-// A file containing a variety of useful typemaps
-
-%typemap(tcl,in) int INTEGER {
- ...
-}
-%typemap(tcl,in) double DOUBLE {
- ...
-}
-%typemap(tcl,out) int INT {
- ...
-}
-%typemap(tcl,out) double DOUBLE {
- ...
-}
-%typemap(tcl,argout) double DOUBLE {
- ...
-}
-// and so on...
-
-</pre></blockquote>
-This file may contain dozens or even hundreds of possible mappings. Now, to use this file with other modules, simply include it in other files and use the <tt>%apply</tt> directive :<p>
-<p>
-<blockquote><pre>// interface.i
-// My interface file
-
-%include stdmap.i // Load the typemap library
-
-// Now grab the typemaps we want to use
-%apply double DOUBLE {double};
-
-// Rest of your declarations
-</pre></blockquote>
-<p>
-In this case, <tt>stdmap.i</tt> contains a variety of standard mappings. The <tt>%apply</tt> directive lets us apply specific versions of these to new datatypes without knowing the underlying implementation details.<p>
-<p>
-To clear a typemap that has been applied, you can use the <tt>%clear</tt> directive. For example :<p>
-<p>
-<blockquote><pre>%clear double x; // Clears any typemaps being applied to double x
-</pre></blockquote>
-<a name="n11"></a><h2> Implementing constraints with typemaps</h2>
-One particularly interesting application of typemaps is the implementation of argument constraints. This can be done with the "check" typemap. When used, this allows you to provide code for checking the values of function arguments. For example :<p>
-<p>
-<blockquote><pre>%module math
-
-%typemap(perl5,check) double *posdouble {
- if ($target &lt; 0) {
- croak("Expecting a positive number");
- }
-}
-
-...
-double sqrt(double posdouble);
-
-</pre></blockquote>
-This provides a sanity check to your wrapper function. If a negative number is passed to this function, a Perl exception will be raised and your program terminated with an error message.<p>
-<p>
-This kind of checking can be particularly useful when working with pointers. For example :<p>
-<p>
-<blockquote><pre>%typemap(python,check) Vector * {
- if ($target == 0) {
- PyErr_SetString(PyExc_TypeError,"NULL Pointer not allowed");
- return NULL;
- }
-}
-
-</pre></blockquote>
-will prevent any function involving a <tt>Vector *</tt> from accepting a NULL pointer. As a result, SWIG can often prevent a potential segmentation faults or other run-time problems by raising an exception rather than blindly passing values to the underlying C/C++ program.<p>
-<a name="n12"></a><h2> Typemap examples</h2>
-Typemaps are inherently language dependent so more examples appear in later chapters. The SWIG<tt> Examples </tt>directory also includes a variety of examples. Sophisticated users may gain more by examining the <tt>typemaps.i</tt> and <tt>constraints.i </tt>SWIG library files.<p>
-<a name="n13"></a><h2> How to break everything with a typemap</h2>
-It should be emphasized that typemaps provide a direct mechanism for modifying SWIG's output. As a result, it can be very easy to break almost everything if you don't know what you're doing. For this reason, it should be stressed that typemaps are not required in order to use SWIG with most kinds of applications. Power users, however, will probably find typemaps to be a useful tool for creating extremely powerful scripting language extensions. <p>
-<a name="n14"></a><h2> Typemaps and the future</h2>
-The current typemap mechanism, while new, will probably form the basis of SWIG 2.0. Rather than having code buried away inside a C++ module, it may soon be possible to redefine almost all of SWIG's code generation on the fly. Future language modules will rely upon typemaps almost exclusively. <p>
-<p>
-
-<p><hr>
-
-<address>SWIG 1.1 - Last Modified : Mon Aug 4 10:46:56 1997</address>
-</body>
-</html>
diff --git a/swigweb/Doc1.1/HTML/ch1.1.png b/swigweb/Doc1.1/HTML/ch1.1.png
deleted file mode 100644
index 70705c86d..000000000
--- a/swigweb/Doc1.1/HTML/ch1.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch1.2.png b/swigweb/Doc1.1/HTML/ch1.2.png
deleted file mode 100644
index ad97299ae..000000000
--- a/swigweb/Doc1.1/HTML/ch1.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.1.png b/swigweb/Doc1.1/HTML/ch10.1.png
deleted file mode 100644
index edfde095e..000000000
--- a/swigweb/Doc1.1/HTML/ch10.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.1.png b/swigweb/Doc1.1/HTML/ch10.table.1.png
deleted file mode 100644
index 8495fdf2c..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.10.png b/swigweb/Doc1.1/HTML/ch10.table.10.png
deleted file mode 100644
index 8c1280236..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.10.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.11.png b/swigweb/Doc1.1/HTML/ch10.table.11.png
deleted file mode 100644
index 2849d8e5f..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.11.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.12.png b/swigweb/Doc1.1/HTML/ch10.table.12.png
deleted file mode 100644
index 90802901d..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.12.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.2.png b/swigweb/Doc1.1/HTML/ch10.table.2.png
deleted file mode 100644
index 2e6b9040d..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.3.png b/swigweb/Doc1.1/HTML/ch10.table.3.png
deleted file mode 100644
index afac75d1e..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.3.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.4.png b/swigweb/Doc1.1/HTML/ch10.table.4.png
deleted file mode 100644
index 41537e410..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.4.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.5.png b/swigweb/Doc1.1/HTML/ch10.table.5.png
deleted file mode 100644
index 4f83fba12..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.5.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.6.png b/swigweb/Doc1.1/HTML/ch10.table.6.png
deleted file mode 100644
index feac182b4..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.6.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.7.png b/swigweb/Doc1.1/HTML/ch10.table.7.png
deleted file mode 100644
index e3e93d148..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.7.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.8.png b/swigweb/Doc1.1/HTML/ch10.table.8.png
deleted file mode 100644
index b6e845d54..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.8.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch10.table.9.png b/swigweb/Doc1.1/HTML/ch10.table.9.png
deleted file mode 100644
index 2f82556a1..000000000
--- a/swigweb/Doc1.1/HTML/ch10.table.9.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch11.1.png b/swigweb/Doc1.1/HTML/ch11.1.png
deleted file mode 100644
index 2cc2becd4..000000000
--- a/swigweb/Doc1.1/HTML/ch11.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch11.2.png b/swigweb/Doc1.1/HTML/ch11.2.png
deleted file mode 100644
index e6d1b55ea..000000000
--- a/swigweb/Doc1.1/HTML/ch11.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch11.3.png b/swigweb/Doc1.1/HTML/ch11.3.png
deleted file mode 100644
index 54ee72442..000000000
--- a/swigweb/Doc1.1/HTML/ch11.3.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch12.1.png b/swigweb/Doc1.1/HTML/ch12.1.png
deleted file mode 100644
index 2072f06a4..000000000
--- a/swigweb/Doc1.1/HTML/ch12.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch2.1.png b/swigweb/Doc1.1/HTML/ch2.1.png
deleted file mode 100644
index 1f5800e6e..000000000
--- a/swigweb/Doc1.1/HTML/ch2.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch2.2.png b/swigweb/Doc1.1/HTML/ch2.2.png
deleted file mode 100644
index 4c340df24..000000000
--- a/swigweb/Doc1.1/HTML/ch2.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch3.1.png b/swigweb/Doc1.1/HTML/ch3.1.png
deleted file mode 100644
index fe08d6ad7..000000000
--- a/swigweb/Doc1.1/HTML/ch3.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch5.1.png b/swigweb/Doc1.1/HTML/ch5.1.png
deleted file mode 100644
index 2b233cb35..000000000
--- a/swigweb/Doc1.1/HTML/ch5.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch5.2.png b/swigweb/Doc1.1/HTML/ch5.2.png
deleted file mode 100644
index ac95aa980..000000000
--- a/swigweb/Doc1.1/HTML/ch5.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch5.3.png b/swigweb/Doc1.1/HTML/ch5.3.png
deleted file mode 100644
index 67eaa59e0..000000000
--- a/swigweb/Doc1.1/HTML/ch5.3.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch6.1.png b/swigweb/Doc1.1/HTML/ch6.1.png
deleted file mode 100644
index 30b0fae6c..000000000
--- a/swigweb/Doc1.1/HTML/ch6.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch6.2.png b/swigweb/Doc1.1/HTML/ch6.2.png
deleted file mode 100644
index 01d27d761..000000000
--- a/swigweb/Doc1.1/HTML/ch6.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch6.table.1.png b/swigweb/Doc1.1/HTML/ch6.table.1.png
deleted file mode 100644
index de8905f15..000000000
--- a/swigweb/Doc1.1/HTML/ch6.table.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch6.table.2.png b/swigweb/Doc1.1/HTML/ch6.table.2.png
deleted file mode 100644
index 2f4e002c7..000000000
--- a/swigweb/Doc1.1/HTML/ch6.table.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch6.table.3.png b/swigweb/Doc1.1/HTML/ch6.table.3.png
deleted file mode 100644
index f5083c303..000000000
--- a/swigweb/Doc1.1/HTML/ch6.table.3.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.1.png b/swigweb/Doc1.1/HTML/ch8.1.png
deleted file mode 100644
index fd2f8e7f2..000000000
--- a/swigweb/Doc1.1/HTML/ch8.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.2.png b/swigweb/Doc1.1/HTML/ch8.2.png
deleted file mode 100644
index 46bcf55bb..000000000
--- a/swigweb/Doc1.1/HTML/ch8.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.3.png b/swigweb/Doc1.1/HTML/ch8.3.png
deleted file mode 100644
index 96eac3e32..000000000
--- a/swigweb/Doc1.1/HTML/ch8.3.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.table.1.png b/swigweb/Doc1.1/HTML/ch8.table.1.png
deleted file mode 100644
index 549350484..000000000
--- a/swigweb/Doc1.1/HTML/ch8.table.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.table.2.png b/swigweb/Doc1.1/HTML/ch8.table.2.png
deleted file mode 100644
index 84f1fc8d0..000000000
--- a/swigweb/Doc1.1/HTML/ch8.table.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.table.3.png b/swigweb/Doc1.1/HTML/ch8.table.3.png
deleted file mode 100644
index 3194983ff..000000000
--- a/swigweb/Doc1.1/HTML/ch8.table.3.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.table.4.png b/swigweb/Doc1.1/HTML/ch8.table.4.png
deleted file mode 100644
index 626e3d9a1..000000000
--- a/swigweb/Doc1.1/HTML/ch8.table.4.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.table.5.png b/swigweb/Doc1.1/HTML/ch8.table.5.png
deleted file mode 100644
index 03cb80fcf..000000000
--- a/swigweb/Doc1.1/HTML/ch8.table.5.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.table.6.png b/swigweb/Doc1.1/HTML/ch8.table.6.png
deleted file mode 100644
index ab2350329..000000000
--- a/swigweb/Doc1.1/HTML/ch8.table.6.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch8.table.7.png b/swigweb/Doc1.1/HTML/ch8.table.7.png
deleted file mode 100644
index 787efe8c6..000000000
--- a/swigweb/Doc1.1/HTML/ch8.table.7.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.1.png b/swigweb/Doc1.1/HTML/ch9.1.png
deleted file mode 100644
index b6ccca209..000000000
--- a/swigweb/Doc1.1/HTML/ch9.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.2.png b/swigweb/Doc1.1/HTML/ch9.2.png
deleted file mode 100644
index c55b7d911..000000000
--- a/swigweb/Doc1.1/HTML/ch9.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.3.png b/swigweb/Doc1.1/HTML/ch9.3.png
deleted file mode 100644
index e600293a5..000000000
--- a/swigweb/Doc1.1/HTML/ch9.3.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.1.png b/swigweb/Doc1.1/HTML/ch9.table.1.png
deleted file mode 100644
index e7e2d876d..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.1.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.10.png b/swigweb/Doc1.1/HTML/ch9.table.10.png
deleted file mode 100644
index 9257773a6..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.10.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.2.png b/swigweb/Doc1.1/HTML/ch9.table.2.png
deleted file mode 100644
index ac6647e17..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.2.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.3.png b/swigweb/Doc1.1/HTML/ch9.table.3.png
deleted file mode 100644
index 0992c6ec9..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.3.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.4.png b/swigweb/Doc1.1/HTML/ch9.table.4.png
deleted file mode 100644
index b9f910a4e..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.4.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.5.png b/swigweb/Doc1.1/HTML/ch9.table.5.png
deleted file mode 100644
index 4e56e5392..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.5.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.6.png b/swigweb/Doc1.1/HTML/ch9.table.6.png
deleted file mode 100644
index bff037cdf..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.6.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.7.png b/swigweb/Doc1.1/HTML/ch9.table.7.png
deleted file mode 100644
index 533ea699d..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.7.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.8.png b/swigweb/Doc1.1/HTML/ch9.table.8.png
deleted file mode 100644
index b794fa61d..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.8.png
+++ /dev/null
Binary files differ
diff --git a/swigweb/Doc1.1/HTML/ch9.table.9.png b/swigweb/Doc1.1/HTML/ch9.table.9.png
deleted file mode 100644
index 55b0e501f..000000000
--- a/swigweb/Doc1.1/HTML/ch9.table.9.png
+++ /dev/null
Binary files differ