[Bind] Add int overloads to buffer size (IntPtr) parameters

As a convenience, int overloads are provided for IntPtr size
parameters (corresponding to BufferSize or size_t). In the vast
majority of cases, a 32bit int is sufficient for buffer sizes,
so these overloads avoid the necessity of annoying (IntPtr) casts.

If more than 2^31-1 elements are required, the IntPtr overloads
remain available. (As always, this requires a 64bit runtime
environment.)
This commit is contained in:
thefiddler 2014-09-02 09:48:39 +02:00
parent 074a4ff807
commit cbe0684d7f
2 changed files with 34 additions and 9 deletions

View file

@ -324,19 +324,18 @@ namespace Bind
}
else
{
// Todo: what is the point of this here? It is overwritten below.
// A few translations for consistency
switch (type.CurrentType.ToLower())
{
case "string":
type.QualifiedType = "String";
break;
}
type.QualifiedType = s;
}
}
if ((type.Array == 0 && type.Pointer == 0 && !type.Reference) &&
(type.QualifiedType.ToLower().Contains("buffersize") ||
type.QualifiedType.ToLower().Contains("sizeiptr") ||
type.QualifiedType.Contains("size_t")))
{
type.WrapperType |= WrapperTypes.SizeParameter;
}
type.CurrentType =
Generator.CSTypes.ContainsKey(type.CurrentType) ?
Generator.CSTypes[type.CurrentType] : type.CurrentType;
@ -960,6 +959,27 @@ namespace Bind
convenience_wrappers.Add(f);
}
}
// Check for IntPtr parameters that correspond to size_t (e.g. GLsizei)
// and add Int32 overloads for convenience.
{
Function f = null;
int i = 0;
foreach (var p in d.Parameters)
{
if ((p.WrapperType & WrapperTypes.SizeParameter) != 0)
{
f = f ?? new Function(d);
f.Parameters[i].QualifiedType = "Int32";
}
i++;
}
if (f != null)
{
convenience_wrappers.Add(f);
}
}
}
return convenience_wrappers;
}

View file

@ -89,6 +89,11 @@ namespace Bind
/// Function takes a String[] parameter
/// </summary>
StringArrayParameter = 1 << 13,
/// <summary>
/// Functions takes an IntPtr that corresponds to a size_t.
/// Add an int32 overload for convenience.
/// </summary>
SizeParameter = 1 << 14,
}
#endregion