Make the output type of a property source read-only.
This commit is contained in:
@@ -4,26 +4,26 @@ using RBeatTime = Cryville.Crtr.BeatTime;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public abstract class PropSrc {
|
||||
int _type;
|
||||
public int Type { get; private set; }
|
||||
public PropSrc(int type) {
|
||||
Type = type;
|
||||
}
|
||||
protected byte[] buf = null;
|
||||
protected virtual bool Invalidated { get { return buf == null; } }
|
||||
public virtual void Invalidate() { buf = null; }
|
||||
public void Get(out int type, out byte[] value) {
|
||||
if (Invalidated) _type = InternalGet();
|
||||
type = _type;
|
||||
if (Invalidated) InternalGet();
|
||||
type = Type;
|
||||
value = buf;
|
||||
}
|
||||
protected abstract int InternalGet();
|
||||
protected abstract void InternalGet();
|
||||
public class Arbitrary : PropSrc {
|
||||
public int Type { get; private set; }
|
||||
readonly byte[] _value;
|
||||
public Arbitrary(int type, byte[] value) {
|
||||
Type = type;
|
||||
public Arbitrary(int type, byte[] value) : base(type) {
|
||||
_value = value;
|
||||
}
|
||||
protected override int InternalGet() {
|
||||
protected override void InternalGet() {
|
||||
buf = _value;
|
||||
return Type;
|
||||
}
|
||||
}
|
||||
public class Boolean : PropSrc {
|
||||
@@ -31,11 +31,10 @@ namespace Cryville.Crtr {
|
||||
bool m_invalidated = true;
|
||||
protected override bool Invalidated { get { return m_invalidated; } }
|
||||
public override void Invalidate() { m_invalidated = true; }
|
||||
public Boolean(Func<bool> cb) { _cb = cb; buf = new byte[4]; }
|
||||
protected override int InternalGet() {
|
||||
public Boolean(Func<bool> cb) : base(PdtInternalType.Number) { _cb = cb; buf = new byte[4]; }
|
||||
protected override void InternalGet() {
|
||||
m_invalidated = false;
|
||||
buf[0] = _cb() ? (byte)1 : (byte)0;
|
||||
return PdtInternalType.Number;
|
||||
}
|
||||
}
|
||||
public class Float : PropSrc {
|
||||
@@ -43,19 +42,18 @@ namespace Cryville.Crtr {
|
||||
bool m_invalidated = true;
|
||||
protected override bool Invalidated { get { return m_invalidated; } }
|
||||
public override void Invalidate() { m_invalidated = true; }
|
||||
public Float(Func<float> cb) { _cb = cb; buf = new byte[4]; }
|
||||
protected override unsafe int InternalGet() {
|
||||
public Float(Func<float> cb) : base(PdtInternalType.Number) { _cb = cb; buf = new byte[4]; }
|
||||
protected override unsafe void InternalGet() {
|
||||
m_invalidated = false;
|
||||
fixed (byte* _ptr = buf) {
|
||||
*(float*)_ptr = _cb();
|
||||
}
|
||||
return PdtInternalType.Number;
|
||||
}
|
||||
}
|
||||
public class String : PropSrc {
|
||||
readonly Func<string> _cb;
|
||||
public String(Func<string> cb) { _cb = cb; }
|
||||
protected override unsafe int InternalGet() {
|
||||
public String(Func<string> cb) : base(PdtInternalType.String) { _cb = cb; }
|
||||
protected override unsafe void InternalGet() {
|
||||
var v = _cb();
|
||||
int strlen = v.Length;
|
||||
buf = new byte[strlen * sizeof(char) + sizeof(int)];
|
||||
@@ -65,21 +63,19 @@ namespace Cryville.Crtr {
|
||||
int i = 0;
|
||||
foreach (var c in v) ptr[i++] = c;
|
||||
}
|
||||
return PdtInternalType.String;
|
||||
}
|
||||
}
|
||||
public class Identifier : PropSrc {
|
||||
readonly Func<int> _cb;
|
||||
public Identifier(Func<int> cb) { _cb = cb; }
|
||||
protected override int InternalGet() {
|
||||
public Identifier(Func<int> cb) : base(PdtInternalType.Undefined) { _cb = cb; }
|
||||
protected override void InternalGet() {
|
||||
buf = BitConverter.GetBytes(_cb());
|
||||
return PdtInternalType.Undefined;
|
||||
}
|
||||
}
|
||||
public class BeatTime : PropSrc {
|
||||
readonly Func<RBeatTime> _cb;
|
||||
public BeatTime(Func<RBeatTime> cb) { _cb = cb; }
|
||||
protected override unsafe int InternalGet() {
|
||||
public BeatTime(Func<RBeatTime> cb) : base(PdtInternalType.Vector) { _cb = cb; }
|
||||
protected override unsafe void InternalGet() {
|
||||
var bt = _cb();
|
||||
buf = new byte[4 * sizeof(int)];
|
||||
fixed (byte* _ptr = buf) {
|
||||
@@ -89,7 +85,6 @@ namespace Cryville.Crtr {
|
||||
*ptr++ = bt.d;
|
||||
*ptr++ = PdtInternalType.Number;
|
||||
}
|
||||
return PdtInternalType.Vector;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user