赞
踩
typedef struct
{
int refs; // reference count
int count_1fen;
int count_2fen;
int count_5fen;
} bank_data_s_type
bank_data_s_type* PiggyBank_New( )
{
bank_data_s_type *pNew = MALLOC(sizeof(bank_data_s_type));
if (pNew != NULL)
MEMSET(pNew, 0x00, sizeof(bank_data_s_type));
PiggyBank_AddRefs(pNew);
return pNew;
}
static void PiggyBank_Free(bank_data_s_type **ppData)
{
if (NULL == ppData)
return;
FREE(*ppData);
*ppData = NULL;
}
int PiggyBank_AddRefs(bank_data_s_type *pData)
{
return pData->refs++;
}
int PiggyBank_Release(bank_data_s_type *pData)
{
if (--pData->refs > 0)
return pData->refs;
PiggyBank_Free(&pData);
return 0;
}
void PiggyBank_Input(bank_data_s_type *pData, int type)
{
… …
}
void PiggyBank_Output(bank_data_s_type *pData, int type)
{
… …
}
int PiggyBank_GetTotal(bank_data_s_type *pData, int type)
{
… …
}
///
enum { COIN_TYPE_NONE, COIN_TYPE_1FEN, COIN_TYPE_2FEN, COIN_TYPE_5FEN };
typedef struct PiggyBank PiggyBank;
PiggyBank* PiggyBank_New( ); int PiggyBank_AddRefs(PiggyBank *pPiggyBank); int PiggyBank_Release(PiggyBank *pPiggyBank); void PiggyBank_Input(PiggyBank *pPiggyBank, int type); void PiggyBank_Output(PiggyBank *pPiggyBank, int type); int PiggyBank_GetTotal(PiggyBank *pPiggyBank, int type); |
储蓄罐封装形式四:PiggyBank.c |
struct PiggyBank { int refs; // reference count int count_1fen; int count_2fen; int count_5fen; };
PiggyBank* PiggyBank_New( ) { PiggyBank *pNew = MALLOC(sizeof(PiggyBank)); if (pNew != NULL) MEMSET(pNew, 0x00, sizeof(PiggyBank)); PiggyBank_AddRefs(pNew); return pNew; }
static void PiggyBank_Free(PiggyBank **ppPiggyBank) { … … }
int PiggyBank_AddRefs(PiggyBank *pPiggyBank) { … … }
int PiggyBank_Release(PiggyBank *pPiggyBank) { … … }
void PiggyBank_Input(PiggyBank *pPiggyBank, int type) { … … } void PiggyBank_Output(PiggyBank *pPiggyBank, int type) { … … }
int PiggyBank_GetTotal(PiggyBank *pPiggyBank, int type) { … … } |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。