날짜 관련 비교해서 만들어야 할 조건이 생겨 하나 만들어봤다...
기존에 있는 tm 구조체, SYSTEMTIME은 데이터만 담고 비교 자체가 없더라...
걍 하나 노가다로 operator로 만들어 봤는데... 쓸만한거 같네...
SDate() void Initialize() SDate& operator=( const SDate& rhsDate ) this->iMonth = rhsDate.iMonth; this->iDay = rhsDate.iDay; this->iHour = rhsDate.iHour; this->iMin = rhsDate.iMin; this->iSec = rhsDate.iSec; bool operator<( const SDate& rhsDate ) const if( this->iMonth > rhsDate.iMonth ) return false; if( this->iDay > rhsDate.iDay ) return false; if( this->iHour > rhsDate.iHour ) return false; if( this->iMin > rhsDate.iMin ) return false; if( this->iSec >= rhsDate.iSec ) return false; return true; bool operator>( const SDate& rhsDate ) const if( this->iMonth < rhsDate.iMonth ) return false; if( this->iDay < rhsDate.iDay ) return false; if( this->iMin < rhsDate.iMin ) return false; if( this->iSec <= rhsDate.iSec ) return false; return true; bool operator==( const SDate& rhsDate ) const return true; bool operator!=( const SDate& rhsDate ) const return false; bool operator<=( const SDate& rhsDate ) const if( this->iMonth > rhsDate.iMonth ) return false; if( this->iDay > rhsDate.iDay ) return false; if( this->iHour > rhsDate.iHour ) return false; if( this->iMin > rhsDate.iMin ) return false; if( this->iSec > rhsDate.iSec ) return false; return true; bool operator>=( const SDate& rhsDate ) const if( this->iMonth < rhsDate.iMonth ) return false; if( this->iDay < rhsDate.iDay ) return false; if( this->iHour < rhsDate.iHour ) return false; if( this->iMin < rhsDate.iMin ) return false; if( this->iSec < rhsDate.iSec ) return false; return true;
// 날짜 관련 구조체. operator 포함
struct SDate
{
int iYear;
int iMonth;
int iDay;
int iHour;
int iMin;
int iSec;
{
Initialize();
}
{
memset( this, 0x00, sizeof(SDate) );
}
{
this->iYear = rhsDate.iYear;
return (*this);
}
{
if( this->iYear > rhsDate.iYear ) return false;
if( this->iYear < rhsDate.iYear ) return true;
if( this->iMonth < rhsDate.iMonth ) return true;
if( this->iDay < rhsDate.iDay ) return true;
if( this->iHour < rhsDate.iHour ) return true;
if( this->iMin < rhsDate.iMin ) return true;
}
{
if( this->iYear < rhsDate.iYear ) return false;
if( this->iYear > rhsDate.iYear ) return true;
if( this->iMonth > rhsDate.iMonth ) return true;
if( this->iDay > rhsDate.iDay ) return true;
if( this->iHour < rhsDate.iHour ) return false
if( this->iHour > rhsDate.iHour ) return true;
if( this->iMin > rhsDate.iMin ) return true;
}
{
if( this->iYear != rhsDate.iYear ) return false;
if( this->iMonth != rhsDate.iMonth ) return false;
if( this->iDay != rhsDate.iDay ) return false;
if( this->iHour != rhsDate.iHour ) return false;
if( this->iMin != rhsDate.iMin ) return false;
if( this->iSec != rhsDate.iSec ) return false;
}
{
if( this->iYear != rhsDate.iYear ) return true;
if( this->iMonth != rhsDate.iMonth ) return true;
if( this->iDay != rhsDate.iDay ) return true;
if( this->iHour != rhsDate.iHour ) return true;
if( this->iMin != rhsDate.iMin ) return true;
if( this->iSec != rhsDate.iSec ) return true;
}
{
if( this->iYear > rhsDate.iYear ) return false;
if( this->iYear < rhsDate.iYear ) return true;
if( this->iMonth < rhsDate.iMonth ) return true;
if( this->iDay < rhsDate.iDay ) return true;
if( this->iHour < rhsDate.iHour ) return true;
if( this->iMin < rhsDate.iMin ) return true;
}
{
if( this->iYear < rhsDate.iYear ) return false;
if( this->iYear > rhsDate.iYear ) return true;
if( this->iMonth > rhsDate.iMonth ) return true;
if( this->iDay > rhsDate.iDay ) return true;
if( this->iHour > rhsDate.iHour ) return true;
if( this->iMin > rhsDate.iMin ) return true;
}
} // !SDate
'[ Programing ] > C++' 카테고리의 다른 글
new, delete 와 malloc, free 차이 (0) | 2013.09.17 |
---|---|
struct 와 class 의 차이 (0) | 2013.09.04 |
memset 메모리 초기화시 0과 0x00 차이. 그리고 그외 초기값 문제점 (0) | 2013.05.22 |
비트 필드 (bit field) (0) | 2013.05.22 |
템플릿 클래스(Template Class)에서 멤버 로 iterator 가지기 (0) | 2013.05.22 |