forked from google/flatbuffers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added IEnumerable getters GetXXXEnumerable to vectors in C#
- Loading branch information
Showing
19 changed files
with
846 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace FlatBuffers | ||
{ | ||
using ObjectType = Double; | ||
|
||
public class FlatBufferDoubleEnumerable : IEnumerable<ObjectType>, IEnumerator<ObjectType> | ||
{ | ||
private int _pos; | ||
private readonly int _end; | ||
private readonly ByteBuffer _buffer; | ||
private const int Size = sizeof(ObjectType); | ||
|
||
public FlatBufferDoubleEnumerable(int pos, int length, ByteBuffer buffer) | ||
{ | ||
_pos = pos; | ||
_end = pos + Size * length; | ||
_buffer = buffer; | ||
} | ||
|
||
public IEnumerator<ObjectType> GetEnumerator() | ||
{ | ||
return this; | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public ObjectType Current { get; private set; } | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
object IEnumerator.Current | ||
{ | ||
get { return Current; } | ||
} | ||
|
||
public bool MoveNext() | ||
{ | ||
if (_pos >= _end) | ||
{ | ||
return false; | ||
} | ||
Current = _buffer.GetDouble(_pos); | ||
_pos += Size; | ||
return true; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace FlatBuffers | ||
{ | ||
using ObjectType = Byte; | ||
|
||
public class FlatBufferEnumerable : IEnumerable<ObjectType>, IEnumerator<ObjectType> | ||
{ | ||
private int _pos; | ||
private readonly int _end; | ||
private readonly ByteBuffer _buffer; | ||
private const int Size = sizeof(ObjectType); | ||
|
||
public FlatBufferEnumerable(int pos, int length, ByteBuffer buffer) | ||
{ | ||
_pos = pos; | ||
_end = pos + Size * length; | ||
_buffer = buffer; | ||
} | ||
|
||
public IEnumerator<ObjectType> GetEnumerator() | ||
{ | ||
return this; | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public ObjectType Current { get; private set; } | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
object IEnumerator.Current | ||
{ | ||
get { return Current; } | ||
} | ||
|
||
public bool MoveNext() | ||
{ | ||
if (_pos >= _end) | ||
{ | ||
return false; | ||
} | ||
Current = _buffer.Get(_pos); | ||
_pos += Size; | ||
return true; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace FlatBuffers | ||
{ | ||
using ObjectType = Single; | ||
|
||
public class FlatBufferFloatEnumerable : IEnumerable<ObjectType>, IEnumerator<ObjectType> | ||
{ | ||
private int _pos; | ||
private readonly int _end; | ||
private readonly ByteBuffer _buffer; | ||
private const int Size = sizeof(ObjectType); | ||
|
||
public FlatBufferFloatEnumerable(int pos, int length, ByteBuffer buffer) | ||
{ | ||
_pos = pos; | ||
_end = pos + Size * length; | ||
_buffer = buffer; | ||
} | ||
|
||
public IEnumerator<ObjectType> GetEnumerator() | ||
{ | ||
return this; | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public ObjectType Current { get; private set; } | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
object IEnumerator.Current | ||
{ | ||
get { return Current; } | ||
} | ||
|
||
public bool MoveNext() | ||
{ | ||
if (_pos >= _end) | ||
{ | ||
return false; | ||
} | ||
Current = _buffer.GetFloat(_pos); | ||
_pos += Size; | ||
return true; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace FlatBuffers | ||
{ | ||
using ObjectType = Int32; | ||
|
||
public class FlatBufferIntEnumerable : IEnumerable<ObjectType>, IEnumerator<ObjectType> | ||
{ | ||
private int _pos; | ||
private readonly int _end; | ||
private readonly ByteBuffer _buffer; | ||
private const int Size = sizeof(ObjectType); | ||
|
||
public FlatBufferIntEnumerable(int pos, int length, ByteBuffer buffer) | ||
{ | ||
_pos = pos; | ||
_end = pos + Size * length; | ||
_buffer = buffer; | ||
} | ||
|
||
public IEnumerator<ObjectType> GetEnumerator() | ||
{ | ||
return this; | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public ObjectType Current { get; private set; } | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
object IEnumerator.Current | ||
{ | ||
get { return Current; } | ||
} | ||
|
||
public bool MoveNext() | ||
{ | ||
if (_pos >= _end) | ||
{ | ||
return false; | ||
} | ||
Current = _buffer.GetInt(_pos); | ||
_pos += Size; | ||
return true; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace FlatBuffers | ||
{ | ||
using ObjectType = Int64; | ||
|
||
public class FlatBufferLongEnumerable : IEnumerable<ObjectType>, IEnumerator<ObjectType> | ||
{ | ||
private int _pos; | ||
private readonly int _end; | ||
private readonly ByteBuffer _buffer; | ||
private const int Size = sizeof(ObjectType); | ||
|
||
public FlatBufferLongEnumerable(int pos, int length, ByteBuffer buffer) | ||
{ | ||
_pos = pos; | ||
_end = pos + Size * length; | ||
_buffer = buffer; | ||
} | ||
|
||
public IEnumerator<ObjectType> GetEnumerator() | ||
{ | ||
return this; | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public ObjectType Current { get; private set; } | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
object IEnumerator.Current | ||
{ | ||
get { return Current; } | ||
} | ||
|
||
public bool MoveNext() | ||
{ | ||
if (_pos >= _end) | ||
{ | ||
return false; | ||
} | ||
Current = _buffer.GetLong(_pos); | ||
_pos += Size; | ||
return true; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace FlatBuffers | ||
{ | ||
public class FlatBufferObjectEnumerable<T> : IEnumerable<T>, IEnumerator<T> | ||
where T : Table, new() | ||
{ | ||
private int _pos; | ||
private readonly int _end; | ||
private readonly ByteBuffer _buffer; | ||
private const int Size = sizeof(int); | ||
|
||
public FlatBufferObjectEnumerable(int pos, int length, ByteBuffer buffer) | ||
{ | ||
_pos = pos; | ||
_end = pos + Size * length; | ||
_buffer = buffer; | ||
} | ||
|
||
public IEnumerator<T> GetEnumerator() | ||
{ | ||
return this; | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public T Current { get; private set; } | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
object IEnumerator.Current | ||
{ | ||
get { return Current; } | ||
} | ||
|
||
public bool MoveNext() | ||
{ | ||
if (_pos >= _end) | ||
{ | ||
return false; | ||
} | ||
Current = new T(); | ||
Current.Initialize(_pos, _buffer); | ||
_pos += Size; | ||
return true; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
Oops, something went wrong.