#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
namespace Omg.Types
{
public interface ISequence<T> : IList<T>
{
}
public interface IBoundedSequence<T> : ISequence<T>
{
int Bound { get; }
}
public sealed class BoundedList<T> : IBoundedSequence<T>
{
private readonly List<T> _items;
public BoundedList(int bound)
{
if (bound < 0)
{
throw new ArgumentOutOfRangeException(nameof(bound));
}
Bound = bound;
_items = new List<T>(bound);
}
public BoundedList(int bound, IEnumerable<T> initial) : this(bound)
{
if (initial is null) throw new ArgumentNullException(nameof(initial));
foreach (var x in initial) Add(x);
}
public int Bound { get; }
public int Count => _items.Count;
public bool IsReadOnly => false;
public T this[int index]
{
get => _items[index];
set => _items[index] = value;
}
public void Add(T item)
{
if (_items.Count >= Bound)
{
throw new ArgumentOutOfRangeException(
nameof(item),
$"BoundedList: bound {Bound} exceeded");
}
_items.Add(item);
}
public void Insert(int index, T item)
{
if (_items.Count >= Bound)
{
throw new ArgumentOutOfRangeException(
nameof(item),
$"BoundedList: bound {Bound} exceeded");
}
_items.Insert(index, item);
}
public void Clear() => _items.Clear();
public bool Contains(T item) => _items.Contains(item);
public void CopyTo(T[] array, int arrayIndex)
=> _items.CopyTo(array, arrayIndex);
public IEnumerator<T> GetEnumerator() => _items.GetEnumerator();
public int IndexOf(T item) => _items.IndexOf(item);
public bool Remove(T item) => _items.Remove(item);
public void RemoveAt(int index) => _items.RemoveAt(index);
IEnumerator IEnumerable.GetEnumerator() => _items.GetEnumerator();
}
public sealed class SequenceList<T> : ISequence<T>
{
private readonly List<T> _items = new();
public int Count => _items.Count;
public bool IsReadOnly => false;
public T this[int index]
{
get => _items[index];
set => _items[index] = value;
}
public void Add(T item) => _items.Add(item);
public void Insert(int index, T item) => _items.Insert(index, item);
public void Clear() => _items.Clear();
public bool Contains(T item) => _items.Contains(item);
public void CopyTo(T[] array, int arrayIndex)
=> _items.CopyTo(array, arrayIndex);
public IEnumerator<T> GetEnumerator() => _items.GetEnumerator();
public int IndexOf(T item) => _items.IndexOf(item);
public bool Remove(T item) => _items.Remove(item);
public void RemoveAt(int index) => _items.RemoveAt(index);
IEnumerator IEnumerable.GetEnumerator() => _items.GetEnumerator();
}
public interface ITopicType<T>
{
}
[AttributeUsage(
AttributeTargets.Property | AttributeTargets.Field,
AllowMultiple = false)]
public sealed class KeyAttribute : Attribute
{
}
[AttributeUsage(
AttributeTargets.Property | AttributeTargets.Field,
AllowMultiple = false)]
public sealed class IdAttribute : Attribute
{
public int Value { get; }
public IdAttribute(int value)
{
Value = value;
}
}
[AttributeUsage(
AttributeTargets.Property | AttributeTargets.Field,
AllowMultiple = false)]
public sealed class OptionalAttribute : Attribute
{
}
[AttributeUsage(
AttributeTargets.Property | AttributeTargets.Field,
AllowMultiple = false)]
public sealed class MustUnderstandAttribute : Attribute
{
}
[AttributeUsage(
AttributeTargets.Property | AttributeTargets.Field,
AllowMultiple = false)]
public sealed class ExternalAttribute : Attribute
{
}
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct,
AllowMultiple = false,
Inherited = false)]
public sealed class NestedAttribute : Attribute
{
}
public enum ExtensibilityKind
{
Final,
Appendable,
Mutable,
}
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct,
AllowMultiple = false,
Inherited = false)]
public sealed class ExtensibilityAttribute : Attribute
{
public ExtensibilityKind Kind { get; }
public ExtensibilityAttribute(ExtensibilityKind kind)
{
Kind = kind;
}
}
}