SWIG Library Reference

  
Version 1.1 Beta 2
December, 1996

Copyright (C) 1996
Dave Beazley

(This file was automatically generated by SWIG)
  

Contents


1. Introduction


This file describes all of the functions in the generic SWIG library.
The SWIG library is a collection of generally useful functions that
can be used to supplement an interface file.  These include functions
to manipulate arrays, functions from the C library, and interesting
modules.

This document is automatically generated by SWIG from the file 
"swig_lib/autodoc.i".   Some modules may supply additional documentation
for a particular target language.  To recreate the documentation for
a particular target language, simply run SWIG on the file 'autodoc.i'
with the appropriate target language option.

This document has been generated for Tcl.

1.1. Call for contributions


My long-term goal is for the SWIG library to be a collection of useful
modules that can be used to quickly put together interesting programs.
To contribute new modules send e-mail to beazley@cs.utah.edu and I
will include them here.

2. Character Class Testing Module


%include ctype.i

This module provides access to a number of functions for testing
characters.   These functions are in the C <ctype.h> library.
Most scripting languages already provide much of this functionality,
but just in case you want to use one of the built-in C functions,
you can use this module.

isalnum c

[ returns int  ]
Returns 1 if isalpha(c) or isdigit(c) is true.   

isalpha c

[ returns int  ]
Returns 1 if isupper(c) or islower(c) is true.   

iscntrl c

[ returns int  ]
Returns 1 if c is a control character.   

isdigit c

[ returns int  ]
Returns 1 if c is a decimal digit.   

isgraph c

[ returns int  ]
Returns 1 if c is a printing character except space.   

islower c

[ returns int  ]
Returns 1 if c is a lower-case letter.   

isprint c

[ returns int  ]
Returns 1 if c is a printing character including space.   

ispunct c

[ returns int  ]
Returns 1 if c is a printing character except space or letter
or digit.   

isspace c

[ returns int  ]
Returns 1 if c is a space, formfeed, newline, carriage return,
tab, or vertical tab.   

isupper c

[ returns int  ]
Returns 1 if c is an upper case letter.   

isxdigit c

[ returns int  ]
Returns 1 if c is a hexadecimal digit.   

tolower c

[ returns char  ]
Converts c to lower case   

toupper c

[ returns char  ]
Converts c to upper case   

3. Memory Allocation Module


%include malloc.i

This module provides access to a few basic C memory management functions.
All functions return void pointers, but realloc() and free() will operate
on any sort of pointer.   Sizes should be specified in bytes.

calloc nobj size

[ returns void * ]
Returns a pointer to a space for an array of nobj objects, each with
size bytes.   Returns NULL if the request can't be satisfied. 
Initializes the space to zero bytes.   

malloc size

[ returns void * ]
Returns a pointer to space for an object of size bytes.  Returns NULL
upon failure.   

realloc ptr size

[ returns void * ]
Changes the size of the object pointed to by ptr to size bytes. 
The contents will be unchanged up the minimum of the old and new
sizes.  Returns a pointer to the new space of NULL upon failure,
in which case *ptr is unchanged.   

free ptr

[ returns void  ]
Deallocates the space pointed to by ptr.  Does nothing if ptr is NULL.
ptr must be a space previously allocated by calloc, malloc, or realloc.   

4. Memory Manipulation Module


%include memory.i

This module provides support for a few memory operations from the C
<string.h> library.  These functions can be used to manipulate binary
data. s and t are of type void *, cs and ct are both of type const void *.

memcpy s ct n

[ returns void * ]
Copy n characters from ct to s, and return s   

memmove s ct n

[ returns void * ]
Same as memcpy except that it works even if the objects overlap.   

memcmp cs ct n

[ returns int  ]
Compare the first n characters of cs with ct.  Returns 0 if
they are equal, <0 if cs < ct, and >0 if cs > ct.   

memchr cs c n

[ returns void * ]
Returns pointer to the first occurrence of character c in cs.   

memset s c n

[ returns void * ]
Place character c into first n characters of s, return s   

5. Perl Library Files


The following modules are available when using the Perl5 language
module.

5.1. perlmain.i


This module provides support for building a new version of the
Perl executable.  This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions.  

This module may only build a stripped down version of the
Perl executable.   Thus, it may be necessary (or desirable)
to hand-edit this file for your particular application.  To
do this, simply copy this file from swig_lib/perl5/perlmain.i
to your working directory and make the appropriate modifications.

This library file works with Perl 5.003.  It may work with earlier
versions, but it hasn't been tested.  As far as I know, this
library is C++ safe.

6. Python Library Files


The following modules are available when using the Python language
module.

6.1. embed.i


This module provides support for building a new version of the
Python executable.  This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions.  This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.

This module will automatically grab all of the Python modules
present in your current Python executable (including any special
purpose modules you have enabled such as tkinter).   Thus, you
may need to provide additional link libraries when compiling.

This library file only works with Python 1.4.  A version 
compatible with Python 1.3 is available as embed13.i.  As far
as I know, this module is C++ safe (well, it works for me).

6.2. embed13.i


This module provides support for building a new version of the
Python 1.3 executable.  This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions.  This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.

This module is functionally equivalent to the embed.i library,
but has a number of changes needed to work with older versions
of Python.

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 :

   <type>_array(size)              : Create a new array of given size
   <type>_get(array, index)        : Get an element from the array
   <type>_set(array, index, value) : Set an element in the array
   <type>_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 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

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.   

8. SWIG Math Module


%include math.i

This module provides access to the C math library and contains most
of the functions in <math.h>.  Most scripting languages already provide
math support, but in certain cases, this module can provide more
direct access.

8.1. Functions


cos x

