Permalink
Browse files

Do not rely on JNA types that are not available on Android.

Replaced generic multiple wrappers by a single Buffer wrapper.

git-svn-id: https://opentk.svn.sourceforge.net/svnroot/opentk/trunk@3105 ebc5dd9b-fb1d-0410-b6f8-d24c324e9604
  • Loading branch information...
1 parent eb9f428 commit 770d00d2168320f5b8f1eae222cc6451b58fc3e7 the_fiddler committed Dec 5, 2011
Showing with 40 additions and 18 deletions.
  1. +40 −18 Source/Bind/JavaSpecWriter.cs
@@ -74,6 +74,8 @@ void WriteBindings(DelegateCollection delegates, FunctionCollection wrappers, En
sw.WriteLine("package {0}.{1};", Settings.OutputNamespace, Settings.GLClass);
sw.WriteLine();
+ sw.WriteLine("import java.nio.*;");
+ sw.WriteLine();
WriteDefinitions(sw, enums, wrappers, Type.CSTypes);
@@ -144,17 +146,25 @@ public void WriteEnums(BindStreamWriter sw, EnumCollection enums)
sw.WriteLine("{");
sw.Indent();
int count = @enum.ConstantCollection.Values.Count;
- foreach (var c in @enum.ConstantCollection.Values)
+ if (count == 0)
{
- sw.WriteLine(String.Format("{0}({1}{2}){3}",
- c.Name,
- !String.IsNullOrEmpty(c.Reference) ? (c.Reference + Settings.NamespaceSeparator) : "",
- !String.IsNullOrEmpty(c.Reference) ? c.Value : c.Value.ToLower(),
- --count == 0 ? ";" : ","));
+ // Java enums must have at least one value.
+ sw.WriteLine("None;");
+ }
+ else
+ {
+ foreach (var c in @enum.ConstantCollection.Values)
+ {
+ sw.WriteLine(String.Format("{0}({1}{2}){3}",
+ c.Name,
+ !String.IsNullOrEmpty(c.Reference) ? (c.Reference + Settings.NamespaceSeparator) : "",
+ !String.IsNullOrEmpty(c.Reference) ? c.Value : c.Value.ToLower(),
+ --count == 0 ? ";" : ","));
+ }
+ sw.WriteLine();
+ sw.WriteLine("{0} mValue;", @enum.Type);
+ sw.WriteLine("{0}({1} value) {{ mValue = value; }}", @enum.Name, @enum.Type);
}
- sw.WriteLine();
- sw.WriteLine("{0} mValue;", @enum.Type);
- sw.WriteLine("{0}({1} value) {{ mValue = value; }}", @enum.Name, @enum.Type);
sw.Unindent();
sw.WriteLine("}");
sw.WriteLine();
@@ -170,14 +180,15 @@ static void WriteWrapper(Function f, BindStreamWriter sw)
var valid = true;
var generic_parameters = GenerateGenericTypeString(f);
var parameters = GenerateParameterString(f, out valid);
+ var ret_parameter = GenerateReturnParameterString(f);
if (!valid)
return;
if (!String.IsNullOrEmpty(generic_parameters))
sw.WriteLine("public static <{0}> {1} {2}({3})", generic_parameters,
- f.ReturnType, f.TrimmedName, parameters);
+ ret_parameter, f.TrimmedName, parameters);
else
- sw.WriteLine("public static {0} {1}({2})", f.ReturnType, f.TrimmedName,
+ sw.WriteLine("public static {0} {1}({2})", ret_parameter, f.TrimmedName,
parameters);
sw.WriteLine("{");
@@ -196,8 +207,6 @@ static void WriteMethodBody(BindStreamWriter sw, Function f)
// sw.WriteLine("GLES20.{0}{1};", f.WrappedDelegate.Name, callstring);
}
- #region GenerateParameterString
-
static string GenerateParameterString(Function f, out bool valid)
{
if (f == null)
@@ -239,6 +248,13 @@ static string GenerateParameterString(Function f, out bool valid)
}
else if (p.Array > 0)
{
+ // Generic arrays are handled in the IntPtr case below.
+ if (p.Generic)
+ {
+ valid = false;
+ return String.Empty;
+ }
+
sb.Append(p.CurrentType);
for (int i = 0; i < p.Array; i++)
sb.Append("[]");
@@ -250,6 +266,10 @@ static string GenerateParameterString(Function f, out bool valid)
valid = false;
return String.Empty;
}
+ else if (p.CurrentType == "IntPtr")
+ {
+ sb.Append("Buffer");
+ }
else
{
sb.Append(p.CurrentType);
@@ -267,10 +287,6 @@ static string GenerateParameterString(Function f, out bool valid)
return sb.ToString();
}
- #endregion
-
- #region GenerateGenericTypeString
-
static string GenerateGenericTypeString(Function f)
{
var parameters = f.Parameters.Where(p => p.Generic);
@@ -291,7 +307,13 @@ static string GenerateGenericTypeString(Function f)
return String.Empty;
}
- #endregion
+ private static string GenerateReturnParameterString(Function f)
+ {
+ if (f.ReturnType.CurrentType == "IntPtr")
+ return "Buffer";
+ else
+ return f.ReturnType.CurrentType;
+ }
static DocProcessor processor = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
static Dictionary<string, string> docfiles;

0 comments on commit 770d00d

Please sign in to comment.