git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
206 lines
5.4 KiB
Text
206 lines
5.4 KiB
Text
/***********************************************************************
|
|
* common.swg
|
|
*
|
|
* This file contains generic SWIG runtime support for pointer
|
|
* type checking as well as a few commonly used macros to control
|
|
* external linkage.
|
|
*
|
|
* Author : David Beazley (beazley@cs.uchicago.edu)
|
|
*
|
|
* Copyright (c) 1999-2000, The University of Chicago
|
|
*
|
|
* This file may be freely redistributed without license or fee provided
|
|
* this copyright message remains intact.
|
|
************************************************************************/
|
|
|
|
#include <string.h>
|
|
|
|
#if defined(_WIN32) || defined(__WIN32__)
|
|
# if defined(_MSC_VER)
|
|
# if defined(STATIC_LINKED)
|
|
# define SWIGEXPORT(a) a
|
|
# define SWIGIMPORT(a) extern a
|
|
# else
|
|
# define SWIGEXPORT(a) __declspec(dllexport) a
|
|
# define SWIGIMPORT(a) extern a
|
|
# endif
|
|
# else
|
|
# if defined(__BORLANDC__)
|
|
# define SWIGEXPORT(a) a _export
|
|
# define SWIGIMPORT(a) a _export
|
|
# else
|
|
# define SWIGEXPORT(a) a
|
|
# define SWIGIMPORT(a) a
|
|
# endif
|
|
# endif
|
|
#else
|
|
# define SWIGEXPORT(a) a
|
|
# define SWIGIMPORT(a) a
|
|
#endif
|
|
|
|
#ifdef SWIG_GLOBAL
|
|
#define SWIGRUNTIME(a) SWIGEXPORT(a)
|
|
#else
|
|
#define SWIGRUNTIME(a) static a
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef void *(*swig_converter_func)(void *);
|
|
typedef struct swig_type_info *(*swig_dycast_func)(void **);
|
|
|
|
typedef struct swig_type_info {
|
|
const char *name;
|
|
swig_converter_func converter;
|
|
const char *str;
|
|
void *clientdata;
|
|
swig_dycast_func dcast;
|
|
struct swig_type_info *next;
|
|
struct swig_type_info *prev;
|
|
} swig_type_info;
|
|
|
|
#ifdef SWIG_NOINCLUDE
|
|
|
|
SWIGIMPORT(swig_type_info *) SWIG_TypeRegister(swig_type_info *);
|
|
SWIGIMPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);
|
|
SWIGIMPORT(void *) SWIG_TypeCast(swig_type_info *, void *);
|
|
SWIGIMPORT(swig_type_info *) SWIG_TypeDynamicCast(swig_type_info *, void **);
|
|
SWIGIMPORT(const char *) SWIG_TypeName(const swig_type_info *);
|
|
SWIGIMPORT(swig_type_info *) SWIG_TypeQuery(const char *);
|
|
SWIGIMPORT(void) SWIG_TypeClientData(swig_type_info *, void *);
|
|
|
|
#else
|
|
|
|
static swig_type_info *swig_type_list = 0;
|
|
|
|
/* Register a type mapping with the type-checking */
|
|
SWIGRUNTIME(swig_type_info *)
|
|
SWIG_TypeRegister(swig_type_info *ti)
|
|
{
|
|
swig_type_info *tc, *head, *ret, *next;
|
|
/* Check to see if this type has already been registered */
|
|
tc = swig_type_list;
|
|
while (tc) {
|
|
if (strcmp(tc->name, ti->name) == 0) {
|
|
/* Already exists in the table. Just add additional types to the list */
|
|
if (tc->clientdata) ti->clientdata = tc->clientdata;
|
|
head = tc;
|
|
next = tc->next;
|
|
goto l1;
|
|
}
|
|
tc = tc->prev;
|
|
}
|
|
head = ti;
|
|
next = 0;
|
|
|
|
/* Place in list */
|
|
ti->prev = swig_type_list;
|
|
swig_type_list = ti;
|
|
|
|
/* Build linked lists */
|
|
l1:
|
|
ret = head;
|
|
tc = ti + 1;
|
|
/* Patch up the rest of the links */
|
|
while (tc->name) {
|
|
head->next = tc;
|
|
tc->prev = head;
|
|
head = tc;
|
|
tc++;
|
|
}
|
|
head->next = next;
|
|
return ret;
|
|
}
|
|
|
|
/* Check the typename */
|
|
SWIGRUNTIME(swig_type_info *)
|
|
SWIG_TypeCheck(char *c, swig_type_info *ty)
|
|
{
|
|
swig_type_info *s;
|
|
if (!ty) return 0; /* Void pointer */
|
|
s = ty->next; /* First element always just a name */
|
|
do {
|
|
if (strcmp(s->name,c) == 0) {
|
|
if (s == ty->next) return s;
|
|
/* Move s to the top of the linked list */
|
|
s->prev->next = s->next;
|
|
if (s->next) {
|
|
s->next->prev = s->prev;
|
|
}
|
|
/* Insert s as second element in the list */
|
|
s->next = ty->next;
|
|
if (ty->next) ty->next->prev = s;
|
|
ty->next = s;
|
|
return s;
|
|
}
|
|
s = s->next;
|
|
} while (s && (s != ty->next));
|
|
return 0;
|
|
}
|
|
|
|
/* Cast a pointer up an inheritance hierarchy */
|
|
SWIGRUNTIME(void *)
|
|
SWIG_TypeCast(swig_type_info *ty, void *ptr)
|
|
{
|
|
if ((!ty) || (!ty->converter)) return ptr;
|
|
return (*ty->converter)(ptr);
|
|
}
|
|
|
|
/* Dynamic pointer casting. Down an inheritance hierarchy */
|
|
SWIGRUNTIME(swig_type_info *)
|
|
SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr)
|
|
{
|
|
swig_type_info *lastty = ty;
|
|
if (!ty || !ty->dcast) return ty;
|
|
while (ty && (ty->dcast)) {
|
|
ty = (*ty->dcast)(ptr);
|
|
if (ty) lastty = ty;
|
|
}
|
|
return lastty;
|
|
}
|
|
|
|
/* Return the name associated with this type */
|
|
SWIGRUNTIME(const char *)
|
|
SWIG_TypeName(const swig_type_info *ty) {
|
|
return ty->name;
|
|
}
|
|
|
|
/* Search for a swig_type_info structure */
|
|
SWIGRUNTIME(swig_type_info *)
|
|
SWIG_TypeQuery(const char *name) {
|
|
swig_type_info *ty = swig_type_list;
|
|
while (ty) {
|
|
if (ty->str && (strcmp(name,ty->str) == 0)) return ty;
|
|
if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
|
|
ty = ty->prev;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* Set the clientdata field for a type */
|
|
SWIGRUNTIME(void)
|
|
SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
|
|
swig_type_info *tc, *equiv;
|
|
if (ti->clientdata == clientdata) return;
|
|
ti->clientdata = clientdata;
|
|
equiv = ti->next;
|
|
while (equiv) {
|
|
if (!equiv->converter) {
|
|
tc = swig_type_list;
|
|
while (tc) {
|
|
if ((strcmp(tc->name, equiv->name) == 0))
|
|
SWIG_TypeClientData(tc,clientdata);
|
|
tc = tc->prev;
|
|
}
|
|
}
|
|
equiv = equiv->next;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
|
|
#endif
|