mirror of https://github.com/mono/CppSharp.git
1 changed files with 12 additions and 62 deletions
@ -1,76 +1,26 @@ |
|||||||
using System.Collections.Generic; |
namespace Cxxi.Generators |
||||||
using System.Linq; |
|
||||||
using System.Text; |
|
||||||
|
|
||||||
namespace Cxxi.Generators |
|
||||||
{ |
{ |
||||||
public abstract class TextTemplate |
public abstract class TextTemplate : TextGenerator |
||||||
{ |
{ |
||||||
private const uint DefaultIndent = 4; |
private const uint DefaultIndent = 4; |
||||||
private const uint MaxIndent = 80; |
private const uint MaxIndent = 80; |
||||||
|
|
||||||
public Generator Generator { get; set; } |
public Driver Driver { get; set; } |
||||||
public DriverOptions DriverOptions { get; set; } |
public DriverOptions Options { get; set; } |
||||||
public Library Library { get; set; } |
public Library Library { get; set; } |
||||||
public ILibrary Transform; |
public ILibrary Transform; |
||||||
public TranslationUnit Module { get; set; } |
public TranslationUnit unit { get; set; } |
||||||
public abstract string FileExtension { get; } |
public abstract string FileExtension { get; } |
||||||
|
|
||||||
protected abstract void Generate(); |
public abstract void Generate(); |
||||||
|
|
||||||
protected StringBuilder Builder; |
|
||||||
protected Stack<uint> CurrentIndent; |
|
||||||
|
|
||||||
private bool isStartOfLine; |
|
||||||
|
|
||||||
protected TextTemplate() |
|
||||||
{ |
|
||||||
Builder = new StringBuilder(); |
|
||||||
CurrentIndent = new Stack<uint>(); |
|
||||||
isStartOfLine = true; |
|
||||||
} |
|
||||||
|
|
||||||
public void Write(string msg, params object[] args) |
|
||||||
{ |
|
||||||
if (isStartOfLine) |
|
||||||
Builder.Append(new string(' ', (int)CurrentIndent.Sum(u => u))); |
|
||||||
|
|
||||||
if (args.Length > 0) |
|
||||||
msg = string.Format(msg, args); |
|
||||||
|
|
||||||
if (msg.Length > 0) |
|
||||||
isStartOfLine = false; |
|
||||||
|
|
||||||
Builder.Append(msg); |
|
||||||
} |
|
||||||
|
|
||||||
public void WriteLine(string msg, params object[] args) |
|
||||||
{ |
|
||||||
Write(msg, args); |
|
||||||
NewLine(); |
|
||||||
} |
|
||||||
|
|
||||||
public void NewLine() |
|
||||||
{ |
|
||||||
Builder.AppendLine(string.Empty); |
|
||||||
isStartOfLine = true; |
|
||||||
} |
|
||||||
|
|
||||||
public void PushIndent(uint indent = DefaultIndent) |
|
||||||
{ |
|
||||||
CurrentIndent.Push(indent); |
|
||||||
} |
|
||||||
|
|
||||||
public void PopIndent() |
|
||||||
{ |
|
||||||
CurrentIndent.Pop(); |
|
||||||
} |
|
||||||
|
|
||||||
public override string ToString() |
protected TextTemplate(Driver driver, TranslationUnit unit) |
||||||
{ |
{ |
||||||
Builder.Clear(); |
Driver = driver; |
||||||
Generate(); |
Options = driver.Options; |
||||||
return Builder.ToString(); |
Library = driver.Library; |
||||||
|
Transform = driver.Transform; |
||||||
|
this.unit = unit; |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
Loading…
Reference in new issue