summaryrefslogtreecommitdiff
path: root/Lib/objc/objc.swg
blob: 0956868440ff57d0dc0fd93cdb95d5e1552b76ab (plain)
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/* -----------------------------------------------------------------------------
 * objc.swg
 *
 * Objective-C typemaps
 * ----------------------------------------------------------------------------- */

%include <objchead.swg>


/* Following are the objcimtype typemaps which contain the Objective-C or C++ types used in the intermediary code */
// Primitive types
%typemap(objcimtype) bool,               const bool &               "BOOL"
%typemap(objcimtype) char,               const char &               "char"
%typemap(objcimtype) signed char,        const signed char &        "signed char"
%typemap(objcimtype) unsigned char,      const unsigned char &      "unsigned char"
%typemap(objcimtype) short,              const short &              "short"
%typemap(objcimtype) unsigned short,     const unsigned short &     "unsigned short"
%typemap(objcimtype) int,                const int &                "int"
%typemap(objcimtype) unsigned int,       const unsigned int &       "unsigned int"
%typemap(objcimtype) long,               const long &               "long"
%typemap(objcimtype) unsigned long,      const unsigned long &      "unsigned long"
%typemap(objcimtype) long long,          const long long &          "long long"
%typemap(objcimtype) unsigned long long, const unsigned long long & "unsigned long long"
%typemap(objcimtype) float,              const float &              "float"
%typemap(objcimtype) double,             const double &             "double"
%typemap(objcimtype) void                                           "void"

// Pointers, references and arrays
%typemap(objcimtype) char *, char *&, char[ANY], char[]   "NSString *"
%typemap(objcimtype) SWIGTYPE "void *"
%typemap(objcimtype) SWIGTYPE [] "void *"
%typemap(objcimtype) SWIGTYPE *  "void *" 
%typemap(objcimtype) SWIGTYPE & "void *"

// Pointer to a class member
%typemap(objcimtype) SWIGTYPE (CLASS::*) "void*"


/* Following are the "in" typemaps for Objective-C/C++ to C conversions */
// Primitive types
%typemap(in) char, 
             signed char, 
             unsigned char, 
             short, 
             unsigned short, 
             int, 
             unsigned int, 
             long, 
             unsigned long, 
             long long, 
             unsigned long long, 
             float, 
             double
%{ $1 = $input; %}
%typemap(in) bool
%{ $1 = $input ? true : false; %}


// Pointer, references and arrays
%typemap(in, noblock=1) char * {
 $1 = 0;
  if ($input) {
		int length = [$input length];
		int bufferSize = sizeof(char) * (length + 1);
		char *buffer = (char*)malloc(bufferSize);
		memset(buffer, 0, bufferSize);
		int i = 0;
		for (; i < length; ++i)
			buffer[i] = [$input characterAtIndex: i];
			$1 = buffer;
	}
	if (!$1) return $null;
}

%typemap(in, noblock=1) char *& ($*1_ltype temp = 0) {
 $1 = 0;
  if ($input) {
		int length = [$input length];
		int bufferSize = sizeof(char) * (length + 1);
		char *buffer = (char*)malloc(bufferSize);
		memset(buffer, 0, bufferSize);
		int i = 0;
		for (; i < length; ++i)
			buffer[i] = [$input characterAtIndex: i];
    temp = ($*1_ltype)buffer;
    if (!temp) return $null;
  }
  $1 = &temp;
}


%typemap(in) char[ANY]
%{ 
	 $1 = 0;
  if ($input) {
		int length = [$input length];
		int bufferSize = sizeof(char) * (length + 1);
		char *buffer = (char*)malloc(bufferSize);
		memset(buffer, 0, bufferSize);
		int i = 0;
		for (; i < length; ++i)
			buffer[i] = [$input characterAtIndex: i];
			$1 = buffer;
	}
	if (!$1) return $null;
%}

