Remove VarStr, for now
[NovacoinLibrary.git] / Novacoin / WrappedList.cs
1 \feffusing System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace Novacoin
8 {
9     public class WrappedListException : Exception
10     {
11         public WrappedListException()
12         {
13         }
14
15         public WrappedListException(string message)
16             : base(message)
17         {
18         }
19
20         public WrappedListException(string message, Exception inner)
21             : base(message, inner)
22         {
23         }
24     }
25
26     public class WrappedList<T>
27     {
28         private int Index;
29         private List<T> Elements;
30
31         public WrappedList(IList<T> List, int Start)
32         {
33             Elements = new List<T>(List);
34             Index = Start;
35         }
36
37         public WrappedList(IList<T> List)
38         {
39             Elements = new List<T>(List);
40             Index = 0;
41         }
42
43         public T GetItem()
44         {
45             if (Elements.Count <= Index)
46             {
47                 throw new WrappedListException("No elements left.");
48             }
49
50             return Elements[Index++];
51         }
52
53         public T GetCurrentItem()
54         {
55             return Elements[Index];
56         }
57
58         public T[] GetItems(int Count)
59         {
60             if (Elements.Count - Index < Count)
61             {
62                 throw new WrappedListException("Unable to read requested amount of data.");
63             }
64
65             T[] result = Elements.Skip(Index).Take(Count).ToArray();
66             Index += Count;
67
68             return result;
69         }
70
71         public T[] GetCurrentItems(int Count)
72         {
73             if (Elements.Count - Index < Count)
74             {
75                 throw new WrappedListException("Unable to read requested amount of data.");
76             }
77
78             T[] result = Elements.Skip(Index).Take(Count).ToArray();
79
80             return result;
81         }
82
83         public IEnumerable<T> GetEnumerableItems(int Count)
84         {
85             if (Elements.Count - Index < Count)
86             {
87                 throw new WrappedListException("Unable to read requested amount of data.");
88             }
89
90             IEnumerable<T> result = Elements.Skip(Index).Take(Count);
91             Index += Count;
92
93             return result;
94         }
95     }
96 }