3 This script checks the OpenCV headers to find methods that take double pointers
4 to OpenCV data structures as in/out parameters.
6 These methods need a special treatment and therefore SWIG typemaps are generated.
11 def convert_name(str):
13 if (str[0:2] == "_p"):
14 p,s = convert_name(str[2:])
19 if (sys.argv.__len__() < 1):
22 infile = open(sys.argv[1],'r')
24 lines = infile.readlines()
33 if (line.find('TYPES TABLE (BEGIN') > -1):
36 if (line.find('TYPES TABLE (END)') > -1):
40 if (stuff.__len__() >= 3):
41 if (stuff[0] == "#define"):
42 mytypes.append(stuff[1][8:])
45 /*//////////////////////////////////////////////////////////////////////////////////////////////////
46 // This file was automatically generated from the extract_doublepointers.py script found in the
47 // 'utils' subdirectory of the OpenCV distribution. Run it on the .cpp file generated by swig to
48 // generate the double pointer typemaps
49 /////////////////////////////////////////////////////////////////////////////////////////////////M*/
52 for mytype in mytypes:
53 p,s = convert_name(mytype)
54 if (p.__len__() >= 2):
55 print '%typemap(in)',s,p,' (void * vptr, $*1_ltype buffer) {'
56 print '\tif ((SWIG_ConvertPtr($input, &vptr, $*1_descriptor, 1)) == -1){'
57 print '\t\tSWIG_fail;';
59 print '\tbuffer = ($*1_ltype) vptr;'
62 #rez = "" + s + " " + p + 'getPtrTo' + s + '( ' + s + ' ' + p[1:] + 'input)'
63 #sys.stdout.write(rez)
64 #sys.stdout.write('\n{\n\t' + s + ' ' + p + 'rez = new ' + s + p[1:] + '();')
65 #sys.stdout.write('\n\t*rez =input;\n\treturn(rez);\n}\n')
66 #sys.stdout.write(rez)
67 #sys.stdout.write(';\n')
71 # print '/* No conversions needed for type ', s, ' */'