diff --git a/IPA.Loader/Config/Data/List.cs b/IPA.Loader/Config/Data/List.cs new file mode 100644 index 00000000..2db84080 --- /dev/null +++ b/IPA.Loader/Config/Data/List.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace IPA.Config.Data +{ + /// + /// A list of s for serialization by an . + /// + public sealed class List : Value, IList + { + private readonly List values = new List(); + + /// + /// Gets the value at the given index in this . + /// + /// the index to retrieve the at + /// the at + /// + public Value this[int index] { get => values[index]; set => values[index] = value; } + + /// + /// Gets the number of elements in the . + /// + /// + public int Count => values.Count; + + bool ICollection.IsReadOnly => ((IList)values).IsReadOnly; + + /// + /// Adds a to the end of this . + /// + /// the to add + /// + public void Add(Value item) => values.Add(item); + + /// + /// Clears the . + /// + /// + public void Clear() => values.Clear(); + + /// + /// Checks if the contains a certian item. + /// + /// the to check for + /// if the item was founc, otherwise + /// + public bool Contains(Value item) => values.Contains(item); + + /// + /// Copies the s in the to the in . + /// + /// the to copy to + /// the starting index to copy to + /// + public void CopyTo(Value[] array, int arrayIndex) => values.CopyTo(array, arrayIndex); + + /// + /// Gets an enumerator to enumerate the . + /// + /// an for this + /// + public IEnumerator GetEnumerator() => ((IList)values).GetEnumerator(); + + /// + /// Gets the index that a given is in the . + /// + /// the to search for + /// the index that the was at, or -1. + /// + public int IndexOf(Value item) => values.IndexOf(item); + + /// + /// Inserts a at an index. + /// + /// the index to insert at + /// the to insert + /// + public void Insert(int index, Value item) => values.Insert(index, item); + + /// + /// Removes a from the . + /// + /// the to remove + /// if the item was removed, otherwise + /// + public bool Remove(Value item) => values.Remove(item); + + /// + /// Removes a at an index. + /// + /// the index to remove a at + /// + public void RemoveAt(int index) => values.RemoveAt(index); + + IEnumerator IEnumerable.GetEnumerator() => ((IList)values).GetEnumerator(); + } + + +} diff --git a/IPA.Loader/Config/Data/Map.cs b/IPA.Loader/Config/Data/Map.cs new file mode 100644 index 00000000..7ad0054e --- /dev/null +++ b/IPA.Loader/Config/Data/Map.cs @@ -0,0 +1,104 @@ +using System.Collections; +using System.Collections.Generic; + +namespace IPA.Config.Data +{ + + /// + /// A map of to for serialization by an . + /// + public sealed class Map : Value, IDictionary + { + private readonly Dictionary values = new Dictionary(); + + /// + /// Accesses the at in the map. + /// + /// the key to get the value associated with + /// the value associated with the + /// + public Value this[string key] { get => values[key]; set => values[key] = value; } + + /// + /// Gets a collection of the keys for the . + /// + /// + public ICollection Keys => values.Keys; + + /// + /// Gets a collection of the values in the . + /// + /// + public ICollection Values => values.Values; + + /// + /// Gets the number of key-value pairs in this . + /// + /// + public int Count => values.Count; + + bool ICollection>.IsReadOnly => ((IDictionary)values).IsReadOnly; + + /// + /// Adds a new with a given key. + /// + /// the key to put the value at + /// the to add + /// + public void Add(string key, Value value) => values.Add(key, value); + + void ICollection>.Add(KeyValuePair item) + => ((IDictionary)values).Add(item); + + /// + /// Clears the of its key-value pairs. + /// + /// + public void Clear() => values.Clear(); + + bool ICollection>.Contains(KeyValuePair item) + => ((IDictionary)values).Contains(item); + + /// + /// Checks if the contains a given . + /// + /// the key to check for + /// if the key exists, otherwise + /// + public bool ContainsKey(string key) => values.ContainsKey(key); + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + => ((IDictionary)values).CopyTo(array, arrayIndex); + + /// + /// Enumerates the 's key-value pairs. + /// + /// an of key-value pairs in this + /// + public IEnumerator> GetEnumerator() => values.GetEnumerator(); + + /// + /// Removes the object associated with a key in this . + /// + /// the key to remove + /// if the key existed, otherwise + /// + public bool Remove(string key) => values.Remove(key); + + bool ICollection>.Remove(KeyValuePair item) + => ((IDictionary)values).Remove(item); + + /// + /// Gets the value associated with the specified key. + /// + /// the key of the value to get + /// the target location of the retrieved object + /// if the key was found and set, otherwise + /// + public bool TryGetValue(string key, out Value value) => values.TryGetValue(key, out value); + + IEnumerator IEnumerable.GetEnumerator() => ((IDictionary)values).GetEnumerator(); + } + + +} diff --git a/IPA.Loader/Config/Data/Value.cs b/IPA.Loader/Config/Data/Value.cs new file mode 100644 index 00000000..5b8b6d03 --- /dev/null +++ b/IPA.Loader/Config/Data/Value.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IPA.Config.Data +{ + /// + /// A base value type for config data abstract representations, to be serialized with an + /// . + /// + public abstract class Value + { + + } + + // not String to prevent overlap with System.String + /// + /// A representing a piece of text. The only reason this is not named + /// String is so that it doesn't conflict with . + /// + public sealed class Text : Value + { + + } + + /// + /// A representing an integer. This may hold a 's + /// worth of data. + /// + public sealed class Integer : Value + { + + } + + /// + /// A representing a floating point value. This may hold a + /// 's worth of data. + /// + public sealed class FloatingPoint : Value + { + + } + + /// + /// A representing a boolean value. + /// + public sealed class Boolean : Value + { + + } + + +} diff --git a/IPA.Loader/IPA.Loader.csproj b/IPA.Loader/IPA.Loader.csproj index da6512b1..6f927018 100644 --- a/IPA.Loader/IPA.Loader.csproj +++ b/IPA.Loader/IPA.Loader.csproj @@ -86,6 +86,9 @@ + + +