Skip to content

Commit

Permalink
fix: [独自ヘッダー]USEATSEX、READDEPTHについても読込エラーを自動削除するように
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic9045 committed Jul 10, 2023
1 parent cd575ca commit edf74d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
26 changes: 18 additions & 8 deletions AtsEx/MapStatements/HeaderSet.Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ static HeaderSet()

public static HeaderSet FromMap(string filePath)
{
(IDictionary<Identifier, IReadOnlyList<Header>> headers, IReadOnlyList<Header> noMapPluginHeaders) = Load(filePath, 0);
return new HeaderSet(headers, noMapPluginHeaders);
(IDictionary<Identifier, IReadOnlyList<Header>> headers, IReadOnlyList<Header> privateHeaders) = Load(filePath, 0);
return new HeaderSet(headers, privateHeaders);
}

private static (IDictionary<Identifier, IReadOnlyList<Header>> Headers, IReadOnlyList<Header> NoMapPluginHeaders) Load(string filePath, int readDepth)
private static (IDictionary<Identifier, IReadOnlyList<Header>> Headers, IReadOnlyList<Header> PrivateHeaders) Load(string filePath, int readDepth)
{
ConcurrentDictionary<Identifier, IReadOnlyList<Header>> headers = new ConcurrentDictionary<Identifier, IReadOnlyList<Header>>();
List<Header> noMapPluginHeaders = new List<Header>();
List<Header> privateHeaders = new List<Header>();

string text;
using (StreamReader sr = new StreamReader(filePath))
Expand Down Expand Up @@ -77,17 +77,27 @@ private static (IDictionary<Identifier, IReadOnlyList<Header>> Headers, IReadOnl
List<Header> list = headers.GetOrAdd(identifier, new List<Header>()) as List<Header>;
list.Add(header);
}
else if (includePath.StartsWith(UseAtsExHeaderFullName))
{
string headerArgument = includePath.Substring(UseAtsExHeaderFullName.Length);

Header header = new Header(UseAtsExHeader, headerArgument, filePath, s.LineIndex, s.CharIndex);
privateHeaders.Add(header);
}
else if (includePath.StartsWith(NoMapPluginHeaderFullName))
{
string headerArgument = includePath.Substring(NoMapPluginHeaderFullName.Length);

Header header = new Header(NoMapPluginHeader, headerArgument, filePath, s.LineIndex, s.CharIndex);
noMapPluginHeaders.Add(header);
privateHeaders.Add(header);
}
else if (includePath.StartsWith(ReadDepthHeaderFullName))
{
string headerArgument = includePath.Substring(ReadDepthHeaderFullName.Length);
int.TryParse(headerArgument, out readDepth);

Header header = new Header(ReadDepthHeader, headerArgument, filePath, s.LineIndex, s.CharIndex);
privateHeaders.Add(header);
}
else if (0 < readDepth)
{
Expand All @@ -96,20 +106,20 @@ private static (IDictionary<Identifier, IReadOnlyList<Header>> Headers, IReadOnl

if (!File.Exists(includeAbsolutePath)) continue;

(IDictionary<Identifier, IReadOnlyList<Header>> headersInIncludedMap, IReadOnlyList<Header> noMapPluginHeadersInIncludedMap) = Load(includeAbsolutePath, readDepth - 1);
(IDictionary<Identifier, IReadOnlyList<Header>> headersInIncludedMap, IReadOnlyList<Header> privateHeadersInIncludedMap) = Load(includeAbsolutePath, readDepth - 1);

foreach (KeyValuePair<Identifier, IReadOnlyList<Header>> pair in headersInIncludedMap)
{
List<Header> list = headers.GetOrAdd(pair.Key, new List<Header>()) as List<Header>;
list.AddRange(pair.Value);
}

noMapPluginHeaders.AddRange(noMapPluginHeadersInIncludedMap);
privateHeaders.AddRange(privateHeadersInIncludedMap);
}
}
}

return (headers, noMapPluginHeaders);
return (headers, privateHeaders);
}
}
}
18 changes: 9 additions & 9 deletions AtsEx/MapStatements/HeaderSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ internal sealed partial class HeaderSet : IHeaderSet, IEnumerable<Header>
{
private readonly IDictionary<Identifier, IReadOnlyList<Header>> Headers;

public IReadOnlyList<Header> NoMapPluginHeaders { get; }
public IReadOnlyList<Header> PrivateHeaders { get; }

public HeaderSet(IDictionary<Identifier, IReadOnlyList<Header>> headers, IReadOnlyList<Header> noMapPluginHeaders)
public HeaderSet(IDictionary<Identifier, IReadOnlyList<Header>> headers, IReadOnlyList<Header> privateHeaders)
{
Headers = headers;
NoMapPluginHeaders = noMapPluginHeaders;
PrivateHeaders = privateHeaders;
}

public IReadOnlyList<IHeader> GetAll(Identifier identifier) => Headers.TryGetValue(identifier, out IReadOnlyList<Header> result) ? result : new List<Header>();
Expand All @@ -34,9 +34,9 @@ private class Enumerator : IEnumerator<Header>
private bool AreHeadersEnumerated = false;

private readonly IEnumerator<Header> HeadersEnumerator;
private readonly IEnumerator<Header> NoMapPluginHeadersEnumerator;
private readonly IEnumerator<Header> PrivateHeadersEnumerator;

private IEnumerator<Header> CurrentEnumerator => AreHeadersEnumerated ? NoMapPluginHeadersEnumerator : HeadersEnumerator;
private IEnumerator<Header> CurrentEnumerator => AreHeadersEnumerated ? PrivateHeadersEnumerator : HeadersEnumerator;

public Header Current => CurrentEnumerator.Current;
object IEnumerator.Current => Current;
Expand All @@ -46,22 +46,22 @@ public Enumerator(HeaderSet source)
Source = source;

HeadersEnumerator = new EnumerableInDictionaryEnumerator<Identifier, Header>(Source.Headers);
NoMapPluginHeadersEnumerator = Source.NoMapPluginHeaders.GetEnumerator();
PrivateHeadersEnumerator = Source.PrivateHeaders.GetEnumerator();

Reset();
}

public void Dispose()
{
HeadersEnumerator.Dispose();
NoMapPluginHeadersEnumerator.Dispose();
PrivateHeadersEnumerator.Dispose();
}

public bool MoveNext()
{
if (AreHeadersEnumerated)
{
return NoMapPluginHeadersEnumerator.MoveNext();
return PrivateHeadersEnumerator.MoveNext();
}
else
{
Expand All @@ -81,7 +81,7 @@ public bool MoveNext()
public void Reset()
{
HeadersEnumerator.Reset();
NoMapPluginHeadersEnumerator.Reset();
PrivateHeadersEnumerator.Reset();

AreHeadersEnumerated = false;
}
Expand Down

0 comments on commit edf74d6

Please sign in to comment.