/// <summary> /// 格納する値を指定してインスタンスを初期化します。 /// </summary> /// <param name="value">格納する値</param> public QiString(string value) { var val = QiValue.Create(QiSignatures.TypeString); val.SetValue(value); QiValue = val; }
private void OnHumanSpeechDetected(QiValue qv) { if (qv.Count > 0 && qv[0].ContentValueKind == QiValueKind.QiString) { System.Windows.Application.Current.Dispatcher.Invoke(() => { ChatEntries.Add(new HumanChatEntryViewModel(qv[0].GetString())); }); } }
internal static bool SetRaw(QiValue v, byte[] data) { var dataPtr = Marshal.AllocHGlobal(data.Length); Marshal.Copy(data, 0, dataPtr, data.Length); var result = Convert.ToBoolean(qi_value_raw_set(v.Handle, dataPtr, data.Length)); Marshal.FreeHGlobal(dataPtr); return(result); }
/// <summary> /// 渡された<see cref="QiSignatures.TypeDynamic"/>シグネチャを持った変数をそのまま格納するか、 /// そうでない場合渡された値を動的型コンテナに格納してインスタンスを初期化します。 /// </summary> /// <param name="value">インスタンスが保持する値</param> public QiDynamic(QiValue value) { if (value.ValueKind == QiValueKind.QiDynamic) { QiValue = value; } else { QiValue = QiValue.Create(QiSignatures.TypeDynamic); QiValue.SetValue(value); } }
/// <summary> /// 渡された<see cref="QiSignatures.TypeDynamic"/>シグネチャを持った変数をそのまま格納するか、 /// そうでない場合渡された値を動的型コンテナに格納してインスタンスを初期化します。 /// </summary> /// <param name="value">インスタンスが保持する値</param> public QiDynamic(QiValue value) { if (value.ValueKind == QiValueKind.QiDynamic) { QiValue = value; } else { QiValue = QiValue.Create(QiSignatures.TypeDynamic); QiValue.SetValue(value); } }
internal static bool SetString(QiValue v, string target) { //NOTE: アンマネージ側はヌル終端文字を想定してるらしい var data = Encoding.UTF8.GetBytes(target); IntPtr tPtr = Marshal.AllocHGlobal(data.Length + 1); Marshal.Copy(data, 0, tPtr, data.Length); Marshal.WriteByte(tPtr, data.Length, 0x00); bool result = Convert.ToBoolean(qi_value_set_string(v.Handle, tPtr)); Marshal.FreeHGlobal(tPtr); return(result); }
internal static string GetString(QiValue v) { IntPtr utf8nullEndStringPtr = qi_value_get_string(v.Handle); int byteLength = 0; //ヌル終端探し(これ上限無いの地味に怖いなあ) while (Marshal.ReadByte(utf8nullEndStringPtr, byteLength) != (byte)0x00) { byteLength++; } var strBytes = new byte[byteLength]; Marshal.Copy(utf8nullEndStringPtr, strBytes, 0, byteLength); return(Encoding.UTF8.GetString(strBytes)); }
private void OnRobotSpeechDetected(QiValue qv) { if (qv.Count == 0 || qv[0].ContentValueKind != QiValueKind.QiString) { return; } string sentence = qv[0].GetString(); if (!string.IsNullOrWhiteSpace(sentence)) { System.Windows.Application.Current.Dispatcher.Invoke(() => { ChatEntries.Add(new RobotChatEntryViewModel(sentence)); }); } }
internal static byte[] GetRaw(QiValue v) { IntPtr data = IntPtr.Zero; int size = 0; int response = qi_value_raw_get(v.Handle, ref data, ref size); //冗長だけど念のためサイズも確認 if (response > 0 && size > 0) { byte[] result = new byte[size]; Marshal.Copy(data, result, 0, size); //(少なくとも自作実装では)元データのポインタを貰う想定なので解放しない //Marshal.FreeHGlobal(data); return(result); } else { Marshal.FreeHGlobal(data); return(new byte[0]); } }
internal static QiObject GetObject(QiValue v) => new QiObject(qi_value_get_object(v.Handle));
internal static QiValue GetMap(QiValue container, QiValue key) => new QiValue(qi_value_map_get(container.Handle, key.Handle));
internal static uint SizeMap(QiValue container) => qi_value_map_size(container.Handle);
internal static QiFuture SetProperty(QiObject obj, string pname, QiValue value) => new QiFuture(qi_object_set_property(obj.Handle, pname, value));
internal static bool SetObject(QiValue v, QiObject obj) => Convert.ToBoolean(qi_value_set_object(v.Handle, obj.Handle));
internal static QiValue GetDynamic(QiValue container) => new QiValue(qi_value_dynamic_get(container.Handle));
internal static QiValue KeysMap(QiValue container) => new QiValue(qi_value_map_keys(container.Handle));
internal static QiValue GetDynamic(QiValue container) => new QiValue(qi_value_dynamic_get(container.Handle));
internal static bool SetDynamic(QiValue container, QiValue value) => Convert.ToBoolean(qi_value_dynamic_set(container.Handle, value.Handle));
internal static int SizeTuple(QiValue container) => qi_value_tuple_size(container.Handle);
internal static QiValue GetTuple(QiValue container, uint idx) => new QiValue(qi_value_tuple_get(container.Handle, idx));
internal static bool SetTuple(QiValue container, uint idx, QiValue element) => Convert.ToBoolean(qi_value_tuple_set(container.Handle, idx, element.Handle));
internal static bool SetTuple(QiValue container, uint idx, QiValue element) => Convert.ToBoolean(qi_value_tuple_set(container.Handle, idx, element.Handle));
internal static int SizeTuple(QiValue container) => qi_value_tuple_size(container.Handle);
internal static QiValue GetMap(QiValue container, QiValue key) => new QiValue(qi_value_map_get(container.Handle, key.Handle));
internal static byte[] GetRaw(QiValue v) { IntPtr data = IntPtr.Zero; int size = 0; int response = qi_value_raw_get(v.Handle, ref data, ref size); //冗長だけど念のためサイズも確認 if(response > 0 && size > 0) { byte[] result = new byte[size]; Marshal.Copy(data, result, 0, size); //(少なくとも自作実装では)元データのポインタを貰う想定なので解放しない //Marshal.FreeHGlobal(data); return result; } else { Marshal.FreeHGlobal(data); return new byte[0]; } }
internal static bool SetMap(QiValue container, QiValue key, QiValue element) => Convert.ToBoolean(qi_value_map_set(container.Handle, key.Handle, element.Handle));
internal static QiFuture Call(QiObject obj, string signature, QiValue qiTuple) => new QiFuture(qi_object_call(obj.Handle, signature, qiTuple.Handle));
internal static bool SetInt64(QiValue v, long target) => Convert.ToBoolean(qi_value_set_int64(v.Handle, target));
/// <summary> /// 格納する値を指定してインスタンスを初期化します。 /// </summary> /// <param name="value">格納する値</param> public QiFloat(float value) { QiValue = QiValue.Create(QiSignatures.TypeFloat); QiValue.SetValue(value); }
internal static bool GetInt64(QiValue v, ref long target) => Convert.ToBoolean(qi_value_get_int64(v.Handle, ref target));
internal static int SizeList(QiValue container) => qi_value_list_size(container.Handle);
internal static long GetInt64WithDefault(QiValue v, long defaultValue) => qi_value_get_int64_default(v.Handle, defaultValue);
internal static bool SetMap(QiValue container, QiValue key, QiValue element) => Convert.ToBoolean(qi_value_map_set(container.Handle, key.Handle, element.Handle));
internal static bool SetFloat(QiValue v, float target) => Convert.ToBoolean(qi_value_set_float(v.Handle, target));
internal static QiValue KeysMap(QiValue container) => new QiValue(qi_value_map_keys(container.Handle));
internal static bool GetFloat(QiValue v, ref float target) => Convert.ToBoolean(qi_value_get_float(v.Handle, ref target));
internal static bool SetObject(QiValue v, QiObject obj) => Convert.ToBoolean(qi_value_set_object(v.Handle, obj.Handle));
internal static void SetValue(QiPromise promise, QiValue value) => qi_promise_set_value(promise.Handle, value.Handle);
internal static QiValue GetTuple(QiValue container, uint idx) => new QiValue(qi_value_tuple_get(container.Handle, idx));
internal static uint SizeMap(QiValue container) => qi_value_map_size(container.Handle);
internal static bool SetDynamic(QiValue container, QiValue value) => Convert.ToBoolean(qi_value_dynamic_set(container.Handle, value.Handle));
public Future SetProperty(string signature, QiValue value) { return(new Future(ObjectNative.qi_object_set_property(this._handle, signature, value.Handle))); }
internal static bool SetRaw(QiValue v, byte[] data) { var dataPtr = Marshal.AllocHGlobal(data.Length); Marshal.Copy(data, 0, dataPtr, data.Length); var result = Convert.ToBoolean(qi_value_raw_set(v.Handle, dataPtr, data.Length)); Marshal.FreeHGlobal(dataPtr); return result; }
internal QiMethodArgumentInfo(QiValue argInfo) { Name = argInfo[0].ToString(); Description = argInfo[1].ToString(); }
internal static float GetFloatWithDefault(QiValue v, float defaultValue) => qi_value_get_float_default(v.Handle, defaultValue);
internal static QiObject GetObject(QiValue v) => new QiObject(qi_value_get_object(v.Handle));
internal QiMethodArgumentInfo(QiValue argInfo) { Name = argInfo[0].ToString(); Description = argInfo[1].ToString(); }
internal static bool SetDouble(QiValue v, double target) => Convert.ToBoolean(qi_value_set_double(v.Handle, target));
public void SetValue(QiValue value) { PromiseNative.qi_promise_set_value(this._handle, value.Handle); }
internal static bool GetDouble(QiValue v, ref double target) => Convert.ToBoolean(qi_value_get_double(v.Handle, ref target));
internal static void SetValue(QiPromise promise, QiValue value) => qi_promise_set_value(promise.Handle, value.Handle);
internal static double GetDoubleWithDefault(QiValue v, double defaultValue) => qi_value_get_double_default(v.Handle, defaultValue);
private static extern IntPtr qi_object_set_property(IntPtr qiObj, string propName, QiValue value);
internal static bool SetString(QiValue v, string target) { //NOTE: アンマネージ側はヌル終端文字を想定してるらしい var data = Encoding.UTF8.GetBytes(target); IntPtr tPtr = Marshal.AllocHGlobal(data.Length + 1); Marshal.Copy(data, 0, tPtr, data.Length); Marshal.WriteByte(tPtr, data.Length, 0x00); bool result = Convert.ToBoolean(qi_value_set_string(v.Handle, tPtr)); Marshal.FreeHGlobal(tPtr); return result; }
internal static int Post(QiObject obj, string signature, QiValue qiTuple) => qi_object_post(obj.Handle, signature, qiTuple.Handle);
internal static string GetString(QiValue v) { IntPtr utf8nullEndStringPtr = qi_value_get_string(v.Handle); int byteLength = 0; //ヌル終端探し(これ上限無いの地味に怖いなあ) while(Marshal.ReadByte(utf8nullEndStringPtr, byteLength) != (byte)0x00) { byteLength++; } var strBytes = new byte[byteLength]; Marshal.Copy(utf8nullEndStringPtr, strBytes, 0, byteLength); return Encoding.UTF8.GetString(strBytes); }
/// <summary> /// 格納する値を指定してインスタンスを初期化します。 /// </summary> /// <param name="value">格納する値</param> public QiDouble(double value) { QiValue = QiValue.Create(QiSignatures.TypeDouble); QiValue.SetValue(value); }
internal static QiValue GetList(QiValue container, uint idx) => new QiValue(qi_value_list_get(container.Handle, idx));
/// <summary>格納する値を指定してインスタンスを初期化します。</summary> /// <param name="data">格納する値</param> public QiByteData(byte[] data) { QiValue = QiValue.Create(QiSignatures.TypeRaw); QiValue.SetValue(data); }
internal static bool AddList(QiValue container, QiValue element) => Convert.ToBoolean(qi_value_list_push_back(container.Handle, element.Handle));