Beispiel #1
0
//--------------------------------------------------------
//	check if string marked as a datum
//--------------------------------------------------------
Bool TLString::IsDatumString(const TString& String,TRef& DatumRef,TRef& ShapeType,Bool& IsJustDatum)
{
	//	split the string - max at 4 splits
	TFixedArray<TStringLowercase<TTempString>, 4> StringParts;
	if ( !String.Split( '_', StringParts ) )
	{
		//	didn't split at all, can't be valid
		return FALSE;
	}

	//	if it splits 4 times, there's too many parts
	if ( StringParts.GetSize() >= 4 )
		return false;

	//	check first part is named "datum"
	if ( StringParts[0] == "datum" )
	{
		//	just a datum
		IsJustDatum = TRUE;
	}
	else if ( StringParts[0] == "anddatum" )
	{
		//	not just a datum
		IsJustDatum = FALSE;
	}
	else
	{
		//	no kinda datum
		return FALSE;
	}

	//	should be 3 parts
	if ( StringParts.GetSize() != 3 )
	{
		TLDebug_Break( TString("Malformed Datum name (%s) on SVG geometry. Should be Datum_SHAPEREF_DATUMREF", String.GetData() ) );
		return FALSE;
	}

	//	make shape ref from 2nd string
	ShapeType.Set( StringParts[1] );
	DatumRef.Set( StringParts[2] );
	
	//	if either are invalid, fail
	if ( !ShapeType.IsValid() || !DatumRef.IsValid() )
	{
		TLDebug_Break( TString("Failed to set valid Ref's from Datum identifier: %s", String.GetData() ) );
		return FALSE;
	}

	return TRUE;
}
GLDEF_C TInt E32Main()
	{
	__UHEAP_MARK;
	CTrapCleanup* cleanup=CTrapCleanup::New();

    msfsMountedList.Reset();
    unmountedFsList.Reset();


	TRAPD(error,RunAppL());
	__ASSERT_ALWAYS(!error, User::Panic(KTxtApp, error));

	delete cleanup;
	__UHEAP_MARKEND;
	return 0;
	}
TInt CExtensionTestConverterImpl::ConvertFromUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
	{
	TFixedArray<CnvUtilities::SCharacterSet, 1> arrayOfAdditionalCharacterSets;
	arrayOfAdditionalCharacterSets[0].iConversionData=&sampleExtensionConversionData;
	arrayOfAdditionalCharacterSets[0].iConvertFromIntermediateBufferInPlace=DummyConvertFromIntermediateBufferInPlace;
	arrayOfAdditionalCharacterSets[0].iEscapeSequence=&KNullDesC8;
	return CnvShiftJis::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, arrayOfAdditionalCharacterSets.Array());
	}
TInt CExtensionTestConverterImpl::ConvertToUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt&, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
	{
	TFixedArray<CnvUtilities::SMethod, 1> arrayOfAdditionalMethods;
	arrayOfAdditionalMethods[0].iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToSampleExtension;
	arrayOfAdditionalMethods[0].iConvertToIntermediateBufferInPlace=DummyConvertToIntermediateBufferInPlace;
	arrayOfAdditionalMethods[0].iConversionData=&sampleExtensionConversionData;
	arrayOfAdditionalMethods[0].iNumberOfBytesPerCharacter=2;
	arrayOfAdditionalMethods[0].iNumberOfCoreBytesPerCharacter=2;
	return CnvShiftJis::ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, arrayOfAdditionalMethods.Array());
	}
