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 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using CppSharp.Types;
namespace CppSharp.Generators.CLI namespace CppSharp.Generators.CLI
{ {
@ -29,21 +28,6 @@ namespace CppSharp.Generators.CLI
/// </summary> /// </summary>
public abstract class CLITextTemplate : TextTemplate 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 CLITypePrinter TypePrinter { get; set; }
public ISet<Include> Includes; public ISet<Include> Includes;
@ -55,6 +39,12 @@ namespace CppSharp.Generators.CLI
Includes = new HashSet<Include>(); Includes = new HashSet<Include>();
} }
public abstract override string FileExtension { get; }
public abstract override void Generate();
#region Helpers
public static string SafeIdentifier(string proposedName) public static string SafeIdentifier(string proposedName)
{ {
return proposedName; return proposedName;
@ -73,7 +63,7 @@ namespace CppSharp.Generators.CLI
return; return;
// Wrap the comment to the line width. // 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); var lines = StringHelpers.WordWrapLines(comment, maxSize);
WriteLine("/// <summary>"); WriteLine("/// <summary>");
@ -112,8 +102,6 @@ namespace CppSharp.Generators.CLI
return string.Join(", ", types); return string.Join(", ", types);
} }
public abstract override string FileExtension { get; } #endregion
public abstract override void Generate();
} }
} }

32
src/Generator/Generators/Template.cs

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