sipParseArgs

Name

sipParseArgs -- Parse the arguments to a C/C++ function without any side effects

Synopsis

int sipParseArgs(int * argsParsedp, PyObject * sipArgs, char * fmt, ...);

Description

Return Value

false (or 0) if an error occurred, else true (or 1).

argsParsedp

Parsing stops if an error is encountered or all arguments / format specifiers are exhausted. The number of arguments parsed so far is stored here along with error flags.

Table C-1. Error flags in sipParseArgs()

Flag NameMeaning
PARSE_OKParse is Ok so far
PARSE_MANYToo many arguments
PARSE_FEWToo few arguments
PARSE_TYPEArgument with a bad type
PARSE_MASKMask covering the error flag bits

sipArgs

A pointer to a tuple which supplies the arguments to be parsed.

fmt

Format string describing arguments. A leading '-' in the format string disposes of the arguments on a successful parse. A '|' in the format string signifies that the following arguments are optional. The following format specifiers are recognized:

Table C-2. Format specifiers for sipParseArgs()

fmtOperand typeexpected C argument(s)
sString or Nonechar **
SSlot name, return the namechar **
GSignal name, return the namechar **
IClass instanceint (*convfunc)(PyObject *), PyObject **
OPython object of any typePyObject **
TPython object of given typePyTypeObject *, PyObject **
RSub-class of QObjectPyObject **
FPython callable objectPyObject **
aByte array or Nonechar **, int *
cCharacterchar *
iIntegerint *
hShort integershort *
lLong integerlong *
fFloatfloat *
dDouble floatdouble *
vVoid pointervoid **

...

A variable number of pointers to the arguments which will take the parsed values.

Examples

Example C-1. Interface for QRegExp::match

// Attempts to match in str, starting from position index. 
// Returns the position of the match, or -1 if there was no match.
// if len is not a null pointer, the length of the match is stored in *len. 
int match(const char* str, int index=0, int*=0) const;
%MemberCode
    // The Python interface returns the position and length as a tuple.
    const char *str;
    int index = 0;

    if (sipParseArgs(&sipArgsParsed, sipArgs, "s|i", &str, &index))
    {
        int pos, len;
        QRegExp *ptr;

        if ((ptr = (QRegExp*) sipGetCppPtr(sipThis, sipClass_QRegExp)) == NULL)
            return NULL;
        pos = ptr -> QRegExp::match(str, index, &len);
        return Py_BuildValue("(ii)", pos, len);
    }
%End