parameters: (self, arg_str, argno)
return_statement: return arg_type, arg_name, modlist, argno
docstring: Parses <arg_type> [arg_name]
          Returns arg_type, arg_name, modlist, argno, where
          modlist is the list of wrapper-related modifiers (such as "output argument", "has counter", ...)
          and argno is the new index of an anonymous argument.
          That is, if no arg_str is just an argument type without argument name, the argument name is set to
          "arg" + str(argno), and then argno is incremented.
docstring_summary: Parses <arg_type> [arg_name]
          Returns arg_type, arg_name, modlist, argno, where
          modlist is the list of wrapper-related modifiers (such as "output argument", "has counter", ...)
          and argno is the new index of an anonymous argument.
          That is, if no arg_str is just an argument type without argument name, the argument name is set to
          "arg" + str(argno), and then argno is incremented.
docstring_tokens: Parses <arg_type > [ arg_name ] Returns arg_type arg_name modlist argno where modlist is the list of wrapper - related modifiers ( such as output argument has counter ... ) and argno is the new index of an anonymous argument . That is if no arg_str is just an argument type without argument name the argument name is set to arg + str ( argno ) and then argno is incremented .
function: def parse_arg(self, arg_str, argno):
          """
          Parses <arg_type> [arg_name]
          Returns arg_type, arg_name, modlist, argno, where
          modlist is the list of wrapper-related modifiers (such as "output argument", "has counter", ...)
          and argno is the new index of an anonymous argument.
          That is, if no arg_str is just an argument type without argument name, the argument name is set to
          "arg" + str(argno), and then argno is incremented.
          """
          modlist = []
  
          # pass 0: extracts the modifiers
          if "CV_OUT" in arg_str:
              modlist.append("/O")
              arg_str = arg_str.replace("CV_OUT", "")
  
          if "CV_IN_OUT" in arg_str:
              modlist.append("/IO")
              arg_str = arg_str.replace("CV_IN_OUT", "")
  
          isarray = False
          npos = arg_str.find("CV_CARRAY")
          if npos >= 0:
              isarray = True
              macro_arg, npos3 = self.get_macro_arg(arg_str, npos)
  
              modlist.append("/A " + macro_arg)
              arg_str = arg_str[:npos] + arg_str[npos3 + 1:]
  
          npos = arg_str.find("CV_CUSTOM_CARRAY")
          if npos >= 0:
              isarray = True
              macro_arg, npos3 = self.get_macro_arg(arg_str, npos)
  
              modlist.append("/CA " + macro_arg)
              arg_str = arg_str[:npos] + arg_str[npos3 + 1:]
  
          npos = arg_str.find("const")
          if npos >= 0:
              modlist.append("/C")
  
          npos = arg_str.find("&")
          if npos >= 0:
              modlist.append("/Ref")
  
          arg_str = arg_str.strip()
          word_start = 0
          word_list = []
          npos = -1
  
          # print self.lineno, ":\t", arg_str
  
          # pass 1: split argument type into tokens
          while 1:
              npos += 1
              t, npos = self.find_next_token(arg_str, [" ", "&", "*", "<", ">", ","], npos)
              w = arg_str[word_start:npos].strip()
              if w == "operator":
                  word_list.append("operator " + arg_str[npos:].strip())
                  break
              if w not in ["", "const"]:
                  word_list.append(w)
              if t not in ["", " ", "&"]:
                  word_list.append(t)
              if not t:
                  break
              word_start = npos + 1
              npos = word_start - 1
  
          arg_type = ""
          arg_name = ""
          angle_stack = []
  
          # print self.lineno, ":\t", word_list
  
          # pass 2: decrypt the list
          wi = -1
          prev_w = ""
          for w in word_list:
              wi += 1
              if w == "*":
                  if prev_w == "char" and not isarray:
                      arg_type = arg_type[:-len("char")] + "c_string"
                  else:
                      arg_type += w
                  continue
              elif w == "<":
                  arg_type += "_"
                  angle_stack.append(0)
              elif w == "," or w == '>':
                  if not angle_stack:
                      print("Error at %d: argument contains ',' or '>' not within template arguments" % (self.lineno,))
                      sys.exit(-1)
                  if w == ",":
                      arg_type += "_and_"
                  elif w == ">":
                      if angle_stack[0] == 0:
                          print("Error at %s:%d: template has no arguments" % (self.hname, self.lineno))
                          sys.exit(-1)
                      if angle_stack[0] > 1:
                          arg_type += "_end_"
                      angle_stack[-1:] = []
              elif angle_stack:
                  arg_type += w
                  angle_stack[-1] += 1
              elif arg_type == "struct":
                  arg_type += " " + w
              elif arg_type and arg_type != "~":
                  arg_name = " ".join(word_list[wi:])
                  break
              else:
                  arg_type += w
              prev_w = w
  
          counter_str = ""
          add_star = False
          if ("[" in arg_name) and not ("operator" in arg_str):
              # print arg_str
              p1 = arg_name.find("[")
              p2 = arg_name.find("]", p1 + 1)
              if p2 < 0:
                  print("Error at %d: no closing ]" % (self.lineno,))
                  sys.exit(-1)
              counter_str = arg_name[p1 + 1:p2].strip()
              if counter_str == "":
                  counter_str = "?"
              if not isarray:
                  modlist.append("/A " + counter_str.strip())
              arg_name = arg_name[:p1]
              add_star = True
  
          if not arg_name:
              if arg_type.startswith("operator"):
                  arg_type, arg_name = "", arg_type
              else:
                  arg_name = "arg" + str(argno)
                  argno += 1
  
          while arg_type.endswith("_end_"):
              arg_type = arg_type[:-len("_end_")]
  
          if add_star:
              arg_type += "*"
  
          arg_type = self.batch_replace(arg_type, [("std::", ""), ("cv::", ""), ("::", "_")])
  
          return arg_type, arg_name, modlist, argno
