2007-08-10 11:27:13 +02:00
|
|
|
#region --- License ---
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
* See license.txt for license info
|
|
|
|
*/
|
2007-07-23 02:15:18 +02:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
2007-08-01 23:14:39 +02:00
|
|
|
using System.IO;
|
2007-07-23 02:15:18 +02:00
|
|
|
|
2007-08-01 11:27:57 +02:00
|
|
|
namespace Bind.Structures
|
2007-07-23 02:15:18 +02:00
|
|
|
{
|
|
|
|
#region class Enum
|
|
|
|
|
|
|
|
public class Enum
|
|
|
|
{
|
2007-08-01 23:14:39 +02:00
|
|
|
internal static EnumCollection GLEnums;
|
|
|
|
|
|
|
|
private static bool enumsLoaded;
|
|
|
|
|
2007-08-05 01:39:56 +02:00
|
|
|
internal static void Initialize(string enumFile, string enumextFile)
|
2007-08-01 23:14:39 +02:00
|
|
|
{
|
|
|
|
if (!enumsLoaded)
|
|
|
|
{
|
2007-08-05 01:39:56 +02:00
|
|
|
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, enumFile))
|
2007-08-01 23:14:39 +02:00
|
|
|
{
|
|
|
|
GLEnums = Bind.MainClass.Generator.ReadEnums(sr);
|
|
|
|
}
|
|
|
|
|
2007-08-05 01:39:56 +02:00
|
|
|
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, enumextFile))
|
2007-08-01 23:14:39 +02:00
|
|
|
{
|
|
|
|
foreach (Bind.Structures.Enum e in Bind.MainClass.Generator.ReadEnums(sr).Values)
|
|
|
|
{
|
|
|
|
//enums.Add(e.Name, e);
|
|
|
|
Utilities.Merge(GLEnums, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enumsLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-01 11:27:57 +02:00
|
|
|
public Enum()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
public Enum(string name)
|
|
|
|
{
|
|
|
|
Name = name;
|
|
|
|
}
|
|
|
|
|
2007-07-23 02:15:18 +02: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 11:27:57 +02:00
|
|
|
sb.AppendLine("public enum " + Name);
|
|
|
|
sb.AppendLine("{");
|
2007-07-23 02:15:18 +02:00
|
|
|
foreach (Constant c in ConstantCollection.Values)
|
|
|
|
{
|
2007-08-01 11:27:57 +02:00
|
|
|
sb.Append(" ");
|
|
|
|
sb.Append(c.ToString());
|
|
|
|
sb.AppendLine(",");
|
|
|
|
}
|
|
|
|
sb.AppendLine("}");
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region class EnumCollection
|
|
|
|
|
|
|
|
class EnumCollection : Dictionary<string, Enum>
|
|
|
|
{
|
2007-08-01 23:14:39 +02:00
|
|
|
internal void AddRange(EnumCollection enums)
|
2007-08-01 11:27:57 +02:00
|
|
|
{
|
2007-08-01 23:14:39 +02:00
|
|
|
foreach (Enum e in enums.Values)
|
2007-08-01 11:27:57 +02:00
|
|
|
{
|
2007-08-01 23:14:39 +02:00
|
|
|
Utilities.Merge(this, e);
|
2007-07-23 02:15:18 +02:00
|
|
|
}
|
2007-08-01 23:14:39 +02:00
|
|
|
}
|
2007-07-23 02:15:18 +02:00
|
|
|
|
2007-08-01 23:14:39 +02: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-07-23 02:15:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|