Ejemplo n.º 1
0
//----------------------------------------------------------------------
// 辞書を作成
tTJSVariant createDictionary(void)
{
	iTJSDispatch2 *obj = TJSCreateDictionaryObject();
	tTJSVariant result(obj, obj);
	obj->Release();
	return result;
}
Ejemplo n.º 2
0
//---------------------------------------------------------------------------
// TVPCreateEventObject
//---------------------------------------------------------------------------
iTJSDispatch2 * TVPCreateEventObject(const tjs_char *type,
	iTJSDispatch2 *targthis, iTJSDispatch2 *targ)
{
	// create a dictionary object for event dispatching ( to "action" method )
	iTJSDispatch2 * object = TJSCreateDictionaryObject();

	static ttstr type_name(TJS_W("type"));
	static ttstr target_name(TJS_W("target"));

	{
		tTJSVariant val(type);
		if(TJS_FAILED(object->PropSet(TJS_MEMBERENSURE|TJS_IGNOREPROP,
			type_name.c_str(), type_name.GetHint(), &val, object)))
				TVPThrowInternalError;
	}

	{
		tTJSVariant val(targthis, targ);
		if(TJS_FAILED(object->PropSet(TJS_MEMBERENSURE|TJS_IGNOREPROP,
			target_name.c_str(), target_name.GetHint(), &val, object)))
				TVPThrowInternalError;
	}
	
	return object;
}
Ejemplo n.º 3
0
		static iTJSDispatch2* toDictionary(double x, double y) {
			iTJSDispatch2 *dic = TJSCreateDictionaryObject();
			tTJSVariant var_x(static_cast<tTVReal>(x)), var_y(static_cast<tTVReal>(y));
			dic->PropSet(TJS_MEMBERENSURE, TJS_W("x"), 0, &var_x, dic);
			dic->PropSet(TJS_MEMBERENSURE, TJS_W("y"), 0, &var_y, dic);
			return dic;
		}
Ejemplo n.º 4
0
/**
 * XMLのノードから tTJSVariantを取得する
 * @param var 結果格納先
 * @param node ノード
 */
