From cbe05e6253b67366c4bc0de59a1f542741d52441 Mon Sep 17 00:00:00 2001 From: triton Date: Sun, 14 Jul 2013 19:22:26 +0100 Subject: [PATCH] Cleaned up TextTemplate class. --- .../Generators/CLI/CLITextTemplate.cs | 28 +++++----------- src/Generator/Generators/Template.cs | 32 +++++++++++-------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/Generator/Generators/CLI/CLITextTemplate.cs b/src/Generator/Generators/CLI/CLITextTemplate.cs index 6041cd6c..17d05c08 100644 --- a/src/Generator/Generators/CLI/CLITextTemplate.cs +++ b/src/Generator/Generators/CLI/CLITextTemplate.cs @@ -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 /// public abstract class CLITextTemplate : TextTemplate { - protected const string DefaultIndent = " "; - protected const uint MaxIndent = 80; - - public delegate void GenerateTextDelegate(CLITextTemplate gen); - - /// - /// Called when the generation is starting. - /// - public GenerateTextDelegate OnStart = delegate { }; - - /// - /// Called when generating namespaces. - /// - public GenerateTextDelegate OnNamespaces = delegate { }; - public CLITypePrinter TypePrinter { get; set; } public ISet Includes; @@ -55,6 +39,12 @@ namespace CppSharp.Generators.CLI Includes = new HashSet(); } + 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 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("/// "); @@ -112,8 +102,6 @@ namespace CppSharp.Generators.CLI return string.Join(", ", types); } - public abstract override string FileExtension { get; } - - public abstract override void Generate(); + #endregion } } \ No newline at end of file diff --git a/src/Generator/Generators/Template.cs b/src/Generator/Generators/Template.cs index 5fc7cd36..3cee968a 100644 --- a/src/Generator/Generators/Template.cs +++ b/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 { - 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(); + } + } + } \ No newline at end of file