Tanoda
IIndexable.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using Leap.Unity.Query;
10
11namespace Leap.Unity {
12
21 public interface IIndexable<T> {
22
23 T this[int idx] { get; }
24
25 int Count { get; }
26 }
27
28 public static class IIndexableExtensions {
29 public static IndexableEnumerator<T> GetEnumerator<T>(this IIndexable<T> indexable) {
30 return new IndexableEnumerator<T>(indexable);
31 }
32
33 public static Query<T> Query<T>(this IIndexable<T> indexable) {
34 var arr = ArrayPool<T>.Spawn(indexable.Count);
35 for (int i = 0; i < indexable.Count; i++) {
36 arr[i] = indexable[i];
37 }
38 return new Query<T>(arr, indexable.Count);
39 }
40 }
41
42 public struct IndexableEnumerator<Element> {
44 int index;
45
47 this.indexable = indexable;
48 index = -1;
49 }
50
52 return this;
53 }
54
55 public bool MoveNext() {
56 if (indexable == null) return false;
57 index++; return index < indexable.Count;
58 }
59
60 public void Reset() {
61 index = -1;
62 }
63
64 public Element Current { get { return indexable[index]; } }
65
66 }
67
68}
This easy-to-implement interface represents the ability to index into a collection of elements of typ...
Definition: IIndexable.cs:21
IndexableEnumerator(IIndexable< Element > indexable)
Definition: IIndexable.cs:46
IIndexable< Element > indexable
Definition: IIndexable.cs:43
IndexableEnumerator< Element > GetEnumerator()
Definition: IIndexable.cs:51
A Query object is a type of immutable ordered collection of elements that can be used to perform usef...
Definition: Query.cs:90