%typemap(in) char[]
%{ 
	$1 = 0;
  if ($input) {
		int length = [$input length];
		int bufferSize = sizeof(char) * (length + 1);
		char *buffer = (char*)malloc(bufferSize);
		memset(buffer, 0, bufferSize);
		int i = 0;
		for (; i < length; ++i)
			buffer[i] = [$input characterAtIndex: i];
			$1 = buffer;
	}
	if (!$1) return $null;
%}

%typemap(in) SWIGTYPE *
%{ $1 = ($1_ltype)$input; %}
%typemap(in) SWIGTYPE &
%{ $1 = ($1_ltype)$input; %} //TBD
%typemap(in) SWIGTYPE []
%{ $1 = ($1_ltype)$input; %} //TBD
%typemap(in) SWIGTYPE
%{ $1 = ($1_ltype)$input; %} //TBD

%typemap(in) const bool & ($*1_ltype temp)
%{ temp = $input ? true : false; 
   $1 = &temp; %}

%typemap(in) const char & ($*1_ltype temp), 
             const signed char & ($*1_ltype temp), 
             const unsigned char & ($*1_ltype temp), 
             const short & ($*1_ltype temp), 
             const unsigned short & ($*1_ltype temp), 
             const int & ($*1_ltype temp), 
             const unsigned int & ($*1_ltype temp), 
             const long & ($*1_ltype temp), 
             const unsigned long & ($*1_ltype temp), 
             const long long & ($*1_ltype temp), 
             const float & ($*1_ltype temp), 
             const double & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input; 
   $1 = &temp; %}


/* Default handling. Object passed by value. Convert to a pointer */
%typemap(in) SWIGTYPE ($&1_type argp)
%{ argp = *($&1_ltype*)&$input; 
   if (!argp) {
		NSException* anException = [NSException exceptionWithName:@"NullPointerException" 
		reason:@"Attempt to dereference null $1_type"
    userInfo:nil];
		@throw anException;
   }
   $1 = *argp; %}

%typemap(in) SWIGTYPE *, SWIGTYPE (CLASS::*) %{ $1 = *($&1_ltype)&$input; %}

%typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input;
  if (!$1) {
		NSException* anException = [NSException exceptionWithName:@"NullPointerException" 
		reason:@"Attempt to dereference null $1_type"
    userInfo:nil];
		@throw anException;
  } %}
	
%typemap(in) SWIGTYPE *& ($*1_ltype temp = 0)
%{ temp = *($1_ltype)&$input;
   $1 = &temp; %}


/* Default array handling */
%typemap(in) SWIGTYPE [] %{ $1 = *($&1_ltype)&$input; %}



/* Following are the "out" typemaps for C to Objective-C conversions */
// Primitive types
%typemap(out) bool
%{ $result = $1 ? YES : No; %}
%typemap(out) char, 
             signed char, 
             unsigned char, 
             short, 
             unsigned short, 
             int, 
             unsigned int, 
             long, 
             unsigned long, 
             long long, 
             unsigned long long, 
             float, 
             double
%{ $result = $1; %}
%typemap(out) void ""


// Pointers, references and arrays
%typemap(out, noblock=1) char * %{ if ($1) $result = [NSString stringWithUTF8String: $1]; %} //TBD
%typemap(out, noblock=1) char *& %{ if (*$1) $result = [NSString stringWithUTF8String: *$1]; %}
%typemap(out, noblock=1) char[ANY], char[] %{ if ($1) $result = [NSString stringWithUTF8String: $1]; %}



%typemap(out) SWIGTYPE [] %{ $result = (void *)$1; %} 

%typemap(out) SWIGTYPE 
#ifdef __cplusplus
%{ $result = (void*)new $1_ltype((const $1_ltype &)$1); %}
#else
{
  $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
  memmove($1ptr, &$1, sizeof($1_type));
  $result = (void*)$1ptr;
}
#endif

%typemap(out) SWIGTYPE *, SWIGTYPE (CLASS::*)
%{ $result = (void*)$1; %} 
%typemap(out) SWIGTYPE &
%{ $result = (void*)$1; %} 

%typemap(out) SWIGTYPE [] %{ $result = $1; %} 

%typemap(out) SWIGTYPE *&
%{ $result = (void*)*$1; %} 



