// Copyright Epic Games, Inc. All Rights Reserved.
namespace EpicGames.BuildGraph.Expressions
{
///
/// Specification for an aggregate target in the graph
///
public class BgAggregate : BgExpr
{
///
/// Name of the aggregate
///
public BgString Name { get; }
///
/// Outputs required for the aggregate
///
public BgList Requires { get; }
///
/// Label to apply to this aggregate
///
public BgLabel? Label { get; }
///
/// Constructor.
///
public BgAggregate(BgString name, params BgNode[] requires)
: this(name, BgList.Create(requires))
{
}
///
/// Constructor.
///
public BgAggregate(BgString name, params BgList[] requires)
: this(name, BgList.Concat(requires))
{
}
///
/// Constructor.
///
public BgAggregate(BgString name, BgList requires, string label)
: this(name, requires, new BgLabel(label))
{
}
///
/// Constructor.
///
public BgAggregate(BgString name, BgList requires, BgLabel? label = null)
: base(BgExprFlags.None)
{
Name = name;
Requires = requires;
Label = label;
}
///
public override void Write(BgBytecodeWriter writer)
{
BgObject obj = BgObject.Empty;
obj = obj.Set(x => x.Name, Name);
obj = obj.Set(x => x.RequiredNodes, Requires);
if (Label != null)
{
obj = obj.Set(x => x.Label, Label);
}
writer.WriteExpr(obj);
}
///
public override BgString ToBgString() => Name;
}
}