⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atotime.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		if(indexOfDot >= 0)		{		    pTimeBuffer[indexOfDot] = '.';		}		//this char is unexpected, so return FALSE with		//  timeValInMillisec set to whatever was read so far:		return FALSE;	    }	} //end of "ch is a non-number" condition.	else if(0L == bufIndx) //we're done with the buffer:	{	    //previous found was seconds_, so translate into ULONG:	    seconds_ = atol(pTimeBuffer);	    timeValInMillisec += seconds_*1000; //converts seconds to ms.	    break; //done with "seconds_[.milliseconds_]" part.	}    } //end "for(bufIndx=timeBufferLen-1; ...".    if(bColonWasFound) //then get the "minutes" part:    {	bColonWasFound = FALSE;	//We've got the ":seconds.msecs" part, so lets get the hours part:	for(bufIndx--; 0L<=bufIndx; bufIndx--)	{	    _CHAR ch = toupper(pTimeBuffer[bufIndx]);	    if('0' > ch  ||  '9' < ch)	    {		if(' ' == ch  ||  '.' == ch)		{		    break;		}		else if(':' == ch)		{		    bColonWasFound = TRUE;		    //previous found was seconds_, so translate into ULONG:		    // (Note: this will do atol("min:sec") which ignores		    // everything at & beyond the first non-num (":") char):		    minutes_ = atol(&pTimeBuffer[bufIndx+1L]);		    timeValInMillisec += minutes_*60000; //minutes to msec		    break; //done w/ "minutes_:seconds_[milliseconds_]" part.		}		else  //unexpected char found, so quit parsing:		{		    //Make sure pTimeBuffer is in original state:		    if(endCharWasChanged)		    {			timeBufferLen++;			pTimeBuffer[timeBufferLen-1] = savedEndChar;		    }		    if(indexOfDot >= 0)		    {			pTimeBuffer[indexOfDot] = '.';		    }		    //this char is unexpected, so return FALSE with		    //  timeValInMillisec set to whatever was read so far:		    return FALSE;		}	    } //end of "ch is a non-number" condition.	    else if(0L == bufIndx) //we're done with the buffer:	    {		//previous found was seconds_, so translate into ULONG:		minutes_ = atol(pTimeBuffer);		timeValInMillisec += minutes_*60000; //minutes to msec		break; //done w/ "minutes_:seconds_[milliseconds_]" part.	    }	} //end "for(; ...".    } //end "if(bColonWasFound) //then get the "minutes" part:".    if(bColonWasFound) //then get the "hours" part:    {	bColonWasFound = FALSE;	//We've got the ":minutes.seconds.msec" part, so lets get the hours:	for(bufIndx--; 0L<=bufIndx; bufIndx--)	{	    _CHAR ch = toupper(pTimeBuffer[bufIndx]);	    if('0' > ch  ||  '9' < ch)	    {		if(' ' == ch  ||  '.' == ch)		{		    break;		}		else if(':' == ch)		{		    bColonWasFound = TRUE;		    //previous found was minutes_, so translate into ULONG:		    // (Note: this will do atol("hrs:min:sec") which ignores		    // everything at & beyond the first non-num (":") char):		    hours_ = atol(&pTimeBuffer[bufIndx+1L]);		    timeValInMillisec += hours_*3600000; //hours to msec		    break;//done w/ "hours_:minutes_:seconds_[milliseconds_]"		}		else  //unexpected char found, so quit parsing:		{		    //Make sure pTimeBuffer is in original state:		    if(endCharWasChanged)		    {			timeBufferLen++;			pTimeBuffer[timeBufferLen-1] = savedEndChar;		    }		    if(indexOfDot >= 0)		    {			pTimeBuffer[indexOfDot] = '.';		    }		    //this char is unexpected, so return FALSE with		    //  timeValInMillisec set to whatever was read so far:		    return FALSE;		}	    } //end of "ch is a non-number" condition.	    else if(0L == bufIndx) //we're done with the buffer:	    {		//previous found was seconds_, so translate into ULONG:		hours_ = atol(pTimeBuffer);		timeValInMillisec += hours_*3600000; //hours to msec		break; //done w/ "hours_:minutes_:seconds_[milliseconds_]".	    }	} //end "for(; ...".    } //end "if(bColonWasFound) //then get the "hours" part:".    if(bColonWasFound) //then get the "days" part:    {	bColonWasFound = FALSE;	//We've got the "hours:minutes.seconds.msec" part, so lets get the days:	for(bufIndx--; 0L<=bufIndx; bufIndx--)	{	    _CHAR ch = toupper(pTimeBuffer[bufIndx]);	    if('0' > ch  ||  '9' < ch)	    {		if(' ' == ch  ||  '.' == ch)		{		    break;		}		else if(':' == ch)		{		    bColonWasFound = TRUE;		    //previous found was minutes_, so translate into ULONG:		    // (Note: this will do atol("hrs:min:sec") which ignores		    // everything at & beyond the first non-num (":") char):		    days_ = atol(&pTimeBuffer[bufIndx+1L]);		    timeValInMillisec += days_*86400000; //days to msec		    break;//done w/ "days_:hours_:minutes_:seconds_[msecs_]"		}		else  //unexpected char found, so quit parsing:		{		    //Make sure pTimeBuffer is in original state:		    if(endCharWasChanged)		    {			timeBufferLen++;			pTimeBuffer[timeBufferLen-1] = savedEndChar;		    }		    if(indexOfDot >= 0)		    {			pTimeBuffer[indexOfDot] = '.';		    }		    //this char is unexpected, so return FALSE with		    //  timeValInMillisec set to whatever was read so far:		    return FALSE;		}	    } //end of "ch is a non-number" condition.	    else if(0L == bufIndx) //we're done with the buffer:	    {		//previous found was seconds_, so translate into ULONG:		hours_ = atol(pTimeBuffer);		timeValInMillisec += hours_*86400000; //days to msec		break; //done w/ "days_:hours_:minutes_:seconds_[msec_]".	    }	} //end "for(; ...".    } //end "if(bColonWasFound ... "days" part:".    if(endCharWasChanged)    {	timeBufferLen++;	//Restore the orignial pTimeBuffer, in case end quote char was removed:	pTimeBuffer[timeBufferLen-1] = savedEndChar;    }        if(indexOfDot >= 0)    {        pTimeBuffer[indexOfDot] = '.';    }    return TRUE;} //end convertTimeStringToULONG32() function body.//If bIsLiveSource is FALSE (defaultable to TRUE), this simply// returns (A>B), else it's live & ULONG32 wrap-around can occur so...// this function tells whether or not time A is later (more recent)// than time B even with ULONG32 wrap-around, e.g., if A is 1234// and B is 4000001234, then we can guess that A is actually more// recent than B because A<B and B-A>ulAcceptableMaxTimeDiff,// so it looks like the clock wrapped around after B and before A.// Conversely, if A>B and A-B>ulAcceptableMaxTimeDiff, then it looks// like the clock wrapped around after A and before B, so A is NOT// more recent.  Returned is a BOOL that contains the answer.// NOTE: there is a concept of "infinity", defined as// TIME_INFINITY (which is 0xfffffffe), and there is a concept// of invalid time, defined as TIME_INVALID (0xffffffff).  The following// chart shows how these values are handled://	    A is:		B is:		return value will be://	    -----		-----		---------------------//	    Infinity		Infinity	FALSE//	    Infinity		Invalid		FALSE//	    Infinity		< 0xfffffffe	TRUE//	    Invalid		Infinity	TRUE//	    Invalid		Invalid		FALSE//	    Invalid		< 0xfffffffe	TRUE//	    < 0xfffffffe	Infinity	FALSE//	    < 0xfffffffe	Invalid		FALSE//	    < 0xfffffffe	< 0xfffffffe	depends; see above algorithm//// If pULTimeDiff is sent in as NULL, it remains NULL, otherwise it will// exit this function containing A minus B, regardless of which is// greater or more recent, noting that A & B are ULONG32s so the result// is always the equivalent of adding 0x100000000 to A and then// subtracting B and then truncating it by removing that 33rd bit, if// still 1:BOOLIsTimeAMoreRecentThanTimeB(	ULONG32 ulTimeA, ULONG32 ulTimeB,	//This is defaultable to TRUE (so assumes isLive if missing):	BOOL bIsLiveSource,	//This is defaultable to NULL:	ULONG32* pULTimeDiff /* OUT */,	//This is defaultable to MAX_ALLOWED_TIME_DIFFERENCE_IN_MSEC:	ULONG32 ulAcceptableMaxTimeDiff){    ULONG32 ulTimeDiff = ulTimeA-ulTimeB;    BOOL bAIsMoreRecent = FALSE;    if(pULTimeDiff)    {	*pULTimeDiff = ulTimeDiff;    }    //If we're not live, just return a straight comparison, assuming that    // the timeline for non-live begins at 0:    if(!bIsLiveSource)    {	return (ulTimeA > ulTimeB);    }    //(In)sanity check:    HX_ASSERT(ulTimeDiff == ulTimeA + (0xFFFFFFFF-ulTimeB + 1L));     if(TIME_INFINITY == ulTimeA)    {	if(TIME_INFINITY == ulTimeB  ||  TIME_INVALID == ulTimeB)	{	    bAIsMoreRecent = FALSE;	}	else	{	    bAIsMoreRecent = TRUE;	}    }    else if(TIME_INVALID == ulTimeA)    {	if(TIME_INVALID == ulTimeB)	{	    bAIsMoreRecent = FALSE;	}	else	{	    bAIsMoreRecent = TRUE;	}    }    else if(TIME_INFINITY == ulTimeB  ||  TIME_INVALID == ulTimeB)    {	bAIsMoreRecent = FALSE;    }    //else both A and B are neither infinite nor invalid:    else if(ulTimeDiff > 0L  &&  ulTimeDiff < ulAcceptableMaxTimeDiff)    {	bAIsMoreRecent = TRUE;    }    else    {        bAIsMoreRecent = FALSE;    }    return bAIsMoreRecent;}BOOLIsTimeASameOrMoreRecentThanTimeB(	ULONG32 ulTimeA, ULONG32 ulTimeB,	//This is defaultable to TRUE (so assumes isLive if missing):	BOOL bIsLiveSource,	//This is defaultable to NULL:	ULONG32* pULTimeDiff /* OUT */,	//This is defaultable to MAX_ALLOWED_TIME_DIFFERENCE_IN_MSEC:	ULONG32 ulAcceptableMaxTimeDiff){    if(ulTimeA == ulTimeB)    {	if(pULTimeDiff)	{	    *pULTimeDiff = ulTimeA-ulTimeB;	}	return TRUE;    }    else    {	return(IsTimeAMoreRecentThanTimeB(ulTimeA, ulTimeB,		bIsLiveSource,		pULTimeDiff,		ulAcceptableMaxTimeDiff) );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -