You Are Here:

Community: Blogs

Paul Todd's Forum Nokia Blog

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.

RSSComments

You must login to post comments. Login
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxHiE2cE20IE27mE20PaulE2cE20butE20youE20canE20alsoE20callE20meE20ToddE20andE20IE20wonE27tE20getE20upsetE2eE20PaulE2eToddE20E7cE2002E20AprilE2cE202007E2023E3a18E20IE20sawE20aE20veryE20interestingE20snippedE20ofE20codeE20onE20theE20newsgroupsE20theE20otherE20dayE2eE20ItE20showedE20howE20peopleE20canE20soE20easilyE20misuseE20SymbianE20programmingE20idiomsE20ifE20theyE20areE20notE20carefulEa0Ea0Ea0E20E52ArrayE3cTIntE3eE2aE20arrayE20E3dE20newE20E28E45E4ceaveE29E20E52ArrayE3cTIntE3eE3bEa0Ea0Ea0E20arrayE2dE3eAppendE281E29E3bEa0Ea0Ea0E20arrayE2dE3eAppendE282E29E3bEa0Ea0Ea0E20deleteE20arrayE3bThisE20isE20notE20theE20originalE20classE2cE20theE20originalE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fblogsE2eforumE2enokiaE2ecomE2fblogE2fpaulE2dtoddsE2dforumE2dnokiaE2dblogE2f2007E2f04E2f02E2fuseE2dandE2dabuseE2dofE2dsymbianE2didiomsX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxPaulE20ToddE27sE20ForumE20NokiaE20BlogE20E7cE20UseE20andE20abuseE20ofE20SymbianE20idiomsX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZBlogContentQ qdcZtypeQUqfntypeZBlogE45ntryQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxHiE2cE20IE27mE20PaulE2cE20butE20youE20canE20alsoE20callE20meE20ToddE20andE20IE20wonE27tE20getE20upsetE2eE20PaulE2eToddE20E7cE2002E20AprilE2cE202007E2023E3a18E20IE20sawE20aE20veryE20interestingE20snippedE20ofE20codeE20onE20theE20newsgroupsE20theE20otherE20dayE2eE20ItE20showedE20howE20peopleE20canE20soE20easilyE20misuseE20SymbianE20programmingE20idiomsE20ifE20theyE20areE20notE20carefulEa0Ea0Ea0E20E52ArrayE3cTIntE3eE2aE20arrayE20E3dE20newE20E28E45E4ceaveE29E20E52ArrayE3cTIntE3eE3bEa0Ea0Ea0E20arrayE2dE3eAppendE281E29E3bEa0Ea0Ea0E20arrayE2dE3eAppendE282E29E3bEa0Ea0Ea0E20deleteE20arrayE3bThisE20isE20notE20theE20originalE20classE2cE20theE20originalE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fblogsE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZcppQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f60QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f80QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZBlogContentQ qfnZtypeQUqfntypeZBlogE45ntryQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZupdatedQDx2007E2d06E2d06X qfnZuserE5ftagQSxs60X qfnZuserE5ftagQSxseriesE2d80X qfnZuserE5ftagQSxsymbianE2dcE2bE2bX qmarsZdescriptionQSxHiE2cE20IE27mE20PaulE2cE20butE20youE20canE20alsoE20callE20meE20ToddE20andE20IE20wonE27tE20getE20upsetE2eE20PaulE2eToddE20E7cE2002E20AprilE2cE202007E2023E3a18E20IE20sawE20aE20veryE20interestingE20snippedE20ofE20codeE20onE20theE20newsgroupsE20theE20otherE20dayE2eE20ItE20showedE20howE20peopleE20canE20soE20easilyE20misuseE20SymbianE20programmingE20idiomsE20ifE20theyE20areE20notE20carefulEa0Ea0Ea0E20E52ArrayE3cTIntE3eE2aE20arrayE20E3dE20newE20E28E45E4ceaveE29E20E52ArrayE3cTIntE3eE3bEa0Ea0Ea0E20arrayE2dE3eAppendE281E29E3bEa0Ea0Ea0E20arrayE2dE3eAppendE282E29E3bEa0Ea0Ea0E20deleteE20arrayE3bThisE20isE20notE20theE20originalE20classE2cE20theE20originalE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZBlogContentQ qrdfZtypeQUqfntypeZBlogE45ntryQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