@Draugnar - but there are 5 different conditions to test for, that would mean 5 different methods, and in the original you needed the local data, so that means passing a bunch of parameters to each method - still not very clean. Especially considering the "//do stuff" might have just been one more API call using the results from above, then comparing it to see if you can continue.
I see your point, but in the cases I was refering to, it was cleaner to just nest the ifs like the logic implied anyway.
Here's one example that just uses M$ APIs to convert from UTC time to LocalTime and the conditions are the success of the APIs (ignore the dots, I put them in there because this forum strips out spaces - I realize this wont compie as is ;-)
/* *** OLD WAY *** */
bool UTCToLocalTime1(const COleDateTime& dtUTC, COleDateTime& dtLocal)
{
....SYSTEMTIME sysTimeLocal, sysTimeUTC;
....FILETIME fileTimeLocal, fileTimeUTC;
....bool.... bRetVal = false;
....do // This is not a loop.
....{
........if (false == dtUTC.GetAsSystemTime(sysTimeUTC))
........{
............break;
........}
........
........if (false == SystemTimeToFileTime(&sysTimeUTC, &fileTimeUTC))
........{
............break;
........}
........if (false == FileTimeToLocalFileTime(&fileTimeUTC, &fileTimeLocal))
........{
............break;
........}
........if (false == FileTimeToSystemTime(&fileTimeLocal, &sysTimeLocal))
........{
............break;
........}
........dtLocal = sysTimeLocal;
........bRetVal = true;
....}
....while(false);
....return bRetVal;
}
/* *** NEW WAY *** */
bool UTCToLocalTime2(const COleDateTime& dtUTC, COleDateTime& dtLocal)
{
....SYSTEMTIME sysTimeLocal, sysTimeUTC;
....FILETIME fileTimeLocal, fileTimeUTC;
....bool.... bRetVal = false;
....if (dtUTC.GetAsSystemTime(sysTimeUTC)) //Get System time
........if (SystemTimeToFileTime(&sysTimeUTC, &fileTimeUTC)) //Convert to File Time
............if (FileTimeToLocalFileTime(&fileTimeUTC, &fileTimeLocal)) //This is the one that actually performs the UTC conversion
................if (FileTimeToSystemTime(&fileTimeLocal, &sysTimeLocal)) //Convert back to system time
................{
....................bRetVal = true;
....................dtLocal = sysTimeLocal;
................}
....return bRetVal;
}
There might be a simpler way to accomplish the task, that's not the point. The point is, that in this case there was nothing really to extract into a seperate function that would have simplified the code at all.