From cbe0684d7f76f2a2ce174b55b35c70aa649a4fe0 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Tue, 2 Sep 2014 09:48:39 +0200 Subject: [PATCH] [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.) --- Source/Bind/FuncProcessor.cs | 38 +++++++++++++++++++++++++++++--------- Source/Bind/Utilities.cs | 5 +++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Source/Bind/FuncProcessor.cs b/Source/Bind/FuncProcessor.cs index cb126e4..81a55cd 100644 --- a/Source/Bind/FuncProcessor.cs +++ b/Source/Bind/FuncProcessor.cs @@ -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; } diff --git a/Source/Bind/Utilities.cs b/Source/Bind/Utilities.cs index 11b4eb4..a8752b7 100644 --- a/Source/Bind/Utilities.cs +++ b/Source/Bind/Utilities.cs @@ -89,6 +89,11 @@ namespace Bind /// Function takes a String[] parameter /// StringArrayParameter = 1 << 13, + /// + /// Functions takes an IntPtr that corresponds to a size_t. + /// Add an int32 overload for convenience. + /// + SizeParameter = 1 << 14, } #endregion -- 2.7.4