2007-08-10 09:27:13 +00:00
|
|
|
#region --- License ---
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
* See license.txt for license info
|
|
|
|
*/
|
2007-07-23 00:15:18 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
2007-08-01 21:14:39 +00:00
|
|
|
using System.IO;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
namespace Bind.Structures
|
2007-07-23 00:15:18 +00:00
|
|
|
{
|
|
|
|
#region class Enum
|
|
|
|
|
|
|
|
public class Enum
|
|
|
|
{
|
2007-08-01 21:14:39 +00:00
|
|
|
internal static EnumCollection GLEnums;
|
2007-09-02 00:40:43 +00:00
|
|
|
internal static EnumCollection AuxEnums;
|
2007-08-01 21:14:39 +00:00
|
|
|
|
|
|
|
private static bool enumsLoaded;
|
|
|
|
|
2007-09-02 00:40:43 +00:00
|
|
|
internal static void Initialize(string enumFile, string enumextFile, string auxFile)
|
|
|
|
{
|
|
|
|
Initialize(enumFile, enumextFile);
|
|
|
|
|
2007-09-02 22:52:00 +00:00
|
|
|
using (System.IO.StreamReader sr = new System.IO.StreamReader(Path.Combine(Settings.InputPath, auxFile)))
|
2007-09-02 00:40:43 +00:00
|
|
|
{
|
|
|
|
AuxEnums = Bind.MainClass.Generator.ReadEnums(sr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-04 23:39:56 +00:00
|
|
|
internal static void Initialize(string enumFile, string enumextFile)
|
2007-08-01 21:14:39 +00:00
|
|
|
{
|
|
|
|
if (!enumsLoaded)
|
|
|
|
{
|
2007-09-02 00:40:43 +00:00
|
|
|
if (!String.IsNullOrEmpty(enumFile))
|
2007-08-01 21:14:39 +00:00
|
|
|
{
|
2007-09-02 00:40:43 +00:00
|
|
|
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, enumFile))
|
|
|
|
{
|
|
|
|
GLEnums = Bind.MainClass.Generator.ReadEnums(sr);
|
|
|
|
}
|
2007-08-01 21:14:39 +00:00
|
|
|
}
|
|
|
|
|
2007-09-02 00:40:43 +00:00
|
|
|
if (!String.IsNullOrEmpty(enumextFile))
|
2007-08-01 21:14:39 +00:00
|
|
|
{
|
2007-09-02 00:40:43 +00:00
|
|
|
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, enumextFile))
|
2007-08-01 21:14:39 +00:00
|
|
|
{
|
2007-09-02 00:40:43 +00:00
|
|
|
foreach (Bind.Structures.Enum e in Bind.MainClass.Generator.ReadEnums(sr).Values)
|
|
|
|
{
|
|
|
|
//enums.Add(e.Name, e);
|
|
|
|
Utilities.Merge(GLEnums, e);
|
|
|
|
}
|
2007-08-01 21:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
enumsLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
public Enum()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
public Enum(string name)
|
|
|
|
{
|
|
|
|
Name = name;
|
|
|
|
}
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
string _name;
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return _name; }
|
|
|
|
set { _name = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
System.Collections.Hashtable _constant_collection = new System.Collections.Hashtable();
|
|
|
|
|
|
|
|
public System.Collections.Hashtable ConstantCollection
|
|
|
|
{
|
|
|
|
get { return _constant_collection; }
|
|
|
|
set { _constant_collection = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
sb.AppendLine("public enum " + Name);
|
|
|
|
sb.AppendLine("{");
|
2007-07-23 00:15:18 +00:00
|
|
|
foreach (Constant c in ConstantCollection.Values)
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
sb.Append(" ");
|
|
|
|
sb.Append(c.ToString());
|
|
|
|
sb.AppendLine(",");
|
|
|
|
}
|
2007-09-22 14:59:33 +00:00
|
|
|
sb.Append("}");
|
2007-08-01 09:27:57 +00:00
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region class EnumCollection
|
|
|
|
|
|
|
|
class EnumCollection : Dictionary<string, Enum>
|
|
|
|
{
|
2007-08-01 21:14:39 +00:00
|
|
|
internal void AddRange(EnumCollection enums)
|
2007-08-01 09:27:57 +00:00
|
|
|
{
|
2007-08-01 21:14:39 +00:00
|
|
|
foreach (Enum e in enums.Values)
|
2007-08-01 09:27:57 +00:00
|
|
|
{
|
2007-08-01 21:14:39 +00:00
|
|
|
Utilities.Merge(this, e);
|
2007-07-23 00:15:18 +00:00
|
|
|
}
|
2007-08-01 21:14:39 +00:00
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
2007-08-01 21:14:39 +00:00
|
|
|
internal void Translate()
|
|
|
|
{
|
|
|
|
foreach (Enum e in this.Values)
|
|
|
|
{
|
|
|
|
foreach (Constant c in e.ConstantCollection.Values)
|
|
|
|
{
|
|
|
|
// There are cases when a value is an aliased constant, with no enum specified.
|
|
|
|
// (e.g. FOG_COORD_ARRAY_TYPE = GL_FOG_COORDINATE_ARRAY_TYPE)
|
|
|
|
// In this case try searching all enums for the correct constant to alias (stupid opengl specs).
|
|
|
|
if (String.IsNullOrEmpty(c.Reference) && !Char.IsDigit(c.Value[0]))
|
|
|
|
{
|
|
|
|
foreach (Enum @enum in this.Values)
|
|
|
|
{
|
|
|
|
// Skip generic GLenum
|
|
|
|
if (@enum.Name == "GLenum")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (@enum.ConstantCollection.ContainsKey(c.Value))
|
|
|
|
{
|
|
|
|
c.Reference = @enum.Name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 15:48:52 +00:00
|
|
|
|
|
|
|
// Obey .Net naming rules:
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.NoAdvancedEnumProcessing) == Settings.Legacy.None)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|