/* Following are the objctype typemaps which contain the Objective-C types used in the proxy code */
// Primitive types
%typemap(objctype) bool,               const bool &               "BOOL"
%typemap(objctype) char,               const char &               "char"
%typemap(objctype) signed char,        const signed char &        "signed char"
%typemap(objctype) unsigned char,      const unsigned char &      "unsigned char"
%typemap(objctype) short,              const short &              "short"
%typemap(objctype) unsigned short,     const unsigned short &     "unsigned short"
%typemap(objctype) int,                const int &                "int"
%typemap(objctype) unsigned int,       const unsigned int &       "unsigned int"
%typemap(objctype) long,               const long &               "long"
%typemap(objctype) unsigned long,      const unsigned long &      "unsigned long"
%typemap(objctype) long long,          const long long &          "long long"
%typemap(objctype) unsigned long long, const unsigned long long & "unsigned long long"
%typemap(objctype) float,              const float &              "float"
%typemap(objctype) double,             const double &             "double"
%typemap(objctype) void                                           "void"

// Pointers, references and arrays
%typemap(objctype) char *, char *&, char[ANY], char[]   "NSString *"
%typemap(objctype) SWIGTYPE "$objcclassname*"
%typemap(objctype) SWIGTYPE [] "NSMutableArray*" //TBD
%typemap(objctype) SWIGTYPE *  "$objcclassname*" 
%typemap(objctype) SWIGTYPE & "$objcclassname*"

// Pointer to a class member
%typemap(objctype) SWIGTYPE (CLASS::*) "$objcclassname*" 



/* Following are the "objcin" typemaps for Objective-C to Objective-C++ conversions */
// Primitive types
%typemap(objcin) bool,               const bool &,
                 char,               const char &,
                 signed char,        const signed char &,
                 unsigned char,      const unsigned char &,
                 short,              const short &,
                 unsigned short,     const unsigned short &,
                 int,                const int &,
                 unsigned int,       const unsigned int &,
                 long,               const long &,
                 unsigned long,      const unsigned long &,
                 long long,          const long long &,
                 unsigned long long, const unsigned long long &,
                 float,              const float &,
                 double,             const double &
    "$objcinput"

// Pointers, references and arrays		
%typemap(objcin) char *, char *&, char[ANY], char[] "$objcinput"
%typemap(objcin) SWIGTYPE "[$objcinput getCptr]"
%typemap(objcin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "[$objcinput getCptr]"
%typemap(objcin) SWIGTYPE (CLASS::*) "" //TBD



/* Following are the "objcout" typemaps for Objective-C++ to Objective-C to conversions */
// Primitive types
%typemap(objcout) char,               const char &,
                 signed char,        const signed char &,
                 unsigned char,      const unsigned char &,
                 short,              const short &,
                 unsigned short,     const unsigned short &,
                 int,                const int &,
                 unsigned int,       const unsigned int &,
                 long,               const long &,
                 unsigned long,      const unsigned long &,
                 long long,          const long long &,
                 unsigned long long, const unsigned long long &,
                 float,              const float &,
                 double,             const double &
{
		$1_ltype ret = $imcall;
    return ret;
}

%typemap(objcout) bool, const bool & {
	  BOOL ret = $imcall;
    return ret;

}
	
// Pointers, references and arrays		
%typemap(objcout) char *, char *&, char[ANY], char[] {
    NSString *ret = $imcall;
    return ret;
  }
%typemap(objcout) void {
    $imcall;
  }
%typemap(objcout) SWIGTYPE {
    void *cPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cPtr] autorelease];
    return ret;
  }
%typemap(objcout) SWIGTYPE & { //TBD
		void *cPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cPtr] autorelease];
    return ret;
  }
	
// TBD: below we need to see if this $objcclassname is Class pointer or some other pointer
// Also see the memory management part
%typemap(objcout) SWIGTYPE * {
		void *cPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cPtr] autorelease];
    return ret;
}
%typemap(objcout) SWIGTYPE [] {
		void *cPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cPtr] autorelease];
    return ret;
}
%typemap(objcout) SWIGTYPE (CLASS::*) {
   	void *cMemberPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cMemberPtr] autorelease];
    return ret;
}

