OSMServer/OSMDatastructure/TagManager.cs
2023-03-30 18:24:57 +02:00

45 lines
1.1 KiB
C#

using System.Runtime.CompilerServices;
namespace OSMDatastructure.Graph;
[Serializable]
public class TagManager
{
public readonly Dictionary<ulong, HashSet<Tag>> wayTags = new();
public bool ContainsKey(ulong wayId, Tag.TagType key)
{
return wayTags.ContainsKey(wayId) && wayTags[wayId].Any(tag => tag.key == key);
}
public object? GetTag(ulong wayId, Tag.TagType key)
{
return ContainsKey(wayId, key) ? wayTags[wayId].First(tag => tag.key == key) : null;
}
public void AddTag(ulong wayId, string key, string value)
{
Tag tag = Tag.ConvertToTag(key, value);
AddTag(wayId, tag);
}
public void AddTag(ulong wayId, Tag tag)
{
if (tag.key != Tag.TagType.EMPTY)
{
if(!wayTags.ContainsKey(wayId))
wayTags.Add(wayId, new HashSet<Tag>());
wayTags[wayId].Add(tag);
}
}
public HashSet<Tag>? GetTagsForWayId(ulong wayId)
{
return wayTags.TryGetValue(wayId, out HashSet<Tag>? value) ? value : null;
}
public bool ContainsWay(ulong wayId)
{
return wayTags.ContainsKey(wayId);
}
}