2019-12-26 23:01:54 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2019-05-24 11:51:54 -04:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace UnrealBuildTool
{
/// <summary>
/// Represents a layer within the rules hierarchy. Any module is created within a certain scope, and may only reference modules in an equal or parent scope (eg. engine modules cannot reference project modules).
/// </summary>
class RulesScope
{
/// <summary>
/// Name of this scope
/// </summary>
public string Name ;
/// <summary>
/// The parent scope
/// </summary>
2020-12-20 18:47:42 -04:00
public RulesScope ? Parent ;
2019-05-24 11:51:54 -04:00
/// <summary>
/// Constructor
/// </summary>
/// <param name="Name">Name of this scope</param>
/// <param name="Parent">The parent scope</param>
2020-12-20 18:47:42 -04:00
public RulesScope ( string Name , RulesScope ? Parent )
2019-05-24 11:51:54 -04:00
{
this . Name = Name ;
this . Parent = Parent ;
}
/// <summary>
/// Checks whether this scope contains another scope
/// </summary>
/// <param name="Other">The other scope to check</param>
/// <returns>True if this scope contains the other scope</returns>
public bool Contains ( RulesScope Other )
{
2020-12-20 18:47:42 -04:00
for ( RulesScope ? Scope = this ; Scope ! = null ; Scope = Scope . Parent )
2019-05-24 11:51:54 -04:00
{
if ( Scope = = Other )
{
return true ;
}
}
return false ;
}
/// <summary>
/// Formats the hierarchy of scopes
/// </summary>
/// <returns>String representing the hierarchy of scopes</returns>
public string FormatHierarchy ( )
{
if ( Parent = = null )
{
return Name ;
}
else
{
return String . Format ( "{0} -> {1}" , Name , Parent . FormatHierarchy ( ) ) ;
}
}
}
}