1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
/******************************************************************************
* $Id: csmodule.i,v 1.12 2006/05/25 15:59:33 tamas Exp $
*
* Project: MapServer
* Purpose: C#-specific enhancements to MapScript
* Author: Tamas Szekeres, szekerest@gmail.com
*
******************************************************************************
*
* C#-specific mapscript code has been moved into this
* SWIG interface file to improve the readibility of the main
* interface file. The main mapscript.i file includes this
* file when SWIGCSHARP is defined (via 'swig -csharp ...').
*
*****************************************************************************/
/*Uncomment the following lines if you want to receive subsequent exceptions as
inner exceptions. Otherwise the exception message will be concatenated*/
//#if SWIG_VERSION >= 0x010329
//#define ALLOW_INNER_EXCEPTIONS
//#endif
%ignore fp;
/******************************************************************************
* Module initialization helper (bug 1665)
*****************************************************************************/
%pragma(csharp) imclasscode=%{
protected class $moduleHelper
{
static $moduleHelper()
{
$module.msSetup();
}
~$moduleHelper()
{
//$module.msCleanup();
}
}
protected static $moduleHelper the$moduleHelper = new $moduleHelper();
%}
/******************************************************************************
* C# exception redefinition
*****************************************************************************/
#ifdef ALLOW_INNER_EXCEPTIONS
%exception
{
errorObj *ms_error;
$action
ms_error = msGetErrorObj();
if (ms_error != NULL && ms_error->code != MS_NOERR) {
if (ms_error->code != MS_NOTFOUND && ms_error->code != -1) {
int ms_errorcode = ms_error->code;
while (ms_error!=NULL && ms_error->code != MS_NOERR) {
char* msg = msAddErrorDisplayString(NULL, ms_error);
if (msg) {
SWIG_CSharpException(SWIG_SystemError, msg);
free(msg);
}
else SWIG_CSharpException(SWIG_SystemError, "MapScript unknown error");
ms_error = ms_error->next;
}
msResetErrorList();
return $null;
}
msResetErrorList();
}
}
#else
%exception
{
errorObj *ms_error;
$action
ms_error = msGetErrorObj();
if (ms_error != NULL && ms_error->code != MS_NOERR) {
if (ms_error->code != MS_NOTFOUND && ms_error->code != -1) {
char* msg = msGetErrorString(";");
if (msg) {
SWIG_CSharpException(SWIG_SystemError, msg);
free(msg);
}
else SWIG_CSharpException(SWIG_SystemError, "MapScript unknown error");
msResetErrorList();
return $null;
}
msResetErrorList();
}
}
#endif
/******************************************************************************
* typemaps for string arrays (for supporting map templates)
*****************************************************************************/
%pragma(csharp) imclasscode=%{
public class StringArrayMarshal : IDisposable {
public readonly IntPtr[] _ar;
public StringArrayMarshal(string[] ar) {
_ar = new IntPtr[ar.Length];
for (int cx = 0; cx < _ar.Length; cx++) {
_ar[cx] = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(ar[cx]);
}
}
public virtual void Dispose() {
for (int cx = 0; cx < _ar.Length; cx++) {
System.Runtime.InteropServices.Marshal.FreeHGlobal(_ar[cx]);
}
GC.SuppressFinalize(this);
}
}
%}
%typemap(imtype, out="IntPtr") char** "IntPtr[]"
%typemap(cstype) char** %{string[]%}
%typemap(in) char** %{ $1 = ($1_ltype)$input; %}
%typemap(out) char** %{ $result = $1; %}
%typemap(csin) char** "new $modulePINVOKE.StringArrayMarshal($csinput)._ar"
%typemap(csout, excode=SWIGEXCODE) char** {
$excode
throw new System.NotSupportedException("Returning string arrays is not implemented yet.");
}
%typemap(csvarin, excode=SWIGEXCODE2) char** %{
set {
$excode
throw new System.NotSupportedException("Setting string arrays is not supported now.");
}
%}
/* specializations */
%typemap(csvarout, excode=SWIGEXCODE2) char** formatoptions %{
get {
IntPtr cPtr = $imcall;
IntPtr objPtr;
string[] ret = new string[this.numformatoptions];
for(int cx = 0; cx < this.numformatoptions; cx++) {
objPtr = System.Runtime.InteropServices.Marshal.ReadIntPtr(cPtr, cx * System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)));
ret[cx]= (objPtr == IntPtr.Zero) ? null : System.Runtime.InteropServices.Marshal.PtrToStringAnsi(objPtr);
}
$excode
return ret;
}
%}
%typemap(csvarout, excode=SWIGEXCODE2) char** values %{
get {
IntPtr cPtr = $imcall;
IntPtr objPtr;
string[] ret = new string[this.numvalues];
for(int cx = 0; cx < this.numvalues; cx++) {
objPtr = System.Runtime.InteropServices.Marshal.ReadIntPtr(cPtr, cx * System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)));
ret[cx]= (objPtr == IntPtr.Zero) ? null : System.Runtime.InteropServices.Marshal.PtrToStringAnsi(objPtr);
}
$excode
return ret;
}
%}
/******************************************************************************
* typemaps for outputFormatObj arrays
*****************************************************************************/
%typemap(ctype) outputFormatObj** "void*"
%typemap(imtype) outputFormatObj** "IntPtr"
%typemap(cstype) outputFormatObj** "outputFormatObj[]"
%typemap(out) outputFormatObj** %{ $result = $1; %}
%typemap(csout, excode=SWIGEXCODE) outputFormatObj** {
IntPtr cPtr = $imcall;
IntPtr objPtr;
outputFormatObj[] ret = new outputFormatObj[this.numoutputformats];
for(int cx = 0; cx < this.numoutputformats; cx++) {
objPtr = System.Runtime.InteropServices.Marshal.ReadIntPtr(cPtr, cx * System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)));
ret[cx] = (objPtr == IntPtr.Zero) ? null : new outputFormatObj(objPtr, false);
}
$excode
return ret;
}
%typemap(csvarout, excode=SWIGEXCODE2) outputFormatObj** %{
get {
IntPtr cPtr = $imcall;
IntPtr objPtr;
outputFormatObj[] ret = new outputFormatObj[this.numoutputformats];
for(int cx = 0; cx < this.numoutputformats; cx++) {
objPtr = System.Runtime.InteropServices.Marshal.ReadIntPtr(cPtr, cx * System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)));
ret[cx] = (objPtr == IntPtr.Zero) ? null : new outputFormatObj(objPtr, false);
}
$excode
return ret;
}
%}
/******************************************************************************
* gdBuffer Typemaps and helpers
*****************************************************************************/
%pragma(csharp) imclasscode=%{
public delegate void SWIGByteArrayDelegate(IntPtr data, int size);
%}
%insert(runtime) %{
/* Callback for returning byte arrays to C# */
typedef void (SWIGSTDCALL* SWIG_CSharpByteArrayHelperCallback)(const unsigned char *, const int);
/* Default callback interface */
static SWIG_CSharpByteArrayHelperCallback SWIG_csharp_bytearray_callback = NULL;
%}
%typemap(ctype) SWIG_CSharpByteArrayHelperCallback %{SWIG_CSharpByteArrayHelperCallback%}
%typemap(imtype) SWIG_CSharpByteArrayHelperCallback %{SWIGByteArrayDelegate%}
%typemap(cstype) SWIG_CSharpByteArrayHelperCallback %{$modulePINVOKE.SWIGByteArrayDelegate%}
%typemap(in) SWIG_CSharpByteArrayHelperCallback %{ $1 = ($1_ltype)$input; %}
%typemap(csin) SWIG_CSharpByteArrayHelperCallback "$csinput"
%csmethodmodifiers getBytes "private";
%ignore imageObj::getBytes();
%extend imageObj
{
void getBytes(SWIG_CSharpByteArrayHelperCallback callback) {
gdBuffer buffer;
buffer.data = msSaveImageBufferGD(self->img.gd, &buffer.size,
self->format);
if( buffer.size == 0 )
{
msSetError(MS_MISCERR, "Failed to get image buffer", "getBytes");
return;
}
callback(buffer.data, buffer.size);
gdFree(buffer.data);
}
}
%ignore imageObj::write;
%typemap(cscode) imageObj %{
private byte[] gdbuffer;
private void CreateByteArray(IntPtr data, int size)
{
gdbuffer = new byte[size];
Marshal.Copy(data, gdbuffer, 0, size);
}
public byte[] getBytes()
{
getBytes(new $modulePINVOKE.SWIGByteArrayDelegate(this.CreateByteArray));
return gdbuffer;
}
public void write(System.IO.Stream stream)
{
getBytes(new $modulePINVOKE.SWIGByteArrayDelegate(this.CreateByteArray));
stream.Write(gdbuffer, 0, gdbuffer.Length);
}
%}
%typemap(ctype) gdBuffer %{void%}
%typemap(imtype) gdBuffer %{void%}
%typemap(cstype) gdBuffer %{byte[]%}
%typemap(out, null="") gdBuffer
%{ SWIG_csharp_bytearray_callback($1.data, $1.size);
if( $1.owns_data ) gdFree($1.data); %}
// SWIGEXCODE is a macro used by many other csout typemaps
#ifdef SWIGEXCODE
%typemap(csout, excode=SWIGEXCODE) gdBuffer {
$imcall;$excode
return $modulePINVOKE.GetBytes();
}
#else
%typemap(csout) gdBuffer {
$imcall;
return $modulePINVOKE.GetBytes();
}
#endif
%pragma(csharp) imclasscode=%{
protected class SWIGByteArrayHelper
{
public delegate void SWIGByteArrayDelegate(IntPtr data, int size);
static SWIGByteArrayDelegate bytearrayDelegate = new SWIGByteArrayDelegate(CreateByteArray);
[DllImport("$dllimport", EntryPoint="SWIGRegisterByteArrayCallback_$module")]
public static extern void SWIGRegisterByteArrayCallback_mapscript(SWIGByteArrayDelegate bytearrayDelegate);
static void CreateByteArray(IntPtr data, int size)
{
arraybuffer = new byte[size];
Marshal.Copy(data, arraybuffer, 0, size);
}
static SWIGByteArrayHelper()
{
SWIGRegisterByteArrayCallback_$module(bytearrayDelegate);
}
}
protected static SWIGByteArrayHelper bytearrayHelper = new SWIGByteArrayHelper();
[ThreadStatic]
private static byte[] arraybuffer;
internal static byte[] GetBytes()
{
return arraybuffer;
}
%}
%insert(runtime) %{
#ifdef __cplusplus
extern "C"
#endif
#ifdef SWIGEXPORT
SWIGEXPORT void SWIGSTDCALL SWIGRegisterByteArrayCallback_$module(SWIG_CSharpByteArrayHelperCallback callback) {
SWIG_csharp_bytearray_callback = callback;
}
#else
DllExport void SWIGSTDCALL SWIGRegisterByteArrayCallback_$module(SWIG_CSharpByteArrayHelperCallback callback) {
SWIG_csharp_bytearray_callback = callback;
}
#endif
%}
/******************************************************************************
* Preventing to take ownership of the memory when constructing objects
* with parent objects (causing nullreference exception, Bug 1743)
*****************************************************************************/
%typemap(csconstruct, excode=SWIGEXCODE) layerObj(mapObj map) %{: this($imcall, true) {
if (map != null) this.swigCMemOwn = false;$excode
}
%}
%typemap(csconstruct, excode=SWIGEXCODE) classObj(layerObj layer) %{: this($imcall, true) {
if (layer != null) this.swigCMemOwn = false;$excode
}
%}
%typemap(csconstruct, excode=SWIGEXCODE) styleObj(classObj parent_class) %{: this($imcall, true) {
if (parent_class != null) this.swigCMemOwn = false;$excode
}
%}
|