📄 mf_tod.c
字号:
/* MF_TOD.c */#include "MF_TOD.h"/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TODConstructIS"int MF_TODConstructIS(MF_TOD this, int seconds){#ifdef MF_DEBUG if((seconds<0 || seconds >= MF_SID) && (seconds != MF_TIME_UNDEFINED)){ MF_ERRA1(MF_ERR_ARG_OUTOFRANGE, 0, "sec = %d", seconds); }#endif this->type = MF_TOD_INT_SEC; this->sec = seconds; this->msec = MF_TIME_UNDEFINED; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TODConstructUndefined"int MF_TODConstructUndefined(MF_TOD this){ this->type = MF_TOD_TYPE_UNDEFINED; this->sec = MF_TIME_UNDEFINED; this->msec = MF_TIME_UNDEFINED; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TODIncrement"int MF_TODIncrement(MF_TOD this, MF_TOD inc, MF_TOD resultTOD, int *resultDays){ int sec;#ifdef MF_DEBUG if(this->type != inc->type){ MF_ERRA(MF_ERR_ARG_OUTOFRANGE,0 ,"input times of day are different types"); }#endif if(this->type == MF_TOD_INT_SEC){ resultTOD->type = MF_TOD_INT_SEC; sec = this->sec + inc->sec; resultTOD->sec = sec%MF_SID; *resultDays = sec/MF_SID; } return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TODDecrement"int MF_TODDecrement(MF_TOD this, MF_TOD dec, MF_TOD resultTOD, int *resultDays){#ifdef MF_DEBUG if(this->type != dec->type){ MF_ERRA(MF_ERR_ARG_OUTOFRANGE,0 ,"input times of day are different types"); }#endif if(this->type == MF_TOD_INT_SEC){ if(this->sec >= dec->sec){ resultTOD->sec = this->sec - dec->sec; *resultDays = 0; } else{ resultTOD->sec = (this->sec + MF_SID) - dec->sec; *resultDays = 1; } } return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TODIsLater"int MF_TODIsLater(MF_TOD earlyTOD, MF_TOD lateTOD, MF_Bool *isLater){#ifdef MF_DEBUG if(earlyTOD->type != lateTOD->type){ MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, "input times of day are different types"); }#endif switch(earlyTOD->type){ case MF_TOD_INT_SEC: if(lateTOD->sec > earlyTOD->sec){ *isLater=MF_TRUE; } else{ *isLater=MF_FALSE; } break; default: MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, "time of day type is not supported by this method"); } return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TODPrint"int MF_TODPrint(MF_TOD this){ char str[32]; switch(this->type){ case MF_TOD_TYPE_UNDEFINED: strcpy(str, "MF_TOD_TYPE_UNDEFINED"); break; case MF_TOD_INT_SEC: strcpy(str, "MF_TOD_INT_SEC"); break; case MF_TOD_INT_MSEC: strcpy(str, "MF_TOD_INT_MSEC"); break; default: strcpy(str, "UNRECOGNIZED TOD TYPE"); } printf("Printing TOD:\n"); printf("type = %s\n", str); printf("seconds = %d\n", this->sec); printf("mseconds = %d\n", this->msec); return(MF_SUCCESS);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -