summaryrefslogtreecommitdiff
path: root/Lib/objc/objc.swg
blob: 0454c25b9705bd243547cbc48ad740b5576d71ad (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
/* -----------------------------------------------------------------------------
 * objc.swg
 *
 * Objective-C module typemaps: 
 * Note that the intermediate layer (ObjectiveC++) is essentially a C layer with the 
 * C++ specific code (such as references) converted to the C code. Since ObjectiveC
 * layer can handle C as is, this makes sense - at least until we decide on something 
 * more appropriate.

 * ----------------------------------------------------------------------------- */

/* 
 * IMTYPE TYPEMAPS: Represents the ObjectiveC++ type corresponding to each C++ type. 
 */
 
// Primary types: ObjectiveC++ understands C primary types.
%typemap(imtype) char               "char"
%typemap(imtype) signed char        "signed char"
%typemap(imtype) unsigned char      "unsigned char"
%typemap(imtype) short              "short"
%typemap(imtype) unsigned short     "unsigned short"
%typemap(imtype) int                "int"
%typemap(imtype) unsigned int       "unsigned int"
%typemap(imtype) long               "long"
%typemap(imtype) unsigned long      "unsigned long"
%typemap(imtype) long long          "long long"
%typemap(imtype) unsigned long long "unsigned long long"
%typemap(imtype) float              "float"
%typemap(imtype) double             "double"
%typemap(imtype) void               "void"

// References to primitive types are treated as pointers in the wrapper(ObjectiveC++) layer.
%typemap(imtype) const char &,              char &                  "char *"
%typemap(imtype) const signed char &, 		signed char &           "signed char *"
%typemap(imtype) const unsigned char &, 	unsigned char &         "unsigned char *"
%typemap(imtype) const short &,				short &                 "short *"
%typemap(imtype) const unsigned short &,	unsigned short &        "unsigned short *"
%typemap(imtype) const int &,		    	int &                   "int *"
%typemap(imtype) const unsigned int &,		unsigned int &          "unsigned int *"
%typemap(imtype) const long &,				long &                  "long *"
%typemap(imtype) const unsigned long &, 	unsigned long &         "unsigned long  *"
%typemap(imtype) const long long &, 		long long &             "long long *"
%typemap(imtype) const unsigned long long &,unsigned long long &    "unsigned long long  *"
%typemap(imtype) const float &, 			float &                 "float *"
%typemap(imtype) const double &,  			double &                "double *"

// Booleans
%typemap(imtype) bool               					"BOOL"
%typemap(imtype) const bool &, bool &, const bool *, bool *             "BOOL *"

//C strings:
%typemap(imtype) char *, const char *, char[ANY], char[]              "NSString *"
%typemap(imtype) char *&                                "NSString *"


// Objects will always be treated as pointers in ObjectiveC++
%typemap(imtype) SWIGTYPE                               "void*" 

// C/C++ prinitve pointers are treated as is in ObjectiveC++
// References to primitive types are treated as pointers in the wrapper(ObjectiveC++) layer.
%typemap(imtype) const signed char *, 		signed char *           "signed char *"
%typemap(imtype) const unsigned char *, 	unsigned char *         "unsigned char *"
%typemap(imtype) const short *,				short *                 "short *"
%typemap(imtype) const unsigned short *,	unsigned short *        "unsigned short *"
%typemap(imtype) const int *,		    	int *                   "int *"
%typemap(imtype) const unsigned int *,		unsigned int *          "unsigned int *"
%typemap(imtype) const long *,				long *                  "long *"
%typemap(imtype) const unsigned long *, 	unsigned long *         "unsigned long  *"
%typemap(imtype) const long long *, 		long long *             "long long *"
%typemap(imtype) const unsigned long long *,unsigned long long *    "unsigned long long  *"
%typemap(imtype) const float *, 			float *                 "float *"
%typemap(imtype) const double *,  			double *                "double *"

// C/C++ object Pointers, are treated as void* in ObjectiveC++
%typemap(imtype) SWIGTYPE *                             "void*"

// Arrays for non-primitive types
%typemap(imtype) SWIGTYPE []                            "void*"

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

// References to non-primitive types
%typemap(imtype) SWIGTYPE &                             "void*"
%typemap(imtype) SWIGTYPE *const&                       "void*"

// Function pointers
%typemap(imtype) SWIGTYPE ((*)(ANY))                    "void*"


/* 
 * IN TYPEMAPS: Used for "in" arguments type conversions: ObjectiveC++ to C++.
 */
%typemap(in) char, 
             signed char, 
             unsigned char, 
             short, 
             unsigned short, 
             int, 
             unsigned int, 
             long, 
             unsigned long, 
             long long, 
             unsigned long long,
             float, 
             double
%{ $1 = ($1_ltype)$input; %}

// No "in" for void
%typemap(in) void ""

// References: are treated as pointers in the wrapper layer (ObjectiveC++)
%typemap(in)	const char &,  			char &,
	     	 const signed char &, 		signed char &,
	         const unsigned char &, 	unsigned char &,
		     const short &,				short &,
		     const unsigned short &,	unsigned short &,
		     const int &,		    	int &,
		     const unsigned int &,		unsigned int &,
			 const long &,				long &,
	     	 const unsigned long &, 	unsigned long &,
	     	 const long long &, 		long long &,
	     	 const unsigned long long &,unsigned long long &,
	      	 const float &, 			float &,
	      	 const double &,  			double &
%{ $1 = ($1_ltype)$input; %}

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

//Booleans:
%typemap(in) bool
%{ $1 = $input? true : false; %}

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


//C strings:
%typemap(in) char *, char[ANY], char[]  {
 $1 = 0;
  if ($input) { // TODO: Find a better way to do this!
		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 = ($1_ltype)buffer;
	}
}

%typemap(in) char *& ($*1_ltype temp = 0) {
 $1 = 0;
  if ($input) { // TODO: Find a better way to do this!
		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;
}

// Objects passed by value: convert from a pointer to the C++ value object.
%typemap(in) SWIGTYPE ($&1_type argp)	
%{ 
  argp = ($&1_ltype)$input;
  $1 = *argp; 
%}

// C/C++ Pointers, primary and object, are treated as pointers in ObjectiveC++
%typemap(in) SWIGTYPE *
%{ $1 = ($1_ltype)$input; %}
   
// Object References
%typemap(in) SWIGTYPE &
%{ $1 = ($1_ltype)$input; %}

%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
%{ temp = *($1_ltype)&$input;
   $1 = ($1_ltype)&temp; %}
   
// Array conversion typemap
%typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %}

// Pointer to a class member will be passed as void*, convert appropriately
%typemap(in) SWIGTYPE (CLASS::*)
%{ $1 = *($&1_ltype)$input; %}

// Function pointers
%typemap(in) SWIGTYPE ((*)(ANY))
%{ $1 = ($1_ltype)$input; %}

%typemap(in) SWIGTYPE *& ($*1_ltype temp = 0)
%{ temp = *($1_ltype)&$input;
   $1 = &temp; %}

/*
 * OUT TYPEMAPS: Used for return-type type conversions: C++ to ObjectiveC++
 */
//Primary types
%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 ""

// References as exported as pointers (by default)
%typemap(out)const char &,  			char &,
	     	 const signed char &, 		signed char &,
	         const unsigned char &, 	unsigned char &,
		     const short &,				short &,
		     const unsigned short &,	unsigned short &,
		     const int &,		    	int &,
		     const unsigned int &,		unsigned int &,
			 const long &,				long &,
	     	 const unsigned long &, 	unsigned long &,
	     	 const long long &, 		long long &,
	     	 const unsigned long long &,unsigned long long &,
	      	 const float &, 			float &,
	      	 const double &,  			double &
%{ $result = $1; %}


%typemap(out)const char *,  			char *,
	     	 const signed char *, 		signed char *,
	         const unsigned char *, 	unsigned char *,
		     const short *,				short *,
		     const unsigned short *,	unsigned short *,
		     const int *,		    	int *,
		     const unsigned int *,		unsigned int *,
			 const long *,				long *,
	     	 const unsigned long *, 	unsigned long *,
	     	 const long long *, 		long long *,
	     	 const unsigned long long *,unsigned long long *,
	      	 const float *, 			float *,
	      	 const double *,  			double *
%{ $result = $1; %}

// Booleans:
%typemap(out) bool
%{  $result = ($1)? YES:NO; %}

%typemap(out) bool& (BOOL temp), bool* (BOOL temp), const bool& (BOOL temp), const bool& (BOOL temp)
%{  temp = (*$1)? YES:NO;
    BOOL* ret = &temp;
    return ret; %}

// C strings: 
%typemap(out)const char *,char * %{ if ($1) $result = [NSString stringWithUTF8String: (const char*)$1]; %}
%typemap(out) char *& %{ if (*$1) $result = [NSString stringWithUTF8String: (const char*)*$1]; %}
%typemap(out) char[ANY], char[] %{ if ($1) $result = [NSString stringWithUTF8String: (const char*)$1]; %}

// Objects returned by value: convert to a pointer.
%typemap(out) SWIGTYPE ($&1_type temp)
#ifdef __cplusplus
%{
  temp = new $1_ltype((const $1_ltype &)$1); 
  $result = (void*)temp;
%}
#else
{
  $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
  memmove($1ptr, &$1, sizeof($1_type));
  temp = $1ptr;
  $result = (void*)temp;
}
#endif

// Pointer objects are returned as void* in the ObjectiveC++ layer
%typemap(out) SWIGTYPE *, SWIGTYPE & 
%{ $result = (void*)$1; %}

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

// Pointer to a class member 
%typemap(out) SWIGTYPE (CLASS::*) 
%{ *($&1_ltype)$result =$1; %}

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

// Function pointers
%typemap(out) SWIGTYPE ((*)(ANY))
%{ $result = (void*)$1; %}

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

/* 
 * OBJCTYPE TYPEMAPS: Represents the ObjectiveC(proxy) type corresponding to each ObjectiveC++ type in the intermediate(wrapper) layer. 
 */
// Primary types
%typemap(objctype)  bool               "BOOL"
%typemap(objctype)  char               "char"
%typemap(objctype)  signed char        "signed char"
%typemap(objctype)  unsigned char      "unsigned char"
%typemap(objctype)  short              "short"
%typemap(objctype)  unsigned short     "unsigned short"
%typemap(objctype)  int                "int"
%typemap(objctype)  unsigned int       "unsigned int"
%typemap(objctype)  long               "long"
%typemap(objctype)  unsigned long      "unsigned long"
%typemap(objctype)  long long          "long long"
%typemap(objctype)  unsigned long long "unsigned long long"
%typemap(objctype)  float              "float"
%typemap(objctype)  double             "double"
%typemap(objctype)  void               "void"

// References will always be treated as pointers in the proxy layer (ObjectiveC)
%typemap(objctype) const bool &,              bool &                  "BOOL *"
%typemap(objctype) const char &,              char &                  "char *"
%typemap(objctype) const signed char &, 		signed char &           "signed char *"
%typemap(objctype) const unsigned char &, 	unsigned char &         "unsigned char *"
%typemap(objctype) const short &,				short &                 "short *"
%typemap(objctype) const unsigned short &,	unsigned short &        "unsigned short *"
%typemap(objctype) const int &,		    	int &                   "int *"
%typemap(objctype) const unsigned int &,		unsigned int &          "unsigned int *"
%typemap(objctype) const long &,				long &                  "long *"
%typemap(objctype) const unsigned long &, 	unsigned long &         "unsigned long  *"
%typemap(objctype) const long long &, 		long long &             "long long *"
%typemap(objctype) const unsigned long long &,unsigned long long &    "unsigned long long  *"
%typemap(objctype) const float &, 			float &                 "float *"
%typemap(objctype) const double &,  			double &                "double *"

//C strings:
%typemap(objctype) char *, const char *, char *&, char[ANY], char[]    "NSString *"

// Objects will always be treated as pointers in ObjectiveC
%typemap(objctype) SWIGTYPE                             "$objcclassname*"

// C/C++ Pointers to primitive types are treated as is
// C/C++ prinitve pointers are treated as is in ObjectiveC++
// References to primitive types are treated as pointers in the wrapper(ObjectiveC++) layer.
%typemap(objctype) const bool *,              bool *                  "BOOL *"
%typemap(objctype) const signed char *, 		signed char *           "signed char *"
%typemap(objctype) const unsigned char *, 	unsigned char *         "unsigned char *"
%typemap(objctype) const short *,				short *                 "short *"
%typemap(objctype) const unsigned short *,	unsigned short *        "unsigned short *"
%typemap(objctype) const int *,		    	int *                   "int *"
%typemap(objctype) const unsigned int *,		unsigned int *          "unsigned int *"
%typemap(objctype) const long *,				long *                  "long *"
%typemap(objctype) const unsigned long *, 	unsigned long *         "unsigned long  *"
%typemap(objctype) const long long *, 		long long *             "long long *"
%typemap(objctype) const unsigned long long *,unsigned long long *    "unsigned long long  *"
%typemap(objctype) const float *, 			float *                 "float *"
%typemap(objctype) const double *,  			double *                "double *"

// C/C++ Pointers are treated as  as pointers in ObjectiveC
%typemap(objctype) SWIGTYPE *                           "$objcclassname*" 

// Arrays to non-primitive types
%typemap(objctype) SWIGTYPE []                          "$objcclassname*"

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

// References to non-primitive types
%typemap(objctype) SWIGTYPE &                           "$objcclassname*"
%typemap(objctype) SWIGTYPE *const&                     "$objcclassname*"

// Function pointers
%typemap(objctype) SWIGTYPE ((*)(ANY))                  "$objcclassname*"


/* 
 * OBJCIN TYPEMAPS: Used for "in" arguments type conversions from ObjectiveC(proxy) layer to ObjectiveC++(wrapper) layer.
 */

// Primary types
%typemap(objcin) bool,
	     char, 
             signed char, 
             unsigned char, 
             short, 
             unsigned short, 
             int, 
             unsigned int, 
             long, 
             unsigned long, 
             long long, 
             unsigned long long,
             float, 
             double
"$objcinput"

// No "objcin" for void
%typemap(objcin) void ""

// References: are treated as pointers in the proxy layer (ObjectiveC)
%typemap(objcin) const bool &,                  bool &, 
                 const char &,  		char &,
	     	 const signed char &, 		signed char &,
	         const unsigned char &, 	unsigned char &,
		     const short &,				short &,
		     const unsigned short &,	unsigned short &,
		     const int &,		    	int &,
		     const unsigned int &,		unsigned int &,
			 const long &,				long &,
	     	 const unsigned long &, 	unsigned long &,
	     	 const long long &, 		long long &,
	     	 const unsigned long long &,unsigned long long &,
	      	 const float &, 			float &,
	      	 const double &,  			double &
"$objcinput"

// C/C++ pointers to primitive types are treated as is in the Proxy layer.
%typemap(objcin)const bool *,              bool *,
             const char *,  			char *,
	     	 const signed char *, 		signed char *,
	         const unsigned char *, 	unsigned char *,
		     const short *,				short *,
		     const unsigned short *,	unsigned short *,
		     const int *,		    	int *,
		     const unsigned int *,		unsigned int *,
			 const long *,				long &,
	     	 const unsigned long *, 	unsigned long &,
	     	 const long long *, 		long long *,
	     	 const unsigned long long *,unsigned long long *,
	      	 const float *, 			float *,
	      	 const double *,  			double *
"$objcinput"

//C strings:
%typemap(objcin) char *, char[ANY], char[]  "$objcinput"
%typemap(objcin) char *&                    "$objcinput"

// Objects passed by value: Convert from an ObjectiveC pointer to the ObjectiveC++ void* pointer.
%typemap(objcin) SWIGTYPE "[$objcinput getCptr]"

// C/C++ Pointers, primary and object, are exported as ObjectiveC pointers
%typemap(objcin) SWIGTYPE *, SWIGTYPE & "[$objcinput getCptr]"
%typemap(objcin) SWIGTYPE "[$objcinput getCptr]"

// Pointer to a class member will be passed as void*, convert appropriately
%typemap(objcin) SWIGTYPE (CLASS::*) "[$objcinput getCptr]" 

%typemap(objcin) SWIGTYPE *const& "[$objcinput getCptr]" 

/*
 * OBJCOUT TYPEMAPS: Used for return-type type conversions: ObjectiveC++(wrapper) to ObjectiveC(proxy)
 */

// Primary types are exported as ObjectiveC primary types
%typemap(objcout) bool,
		char,
	      signed char,
	      unsigned char,
	      short,
	      unsigned short,
	      int,
	      unsigned int,
	      long,
	      unsigned long,
	      long long,
	      unsigned long long,
	      float,
	      double
%{ return $imcall; %}

%typemap(objcout) void "$imcall;"

%typemap(objcout) const bool &,         bool &,
             const char &,  			char &,
	     	 const signed char &, 		signed char &,
	         const unsigned char &, 	unsigned char &,
		     const short &,				short &,
		     const unsigned short &,	unsigned short &,
		     const int &,		    	int &,
		     const unsigned int &,		unsigned int &,
			 const long &,				long &,
	     	 const unsigned long &, 	unsigned long &,
	     	 const long long &, 		long long &,
	     	 const unsigned long long &,unsigned long long &,
	      	 const float &, 			float &,
	      	 const double &,  			double &
%{ return $imcall; %}

%typemap(objcout)const bool *,              bool *,
             const char *,  			char *,
	     	 const signed char *, 		signed char *,
	         const unsigned char *, 	unsigned char *,
		     const short *,				short *,
		     const unsigned short *,	unsigned short *,
		     const int *,		    	int *,
		     const unsigned int *,		unsigned int *,
			 const long *,				long *,
	     	 const unsigned long *, 	unsigned long *,
	     	 const long long *, 		long long *,
	     	 const unsigned long long *,unsigned long long *,
	      	 const float *, 			float *,
	      	 const double *,  			double *
%{ return $imcall; %}

// C strings: 
%typemap(objcout)const char *,char * 
%{  NSString *ret = $imcall;
    return ret; %}

%typemap(objcout) char *& 
%{  NSString *ret = $imcall;
    return ret; %}

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

// Objects returned by value: Convert the void* pointer to the ObjectiveC pointer.
// Here, for now, we presume that the returned C++ pointers will not have to be deleted by the client directly
// As such, we mark swigOwnCObject as NO. This has to be reviewed again.
%typemap(objcout) SWIGTYPE
%{   void* cPtr = $imcall;
     $objcclassname* ret = nil;
     if(cPtr) {
        ret = [[[$objcclassname alloc] initWithCptr:cPtr swigOwnCObject:NO] autorelease];
     }
    return ret; %}

// Pointer objects are returned as ObjectiveC pointers
// Here, for now, we presume that the returned C++ pointers will not have to be deleted by the client directly
// As such, we mark swigOwnCObject as NO. This has to be reviewed again.
%typemap(objcout) SWIGTYPE &
%{   void* cPtr = $imcall;
     $objcclassname* ret = nil;
     if(cPtr) {
        ret = [[[$objcclassname alloc] initWithCptr:cPtr swigOwnCObject:NO] autorelease];
     }
    return ret; %}
	
%typemap(objcout) SWIGTYPE *
%{   void* cPtr = $imcall;
     $objcclassname* ret = nil;
     if(cPtr) {
        ret = [[[$objcclassname alloc] initWithCptr:cPtr swigOwnCObject:NO] autorelease];
     }
    return ret; %}
    
// C function pointer
%typemap(objcout) SWIGTYPE ((*)(ANY)) 
%{   void* cPtr = $imcall;
     $objcclassname* ret = nil;
     if(cPtr) {
        ret = [[[$objcclassname alloc] initWithCptr:cPtr swigOwnCObject:NO] autorelease];
     }
    return ret; %}
    
%typemap(objcvarout) SWIGTYPE ((*)(ANY)) 
%{ $objcclassname* $objcvarname = [[[$objcclassname alloc] initWithCptr:($imcall) swigOwnCObject:NO] autorelease]; %}

// Pointer to a class member will be returned as id
%typemap(objcout) SWIGTYPE (CLASS::*) 
%{   void* cPtr = $imcall;
     $objcclassname* ret = nil;
     if(cPtr) {
        ret = [[[$objcclassname alloc] initWithCptr:cPtr swigOwnCObject:NO] autorelease];
     }
    return ret; %}

%typemap(objcout) SWIGTYPE *const& 
%{   void* cPtr = $imcall;
     $objcclassname* ret = nil;
     if(cPtr) {
        ret = [[[$objcclassname alloc] initWithCptr:cPtr swigOwnCObject:NO] autorelease];
     }
    return ret; %}
 
/* apply typemaps */
// Treat references to arrays like like references to a single element.
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
%apply unsigned long { size_t };
%apply const unsigned long & { const size_t & };

/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }

/* Exception handling */
 
%typemap(throws) int, 
                 long, 
                 short, 
                 unsigned int, 
                 unsigned long, 
                 unsigned short
%{ char error_msg[256];
   sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
   SWIG_ObjcThrowException(SWIG_ObjcRuntimeException, error_msg);
   return $null; %}
 
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY]
%{ (void)$1;
   SWIG_ObjcThrowException(SWIG_ObjcRuntimeException, "C++ $1_type exception thrown");
   return $null; %}

%typemap(throws) char *
%{ SWIG_ObjcThrowException(SWIG_ObjcRuntimeException, $1);
   return $null; %}


#define %objcexception(exceptionclasses) %feature("except",throws=exceptionclasses)
#define %noobjcexception            %feature("except","0",throws="")
#define %clearobjcexception         %feature("except","",throws="")

/* Additional typemaps */
// Typemaps containing ObjectiveC code used when generating ObjectiveC proxy classes.
%include <objcproxycode.swg>

// Typemaps for handling enums
%include <objcenums.swg>

// ObjectiveC runtime support code.
%include <objcruntime.swg>

// List of all reserved ObjectiveC keywords.
%include <objckw.swg>