[ returns double  ]
Cosine of x   

sin x

[ returns double  ]
Sine of x   

tan x

[ returns double  ]
Tangent of x   

acos x

[ returns double  ]
Inverse cosine in range [-PI/2,PI/2], x in [-1,1].   

asin x

[ returns double  ]
Inverse sine in range [0,PI], x in [-1,1].   

atan x

[ returns double  ]
Inverse tangent in range [-PI/2,PI/2].   

atan2 y x

[ returns double  ]
Inverse tangent of y/x in range [-PI,PI].   

cosh x

[ returns double  ]
Hyperbolic cosine of x   

sinh x

[ returns double  ]
Hyperbolic sine of x   

tanh x

[ returns double  ]
Hyperbolic tangent of x   

exp x

[ returns double  ]
Natural exponential function e^x   

log x

[ returns double  ]
Natural logarithm ln(x), x > 0   

log10 x

[ returns double  ]
Base 10 logarithm, x > 0   

pow x y

[ returns double  ]
Power function x^y.   

sqrt x

[ returns double  ]
Square root. x >= 0   

fabs x

[ returns double  ]
Absolute value of x   

ceil x

[ returns double  ]
Smallest integer not less than x, as a double   

floor x

[ returns double  ]
Largest integer not greater than x, as a double   

fmod x y

[ returns double  ]
Floating-point remainder of x/y, with the same sign as x.   

8.2. Mathematical constants


$M_E = 2.7182818284590452354

$M_LOG2E = 1.4426950408889634074

$M_LOG10E = 0.43429448190325182765

$M_LN2 = 0.69314718055994530942

$M_LN10 = 2.30258509299404568402

$M_PI = 3.14159265358979323846

$M_PI_2 = 1.57079632679489661923

$M_PI_4 = 0.78539816339744830962

$M_1_PI = 0.31830988618379067154

$M_2_PI = 0.63661977236758134308

$M_2_SQRTPI = 1.12837916709551257390

$M_SQRT2 = 1.41421356237309504880

$M_SQRT1_2 = 0.70710678118654752440


9. Tcl Library Files


The following library modules are available when using the Tcl
language module.

9.1. tclsh.i


This module provides the Tcl_AppInit() function needed to build a 
new version of the tclsh executable.   This file should not be used
when using dynamic loading.   To make an interface file work with
both static and dynamic loading, put something like this in your
interface file :

     #ifdef STATIC
     %include tclsh.i
     #endif

9.2. wish.i


This module provides the Tk_AppInit() function needed to build a 
new version of the wish executable.   Like tclsh.i, this file should
not be used with dynamic loading.  To make an interface file work with
both static and dynamic loading, put something like this in your
interface file :

     #ifdef STATIC
     %include wish.i
     #endif

A startup file may be specified by defining the symbol SWIG_RcFileName
as follows (this should be included in a code-block) :

     #define SWIG_RcFileName    "~/.mywishrc"

9.3. expect.i


This module provides a main() function for building an extended version of
Expect.  It has been tested with Expect 5.19, but may need modification
for newer versions.

9.4. expectk.i


This module provides a main() function for building an extended version of
expectk.  It has been tested with Expect 5.19, but may need modification
for newer versions.

9.5. blt.i


This module initializes the BLT package.  This is usually done in
combination with the wish.i or similar module.  For example :

      %include wish.i        // Build a new wish executable
      %include blt.i         // Initialize BLT

9.6. tix.i


This module initializes the Tix extension.  This is usually done in
combination with the wish.i or similar module.  For example :

      %include wish.i        // Build a new wish executable
      %include tix.i         // Initialize Tix

9.7. ish.i


This module provides a main() program needed to build a new version
of the [incr Tcl] 'ish' executable.  It has been tested with itcl 2.1,
but may need tweaking for later versions and for use with C++.

9.8. itclsh.i


This module provides a main() program needed to build a new version
of the [incr Tcl] 'itclsh' executable.  It has been tested with itcl 2.1,
but may need tweaking for later versions and for use with C++.

9.9. iwish.i


This module provides a main() program needed to build a new version
of the [incr Tcl] 'iwish' executable.  It has been tested with itcl 2.1,
but may need tweaking for later versions and for use with C++.

9.10. itkwish.i


This module provides a main() program needed to build a new version
of the [incr Tcl] 'itkwish' executable.  It has been tested with itcl 2.1,
but may need tweaking for later versions and for use with C++.

10. Timer Functions


%include timers.i

This module provides a collection of timing functions designed for
performance analysis and benchmarking of different code fragments. 

A total of 64 different timers are available.   Each timer can be
managed independently using four functions :

    timer_clear(int n)          Clears timer n
    timer_start(int n)          Start timer n
    timer_stop(int n)           Stop timer n
    timer_elapsed(int n)        Return elapsed time (in seconds)

All timers measure CPU time.

Since each timer can be accessed independently, it is possible
to use groups of timers for measuring different aspects of code
performance.   To use a timer, simply use code like this :

      timer_clear 0
      timer_start 0
      .. a bunch of Tcl code ...
      timer_stop 0
      puts "[timer_elapsed 0] seconds of CPU time"

A single timer can be stopped and started repeatedly to provide
a cummulative timing effect.

As a general performance note, making frequent calls to the timing
functions can severely degrade performance (due to operating system
overhead).   The resolution of the timers may be poor for extremely
short code fragments.   Therefore, the timers work best for
computationally intensive operations.

timer_clear n

[ returns void  ]
Clears timer n.   

timer_start n

[ returns void  ]
Starts timer n.   

timer_stop n

[ returns void  ]
Stops timer n.   

timer_elapsed n

[ returns double  ]
Return the elapsed time (in seconds) of timer n