Beispiel #5
0
TLNetwork::TTempAddrInfo::TTempAddrInfo(TRefRef Protocol,u16 Port) :
	m_pAddrInfo	( NULL )
{
	//	setup the addrinfo we want
	struct addrinfo hints;
    ZeroMemory(&hints, sizeof(hints));

	//	gr: INET is ipv4
    hints.ai_family = AF_INET;
    hints.ai_flags = AI_PASSIVE;

	if ( Protocol == "TCP" )
	{
		//	stream is TCP
		hints.ai_socktype = SOCK_STREAM;
		hints.ai_protocol = IPPROTO_TCP;
	}
	else // UDP
	{
		hints.ai_socktype = SOCK_DGRAM;
		hints.ai_protocol = IPPROTO_UDP;
	}

	//	need port in a string
	TTempString PortString;
	PortString << Port;

	//	Resolve the local address and port
	TFixedArray<char,100> AnsiPortString;
	PortString.GetAnsi( AnsiPortString );

	int Error = getaddrinfo( NULL, AnsiPortString.GetData(), &hints, &m_pAddrInfo );
    if ( Error != 0 )
	{
		//	failed
		return;
	}
}
Beispiel #6
0
/**
Create a canonical Huffman encoding table

This generates the huffman codes used by TBitOutput::HuffmanL() to write huffman encoded data.
The input is table of code lengths, as generated by Huffman::HuffmanL() and must represent a
valid huffman code.
	
@param "const TUint32 aHuffman[]" The table of code lengths as generated by Huffman::HuffmanL()
@param "TInt aNumCodes" The number of codes in the table
@param "TUint32 aEncodeTable[]" The table for the output huffman codes. This must be the same
size as the code-length table, and can safely be the same table.

@panic "USER ???" If the provided code is not a valid Huffman coding
	
@see IsValid()
@see HuffmanL()
*/
void Huffman::Encoding(const TUint32 aHuffman[],TInt aNumCodes,TUint32 aEncodeTable[])
{
	if (!IsValid(aHuffman,aNumCodes)) 
		throw E32ImageCompressionError(E32ImageCompressionError::HUFFMANINVALIDCODINGERROR);

	TFixedArray<TInt,KMaxCodeLength> lenCount;
	lenCount.Reset();

	TInt ii;
	for (ii=0;ii<aNumCodes;++ii)
	{
		TInt len=aHuffman[ii]-1;
		if (len>=0)
			++lenCount[len];
	}

	TFixedArray<TUint,KMaxCodeLength> nextCode;
	TUint code=0;
	for (ii=0;ii<KMaxCodeLength;++ii)
	{
		code<<=1;
		nextCode[ii]=code;
		code+=lenCount[ii];
	}

	for (ii=0;ii<aNumCodes;++ii)
	{
		TInt len=aHuffman[ii];
		if (len==0)
			aEncodeTable[ii]=0;
		else
		{
			aEncodeTable[ii] = (nextCode[len-1]<<(KMaxCodeLength-len))|(len<<KMaxCodeLength);
			++nextCode[len-1];
		}
	}
}
Beispiel #7
0
//------------------------------------------------------
//	create a transformed shape from a body shape
//------------------------------------------------------
TPtr<TLMaths::TShape> TLPhysics::GetShapeFromBodyShape(b2Fixture& BodyShape,const TLMaths::TTransform& Transform)
{
	//	gr: I figured the accurate/fast verison would transform by box2d. 
	//		but if we use the box2D transform, then it's out of date if the
	//		node is disabled(body frozen) and the transform[on the node] is changed as the
	//		body's transform cannot be changed until it's enabled (body is unfrozen). 

	//	gr: change this to use box2D when ENABLED and use our node transform when DISABLED.
//#define TRANSFORM_BY_BOX2D

//	b2Body& Body = *BodyShape.GetBody();
	b2Shape* pBodyShape = BodyShape.GetShape();
	
	if ( !pBodyShape )
	{
		TLDebug_Break("Fixture missing shape");
		return NULL;
	}

	if ( BodyShape.GetType() == b2_polygonShape )
	{
		b2PolygonShape& PolyShape = static_cast<b2PolygonShape&>( *pBodyShape );

#ifdef TRANSFORM_BY_BOX2D
		const b2XForm& Bodyxf = Body.GetXForm();
#endif

		//	get a list of the points
		TFixedArray<float2,100> Points;
		for ( s32 p=0;	p<PolyShape.GetVertexCount();	p++ )
		{
			#ifdef TRANSFORM_BY_BOX2D
				//	transform by bodys transform
				b2Vec2 WorldPos = b2Mul( Bodyxf, PolyShape.GetVertex(p) );

				//	gr: transform by ourtransform for scale? or instead of the box2d one? as box2d lacks scale
				float2 WorldPos2( WorldPos.x, WorldPos.y );
			#else
				//	transform by OUR transform
				float2 WorldPos2( PolyShape.GetVertex(p).x, PolyShape.GetVertex(p).y );
				Transform.Transform( WorldPos2 );
			#endif

			Points.Add( WorldPos2 );
		}

		//	create shape
		return new TLMaths::TShapePolygon2D( Points );
	}
	else if ( BodyShape.GetType() == b2_circleShape )
	{
		b2CircleShape& CircleShape = static_cast<b2CircleShape&>( *pBodyShape );

		#ifdef TRANSFORM_BY_BOX2D
			//	transform by bodys transform to put shape in world space
			const b2XForm& Bodyxf = Body.GetXForm();
			b2Vec2 WorldPos = b2Mul( Bodyxf, CircleShape.m_p );
		#else
			//	transform by OUR transform
			float2 WorldPos( CircleShape.m_p.x, CircleShape.m_p.y );
			Transform.Transform( WorldPos );
		#endif

		//	make circle
		TLMaths::TSphere2D Circle( float2( WorldPos.x, WorldPos.y ), CircleShape.m_radius );
		return new TLMaths::TShapeSphere2D( Circle );
	}
	else if ( BodyShape.GetType() == b2_edgeShape )
	{
		b2EdgeShape& EdgeShape = static_cast<b2EdgeShape&>( *pBodyShape );
	
		//	make line
		#ifdef TRANSFORM_BY_BOX2D
			//	transform by bodys transform to put shape in world space
			const b2XForm& Bodyxf = Body.GetXForm();
			b2Vec2 v1 = b2Mul( Bodyxf, EdgeShape.GetVertex1() );
			b2Vec2 v2 = b2Mul( Bodyxf, EdgeShape.GetVertex2() );
			TLMaths::TLine2D Line( float2( v1.x, v1.y ), float2( v2.x, v2.y ) );
		#else
			//	transform by OUR transform
			const b2Vec2& v1 = EdgeShape.GetVertex1();
			const b2Vec2& v2 = EdgeShape.GetVertex2();
			TLMaths::TLine2D Line( float2( v1.x, v1.y ), float2( v2.x, v2.y ) );
			Line.Transform( Transform );
		#endif
			
		return new TLMaths::TShapeLine2D( Line );
	}
	else
	{
		TLDebug_Break("Invalid body shape");
	}

	return NULL;
}
Beispiel #8
0
//--------------------------------------------------------
//	init the session
//--------------------------------------------------------
bool TLSpotify::TSession::Initialise(TRef& ErrorRef)
{
	//	init session
	if ( !m_pSession )
	{
		sp_session_config config;
		
		config.api_version = SPOTIFY_API_VERSION;
		
		// The path of the directory to store the cache. This must be specified.
		// Please read the documentation on preferred values.
		config.cache_location = "tmp";
		
		// The path of the directory to store the settings. This must be specified.
		// Please read the documentation on preferred values.
		config.settings_location = "tmp";
		
		// The key of the application. They are generated by Spotify,
		// and are specific to each application using libspotify.
		config.application_key = m_Key.GetData();
		config.application_key_size = m_Key.GetSize();
		
		// This identifies the application using some
		// free-text string [1, 255] characters.
		TFixedArray<char,255> AgentString;
		m_AgentName.GetAnsi( AgentString );
		config.user_agent = AgentString.GetData();
		
		// Register the callbacks.
		config.callbacks = &g_Callbacks;
		
		//	https://developer.spotify.com/en/libspotify/docs/group__session.html
		//	In the future, this will be renamed to sp_session_create() and will have a corresponding sp_session_release() function.
		sp_error Error = sp_session_init( &config, &m_pSession );
		
		if ( Error != SP_ERROR_OK )
		{
			//sp_error_message(error));
			ErrorRef = "Init";
			Shutdown();
			return false;
		}
		
		//	where is the session?
		if ( !m_pSession )
		{
			ErrorRef = "NoSession";
			Shutdown();
			return false;
		}
	}
	
	//	log in session
	if ( !IsLoggedIn() )
	{
		TFixedArray<char,255> UserNameString;
		m_UserName.GetAnsi( UserNameString );
		TFixedArray<char,255> PasswordString;
		m_Password.GetAnsi( PasswordString );
		
		//	attempt login
		sp_error Error = sp_session_login( m_pSession, UserNameString.GetData(), PasswordString.GetData() );
		if ( Error != SP_ERROR_OK )
		{
			ErrorRef = "Login";
			Shutdown();
			return false;
		}
		
		//	logged in! fetch the user
		m_pUser = sp_session_user( m_pSession );
		if ( !m_pUser )
		{
			ErrorRef = "NoUser";
			//	set pointer to something so we attempt to logout, even though it's not valid
			m_pUser = (sp_user*)0xdeadf00d;
			Shutdown();
			return false;
		}
	}
	
	return true;
}