Opentk/Source/OpenGL/Bind/WriteSpecs.cs

203 lines
6.2 KiB
C#
Raw Normal View History

2006-10-08 18:26:43 +00:00
#region License
//Copyright (c) 2006 Stephen Apostolopoulos
//See license.txt for license info
#endregion
2006-09-28 22:07:53 +00:00
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections;
namespace OpenTK.OpenGL.Bind
{
static partial class SpecWriter
{
#region WriteSpecs
2006-10-10 23:40:36 +00:00
public static void WriteSpecs(string output_path, string class_name, List<Function> functions, List<Function> wrappers, Hashtable enums)
2006-09-28 22:07:53 +00:00
{
2006-10-10 23:40:36 +00:00
string filename = Path.Combine(output_path, class_name + ".cs");
2006-09-28 22:07:53 +00:00
if (!Directory.Exists(Settings.OutputPath))
Directory.CreateDirectory(Settings.OutputPath);
StreamWriter sw = new StreamWriter(filename, false);
2006-10-10 23:40:36 +00:00
Console.WriteLine("Writing {0} class to {1}", class_name, filename);
2006-09-28 22:07:53 +00:00
WriteLicense(sw);
sw.WriteLine("using System;");
sw.WriteLine("using System.Runtime.InteropServices;");
sw.WriteLine("using System.Text;");
2006-09-28 22:07:53 +00:00
sw.WriteLine();
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{");
WriteTypes(sw);
WriteEnums(sw, enums);
2006-10-10 23:40:36 +00:00
sw.WriteLine(" public static partial class {0}", class_name);
2006-09-28 22:07:53 +00:00
sw.WriteLine(" {");
WriteFunctionSignatures(sw, functions);
WriteDllImports(sw, functions);
WriteFunctions(sw, functions);
WriteWrappers(sw, wrappers);
sw.WriteLine(" }");
sw.WriteLine("}");
sw.WriteLine();
sw.Flush();
sw.Close();
}
#endregion
2006-10-08 18:26:43 +00:00
#region WriteLicense
2006-09-28 22:07:53 +00:00
public static void WriteLicense(StreamWriter sw)
{
2006-10-08 18:26:43 +00:00
sw.WriteLine("#region License");
sw.WriteLine("//Copyright (c) 2006 Stephen Apostolopoulos");
sw.WriteLine("//See license.txt for license info");
sw.WriteLine("#endregion");
sw.WriteLine();
2006-09-28 22:07:53 +00:00
}
2006-10-08 18:26:43 +00:00
#endregion
2006-09-28 22:07:53 +00:00
#region Write types
2006-09-28 22:07:53 +00:00
private static void WriteTypes(StreamWriter sw)
{
sw.WriteLine(" #region Types");
//foreach ( c in constants)
2006-10-10 23:40:36 +00:00
foreach (string key in Translation.CSTypes.Keys)
2006-09-28 22:07:53 +00:00
{
2006-10-10 23:40:36 +00:00
sw.WriteLine(" using {0} = System.{1};", key, Translation.CSTypes[key]);
2006-09-28 22:07:53 +00:00
//sw.WriteLine(" public const {0};", c.ToString());
}
sw.WriteLine(" #endregion");
sw.WriteLine();
}
2006-09-28 22:07:53 +00:00
#endregion
#region Write enums
private static void WriteEnums(StreamWriter sw, Hashtable enums)
{
sw.WriteLine(" #region Enums");
sw.WriteLine(" public struct Enums");
sw.WriteLine(" {");
#region Missing constants
sw.WriteLine(" #region Missing Constants");
sw.WriteLine();
sw.WriteLine();
sw.WriteLine(" #endregion");
sw.WriteLine();
#endregion
foreach (Enum e in enums.Values)
{
sw.WriteLine(e.ToString());
}
sw.WriteLine(" }");
sw.WriteLine(" #endregion");
sw.WriteLine();
}
#endregion
#region Write function signatures
private static void WriteFunctionSignatures(StreamWriter sw, List<Function> functions)
{
sw.WriteLine(" #region Function signatures");
sw.WriteLine();
sw.WriteLine(" public static class Delegates");
sw.WriteLine(" {");
foreach (Function f in functions)
{
sw.WriteLine(" public delegate {0};", f.ToString());
}
sw.WriteLine(" }");
sw.WriteLine(" #endregion");
sw.WriteLine();
}
#endregion
#region Write dll imports
private static void WriteDllImports(StreamWriter sw, List<Function> functions)
{
sw.WriteLine(" #region Imports");
sw.WriteLine();
sw.WriteLine(" internal class Imports");
sw.WriteLine(" {");
foreach (Function f in functions)
{
if (!f.Extension)
{
2006-10-08 18:26:43 +00:00
sw.WriteLine(" [DllImport(\"opengl32.dll\", EntryPoint = \"gl{0}\")]", f.Name.TrimEnd('_'));
2006-09-28 22:07:53 +00:00
sw.WriteLine(" public static extern {0};", f.ToString());
}
}
sw.WriteLine(" }");
sw.WriteLine(" #endregion");
sw.WriteLine();
}
#endregion
#region Write functions
2006-10-10 23:40:36 +00:00
2006-09-28 22:07:53 +00:00
private static void WriteFunctions(StreamWriter sw, List<Function> functions)
{
sw.WriteLine(" #region Function initialisation");
sw.WriteLine();
foreach (Function f in functions)
{
sw.WriteLine(" public static Delegates.{0} {0};", f.Name);
}
sw.WriteLine();
2006-09-28 22:07:53 +00:00
sw.WriteLine(" #endregion");
sw.WriteLine();
}
2006-10-10 23:40:36 +00:00
2006-09-28 22:07:53 +00:00
#endregion
#region Write wrappers
2006-10-10 23:40:36 +00:00
2006-09-28 22:07:53 +00:00
public static void WriteWrappers(StreamWriter sw, List<Function> wrappers)
{
sw.WriteLine(" #region Wrappers");
sw.WriteLine();
2006-10-10 23:40:36 +00:00
if (wrappers != null)
2006-09-28 22:07:53 +00:00
{
2006-10-10 23:40:36 +00:00
foreach (Function w in wrappers)
{
sw.WriteLine(" #region {0}{1}", w.Name, w.Parameters.ToString());
sw.WriteLine();
sw.WriteLine(" public static");
sw.WriteLine(w.ToString(" "));
sw.WriteLine(" #endregion");
sw.WriteLine();
}
2006-09-28 22:07:53 +00:00
}
2006-10-10 23:40:36 +00:00
sw.WriteLine(" #endregion");
2006-09-28 22:07:53 +00:00
}
2006-10-10 23:40:36 +00:00
2006-09-28 22:07:53 +00:00
#endregion
}
}