Browse Source

Cleaned up TextTemplate class.

pull/12/merge
triton 12 years ago
parent
commit
cbe05e6253
  1. 28
      src/Generator/Generators/CLI/CLITextTemplate.cs
  2. 32
      src/Generator/Generators/Template.cs

28
src/Generator/Generators/CLI/CLITextTemplate.cs

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using CppSharp.Types;
namespace CppSharp.Generators.CLI
{
@ -29,21 +28,6 @@ namespace CppSharp.Generators.CLI @@ -29,21 +28,6 @@ namespace CppSharp.Generators.CLI
/// </summary>
public abstract class CLITextTemplate : TextTemplate
{
protected const string DefaultIndent = " ";
protected const uint MaxIndent = 80;
public delegate void GenerateTextDelegate(CLITextTemplate gen);
/// <summary>
/// Called when the generation is starting.
/// </summary>
public GenerateTextDelegate OnStart = delegate { };
/// <summary>
/// Called when generating namespaces.
/// </summary>
public GenerateTextDelegate OnNamespaces = delegate { };
public CLITypePrinter TypePrinter { get; set; }
public ISet<Include> Includes;
@ -55,6 +39,12 @@ namespace CppSharp.Generators.CLI @@ -55,6 +39,12 @@ namespace CppSharp.Generators.CLI
Includes = new HashSet<Include>();
}
public abstract override string FileExtension { get; }
public abstract override void Generate();
#region Helpers
public static string SafeIdentifier(string proposedName)
{
return proposedName;
@ -73,7 +63,7 @@ namespace CppSharp.Generators.CLI @@ -73,7 +63,7 @@ namespace CppSharp.Generators.CLI
return;
// Wrap the comment to the line width.
var maxSize = (int)(MaxIndent - CurrentIndent.Count - "/// ".Length);
var maxSize = (int)(Options.MaxIndent - CurrentIndent.Count - "/// ".Length);
var lines = StringHelpers.WordWrapLines(comment, maxSize);
WriteLine("/// <summary>");
@ -112,8 +102,6 @@ namespace CppSharp.Generators.CLI @@ -112,8 +102,6 @@ namespace CppSharp.Generators.CLI
return string.Join(", ", types);
}
public abstract override string FileExtension { get; }
public abstract override void Generate();
#endregion
}
}

32
src/Generator/Generators/Template.cs

@ -1,25 +1,31 @@ @@ -1,25 +1,31 @@
namespace CppSharp.Generators
using System.Collections.Generic;
using System.Text;
namespace CppSharp.Generators
{
public abstract class TextTemplate : TextGenerator
{
private const uint DefaultIndent = 4;
private const uint MaxIndent = 80;
public Driver Driver { get; set; }
public DriverOptions Options { get; set; }
public Library Library { get; set; }
public ILibrary Transform;
public TranslationUnit TranslationUnit { get; set; }
public abstract string FileExtension { get; }
public abstract void Generate();
public Driver Driver { get; private set; }
public DriverOptions Options { get; private set; }
public Library Library { get; private set; }
public TranslationUnit TranslationUnit { get; private set; }
protected TextTemplate(Driver driver, TranslationUnit unit)
{
Driver = driver;
Options = driver.Options;
Library = driver.Library;
Transform = driver.Transform;
TranslationUnit = unit;
}
public abstract string FileExtension { get; }
public abstract void Generate();
public virtual string GenerateText()
{
return base.ToString();
}
}
}
Loading…
Cancel
Save