/// <exception cref="TjsException"></exception> protected internal override int Process(Variant result, Variant[] param, Dispatch2 objthis) { ArrayNI ni = (ArrayNI)objthis.GetNativeInstance(ArrayClass.ClassID); if (ni == null) { return(Error.E_NATIVECLASSCRASH); } if (ni.mItems.IsEmpty()) { if (result != null) { result.Clear(); } } else { if (result != null) { result.Set(ni.mItems[0]); } ((ArrayObject)objthis).Erase(ni, 0); } return(Error.S_OK); }
public void TestListAdd() { Variant v = new Variant(Variant.EnumType.List); Assert.Throws <VariantException>(delegate { v.Add("key", new Variant()); }); Assert.Throws <VariantException>(delegate { v.Add(new DateTime(0), new Variant()); }); v.Add(new Variant("value1")); v.Add(new Variant(2.0)); Assert.AreEqual(v.Count, 2); Assert.IsFalse(v.Empty); Assert.AreEqual(Variant.EnumType.String, v[0].Type); Assert.AreEqual("value1", v[0].As <string>()); Assert.AreEqual(Variant.EnumType.Double, v[1].Type); Assert.AreEqual(2.0, v[1].As <double>()); Assert.Throws <VariantException>(delegate { Variant w = v[-1]; }); Assert.Throws <VariantException>(delegate { Variant w = v[2]; }); v[0] = new Variant("other"); Assert.AreEqual(v[0].As <string>(), "other"); v.Clear(); Assert.AreEqual(v.Count, 0); Assert.IsTrue(v.Empty); }
public virtual void Clear(ArrayNI ni) { // clear members int count = ni.mItems.Count; for (int i = 0; i < count; i++) { Variant v = ni.mItems[i]; v.Clear(); } ni.mItems.Clear(); }
/// <exception cref="VariantException"></exception> /// <exception cref="TjsException"></exception> public override int FuncCall(int flag, string membername, Variant result, Variant [] param, Dispatch2 objthis) { if (membername != null) { return(base.FuncCall(flag, membername, result, param, objthis)); } if (result != null) { result.Clear(); } return(Process(result, param, objthis)); }
public void Release(Variant va) { if (va == null) { return; } va.Clear(); int poolSize = mPool.Count; if (poolSize < LIMIT_SIZE) { mPool.AddItem(va); } }
/// <exception cref="VariantException"></exception> /// <exception cref="TjsException"></exception> public override int PropGet(int flag, string membername, Variant result, Dispatch2 objthis) { int hr = base.PropGet(flag, membername, result, objthis); if (hr == Error.E_MEMBERNOTFOUND && (flag & Interface.MEMBERMUSTEXIST) == 0) { if (result != null) { result.Clear(); } // returns void return(Error.S_OK); } return(hr); }
/// <exception cref="VariantException"></exception> /// <exception cref="TjsException"></exception> public virtual void RegisterNCM(string name, Dispatch2 dsp, string className, int type, int flags) { string tname = Tjs.MapGlobalStringMap(name); // add to this //Variant val = new Variant(dsp); //propSet( (Interface.MEMBERENSURE | Interface.IGNOREPROP) | flags, tname, val, this); mWorkParam.Set(dsp); try { PropSet((Interface.MEMBERENSURE | Interface.IGNOREPROP) | flags, tname, mWorkParam , this); } finally { mWorkParam.Clear(); } }
public void Clear() { if (mNodes != null) { int count = mNodes.Count; for (int i = 0; i < count; i++) { ExprNode node = mNodes[i]; node?.Clear(); } mNodes.Clear(); mNodes = null; } if (mVal != null) { mVal.Clear(); mVal = null; } }
public virtual int Remove(ArrayNI ni, Variant @ref, bool removeall) { int count = 0; IntVector todelete = new IntVector(); int arrayCount = ni.mItems.Count; for (int i = 0; i < arrayCount; i++) { Variant v = ni.mItems[i]; if (@ref.DiscernCompareInternal(v)) { count++; todelete.Add(i); if (!removeall) { break; } } } // list objects up int delCount = todelete.Size(); for (int i_1 = 0; i_1 < delCount; i_1++) { int pos = todelete.Get(i_1); Variant v = ni.mItems[pos]; v.Clear(); } // remove items found for (int i_2 = delCount - 1; i_2 >= 0; i_2--) { ni.mItems.Remove(todelete.Get(i_2)); } todelete = null; return(count); }
public static void JavaObjectToVariant(Variant result, Type type, object src) { if (result == null) { return; } if (type.GetTypeInfo().IsPrimitive) { // プリミティブタイプの场合 if (type == typeof(int)) { result.Set(((int)src)); } else if (type == typeof(double)) { result.Set(((double)src)); } else if (type == typeof(bool)) { result.Set(((bool)src) ? 1 : 0); } else if (type == typeof(float)) { result.Set(((float)src)); } else if (type == typeof(long)) { result.Set(((long)src)); } else if (type == typeof(char)) { result.Set((char)src); } else if (type == typeof(byte)) { result.Set(((byte)src)); } else if (type == typeof(short)) { result.Set(((short)src)); } else { // may be Void.TYPE result.Clear(); } } else { if (type == typeof(string)) { result.Set((string)src); } else if (type == typeof(ByteBuffer)) { result.Set((ByteBuffer)src); } else if (type == typeof(Variant)) { result.Set((Variant)src); } else if (type == typeof(VariantClosure)) { result.Set(((VariantClosure)src).mObject, ((VariantClosure)src).mObjThis); } else if (type == typeof(Dispatch2)) { result.Set((Dispatch2)src); } else { // その他 のクラス, 直接入れてしまう result.SetJavaObject(src); } } }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public override int FuncCall(int flag, string membername, Variant result, Variant [] param, Dispatch2 objthis) { if (membername != null) { return base.FuncCall(flag, membername, result, param, objthis); } if (param.Length < mParamTypes.Length) { return Error.E_INVALIDPARAM; } // パラメータが少ない if (result != null) { result.Clear(); } object self; if (mIsStatic) { self = null; } else { // static 时は null if (objthis == null) { return Error.E_NATIVECLASSCRASH; } NativeJavaInstance ni = (NativeJavaInstance)objthis.GetNativeInstance(mClassID); if (ni == null) { return Error.E_FAIL; } self = ni.GetNativeObject(); if (self == null) { return Error.E_NATIVECLASSCRASH; } } int er = Error.S_OK; object[] args = NativeJavaClass.VariantArrayToJavaObjectArray(param, mParamTypes); try { object ret = mProcess.Invoke(self, args); if (result != null) { NativeJavaClass.JavaObjectToVariant(result, mReturnType, ret); } } catch (ArgumentException) { er = Error.E_INVALIDPARAM; } catch (MemberAccessException) { er = Error.E_ACCESSDENYED; } catch (TargetInvocationException e) { Exception t = e.InnerException; if (t is VariantException) { throw (VariantException)t; } else { if (t is TJSException) { throw (TJSException)t; } else { throw new TJSException(t.ToString()); } } } return er; }
/// <exception cref="VariantException"></exception> /// <exception cref="TjsException"></exception> public override int FuncCall(int flag, string membername, Variant result, Variant [] param, Dispatch2 objthis) { if (membername != null) { return(base.FuncCall(flag, membername, result, param, objthis)); } if (param.Length < mParamTypes.Length) { return(Error.E_INVALIDPARAM); } // パラメータが少ない if (result != null) { result.Clear(); } object self; if (mIsStatic) { self = null; } else { // static 时は null if (objthis == null) { return(Error.E_NATIVECLASSCRASH); } NativeJavaInstance ni = (NativeJavaInstance)objthis.GetNativeInstance(mClassID); if (ni == null) { return(Error.E_FAIL); } self = ni.GetNativeObject(); if (self == null) { return(Error.E_NATIVECLASSCRASH); } } int er = Error.S_OK; object[] args = NativeJavaClass.VariantArrayToJavaObjectArray(param, mParamTypes); try { object ret = mProcess.Invoke(self, args); if (result != null) { NativeJavaClass.JavaObjectToVariant(result, mReturnType, ret); } } catch (ArgumentException) { er = Error.E_INVALIDPARAM; } catch (MemberAccessException) { er = Error.E_ACCESSDENIED; } catch (TargetInvocationException e) { Exception t = e.InnerException; if (t is VariantException) { throw (VariantException)t; } else { if (t is TjsException) { throw (TjsException)t; } else { throw new TjsException(t.ToString()); } } } return(er); }
public static void JavaObjectToVariant(Variant result, Type type, object src) { if (result == null) { return; } if (type.IsPrimitive) { // プリミティブタイプの场合 if (type.Equals(typeof(int))) { result.Set(((int)src)); } else { if (type.Equals(typeof(double))) { result.Set(((double)src)); } else { if (type.Equals(typeof(bool))) { result.Set(((bool)src) ? 1 : 0); } else { if (type.Equals(typeof(float))) { result.Set(((float)src)); } else { if (type.Equals(typeof(long))) { result.Set(((long)src)); } else { if (type.Equals(typeof(char))) { result.Set((int)((char)src)); } else { if (type.Equals(typeof(byte))) { result.Set(((byte)src)); } else { if (type.Equals(typeof(short))) { result.Set(((short)src)); } else { // may be Void.TYPE result.Clear(); } } } } } } } } } else { if (type.Equals(typeof(string))) { result.Set((string)src); } else { if (type.Equals(typeof(ByteBuffer))) { result.Set((ByteBuffer)src); } else { if (type.Equals(typeof(Variant))) { result.Set((Variant)src); } else { if (type.Equals(typeof(VariantClosure))) { result.Set(((VariantClosure)src).mObject, ((VariantClosure)src).mObjThis); } else { if (type.Equals(typeof(Dispatch2))) { result.Set((Dispatch2)src); } else { // その他 のクラス, 直接入れてしまう result.SetJavaObject(src); } } } } } } }