?? mf_time.c
字號:
/* MF_Time.c */#include "MF_Time.h"#include "MF_Error.h"/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeNewIS"MF_Time MF_TimeNewIS(int days, int seconds) { MF_Time time = MF_NULL; time = (MF_Time) malloc (sizeof(struct TimeClass)); if(!time) return(MF_NULL); MF_TimeConstructIS(time, days, seconds); return(time);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeNewUndefined"MF_Time MF_TimeNewUndefined() { MF_Time time = MF_NULL; time = (MF_Time) malloc (sizeof(struct TimeClass)); if(!time) return(MF_NULL); MF_TimeConstructUndefined(time); return(time);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeConstructIS"int MF_TimeConstructIS(MF_Time this, int days, int seconds){ #ifdef MF_DEBUG if(MF_TIME_NEGATIVE_ATTR_IS(days, seconds)){ MF_ERRA2(MF_ERR_ARG_OUTOFRANGE, 0, "days or seconds are invalid: days = %d, seconds = %d", days, seconds); }#endif if(MF_TIME_UNDEFINED_ATTR_IS(days, seconds)){ MF_TimeConstructUndefined(this); } else{ MF_TODConstructIS(&this->tod, seconds%MF_SID); this->day = days + seconds/MF_SID; } return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeConstruct"{ this->day = days; this->tod = *tod; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeConstructUndefined"int MF_TimeConstructUndefined(MF_Time this){ this->day = MF_TIME_UNDEFINED; MF_TODConstructUndefined(&this->tod); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeCopyConstruct"int MF_TimeCopyConstruct(MF_Time this, MF_Time orig){ this->day = orig->day; this->tod = orig->tod; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeCopy"int MF_TimeCopy(MF_Time this, MF_Time orig){ #ifdef MF_DEBUG if((this->tod.type != orig->tod.type) && (this->tod.type != MF_TOD_TYPE_UNDEFINED)){ MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, "argument TOD types are different or uninitialized"); }#endif this->day = orig->day; this->tod = orig->tod; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeSetIS"int MF_TimeSetIS(MF_Time this, int days, int seconds){#ifdef MF_DEBUG if((MF_TIME_NEGATIVE_ATTR_IS(days, seconds)) || (MF_TIME_UNDEFINED_ATTR_IS(days, seconds))){ MF_ERRA2(MF_ERR_ARG_OUTOFRANGE, 0, "days or seconds are invalid or undefined: days = %d, seconds = %d", days, seconds); }#endif if(seconds < MF_SID){ MF_TODConstructIS(&this->tod, seconds); this->day = days; } else{ MF_TODConstructIS(&this->tod, seconds%MF_SID); this->day = days + seconds/MF_SID; } return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeGetIS"int MF_TimeGetIS(MF_Time this, int *days, int *seconds){ *days = this->day; *seconds = this->tod.sec; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeGetDays"int MF_TimeGetDays(MF_Time this, double *days){ *days = (double)(this->day)+(double)(this->tod.sec)/(double)MF_SID; return(MF_SUCCESS); }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeIncrementIS"int MF_TimeIncrementIS(MF_Time this, MF_Time incTime, int days, int seconds){#ifdef MF_DEBUG if((MF_TIME_NEGATIVE_ATTR_IS(days, seconds)) || (MF_TIME_UNDEFINED_ATTR_IS(days, seconds))){ MF_ERRA2(MF_ERR_ARG_OUTOFRANGE, 0, "days or seconds are invalid or undefined: days = %d, seconds = %d", days, seconds); } if((MF_TIME_INVALID_IS(*this)) || (MF_TIME_UNDEFINED_IS(*this))){ MF_ERRA2(MF_ERR_ARG_OUTOFRANGE, 0, "time is invalid or undefined: days = %d, seconds = %d", this->day, this->tod.sec); }#endif MF_TimeConstructIS(incTime, this->day + days + incTime->tod.sec/MF_SID, (this->tod.sec + seconds)%MF_SID ); return(MF_SUCCESS); }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeDiff"int MF_TimeDiff(MF_Time earlyTime, MF_Time lateTime, MF_Time diff, MF_Bool *isLater){ int day, sec; day = lateTime->day - earlyTime->day; if(day == 0){ sec = lateTime->tod.sec - earlyTime->tod.sec; *isLater = (sec>=0) ? MF_TRUE : MF_FALSE; sec = abs(sec); } else { if (day < 0){ *isLater = MF_FALSE; day *=-1; day--; sec = earlyTime->tod.sec + MF_SID - lateTime->tod.sec; } else{ if (day > 0){ *isLater = MF_TRUE; day--; sec = lateTime->tod.sec + MF_SID - earlyTime->tod.sec; } } day += sec/MF_SID; sec = sec%MF_SID; } MF_TimeSetIS(diff, day, sec); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeDecrementIS"int MF_TimeDecrementIS(MF_Time this, MF_Time decTime, int days, int seconds){ MF_TimeClass earlyTime, diff; MF_Bool isLater;#ifdef MF_DEBUG if((MF_TIME_NEGATIVE_ATTR_IS(days, seconds)) || (MF_TIME_UNDEFINED_ATTR_IS(days, seconds))){ MF_ERRA2(MF_ERR_ARG_OUTOFRANGE, 0, "days or seconds are invalid or undefined: days = %d, seconds = %d", days, seconds); }#endif MF_TimeConstructIS(&earlyTime, days, seconds); MF_TimeConstructUndefined(&diff); MF_TimeDiff(&earlyTime, this, &diff, &isLater); if(isLater == MF_FALSE){ MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, "decrement is larger than time value"); } else{ MF_TimeCopy(decTime, &diff); } return(MF_SUCCESS); }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimePrint"int MF_TimePrint(MF_Time this){ printf("Printing Time:\n"); printf("day = %d\n", this->day); printf("Printing Time internal TOD:\n"); MF_TODPrint(&this->tod); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeDelete"void MF_TimeDelete (MF_Time this){ free(this); return;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -