// += /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public void AddEqual(Kirikiri.Tjs2.Variant rhs) { if (mObject is string || rhs.mObject is string) { if (mObject is string && rhs.mObject is string) { // both are string mObject = (string)mObject + (string)rhs.mObject; return; } string s1 = AsString(); string s2 = rhs.AsString(); if (s1 != null && s2 != null) { StringBuilder builder = new StringBuilder(256); builder.Append(s1); builder.Append(s2); mObject = builder.ToString(); } else { if (s1 != null) { mObject = s1; } else { mObject = s2; } } //mObject = s1 + s2; return; } if (mObject != null && rhs.mObject != null) { if (mObject.GetType().IsAssignableFrom(rhs.mObject.GetType())) { // 同じクラス if (mObject is ByteBuffer) { ByteBuffer b1 = (ByteBuffer)mObject; ByteBuffer b2 = (ByteBuffer)rhs.mObject; ByteBuffer result = ByteBuffer.Allocate(b1.Capacity() + b2.Capacity()); b1.Position(0); b2.Position(0); result.Put(b1); result.Put(b2); result.Position(0); mObject = result; return; } if (mObject is int) { int result = ((int)mObject) + ((int)rhs.mObject); mObject = Sharpen.Extensions.ValueOf(result); return; } } } if (mObject == null) { if (rhs.mObject != null) { if (rhs.mObject is int) { mObject = Sharpen.Extensions.ValueOf(((int)rhs.mObject)); return; } else { if (rhs.mObject is double) { mObject = (((double)rhs.mObject)); return; } } } } if (rhs.mObject == null) { if (mObject != null) { if (mObject is int) { return; } else { if (mObject is double) { return; } } } } mObject = (AsDouble() + rhs.AsDouble()); }
// + /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public Kirikiri.Tjs2.Variant Add(Kirikiri.Tjs2.Variant val) { if (mObject is string || val.mObject is string) { string s1 = AsString(); string s2 = val.AsString(); if (s1 != null && s2 != null) { StringBuilder builder = new StringBuilder(256); builder.Append(s1); builder.Append(s2); return new Kirikiri.Tjs2.Variant(builder.ToString()); } else { if (s1 != null) { return new Kirikiri.Tjs2.Variant(s1); } else { return new Kirikiri.Tjs2.Variant(s2); } } } if (mObject != null && val.mObject != null) { if (mObject.GetType().IsAssignableFrom(val.mObject.GetType())) { // 同じクラス if (mObject is ByteBuffer) { ByteBuffer b1 = (ByteBuffer)mObject; ByteBuffer b2 = (ByteBuffer)val.mObject; ByteBuffer result = ByteBuffer.Allocate(b1.Capacity() + b2.Capacity()); b1.Position(0); b2.Position(0); result.Put(b1); result.Put(b2); result.Position(0); return new Kirikiri.Tjs2.Variant(result); } if (mObject is int) { int result = ((int)mObject) + ((int)val.mObject); return new Kirikiri.Tjs2.Variant(result); } } } if (mObject == null) { if (val.mObject != null) { if (val.mObject is int) { return new Kirikiri.Tjs2.Variant(((int)val.mObject)); } else { if (val.mObject is double) { return new Kirikiri.Tjs2.Variant(((double)val.mObject)); } } } } if (val.mObject == null) { if (mObject != null) { if (mObject is int) { return new Kirikiri.Tjs2.Variant(((int)mObject)); } else { if (mObject is double) { return new Kirikiri.Tjs2.Variant(((double)mObject)); } } } } return new Kirikiri.Tjs2.Variant(AsDouble() + val.AsDouble()); }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public int LittlerThanForSort(Kirikiri.Tjs2.Variant val) { if ((mObject is string) == false || (val.mObject is string) == false) { if ((mObject is int) && (val.mObject is int)) { return ((int)val.mObject) - ((int)mObject); } double ret = val.AsDouble() - AsDouble(); if (ret == 0.0) { return 0; } else { if (ret < 0.0) { return -1; } else { return 1; } } } string s1 = AsString(); string s2 = val.AsString(); return Sharpen.Runtime.CompareOrdinal(s2, s1); }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public bool LittlerThan(Kirikiri.Tjs2.Variant val) { if ((mObject is string) == false || (val.mObject is string) == false) { if ((mObject is int) && (val.mObject is int)) { return ((int)mObject) > ((int)val.mObject); } return AsDouble() > val.AsDouble(); } string s1 = AsString(); string s2 = val.AsString(); return Sharpen.Runtime.CompareOrdinal(s1, s2) > 0; }
// /= /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public void DivideEqual(Kirikiri.Tjs2.Variant rhs) { double l = AsDouble(); double r = rhs.AsDouble(); mObject = (l / r); }
// / /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public Kirikiri.Tjs2.Variant Divide(Kirikiri.Tjs2.Variant val) { double l = AsDouble(); double r = val.AsDouble(); return new Kirikiri.Tjs2.Variant(l / r); }