Exemplo n.º 1
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.º 2
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("");
}