A question of indentation!
-
Len Holgate wrote: The indentation isn't the problem, you're just doing too much in one function The problem is that each of these functions require something from the previous function. For example if fn_1 allocs something, then fn_2 uses that and allocs something else used by fn_3 and so on. On failure at any point I also have to call the respective deallocing PGP functions in reverse order Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
Nish - Native CPian wrote: The problem is that each of these functions require something from the previous function. For example if fn_1 allocs something, then fn_2 uses that and allocs something else used by fn_3 and so on. On failure at any point I also have to call the respective deallocing PGP functions in reverse order That's the point. If you need to allocate a resource you do so in the constructor, you then use the resource, perhaps to allocate another resource, and release it in the destructor, hence you end up with code like:
CUsesPGP usesPGP(initStuff);
CPGPProvider provider("MyProvider");
CPGPKey key provider.GetKey("Blah");
CPGPData data(pData, length);
data.Encrypt(key);
The c++ class construction order makes sure that the resources are released correctly even if an exception is thrown. Methods throw exceptions so that the user cant ignore errors by default. The code is pretty much self documenting so you dont need huge comment blocks that get out of date. Oh, and it fixes your indentation problem... Len Holgate www.jetbyte.com The right code, right now.