%typemap(argout) char[ANY], char[] ""

/* Following are the typemaps used for the generation of proxy and type wrapper class code */
%typemap(objcbase,notderived="")                      SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "NSObject"
%typemap(objcclassinterface)            SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "@interface"
%typemap(objcclassimplementation)            SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "@implementation"
%typemap(objccode)                      SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(objcimports)                   SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(objcinterfaces)                SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(objcinterfaces_derived)        SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""

// Proxy classes (base classes, ie, not derived classes)
%typemap(objcinterface) SWIGTYPE %{
{
	void *swigCPtr;
	BOOL swigCMemOwn;
}
- (void*)getCptr;
- (id)initWithCptr: (void*) cptr;
%}

%typemap(objcbody) SWIGTYPE %{
- (void*)getCptr {
	return swigCPtr;
}

- (id)initWithCptr: (void*) cptr{
	if((self = [super init])) {
		swigCPtr = cptr;
	}
	return self;
}
%}


// Derived proxy classes
%typemap(objcinterface_derived) SWIGTYPE %{
- (void*)getCptr;
- (id)initWithCptr: (void*) cptr;
%}

%typemap(objcbody_derived) SWIGTYPE %{
- (void*)getCptr {
	return swigCPtr;
}

-(id)initWithCptr: (void*) cptr {
	if((self = [super init])) {
		swigCPtr = cptr;
	}
	return self;
}
%}

// Typewrapper classes
%typemap(interface) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
{
	void *swigCPtr;
	BOOL swigCMemOwn;
}
- (void*)getCptr;
- (id)initWithCptr: (void*) cptr;
%}

%typemap(objcbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
- (void*)getCptr {
	return swigCPtr;
}

- (id)init {
	if((self = [super init])) {
		swigCPtr = 0;
	}
	return self;
}

- (id)initWithCptr: (void*) cptr{
	if((self = [super init])) {
		swigCPtr = cptr;
	}
	return self;
}
%}


/* Following are the typemaps used for Objective-C setter and getters for global variables */
// Primitive types
%typemap(objcvarin) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
		$imcall;
%}

// Pointers, references and arrays
%typemap(objcvarin) char *, char *&, char[ANY], char[] %{
		$imcall;
%}

%typemap(objcvarout) bool,              const bool &,
                 char,               const char &,
                 signed char,        const signed char &,
                 unsigned char,      const unsigned char &,
                 short,              const short &,
                 unsigned short,     const unsigned short &,
                 int,                const int &,
                 unsigned int,       const unsigned int &,
                 long,               const long &,
                 unsigned long,      const unsigned long &,
                 long long,          const long long &,
                 unsigned long long, const unsigned long long &,
                 float,              const float &,
                 double,             const double &
%{
		$1_ltype ret = $imcall;
    return ret;
%}

%typemap(objcvarout) char *, char *&, char[ANY], char[] %{
		NSString* ret = $imcall;
    return ret;
%}

%typemap(objcvarout) void %{
    $imcall;
%}

%typemap(objcvarout) SWIGTYPE { 
    void *cPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cPtr] autorelease];
    return ret;
}
	
%typemap(objcvarout) SWIGTYPE & { 
		void *cPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cPtr] autorelease];
    return ret;
}
	
// TBD: below we need to see if this $objcclassname is Class pointer or some other pointer
// Also see the memory management part
%typemap(objcvarout) SWIGTYPE * {
		void *cPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cPtr] autorelease];
    return ret;
}
%typemap(objcvarout) SWIGTYPE [] {
		void *cPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cPtr] autorelease];
    return ret;
}
%typemap(objcvarout) SWIGTYPE (CLASS::*) {
   	void *cMemberPtr = $imcall;
		$objcclassname* ret = (cPtr == NULL) ? nil : [[[$objcclassname alloc] initWithCptr: cMemberPtr] autorelease];
    return ret;
}