static void
getVariantFromNode(tTJSVariant &var, xml_node *node)
{
	if (node && node->type() == rapidxml::node_element) {
		if (_wcsicmp(node->name(), L"undefined") == 0) {
			var.Clear();
		} else if (_wcsicmp(node->name(), L"null") == 0) {
			var = tTJSVariant((iTJSDispatch2*)NULL);
		} else if (_wcsicmp(node->name(), L"array") == 0) {
			iTJSDispatch2 *array = TJSCreateArrayObject();
			for (xml_node *propNode = node->first_node(); propNode; propNode = propNode->next_sibling()) {
				if (_wcsicmp(propNode->name(), L"property") == 0) {
					xml_attribute *attr_id = propNode->first_attribute(L"id");
					if (attr_id) {
						tjs_int id = wcstol(attr_id->value(), NULL, 10);
						xml_node *valueNode = propNode->first_node();
						if (valueNode) {
							tTJSVariant value;
							getVariantFromNode(value, valueNode);
							array->PropSetByNum(0, id, &value, array);
						}
					}
				}
			}
			var = tTJSVariant(array, array);
			array->Release();
		} else if (_wcsicmp(node->name(), L"object") == 0) {
			iTJSDispatch2 *dict = TJSCreateDictionaryObject();
			for (xml_node *propNode = node->first_node(); propNode; propNode = propNode->next_sibling()) {
				if (_wcsicmp(propNode->name(), L"property") == 0) {
					xml_attribute *attr_id = propNode->first_attribute(L"id");
					if (attr_id) {
						ttstr id = attr_id->value();
						if (id.length() > 0) {
							xml_node *valueNode = propNode->first_node();
							if (valueNode) {
								tTJSVariant value;
								getVariantFromNode(value, valueNode);
								dict->PropSet(0, id.c_str(), 0, &value, dict);
							}
						}
					}
				}
			}
			var = tTJSVariant(dict, dict);
			dict->Release();
		} else if (_wcsicmp(node->name(), L"string") == 0) {
			var = node->value();
		} else if (_wcsicmp(node->name(), L"number") == 0) {
			var = wcstod(node->value(), NULL);
		}
	} else {
		var.Clear();
	}
}
Ejemplo n.º 5
0
tTJSDictionaryObject* tTJSBinarySerializer::CreateDictionary( tjs_uint count ) {
	if( DicClass == NULL ) {
		iTJSDispatch2* dsp = TJSCreateDictionaryObject(&DicClass);
		dsp->Release();
	}
	tTJSDictionaryObject* dic;
	tTJSVariant param[1] = { (tjs_int)count };
	tTJSVariant *pparam[1] = { param };
	DicClass->CreateNew( 0, NULL,  NULL, (iTJSDispatch2**)&dic, 1, pparam, DicClass );
	return dic;
}
Ejemplo n.º 6
0
//----------------------------------------------------------------------
// 構造体比較関数
tTJSVariant
ScriptsAdd::clone(tTJSVariant obj)
{
	// タイプがオブジェクトなら細かく判定
	if (obj.Type() == tvtObject) {

		tTJSVariantClosure &o1 = obj.AsObjectClosureNoAddRef();
		
		// Arrayの複製
		if (o1.IsInstanceOf(0, NULL, NULL, L"Array", NULL)== TJS_S_TRUE) {
			iTJSDispatch2 *array = TJSCreateArrayObject();
			tTJSVariant o1Count;
			(void)o1.PropGet(0, L"count", &countHint, &o1Count, NULL);
			tjs_int count = o1Count;
			tTJSVariant val;
			tTJSVariant *args[] = {&val};
			for (tjs_int i = 0; i < count; i++) {
				(void)o1.PropGetByNum(TJS_IGNOREPROP, i, &val, NULL);
				val = ScriptsAdd::clone(val);
				static tjs_uint addHint = 0;
				(void)array->FuncCall(0, TJS_W("add"), &addHint, 0, 1, args, array);
			}
			tTJSVariant result(array, array);
			array->Release();
			return result;
		}
		
		// Dictionaryの複製
		if (o1.IsInstanceOf(0, NULL, NULL, L"Dictionary", NULL)== TJS_S_TRUE) {
			iTJSDispatch2 *dict = TJSCreateDictionaryObject();
			DictMemberCloneCaller *caller = new DictMemberCloneCaller(dict);
			tTJSVariantClosure closure(caller);
			o1.EnumMembers(TJS_IGNOREPROP, &closure, NULL);
			caller->Release();
			tTJSVariant result(dict, dict);
			dict->Release();
			return result;
		}

		// cloneメソッドの呼び出しに成功すればそれを返す
		tTJSVariant result;
		static tjs_uint cloneHint = 0;
		if (o1.FuncCall(0, L"clone", &cloneHint, &result, 0, NULL, NULL)== TJS_S_TRUE) {
			return result;
		}
	}
	
	return obj;
}
Ejemplo n.º 7
0
//---------------------------------------------------------------------------
tjs_error TJS_INTF_METHOD tTJSDictionaryNI::tAssignStructCallback::FuncCall(
	tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
	tTJSVariant *result, tjs_int numparams, tTJSVariant **param,
	iTJSDispatch2 *objthis)
{
	// called indirectly from tTJSDictionaryNI::AssignStructure or
	// tTJSArrayNI::AssignStructure

	if(numparams < 3) return TJS_E_BADPARAMCOUNT;

	// hidden members are not processed
	tjs_uint32 flags = (tjs_int)*param[1];
	if(flags & TJS_HIDDENMEMBER)
	{
		if(result) *result = (tjs_int)1;
		return TJS_S_OK;
	}

	tTJSVariant &value = *param[2];

	tTJSVariantType type = value.Type();
	if(type == tvtObject)
	{
		// object

		iTJSDispatch2 *dsp = value.AsObjectNoAddRef();
		// determin dsp's object type

		tTJSVariant val;

		tTJSDictionaryNI *dicni = NULL;
		tTJSArrayNI *arrayni = NULL;

		if(dsp && TJS_SUCCEEDED(dsp->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
			TJSGetDictionaryClassID(), (iTJSNativeInstance**)&dicni)) )
		{
			// dictionary
			bool objrec = false;
			std::vector<iTJSDispatch2 *>::iterator i;
			for(i = Stack->begin(); i != Stack->end(); i++)
			{
				if(*i == dsp)
				{
					// object recursion detected
					objrec = true;
					break;
				}
			}
			if(objrec)
			{
				val.SetObject(NULL); // becomes null
			}
			else
			{
				iTJSDispatch2 * newobj = TJSCreateDictionaryObject();
				val.SetObject(newobj, newobj);
				newobj->Release();
				tTJSDictionaryNI * newni = NULL;
				if(TJS_SUCCEEDED(newobj->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
					TJSGetDictionaryClassID(), (iTJSNativeInstance**)&newni)) )
				{
					newni->AssignStructure(dsp, *Stack);
				}
			}
		}
		else if(dsp && TJS_SUCCEEDED(dsp->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
			TJSGetArrayClassID(), (iTJSNativeInstance**)&arrayni)) )
		{
			// array
			bool objrec = false;
			std::vector<iTJSDispatch2 *>::iterator i;
			for(i = Stack->begin(); i != Stack->end(); i++)
			{
				if(*i == dsp)
				{
					// object recursion detected
					objrec = true;
					break;
				}
			}
			if(objrec)
			{
				val.SetObject(NULL); // becomes null
			}
			else
			{
				iTJSDispatch2 * newobj = TJSCreateArrayObject();
				val.SetObject(newobj, newobj);
				newobj->Release();
				tTJSArrayNI * newni = NULL;
				if(TJS_SUCCEEDED(newobj->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
					TJSGetArrayClassID(), (iTJSNativeInstance**)&newni)) )
				{
					newni->AssignStructure(dsp, *Stack);
				}
			}
		}
		else
		{
			// other object types
			val = value;
		}

		Dest->PropSetByVS(TJS_MEMBERENSURE|TJS_IGNOREPROP, param[0]->AsStringNoAddRef(), &val, Dest);
	}
	else
	{
		// other types
		Dest->PropSetByVS(TJS_MEMBERENSURE|TJS_IGNOREPROP, param[0]->AsStringNoAddRef(), &value, Dest);
	}

	if(result) *result = (tjs_int)1;
	return TJS_S_OK;
}