using System;
using System.Collections.Generic;
namespace Vellum.Generator
{
///
/// Holds the converters a compilation can save with, and the ones with something wrong.
///
public sealed class ConverterList : IEquatable
{
public readonly EquatableArray Usable;
public readonly EquatableArray Problems;
public ConverterList(EquatableArray usable, EquatableArray problems)
{
Usable = usable;
Problems = problems;
}
///
/// Returns the name of each type something here converts, which is how a saved type finds its converter. A
/// family isn't a converter of its base class, so it's not counted.
///
public HashSet ConvertedNames()
{
var returnMe = new HashSet();
foreach (ConverterModel converter in Usable.Items)
{
if (converter.FamilyBase == null)
{
returnMe.Add(converter.ConvertedName);
}
}
return returnMe;
}
///
/// Returns, for each type something here converts, the positions of its type arguments that its converter
/// marks [Saveable]. The other arguments can be anything.
///
public Dictionary> SaveableArguments()
{
var returnMe = new Dictionary>();
foreach (ConverterModel converter in Usable.Items)
{
if (converter.FamilyBase == null)
{
returnMe[converter.ConvertedName] = converter.SaveablePositions;
}
}
return returnMe;
}
///
/// Returns the name of the base class of each family here, since a type derived from one is saved by it, with
/// the positions of that class's type arguments that the family marks [Saveable].
///
public Dictionary> FamilyBaseNames()
{
var returnMe = new Dictionary>();
foreach (ConverterModel converter in Usable.Items)
{
if (converter.FamilyBase != null)
{
returnMe[converter.FamilyBase] = converter.SaveablePositions;
}
}
return returnMe;
}
///
/// Returns the name of the interface of each interface family here, with the name of each interface it
/// extends.
///
public Dictionary> InterfaceFamilies()
{
var returnMe = new Dictionary>();
foreach (ConverterModel converter in Usable.Items)
{
if (converter.FamilyIsInterface)
{
returnMe[converter.FamilyBase] = converter.FamilyExtends;
}
}
return returnMe;
}
///
/// Returns the name of each assembly that defines the interface of an interface family here.
///
public HashSet InterfaceFamilyAssemblies()
{
var returnMe = new HashSet();
foreach (ConverterModel converter in Usable.Items)
{
if (converter.FamilyIsInterface)
{
returnMe.Add(converter.FamilyBaseAssembly);
}
}
return returnMe;
}
public bool Equals(ConverterList other)
{
return other != null && Usable.Equals(other.Usable) && Problems.Equals(other.Problems);
}
public override bool Equals(object obj)
{
return Equals(obj as ConverterList);
}
public override int GetHashCode()
{
return Usable.GetHashCode() * 31 + Problems.GetHashCode();
}
}
}