Avoid singletons

A reference to a Settings instance must now be stored explicitly.
This commit is contained in:
Stefanos A. 2013-11-01 09:26:13 +01:00
parent e1f064b634
commit 33e6a6eae2
2 changed files with 37 additions and 11 deletions

View file

@ -46,6 +46,9 @@ namespace Bind
const string DigitPrefix = "T"; // Prefix for identifiers that start with a digit
const string OutputFileHeader = "gl++.h";
IBind Generator { get; set; }
Settings Settings { get { return Generator.Settings; } }
#region Verbatim parts of output file
const string GetAddressDefinition = @"
@ -293,6 +296,7 @@ typedef const char* GLstring;
public void WriteBindings(IBind generator)
{
Generator = generator;
WriteBindings(generator.Delegates, generator.Wrappers, generator.Enums);
}
@ -328,7 +332,7 @@ typedef const char* GLstring;
WriteGetAddress(sw);
WriteTypes(sw);
WriteEnums(sw, enums);
WriteDefinitions(sw, enums, wrappers, Type.CSTypes); // Core definitions
WriteDefinitions(sw, enums, wrappers, Generator.CSTypes); // Core definitions
sw.Unindent();
sw.WriteLine("}");
@ -471,7 +475,7 @@ typedef const char* GLstring;
void WriteDefinitions(BindStreamWriter sw,
EnumCollection enums, FunctionCollection wrappers,
Dictionary<string, string> CSTypes)
IDictionary<string, string> CSTypes)
{
sw.WriteLine("namespace {0}", Settings.GLClass);
sw.WriteLine("{");
@ -553,7 +557,7 @@ typedef const char* GLstring;
#endregion
static string GetNamespace(string ext)
string GetNamespace(string ext)
{
if (ext == "Core")
return Settings.GLClass;
@ -661,8 +665,17 @@ typedef const char* GLstring;
return sb.ToString();
}
static DocProcessor processor = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
static Dictionary<string, string> docfiles;
DocProcessor processor_;
DocProcessor Processor
{
get
{
if (processor_ == null)
processor_ = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
return processor_;
}
}
Dictionary<string, string> docfiles;
void WriteDocumentation(BindStreamWriter sw, Function f)
{
if (docfiles == null)
@ -686,7 +699,7 @@ typedef const char* GLstring;
string doc = null;
if (docfiles.ContainsKey(docfile))
{
doc = processor.ProcessFile(docfiles[docfile]);
doc = Processor.ProcessFile(docfiles[docfile]);
}
if (doc == null)
{

View file

@ -47,10 +47,14 @@ namespace Bind
BindStreamWriter sw_h = new BindStreamWriter(Path.GetTempFileName());
IBind Generator { get; set; }
Settings Settings { get { return Generator.Settings; } }
#region WriteBindings
public void WriteBindings(IBind generator)
{
Generator = generator;
WriteBindings(generator.Delegates, generator.Wrappers, generator.Enums);
}
@ -77,7 +81,7 @@ namespace Bind
sw.WriteLine("import java.nio.*;");
sw.WriteLine();
WriteDefinitions(sw, enums, wrappers, Type.CSTypes);
WriteDefinitions(sw, enums, wrappers, Generator.CSTypes);
sw.Flush();
sw.Close();
@ -100,7 +104,7 @@ namespace Bind
void WriteDefinitions(BindStreamWriter sw,
EnumCollection enums, FunctionCollection wrappers,
Dictionary<string, string> CSTypes)
IDictionary<string, string> CSTypes)
{
sw.WriteLine("public class {0}", Settings.GLClass);
sw.WriteLine("{");
@ -312,8 +316,17 @@ namespace Bind
return f.ReturnType.CurrentType;
}
static DocProcessor processor = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
static Dictionary<string, string> docfiles;
DocProcessor processor_;
DocProcessor Processor
{
get
{
if (processor_ == null)
processor_ = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
return processor_;
}
}
Dictionary<string, string> docfiles;
void WriteDocumentation(BindStreamWriter sw, Function f)
{
if (docfiles == null)
@ -337,7 +350,7 @@ namespace Bind
string doc = null;
if (docfiles.ContainsKey(docfile))
{
doc = processor.ProcessFile(docfiles[docfile]);
doc = Processor.ProcessFile(docfiles[docfile]);
}
if (doc == null)
{