/*
 * Objective-C constructor and destructor typemaps:
 *
 * The objcconstruct typemap is inserted when a proxy class's constructor is generated.
 * This typemap allows control over what code is executed in the constructor as
 * well as specifying who owns the underlying C/C++ object. Normally, Objective-C has
 * ownership and the underlying C/C++ object is deallocated when the Objective-C object
 * is deallocated (swigCMemOwn is YES.) If swigCMemOwn is No, C/C++ is
 * ultimately responsible for deallocating the underlying object's memory.
 *
 */

%typemap(objcconstruct) SWIGTYPE {
	if((self = [super init])) {
		swigCPtr = $imcall;
	}
	return self;
}

%typemap(objcdestruct, methodname="dealloc") SWIGTYPE {
  if (swigCPtr != 0) {
	  if (swigCMemOwn) {
		  swigCMemOwn = YES;
      $imcall;
	  }
    swigCPtr = 0;
  }
  [super dealloc];
}




/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions 
 * that cannot be overloaded in Objective-C as more than one C++ type maps to a single Objective-C type */

%typecheck(SWIG_TYPECHECK_BOOL) /* Objective-C boolean */
    BOOL,
    bool,
    const bool &
    ""

%typecheck(SWIG_TYPECHECK_CHAR) /* Objective-C char */
    char, 
    const char &
    ""

%typecheck(SWIG_TYPECHECK_INT8) /* Objective-C byte */
    signed char,
    const signed char &
    ""

%typecheck(SWIG_TYPECHECK_INT16) /* Objective-C short */
    unsigned char, 
    short, 
    const unsigned char &, 
    const short &
    ""

%typecheck(SWIG_TYPECHECK_INT32) /* Objective-C int */
    unsigned short, 
    int, 
    long, 
    const unsigned short &, 
    const int &, 
    const long &
    ""

%typecheck(SWIG_TYPECHECK_INT64) /* Objective-C long */
    unsigned int, 
    unsigned long, 
    long long, 
    const unsigned int &, 
    const unsigned long &, 
    const long long &
    ""

%typecheck(SWIG_TYPECHECK_INT128) /* Objective-C BigInteger */
    unsigned long long,
    const unsigned long long &
    ""

%typecheck(SWIG_TYPECHECK_FLOAT) /* Objective-C float */
    float,
    const float &
    ""

%typecheck(SWIG_TYPECHECK_DOUBLE) /* Objective-C double */
    double,
    const double &
    ""

%typecheck(SWIG_TYPECHECK_STRING) /* Objective-C String */
    char *,
    char *&,
    char[ANY],
    char []
    ""

%typecheck(SWIG_TYPECHECK_POINTER) /* Default */
    SWIGTYPE, 
    SWIGTYPE *, 
    SWIGTYPE &, 
    SWIGTYPE [],
    SWIGTYPE (CLASS::*)
    ""


// Exception handling

%typemap(throws) int, 
                 long, 
                 short, 
                 unsigned int, 
                 unsigned long, 
                 unsigned short
%{ NSString* aFormat = [NSString stringWithString:@"The value is %d"];
	[NSException raise:@"$1_type exception" format: aFormat, $1] %}

%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY]
%{ NSString* aFormat = [NSString stringWithString:@"The value is %d"];
	[NSException raise:@"$1_type exception" format: aFormat, $1] %}
	
%typemap(throws) char *
%{ NSString* aFormat = [NSString stringWithString:@"%s"];
	[NSException raise:@"$1_type exception" format: aFormat, $1] %}


// Objective-C specific directives
#define %objcconst(flag)              %feature("objc:const","flag")
#define %objcconstvalue(value)        %feature("objc:constvalue",value)
#define %objcenum(wrapapproach)       %feature("objc:enum","wrapapproach")
#define %objcmethodmodifiers          %feature("objc:methodmodifiers")
#define %objcnothrowexception         %feature("except")
#define %objcattributes               %feature("objc:attributes")

// Some ANSI C typemaps
%apply unsigned long { size_t };
%apply const unsigned long & { const size_t & };
	
// Default enum handling
%include <enums.swg>