C-String to Descriptor Convertor

Login to reply to this topic.
Sun, 2003-11-16 03:31
Joined: 2003-11-16
Forum posts: 1
My first day on UIQ and I am *shocked* at what seems to be the heinous descriptor system. My god, who's idea was that!? Ok cell phones are predominantly literals based, but i need dynamic strings and at least something heading towards char* flexibility. (User Input!?)

Right so after racking these forums (many thanks to all those who've posted) I've come up with a 3 line converter which is probably a bad idea for some reason I'll soon encounter, but what the hell.  Evil

Code:
//================================================
// Function to convert CStrings -> TBuf16<128>
//================================================
TBuf16<128> str_c(char* input)
{
    TPtrC8 ptr((TText8*)input);
    TBuf16<128> buf;
    buf.Copy(ptr);
    return buf;
}

//================================================
// Main Test Function
//================================================
void main()
{
   char* myData = "isocube lives\n";
   console->Printf(str_c(myData));
}

I thought I'd share with you guys, to see whether I'm this is a good idea or not. Huh:

Sun, 2003-11-16 11:53
Joined: 2003-10-08
Forum posts: 19
Re: C-String to Descriptor Convertor
We fortunately have some Macros ("_L()" and "_LIT()") you should really take a look at Smiley

Regards,

Felix
Sun, 2003-11-16 12:45
Joined: 2003-05-27
Forum posts: 363
C-String to Descriptor Convertor
Consider what the "char* flexibility" has done for the UNIX and Windows platforms stability and security Smiley.

Regards,
Pawel
Sun, 2003-11-16 22:19
Anonymous (not verified)
Forum posts: 2019
C-String to Descriptor Convertor
Yeah I'm very aware of _L and _LIT (although I heard from several people that _L is frowned upon by symbian nowadays cos of the memory implications)

The point is these macros create literals encoded in your program, so unless you know what these are and how big they're gonna be at build they're useless...

If you obtain input during your codes run time - surely a literal makes no sense this context. So how *do you* handle text input or strings from files during run time?
Sun, 2003-11-16 22:53
Joined: 2003-05-27
Forum posts: 363
C-String to Descriptor Convertor
Hi,

All APIs in Symbian use descriptors for all sorts of binary and textual data, so you should use these too. See for example the class RFile - its methods take TDes8 arguments for reading and writing, hence you can use e.g. TBuf8<> in your code to store the data.

I really recommend one of the Symbian books - you will get an in-depth view of the reasoning behind the unfamiliar patterns.

Cheers,
Pawel
Sun, 2003-11-16 23:17
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 1886
C-String to Descriptor Convertor
You can also try HBufC to hold your strings and take benefit of the ReAlloc() method.

Cheers,
Eric

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

  • Login to reply to this topic.