Exemplo n.º 1
0
static void
getVariantString(tTJSVariant &var, IWriter *writer)
{
	switch(var.Type()) {

	case tvtVoid:
		writer->write(L"void");
		break;
		
	case tvtObject:
		{
			iTJSDispatch2 *obj = var.AsObjectNoAddRef();
			if (obj == NULL) {
				writer->write(L"null");
			} else if (obj->IsInstanceOf(TJS_IGNOREPROP,NULL,NULL,L"Array",obj) == TJS_S_TRUE) {
				getArrayString(obj, writer);
			} else {
				getDictString(obj, writer);
			}
		}
		break;
		
	case tvtString:
		quoteString(var.GetString(), writer);
		break;

        case tvtOctet:
               quoteOctet(var.AsOctetNoAddRef(), writer);
               break;

	case tvtInteger:
		writer->write(L"int ");
		writer->write((tTVInteger)var);
		break;

	case tvtReal:
		writer->write(L"real ");
		writer->write((tTVReal)var);
		break;

	default:
		writer->write(L"void");
		break;
	};
}
Exemplo n.º 2
0
/**
 * バイアント値を格納する
 */
void tTJSBinarySerializer::PutVariant( tTJSBinaryStream* stream, tTJSVariant& v )
{
	tTJSVariantType type = v.Type();
	switch( type ) {
	case tvtVoid: {
		tjs_uint8 tmp[1];
		tmp[0] = TYPE_VOID;
		stream->Write( tmp, sizeof(tmp) );
		break;
	}
	case tvtObject:
		break;
/*
		{
		iTJSDispatch2* obj = v.AsObjectNoAddRef();
		iTJSDispatch2* objthis = v.AsObjectThisNoAddRef();
		if( obj == NULL && objthis == NULL ) {
			Put( TYPE_NIL );
		} else {
			SaveStructured
		}
		break;
	}
*/
	case tvtString:
		PutString( stream, v.AsStringNoAddRef() );
		break;
	case tvtOctet:
		PutOctet( stream, v.AsOctetNoAddRef() );
		break;
	case tvtInteger:
		PutInteger( stream, v.AsInteger() );
		break;
	case tvtReal:
		PutDouble( stream, v.AsReal() );
		break;
	default:
		break;
	}
}
Exemplo n.º 3
0
//---------------------------------------------------------------------------
tTJSString TJSVariantToReadableString(const tTJSVariant &val,
	tjs_int maxlen)
{
	// convert given variant to human-readable string
	// ( eg. "(string)\"this is a\\nstring\"" )

	tTJSVariantType type = val.Type();

	switch(type)
	{
	case tvtVoid:
	  {
		tTJSString str(TJS_W("(void)"));
		TJSTrimStringLength(str, maxlen);
		return str;
	  }
	case tvtInteger:
	  {
		tTJSString str(TJS_W("(int)"));
		str += (tTJSString)val;
		TJSTrimStringLength(str, maxlen);
		return str;
	  }
	case tvtReal:
	  {
		tTJSString str(TJS_W("(real)"));
		str += (tTJSString)val;
		TJSTrimStringLength(str, maxlen);
		return str;
	  }
	case tvtString:
	  {
		tTJSString str(TJS_W("(string)\""));
		str += ttstr(val).EscapeC();
		str += TJS_W("\"");
		TJSTrimStringLength(str, maxlen);
		return str;
	  }
	case tvtOctet:
	  {
		// TODO: octet conversion
		tTJSString str(TJS_W("(octet)<% "));
		tTJSVariantString * s = TJSOctetToListString(val.AsOctetNoAddRef());
		try
		{
			str += s;
		}
		catch(...)
		{
			if(s) s->Release();
			throw;
		}
		if(s) s->Release();
		str += TJS_W(" %>");
		TJSTrimStringLength(str, maxlen);
		return str;
	  }
	case tvtObject:
	  {
		tTJSString str(TJS_W("(object)"));
		try
		{
			str += ttstr(val);
		}
		catch(...)
		{
		}
		TJSTrimStringLength(str, maxlen);
		return str;
	  }
	}
	return TJS_W("");
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------
tTJSString TJSVariantToExpressionString(const tTJSVariant &val)
{
	// convert given variant to string which can be interpret as an expression.
	// this function does not convert objects ( returns empty string )

	tTJSVariantType type = val.Type();

	switch(type)
	{
	case tvtVoid:
	  {
		return TJS_W("void");
	  }
	case tvtInteger:
	  {
		return ttstr(val);
	  }
	case tvtReal:
	  {
		tTJSString str;
		tTJSVariantString *s = TJSRealToHexString(val.AsReal());
		try
		{
			str = s;
		}
		catch(...)
		{
			if(s) s->Release();
			throw;
		}
		if(s) s->Release();
		return str + TJS_W(" /" "* ") + ttstr(val) + TJS_W(" *" "/");
	  }
	case tvtString:
	  {
		tTJSString str(TJS_W("\""));
		str += ttstr(val).EscapeC();
		str += TJS_W("\"");
		return str;
	  }
	case tvtOctet:
	  {
		tTJSString str(TJS_W("<% "));
		tTJSVariantString * s = TJSOctetToListString(val.AsOctetNoAddRef());
		try
		{
			str += s;
		}
		catch(...)
		{
			if(s) s->Release();
			throw;
		}
		if(s) s->Release();
		str += TJS_W(" %>");
		return str;
	  }
	case tvtObject:
	  {
		return TJS_W("");
	  }
	}
	return TJS_W("");
}
Exemplo n.º 5
0
/**
 * tTJSVariant を VARIANT に格納する
 * @param result 格納先
 * @param variant 格納元
 */
void
IDispatchWrapper::storeVariant(VARIANT &result, tTJSVariant &variant)
{
	VariantClear(&result);
	switch (variant.Type()) {
	case tvtVoid:
		//log(L"void");
		break;
	case tvtObject:
		// オブジェクト
		//log(L"object");
		{
			switch (variant.Type()) {
			case tvtObject:
				V_VT(&result)       = VT_DISPATCH;
				V_DISPATCH(&result) = new IDispatchWrapper(variant.AsObjectNoAddRef());
				break;
			default:
				V_VT(&result) = VT_NULL;
				break;
			}
		}
		break;
	case tvtString:
		//log(L"string");
		// 文字列
		V_VT(&result) = VT_BSTR;
		V_BSTR(&result) = SysAllocString(variant.GetString());
		break;
	case tvtOctet:
		//log(L"octet");
		// オクテット列
		{
			tTJSVariantOctet *octet = variant.AsOctetNoAddRef();
			if (octet) {
				SAFEARRAY *psa;
				SAFEARRAYBOUND sabound;
				sabound.lLbound = 0;
				sabound.cElements = octet->GetLength();
				if ((psa = SafeArrayCreate(VT_UI1, 1, &sabound))) {
					// データをコピーする
					unsigned char *p;
					if (SUCCEEDED(SafeArrayAccessData(psa, (LPVOID*)&p))) {
						memcpy(p, octet->GetData(), octet->GetLength());
						SafeArrayUnaccessData(psa);
						V_VT(&result) = VT_ARRAY | VT_UI1;
						V_ARRAY(&result) = psa;
					} else {
						SafeArrayDestroy(psa);
					}
				} else {
					// メモリ不足例外
				}
			}
		}
		break;
	case tvtInteger:
		// COM は 64bit をサポートしていない!!
		// ということで COM に渡す引数で整数値は 32bit を超えないように注意すること(涙)
		//log(L"integer");
		V_VT(&result) = VT_I4;
		V_I4(&result) = (int)(variant);
		break;
	case tvtReal:
		//log(L"real");
		V_VT(&result) = VT_R8;
		V_R8(&result) = (double)(variant);
		break;
	}
}