Skip to content

Commit

Permalink
Add missing internal list builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Feb 5, 2024
1 parent c3ec51c commit 1c277f2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{{~ if create_lists ~}}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Modified by the Tsu (https://github.com/GGG-KILLER/Tsu) project for embedding into other projects.
// <auto-generated />

#nullable enable

namespace {{ green_base.namespace | not_global }}
{
internal readonly struct {{ suffix }}ListBuilder<TNode> where TNode : {{ green_base.csharp | not_null }}
{
private readonly {{ suffix }}ListBuilder _builder;

public {{ suffix }}ListBuilder(int size)
: this(new {{ suffix }}ListBuilder(size))
{
}

public static {{ suffix }}ListBuilder<TNode> Create() => new(8);

internal {{ suffix }}ListBuilder({{ suffix }}ListBuilder builder)
{
_builder = builder;
}

public bool IsNull => _builder == null;

public int Count => _builder.Count;

public TNode? this[int index]
{
get => (TNode?) _builder[index];

set => _builder[index] = value;
}

public void Clear() => _builder.Clear();

public {{ suffix }}ListBuilder<TNode> Add(TNode node)
{
_builder.Add(node);
return this;
}

public void AddRange(TNode[] items, int offset, int length) =>
_builder.AddRange(items, offset, length);

public void AddRange({{ suffix }}List<TNode> nodes) => _builder.AddRange(nodes);

public void AddRange({{ suffix }}List<TNode> nodes, int offset, int length) =>
_builder.AddRange(nodes, offset, length);

public bool Any({{ kind_enum.csharp | not_null }} kind) => _builder.Any(kind);

public {{ suffix }}List<TNode> ToList() => _builder.ToList();

public {{ green_base.csharp | not_null }}? ToListNode() => _builder.ToListNode();

public static implicit operator {{ suffix }}ListBuilder({{ suffix }}ListBuilder<TNode> builder) => builder._builder;

public static implicit operator {{ suffix }}List<TNode>({{ suffix }}ListBuilder<TNode> builder)
{
if (builder._builder != null)
{
return builder.ToList();
}

return default;
}

public {{ suffix }}List<TDerived> ToList<TDerived>() where TDerived : {{ green_base.csharp | not_null }} =>
new(ToListNode());
}
}
{{~ end ~}}
1 change: 1 addition & 0 deletions Tsu.Trees.RedGreen/src/Tsu.Trees.RedGreen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<EmbeddedResource Include="Templates/Internal/GreenWalker.sbn-cs" Visible="true" LogicalName="Internal/GreenWalker.sbn-cs" />
<EmbeddedResource Include="Templates/Internal/GreenList.sbn-cs" Visible="true" LogicalName="Internal/GreenList.sbn-cs" />
<EmbeddedResource Include="Templates/Internal/GreenListBuilder.sbn-cs" Visible="true" LogicalName="Internal/GreenListBuilder.sbn-cs" />
<EmbeddedResource Include="Templates/Internal/GreenListBuilder`1.sbn-cs" Visible="true" LogicalName="Internal/GreenListBuilder`1.sbn-cs" />
<EmbeddedResource Include="Templates/Internal/GreenList.WithTwoChildren.sbn-cs" Visible="true" LogicalName="Internal/GreenList.WithTwoChildren.sbn-cs" />
<EmbeddedResource Include="Templates/Internal/GreenList.WithThreeChildren.sbn-cs" Visible="true" LogicalName="Internal/GreenList.WithThreeChildren.sbn-cs" />
<EmbeddedResource Include="Templates/Internal/GreenList.WithManyChildren.sbn-cs" Visible="true" LogicalName="Internal/GreenList.WithManyChildren.sbn-cs" />
Expand Down

0 comments on commit 1c277f2

Please sign in to comment.