3 This script extracts macros functions from the OpenCV headers and attempts to generate
4 standard C function prototypes. Type information is missing in the macros, so SWIG
5 cannot generate C code for them unless we provide this.
24 "edge":"CvGraphEdge *",
25 "vertex":"CvGraphVtx *",
28 "reader":"CvSeqReader",
29 "writer":"CvSeqWriter",
30 "hist":"CvHistogram *",
56 "node":"CvSparseNode *",
57 "storage":"CvMemStorage *",
63 "real_scalar":"double",
68 "line_iterator":"CvLineIterator",
72 # "contour":"const void*", # handled as a special case in cvshadow
79 "cvContourPerimeter":"double",
81 "CV_NEXT_GRAPH_EDGE":"CvGraphEdge *",
87 "CV_NEXT_LINE_POINT":"void",
92 #"CV_MAKETYPE":"", # SWIG 1.3.29 doesn't like this one for some indeterminant reason
93 "CV_TURN_ON_IPL_COMPATIBILITY":"",
94 "CV_MAT_ELEM_PTR_FAST":"void * CV_MAT_ELEM_PTR_FAST(CvMat mat,int row,int col,int pix_size);",
95 "CV_MAT_ELEM_PTR":"void * CV_MAT_ELEM_PTR(CvMat mat,int row,int col);",
96 "CV_NODE_VAL":"void * CV_NODE_VAL(CvSparseMat* mat,CvSparseNode * node);",
97 "CV_NODE_IDX":"int * CV_NODE_IDX(CvSparseMat* mat,CvSparseNode * node);",
98 "CV_READ_CHAIN_POINT":"void CV_READ_CHAIN_POINT(CvPoint _pt, CvChainPtReader reader);",
99 "CV_SUBDIV2D_NEXT_EDGE":"CvQuadEdge2D* CV_SUBDIV2D_NEXT_EDGE(CvSubdiv2DEdge edge);",
100 "cvFree":"void cvFree(void ** ptr);",
106 /*//////////////////////////////////////////////////////////////////////////////////////////////////
107 // This file is automatically generated from the extract_macros.py script found in the 'utils'
108 // subdirectory of the OpenCV distribution. If the generated function prototypes are missing or
109 // incorrect, it is likely that a name->type mapping will have to be added to the script
110 /////////////////////////////////////////////////////////////////////////////////////////////////M*/
113 print "// This file was generated from the following header files: "
114 print "// %s" % "\n// ".join(sys.argv[1:])
117 def determine_return_type(name, arguments):
118 if RET_MAP.has_key( name ):
120 if name.find("_IS_")>=0 or \
121 name.find("_HAS_")>=0 or \
122 name.find("_KIND")>=0 or \
123 name.find("_ARE_")>=0 or \
124 name.find("_SIZE")>=0 or \
125 name.find("Idx")>=0 or \
126 name.find("Count")>=0 or \
127 (name.find("TYPE")>=0 and not name.find("TYPES")>=0):
129 if re.match( r"CV_(?:8|16|32|64)(?:U|S|F)C", name ):
131 if len(arguments) is 1 and arguments[0].startswith("double"):
133 if name.find("_PTR")>=0:
135 if name.endswith("POINT"):
142 for fn in sys.argv[1:]:
147 for l in f.xreadlines():
148 m = re.match( r"^#define\s+((?:CV_|IPL_|cv)\w+)\s*\(([_, a-zA-Z0-9]*)\)\s*(.*)", l )
150 if m and not m.group(1).endswith("FIELDS") and not MACROS.has_key(m.group(1)):
151 macro_name = m.group(1)
152 args = m.group(2).strip().split(",")
155 ret=determine_return_type( macro_name, args )
157 # assign type to each argument
158 no_args = len(args) is 0
166 if ARG_MAP.has_key( arg ):
167 if ARG_MAP[arg] is "ignore":
170 typed_args.append( "%s %s"%( ARG_MAP[arg], arg ) )
172 sys.stderr.write( "\"%s\":\"?\", in macro '%s'\n" % (arg, macro_name) )
175 if not ignore and (no_args or len(typed_args)>0):
176 decl = "%s %s(%s);" % (ret, macro_name, ",".join( typed_args) )
177 MACROS[ macro_name ] = decl