Naming convention for function that leaves 2 or more objects on the cleanup stack
Hi!
Does anybody know the naming rule for the function that leaves 2 or more objects on the cleanup stack?
For example, I need a function that will create 2 HBufC objects and leaves them on the cleanup stack. Would it be right to name it like this:
[code]
void GiveSomeStuffLC2(HBufC*& aBuf1, HBufC*& aBuf2)
{
aBuf1 = HBufC::NewLC(0);
aBuf2 = HBUfC::NewLC(0);
}[/code]
Re: Naming convention for function that leaves 2 or more objects on the cleanup stack
[QUOTE='» Symbian OS guide » Essential idioms » Naming conventions']
An allocation or construction function which places data on the cleanup stack ends with ...LC()[/QUOTE]So it is not about how much data you leave on the stack but the fact that you are leaving the data there. However you need to make sure to document the method properly...
Re: Naming convention for function that leaves 2 or more objects on the cleanup stack
But Ii think it can be little confusing, if I will place this into library and end the name with single 'LC'.
Thanks anyway!
Re: Naming convention for function that leaves 2 or more objects on the cleanup stack
The Best Way:
void GiveSomeStuffLC2(TDesC& aBuf1, TDesC& aBuf2)
{
HBufC* Buf1 = HBufC::NewL(aBuf1.Length());
HBufC* Buf2 = HBUfC::NewL(aBuf1.Length());
//--------------------->
// Do what ever her
//---------------------->
delete Buf1;
delete Buf2;
}
Good lack.
Re: Naming convention for function that leaves 2 or more objects on the cleanup stack
Hi mubx2000,
The question was about naming convention, not about the way of code organizing. I'm sure to use the function that leaves 2 objects on the cleanup stack.
Thanks,
Sergey
Re: Naming convention for function that leaves 2 or more objects on the cleanup stack
[QUOTE=mubx2000]The Best Way:
void GiveSomeStuffLC2(TDesC& aBuf1, TDesC& aBuf2)
{
HBufC* Buf1 = HBufC::NewL(aBuf1.Length());
HBufC* Buf2 = HBUfC::NewL(aBuf1.Length());
//--------------------->
// Do what ever her
//---------------------->
delete Buf1;
delete Buf2;
}
Good lack.[/QUOTE]Yeah, this code really lacks of good parts. Possible leak of Buf1 and improper naming - not a single object pushed on the Cleanup Stack.
Re: Naming convention for function that leaves 2 or more objects on the cleanup stack
[QUOTE=payu.sergey]I'm sure to use the function that leaves 2 objects on the cleanup stack.[/QUOTE]Although having CBlah *&aBlah parameters is perfectly valid, C++ methods have one return value in general.
Anyway, the Symbian source uses LCC (or even LCCC) in this case.
Re: Naming convention for function that leaves 2 or more objects on the cleanup stack
[QUOTE=wizard_hu_]Anyway, the Symbian source uses LCC (or even LCCC) in this case.[/QUOTE]
Let's hope that nobody has the idea of implementing such a method with a variable argument list. How would that one look like ? :)
Leaving the joke aside, LC should be enough as long as you document the method. It tells that the method can leave and that if not some objects are left on the stack. As always it is up to the caller to know which objects and how many they are.