function_tokens: def parse_arg ( self , arg_str , argno ) : modlist = [ ] # pass 0: extracts the modifiers if "CV_OUT" in arg_str : modlist . append ( "/O" ) arg_str = arg_str . replace ( "CV_OUT" , "" ) if "CV_IN_OUT" in arg_str : modlist . append ( "/IO" ) arg_str = arg_str . replace ( "CV_IN_OUT" , "" ) isarray = False npos = arg_str . find ( "CV_CARRAY" ) if npos >= 0 : isarray = True macro_arg , npos3 = self . get_macro_arg ( arg_str , npos ) modlist . append ( "/A " + macro_arg ) arg_str = arg_str [ : npos ] + arg_str [ npos3 + 1 : ] npos = arg_str . find ( "CV_CUSTOM_CARRAY" ) if npos >= 0 : isarray = True macro_arg , npos3 = self . get_macro_arg ( arg_str , npos ) modlist . append ( "/CA " + macro_arg ) arg_str = arg_str [ : npos ] + arg_str [ npos3 + 1 : ] npos = arg_str . find ( "const" ) if npos >= 0 : modlist . append ( "/C" ) npos = arg_str . find ( "&" ) if npos >= 0 : modlist . append ( "/Ref" ) arg_str = arg_str . strip ( ) word_start = 0 word_list = [ ] npos = - 1 # print self.lineno, ":\t", arg_str # pass 1: split argument type into tokens while 1 : npos += 1 t , npos = self . find_next_token ( arg_str , [ " " , "&" , "*" , "<" , ">" , "," ] , npos ) w = arg_str [ word_start : npos ] . strip ( ) if w == "operator" : word_list . append ( "operator " + arg_str [ npos : ] . strip ( ) ) break if w not in [ "" , "const" ] : word_list . append ( w ) if t not in [ "" , " " , "&" ] : word_list . append ( t ) if not t : break word_start = npos + 1 npos = word_start - 1 arg_type = "" arg_name = "" angle_stack = [ ] # print self.lineno, ":\t", word_list # pass 2: decrypt the list wi = - 1 prev_w = "" for w in word_list : wi += 1 if w == "*" : if prev_w == "char" and not isarray : arg_type = arg_type [ : - len ( "char" ) ] + "c_string" else : arg_type += w continue elif w == "<" : arg_type += "_" angle_stack . append ( 0 ) elif w == "," or w == '>' : if not angle_stack : print ( "Error at %d: argument contains ',' or '>' not within template arguments" % ( self . lineno , ) ) sys . exit ( - 1 ) if w == "," : arg_type += "_and_" elif w == ">" : if angle_stack [ 0 ] == 0 : print ( "Error at %s:%d: template has no arguments" % ( self . hname , self . lineno ) ) sys . exit ( - 1 ) if angle_stack [ 0 ] > 1 : arg_type += "_end_" angle_stack [ - 1 : ] = [ ] elif angle_stack : arg_type += w angle_stack [ - 1 ] += 1 elif arg_type == "struct" : arg_type += " " + w elif arg_type and arg_type != "~" : arg_name = " " . join ( word_list [ wi : ] ) break else : arg_type += w prev_w = w counter_str = "" add_star = False if ( "[" in arg_name ) and not ( "operator" in arg_str ) : # print arg_str p1 = arg_name . find ( "[" ) p2 = arg_name . find ( "]" , p1 + 1 ) if p2 < 0 : print ( "Error at %d: no closing ]" % ( self . lineno , ) ) sys . exit ( - 1 ) counter_str = arg_name [ p1 + 1 : p2 ] . strip ( ) if counter_str == "" : counter_str = "?" if not isarray : modlist . append ( "/A " + counter_str . strip ( ) ) arg_name = arg_name [ : p1 ] add_star = True if not arg_name : if arg_type . startswith ( "operator" ) : arg_type , arg_name = "" , arg_type else : arg_name = "arg" + str ( argno ) argno += 1 while arg_type . endswith ( "_end_" ) : arg_type = arg_type [ : - len ( "_end_" ) ] if add_star : arg_type += "*" arg_type = self . batch_replace ( arg_type , [ ( "std::" , "" ) , ( "cv::" , "" ) , ( "::" , "_" ) ] ) return arg_type , arg_name , modlist , argno