Commit 1271c383 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell Committed by Code Review
Browse files

Merge topic 'python-tuple-initialization' into master

46e6489a ENH: Make python initialize vtkTuple after construction.
parents 44362146 46e6489a
......@@ -536,6 +536,36 @@ int vtkWrap_HasPublicCopyConstructor(ClassInfo *data)
return 1;
}
/* -------------------------------------------------------------------- */
/* Get the size for subclasses of vtkTuple */
int vtkWrap_GetTupleSize(ClassInfo *data, HierarchyInfo *hinfo)
{
HierarchyEntry *entry;
const char *classname = NULL;
size_t m;
int size = 0;
entry = vtkParseHierarchy_FindEntry(hinfo, data->Name);
if (entry && vtkParseHierarchy_IsTypeOfTemplated(
hinfo, entry, data->Name, "vtkTuple", &classname))
{
/* attempt to get count from template parameter */
if (classname)
{
m = strlen(classname);
if (m > 2 && classname[m - 1] == '>' &&
isdigit(classname[m-2]) && (classname[m-3] == ' ' ||
classname[m-3] == ',' || classname[m-3] == '<'))
{
size = classname[m-2] - '0';
}
free((char *)classname);
}
}
return size;
}
/* -------------------------------------------------------------------- */
/* This sets the CountHint for vtkDataArray methods where the
* tuple size is equal to GetNumberOfComponents. */
......@@ -543,12 +573,9 @@ void vtkWrap_FindCountHints(
ClassInfo *data, HierarchyInfo *hinfo)
{
int i;
int count;
const char *countMethod;
const char *classname;
FunctionInfo *theFunc;
HierarchyEntry *entry;
size_t m;
char digit;
/* add hints for array GetTuple methods */
if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkDataArray"))
......@@ -622,27 +649,16 @@ void vtkWrap_FindCountHints(
theFunc->Arguments[0]->Count == 0 &&
hinfo)
{
entry = vtkParseHierarchy_FindEntry(hinfo, data->Name);
if (entry && vtkParseHierarchy_IsTypeOfTemplated(
hinfo, entry, data->Name, "vtkTuple", &classname))
count = vtkWrap_GetTupleSize(data, hinfo);
if (count)
{
/* attempt to get count from template parameter */
if (classname)
{
m = strlen(classname);
if (m > 2 && classname[m - 1] == '>' &&
isdigit(classname[m-2]) && (classname[m-3] == ' ' ||
classname[m-3] == ',' || classname[m-3] == '<'))
{
digit = classname[m-2];
theFunc->Arguments[0]->Count = digit - '0';
vtkParse_AddStringToArray(
&theFunc->Arguments[0]->Dimensions,
&theFunc->Arguments[0]->NumberOfDimensions,
vtkParse_DuplicateString(&digit, 1));
}
free((char *)classname);
}
char counttext[24];
sprintf(counttext, "%d", count);
theFunc->Arguments[0]->Count = count;
vtkParse_AddStringToArray(
&theFunc->Arguments[0]->Dimensions,
&theFunc->Arguments[0]->NumberOfDimensions,
vtkParse_DuplicateString(counttext, strlen(counttext)));
}
}
......
......@@ -161,6 +161,11 @@ void vtkWrap_ExpandTypedefs(ClassInfo *data, HierarchyInfo *hinfo);
void vtkWrap_FindCountHints(
ClassInfo *data, HierarchyInfo *hinfo);
/**
* Get the size of a fixed-size tuple
*/
int vtkWrap_GetTupleSize(ClassInfo *data, HierarchyInfo *hinfo);
/**
* Apply any hints about methods that return a new object instance,
* i.e. factory methods and the like. Reference counts must be
......
......@@ -63,7 +63,7 @@ static void vtkWrapPython_CustomMethods(
/* print out the code for one method, including all of its overloads */
void vtkWrapPython_GenerateOneMethod(
FILE *fp, const char *classname, ClassInfo *data,
FILE *fp, const char *classname, ClassInfo *data, HierarchyInfo *hinfo,
FunctionInfo *wrappedFunctions[], int numberOfWrappedFunctions, int fnum,
int is_vtkobject, int do_constructors);
......@@ -95,7 +95,7 @@ static void vtkWrapPython_SaveArrayArgs(
/* generate the code that calls the C++ method */
static void vtkWrapPython_GenerateMethodCall(
FILE *fp, FunctionInfo *currentFunction, ClassInfo *data,
int is_vtkobject);
HierarchyInfo *hinfo, int is_vtkobject);
/* Write back to all the reference arguments and array arguments */
static void vtkWrapPython_WriteBackToArgs(
......@@ -1726,7 +1726,7 @@ void vtkWrapPython_SaveArrayArgs(FILE *fp, FunctionInfo *currentFunction)
/* generate the code that calls the C++ method */
static void vtkWrapPython_GenerateMethodCall(
FILE *fp, FunctionInfo *currentFunction, ClassInfo *data,
int is_vtkobject)
HierarchyInfo *hinfo, int is_vtkobject)
{
char methodname[256];
ValueInfo *arg;
......@@ -1895,6 +1895,21 @@ static void vtkWrapPython_GenerateMethodCall(
}
}
if (is_constructor)
{
/* initialize tuples created with default constructor */
if (currentFunction->NumberOfArguments == 0 && hinfo)
{
n = vtkWrap_GetTupleSize(data, hinfo);
for (i = 0; i < n; i++)
{
fprintf(fp,
" (*op)[%d] = 0;\n",
i);
}
}
}
fprintf(fp,
"\n");
}
......@@ -2291,7 +2306,7 @@ static void vtkWrapPython_OverloadMasterMethod(
/* Write out the code for one method (including all its overloads) */
void vtkWrapPython_GenerateOneMethod(
FILE *fp, const char *classname, ClassInfo *data,
FILE *fp, const char *classname, ClassInfo *data, HierarchyInfo *hinfo,
FunctionInfo *wrappedFunctions[], int numberOfWrappedFunctions, int fnum,
int is_vtkobject, int do_constructors)
{
......@@ -2405,7 +2420,7 @@ void vtkWrapPython_GenerateOneMethod(
vtkWrapPython_SaveArrayArgs(fp, theOccurrence);
/* generate the code that calls the C++ method */
vtkWrapPython_GenerateMethodCall(fp, theOccurrence, data,
vtkWrapPython_GenerateMethodCall(fp, theOccurrence, data, hinfo,
is_vtkobject);
/* write back to all array args */
......@@ -2564,7 +2579,8 @@ static void vtkWrapPython_GenerateMethods(
fprintf(fp,"\n");
vtkWrapPython_GenerateOneMethod(
fp, classname, data, wrappedFunctions, numberOfWrappedFunctions,
fp, classname, data, hinfo,
wrappedFunctions, numberOfWrappedFunctions,
fnum, is_vtkobject, do_constructors);
} /* is this method non NULL */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment