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 *",
27 "reader":"CvSeqReader",
28 "writer":"CvSeqWriter",
29 "hist":"CvHistogram *",
55 "node":"CvSparseNode *",
56 "storage":"CvMemStorage *",
62 "real_scalar":"double",
67 "line_iterator":"CvLineIterator",
71 # "contour":"const void*", # handled as a special case in cvshadow
79 "CV_NEXT_GRAPH_EDGE":"CvGraphEdge *",
85 "CV_NEXT_LINE_POINT":"void",
90 #"CV_MAKETYPE":"", # SWIG 1.3.29 doesn't like this one for some indeterminant reason
91 "CV_TURN_ON_IPL_COMPATIBILITY":"",
92 "CV_MAT_ELEM_PTR_FAST":"void * CV_MAT_ELEM_PTR_FAST(CvMat mat,int row,int col,int pix_size);",
93 "CV_MAT_ELEM_PTR":"void * CV_MAT_ELEM_PTR(CvMat mat,int row,int col);",
94 "CV_NODE_VAL":"void * CV_NODE_VAL(CvSparseMat* mat,CvSparseNode * node);",
95 "CV_NODE_IDX":"int * CV_NODE_IDX(CvSparseMat* mat,CvSparseNode * node);",
96 "CV_READ_CHAIN_POINT":"void CV_READ_CHAIN_POINT(CvPoint _pt, CvChainPtReader reader);",
97 "CV_SUBDIV2D_NEXT_EDGE":"CvQuadEdge2D* CV_SUBDIV2D_NEXT_EDGE(CvSubdiv2DEdge edge);",
98 "cvFree":"void cvFree(void ** ptr);",
104 /*//////////////////////////////////////////////////////////////////////////////////////////////////
105 // This file is automatically generated from the extract_macros.py script found in the 'utils'
106 // subdirectory of the OpenCV distribution. If the generated function prototypes are missing or
107 // incorrect, it is likely that a name->type mapping will have to be added to the script
108 /////////////////////////////////////////////////////////////////////////////////////////////////M*/
111 def determine_return_type(name, arguments):
112 if RET_MAP.has_key( name ):
114 if name.find("_IS_")>=0 or \
115 name.find("_HAS_")>=0 or \
116 name.find("_KIND")>=0 or \
117 name.find("_ARE_")>=0 or \
118 name.find("_SIZE")>=0 or \
119 name.find("Idx")>=0 or \
120 name.find("Count")>=0 or \
121 (name.find("TYPE")>=0 and not name.find("TYPES")>=0):
123 if re.match( r"CV_(?:8|16|32|64)(?:U|S|F)C", name ):
125 if len(arguments) is 1 and arguments[0].startswith("double"):
127 if name.find("_PTR")>=0:
129 if name.endswith("POINT"):
136 for fn in sys.argv[1:]:
141 for l in f.xreadlines():
142 m = re.match( r"^#define\s+((?:CV_|IPL_|cv)\w+)\s*\(([_, a-zA-Z0-9]*)\)\s*(.*)", l )
144 if m and not m.group(1).endswith("FIELDS") and not MACROS.has_key(m.group(1)):
145 macro_name = m.group(1)
146 args = m.group(2).strip().split(",")
149 ret=determine_return_type( macro_name, args )
151 # assign type to each argument
152 no_args = len(args) is 0
160 if ARG_MAP.has_key( arg ):
161 if ARG_MAP[arg] is "ignore":
164 typed_args.append( "%s %s"%( ARG_MAP[arg], arg ) )
166 sys.stderr.write( "\"%s\":\"?\", in macro '%s'\n" % (arg, macro_name) )
169 if not ignore and (no_args or len(typed_args)>0):
170 decl = "%s %s(%s);" % (ret, macro_name, ",".join( typed_args) )
171 MACROS[ macro_name ] = decl