Join Now

Hi, I'm Paul, but you can also call me Todd and I won't get upset.

Variants and Symbian

Paul.Todd | 18 July, 2007 23:08

Been a while since I had a chance to post. What with the startup, summer holidays and work intruding.
The Champions day in Singapore was good fun, even got to meet Jukka and Anthony Pranata and
even got to do a day out around Singapore with Sammi and PushL.

During the week, I had an interesting chat with Kevin Sharp about articles and blogs, so there
will be more source and articles on the Wiki and the blog will cover more reasons about why
I did something a certain way, rather than trying to cram it into a blog entry

Recently I posted a new Wiki article which implements a Variant class for Symbian.

A lot of the problems in Symbian revolve around the ownership of objects.

In particular my implementation differed from Nokia's one in that I decided that if the user wanted to
add a string to the Variant then the Variant would own that string or data.

This differs from the approach Nokia took with their variant class in the AIW* API.

I decided amongst three possible types.

Use a T class and push the ownership issues onto the person using the class. For example if you had an
HBufC then you were responsible for the resource management which is a bit of a cop out really and not
aligned with the standard Symbian programming idioms.

Use a C class then the resource management issues are managable using Symbian Idioms, but its a pain to always
have to dereference a pointer.

Finally I decided on an R class as the halfway point between an T class and a C class. The variant can own
resources, so if you have dynamic data, then you need to put the variant  onto the cleanup stack or call Release
when you have finished with it. This also means you can treat variants more like local variables, rather than
pointers.

Internally the variant stores all the classes it supports as a union, much like the Windows implementation does,
though not as flexibly, primarily becuase Windows handles arrays so much better than Symbian. (Though Symbian
could make a much better job of it if the RArrayBase class were publically inherited!)

What else do I want to do with RVariant?
I was thinking about adding TPtr support; the problem being when it comes to serializing the data, where you do not
know the destination, so if you are going across processes or writing to disk you invalidate the pointer.

One thing is also adding in a TAny* pointer so arbitrary pointers could be put into a variant.

With both of there the role of ownership really needs to be considered and for that reason I decided against putting
any specific Variant type for pointers, at least until I get the role of ownership sorted out in my head!

One thing that might be useful is a change type function. In Windows there is a function called VariantChangeType that converts a variant from one type to another type where possible.

Comments

You must login to post comments. Login
 
 
Powered by LifeType
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZcppQ
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtopicQUqfnTopicZseriesE5f80Q
     qfnZtypeQUqfnTypeZBlogContentQ
     qfnZtypeQUqfnTypeZBlogE45ntryQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX