-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from phit/feature/longarray
Added support for Long Arrays
- Loading branch information
Showing
8 changed files
with
294 additions
and
1 deletion.
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
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,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Substrate.Nbt | ||
{ | ||
/// <summary> | ||
/// A concrete <see cref="SchemaNode"/> representing a <see cref="TagNodeLongArray"/>. | ||
/// </summary> | ||
public sealed class SchemaNodeLongArray : SchemaNode | ||
{ | ||
private int _length; | ||
|
||
/// <summary> | ||
/// Gets the expected length of the corresponding long array. | ||
/// </summary> | ||
public int Length | ||
{ | ||
get { return _length; } | ||
} | ||
|
||
/// <summary> | ||
/// Indicates whether there is an expected length of the corresponding int array. | ||
/// </summary> | ||
public bool HasExpectedLength | ||
{ | ||
get { return _length > 0; } | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new <see cref="SchemaNodeLongArray"/> representing a <see cref="TagNodeLongArray"/> named <paramref name="name"/>. | ||
/// </summary> | ||
/// <param name="name">The name of the corresponding <see cref="TagNodeIntArray"/>.</param> | ||
public SchemaNodeLongArray (string name) | ||
: base(name) | ||
{ | ||
_length = 0; | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new <see cref="SchemaNodeLongArray"/> with additional options. | ||
/// </summary> | ||
/// <param name="name">The name of the corresponding <see cref="TagNodeLongArray"/>.</param> | ||
/// <param name="options">One or more option flags modifying the processing of this node.</param> | ||
public SchemaNodeLongArray (string name, SchemaOptions options) | ||
: base(name, options) | ||
{ | ||
_length = 0; | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new <see cref="SchemaNodeLongArray"/> representing a <see cref="TagNodeLongArray"/> named <paramref name="name"/> with expected length <paramref name="length"/>. | ||
/// </summary> | ||
/// <param name="name">The name of the corresponding <see cref="TagNodeIntArray"/>.</param> | ||
/// <param name="length">The expected length of corresponding byte array.</param> | ||
public SchemaNodeLongArray (string name, int length) | ||
: base(name) | ||
{ | ||
_length = length; | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new <see cref="SchemaNodeLongArray"/> with additional options. | ||
/// </summary> | ||
/// <param name="name">The name of the corresponding <see cref="TagNodeLongArray"/>.</param> | ||
/// <param name="length">The expected length of corresponding byte array.</param> | ||
/// <param name="options">One or more option flags modifying the processing of this node.</param> | ||
public SchemaNodeLongArray (string name, int length, SchemaOptions options) | ||
: base(name, options) | ||
{ | ||
_length = length; | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a default <see cref="TagNodeLongArray"/> satisfying the constraints of this node. | ||
/// </summary> | ||
/// <returns>A <see cref="TagNodeString"/> with a sensible default value.</returns> | ||
public override TagNode BuildDefaultTree () | ||
{ | ||
return new TagNodeLongArray(new long[_length]); | ||
} | ||
} | ||
} |
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,112 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Substrate.Nbt | ||
{ | ||
public sealed class TagNodeLongArray : TagNode | ||
{ | ||
private long[] _data = null; | ||
|
||
/// <summary> | ||
/// Converts the node to itself. | ||
/// </summary> | ||
/// <returns>A reference to itself.</returns> | ||
public override TagNodeLongArray ToTagLongArray () | ||
{ | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the tag type of the node. | ||
/// </summary> | ||
/// <returns>The TAG_LONG_ARRAY tag type.</returns> | ||
public override TagType GetTagType () | ||
{ | ||
return TagType.TAG_LONG_ARRAY; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets an long array of tag data. | ||
/// </summary> | ||
public long[] Data | ||
{ | ||
get { return _data; } | ||
set { _data = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the length of the stored byte array. | ||
/// </summary> | ||
public int Length | ||
{ | ||
get { return _data.Length; } | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new byte array node with a null data value. | ||
/// </summary> | ||
public TagNodeLongArray() { } | ||
|
||
/// <summary> | ||
/// Constructs a new byte array node. | ||
/// </summary> | ||
/// <param name="d">The value to set the node's tag data value.</param> | ||
public TagNodeLongArray(long[] d) | ||
{ | ||
_data = d; | ||
} | ||
|
||
/// <summary> | ||
/// Makes a deep copy of the node. | ||
/// </summary> | ||
/// <returns>A new long array node representing the same data.</returns> | ||
public override TagNode Copy () | ||
{ | ||
long[] arr = new long[_data.Length]; | ||
_data.CopyTo(arr, 0); | ||
|
||
return new TagNodeLongArray(arr); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a string representation of the node's data. | ||
/// </summary> | ||
/// <returns>String representation of the node's data.</returns> | ||
public override string ToString () | ||
{ | ||
return _data.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a single long at the specified index. | ||
/// </summary> | ||
/// <param name="index">Valid index within stored long array.</param> | ||
/// <returns>The long value at the given index of the stored byte array.</returns> | ||
public long this[int index] | ||
{ | ||
get { return _data[index]; } | ||
set { _data[index] = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Converts a system long array to a long array node representing the same data. | ||
/// </summary> | ||
/// <param name="i">A long array.</param> | ||
/// <returns>A new long array node containing the given value.</returns> | ||
public static implicit operator TagNodeLongArray(long[] i) | ||
{ | ||
return new TagNodeLongArray(i); | ||
} | ||
|
||
/// <summary> | ||
/// Converts an long array node to a system long array representing the same data. | ||
/// </summary> | ||
/// <param name="i">An long array node.</param> | ||
/// <returns>A system long array set to the node's data.</returns> | ||
public static implicit operator long[] (TagNodeLongArray i) | ||
{ | ||
return i._data; | ||
} | ||
} | ||
} |
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
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