C-String to Descriptor Convertor
| Sun, 2003-11-16 03:31 | |
|
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. 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. : |
|






:
Forum posts: 19
Regards,
Felix
Forum posts: 363
Regards,
Pawel
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?
Forum posts: 363
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
Forum posts: 1886
Cheers,
Eric
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant