2021-12-16 13:55:22 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-03-24 17:05:58 -04:00
|
|
|
using Microsoft.Extensions.Logging;
|
2021-12-16 13:55:22 -05:00
|
|
|
|
2022-06-24 19:08:20 -04:00
|
|
|
namespace EpicGames.BuildGraph.Expressions
|
2021-12-16 13:55:22 -05:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Specification for a graph in fluent syntax
|
|
|
|
|
/// </summary>
|
2022-06-24 18:30:51 -04:00
|
|
|
public class BgGraph : BgExpr
|
2021-12-16 13:55:22 -05:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2022-06-24 15:18:50 -04:00
|
|
|
/// Nodes for the graph
|
2021-12-16 13:55:22 -05:00
|
|
|
/// </summary>
|
2022-06-24 18:30:51 -04:00
|
|
|
public BgList<BgNode> Nodes { get; }
|
2021-12-16 13:55:22 -05:00
|
|
|
|
2022-06-24 15:18:50 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Aggregates for the graph
|
|
|
|
|
/// </summary>
|
2022-06-24 18:30:51 -04:00
|
|
|
public BgList<BgAggregate> Aggregates { get; }
|
2021-12-16 13:55:22 -05:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor
|
|
|
|
|
/// </summary>
|
2022-06-24 18:30:51 -04:00
|
|
|
public BgGraph(BgList<BgNode> nodes, BgList<BgAggregate> aggregates)
|
2022-06-24 15:18:50 -04:00
|
|
|
: base(BgExprFlags.ForceFragment)
|
2021-12-16 13:55:22 -05:00
|
|
|
{
|
2022-06-24 15:18:50 -04:00
|
|
|
Nodes = nodes;
|
|
|
|
|
Aggregates = aggregates;
|
2021-12-16 13:55:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-06-24 15:18:50 -04:00
|
|
|
/// Implicit conversion from a node spec
|
2021-12-16 13:55:22 -05:00
|
|
|
/// </summary>
|
2022-06-24 18:30:51 -04:00
|
|
|
public static implicit operator BgGraph(BgNode node)
|
2021-12-16 13:55:22 -05:00
|
|
|
{
|
2022-06-24 18:30:51 -04:00
|
|
|
return new BgGraph(node, BgList<BgAggregate>.Empty);
|
2021-12-16 13:55:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-06-24 15:18:50 -04:00
|
|
|
/// Implicit conversion from a list of node specs
|
2021-12-16 13:55:22 -05:00
|
|
|
/// </summary>
|
2022-06-24 18:30:51 -04:00
|
|
|
public static implicit operator BgGraph(BgList<BgNode> nodes)
|
2021-12-16 13:55:22 -05:00
|
|
|
{
|
2022-06-24 18:30:51 -04:00
|
|
|
return new BgGraph(nodes, BgList<BgAggregate>.Empty);
|
2021-12-16 13:55:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-06-24 15:18:50 -04:00
|
|
|
/// Implicit conversion from an aggregate spec
|
2021-12-16 13:55:22 -05:00
|
|
|
/// </summary>
|
2022-06-24 18:30:51 -04:00
|
|
|
public static implicit operator BgGraph(BgAggregate aggregate)
|
2021-12-16 13:55:22 -05:00
|
|
|
{
|
2022-06-24 18:30:51 -04:00
|
|
|
return new BgGraph(BgList<BgNode>.Empty, aggregate);
|
2021-12-16 13:55:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-06-24 15:18:50 -04:00
|
|
|
/// Implicit conversion from a list of node specs
|
2021-12-16 13:55:22 -05:00
|
|
|
/// </summary>
|
2022-06-24 18:30:51 -04:00
|
|
|
public static implicit operator BgGraph(BgList<BgAggregate> aggregates)
|
2021-12-16 13:55:22 -05:00
|
|
|
{
|
2022-06-24 18:30:51 -04:00
|
|
|
return new BgGraph(BgList<BgNode>.Empty, aggregates);
|
2021-12-16 13:55:22 -05:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:18:50 -04:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override void Write(BgBytecodeWriter writer)
|
2021-12-16 13:55:22 -05:00
|
|
|
{
|
2022-07-01 14:47:54 -04:00
|
|
|
BgObject<BgGraphExpressionDef> obj = BgObject<BgGraphExpressionDef>.Empty;
|
|
|
|
|
obj = obj.Set(x => x.Nodes, Nodes);
|
|
|
|
|
obj = obj.Set(x => x.Aggregates, Aggregates);
|
|
|
|
|
writer.WriteExpr(obj);
|
2021-12-16 13:55:22 -05:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:18:50 -04:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override BgString ToBgString() => "{Graph}";
|
2021-12-16 13:55:22 -05:00
|
|
|
}
|
|
|
|
|
}
|