diff options
author | joye <joye> | 2014-07-09 18:38:16 (GMT) |
---|---|---|
committer | joye <joye> | 2014-07-09 18:38:16 (GMT) |
commit | f96f755cc828847cdbbc76daec69c320f567b5ce (patch) | |
tree | 1d17e10ee00fcb883321a40dc23348f774468b09 /src | |
parent | 938aacc356d7a55e0bc43182f313caf435dac3a1 (diff) | |
download | blt-f96f755cc828847cdbbc76daec69c320f567b5ce.zip blt-f96f755cc828847cdbbc76daec69c320f567b5ce.tar.gz blt-f96f755cc828847cdbbc76daec69c320f567b5ce.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r-- | src/bltChain.C | 57 | ||||
-rw-r--r-- | src/bltChain.h | 44 |
2 files changed, 52 insertions, 49 deletions
diff --git a/src/bltChain.C b/src/bltChain.C index b266e42..ddcd367 100644 --- a/src/bltChain.C +++ b/src/bltChain.C @@ -38,44 +38,46 @@ using namespace Blt; (((size_t)a + (sizeof(double) - 1)) & (~(sizeof(double) - 1))) #endif -Chain Blt::Chain_Create(void) +Chain* Blt::Chain_Create(void) { - Chain chainPtr =(Chain)malloc(sizeof(_Chain)); + Chain* chainPtr =(Chain*)malloc(sizeof(Chain)); if (chainPtr) Chain_Init(chainPtr); + return chainPtr; } -ChainLink Blt::Chain_AllocLink(size_t extraSize) +ChainLink* Blt::Chain_AllocLink(size_t extraSize) { - size_t linkSize = ALIGN(sizeof(_ChainLink)); - ChainLink linkPtr = (ChainLink)calloc(1, linkSize + extraSize); + size_t linkSize = ALIGN(sizeof(ChainLink)); + ChainLink* linkPtr = (ChainLink*)calloc(1, linkSize + extraSize); if (extraSize > 0) { // Point clientData at the memory beyond the normal structure linkPtr->clientData = (ClientData)((char *)linkPtr + linkSize); } + return linkPtr; } -void Blt::Chain_InitLink(ChainLink linkPtr) +void Blt::Chain_InitLink(ChainLink* linkPtr) { linkPtr->clientData = NULL; linkPtr->next = linkPtr->prev = NULL; } -ChainLink Blt::Chain_NewLink(void) +ChainLink* Blt::Chain_NewLink(void) { - ChainLink linkPtr = (ChainLink)malloc(sizeof(_ChainLink)); + ChainLink* linkPtr = (ChainLink*)malloc(sizeof(ChainLink)); linkPtr->clientData = NULL; linkPtr->next = linkPtr->prev = NULL; return linkPtr; } -void Blt::Chain_Reset(Chain chainPtr) +void Blt::Chain_Reset(Chain* chainPtr) { if (chainPtr) { - ChainLink oldPtr; - ChainLink linkPtr = chainPtr->head; + ChainLink* oldPtr; + ChainLink* linkPtr = chainPtr->head; while (linkPtr) { oldPtr = linkPtr; @@ -86,7 +88,7 @@ void Blt::Chain_Reset(Chain chainPtr) } } -void Blt::Chain_Destroy(Chain chainPtr) +void Blt::Chain_Destroy(Chain* chainPtr) { if (chainPtr) { Chain_Reset(chainPtr); @@ -95,13 +97,14 @@ void Blt::Chain_Destroy(Chain chainPtr) } } -void Blt::Chain_Init(Chain chainPtr) +void Blt::Chain_Init(Chain* chainPtr) { chainPtr->nLinks = 0; chainPtr->head = chainPtr->tail = NULL; } -void Blt::Chain_LinkAfter(Chain chainPtr, ChainLink linkPtr, ChainLink afterPtr) +void Blt::Chain_LinkAfter(Chain* chainPtr, ChainLink* linkPtr, + ChainLink* afterPtr) { if (chainPtr->head == NULL) chainPtr->tail = chainPtr->head = linkPtr; @@ -126,8 +129,8 @@ void Blt::Chain_LinkAfter(Chain chainPtr, ChainLink linkPtr, ChainLink afterPtr) chainPtr->nLinks++; } -void Blt::Chain_LinkBefore(Chain chainPtr, ChainLink linkPtr, - ChainLink beforePtr) +void Blt::Chain_LinkBefore(Chain* chainPtr, ChainLink* linkPtr, + ChainLink* beforePtr) { if (chainPtr->head == NULL) chainPtr->tail = chainPtr->head = linkPtr; @@ -152,7 +155,7 @@ void Blt::Chain_LinkBefore(Chain chainPtr, ChainLink linkPtr, chainPtr->nLinks++; } -void Blt::Chain_UnlinkLink(Chain chainPtr, ChainLink linkPtr) +void Blt::Chain_UnlinkLink(Chain* chainPtr, ChainLink* linkPtr) { // Indicates if the link is actually remove from the chain int unlinked; @@ -180,35 +183,35 @@ void Blt::Chain_UnlinkLink(Chain chainPtr, ChainLink linkPtr) linkPtr->prev = linkPtr->next = NULL; } -void Blt::Chain_DeleteLink(Chain chain, ChainLink link) +void Blt::Chain_DeleteLink(Chain* chain, ChainLink* link) { Chain_UnlinkLink(chain, link); free(link); link = NULL; } -ChainLink Blt::Chain_Append(Chain chain, ClientData clientData) +ChainLink* Blt::Chain_Append(Chain* chain, ClientData clientData) { - ChainLink link = Chain_NewLink(); - Chain_LinkAfter(chain, link, (ChainLink)NULL); + ChainLink* link = Chain_NewLink(); + Chain_LinkAfter(chain, link, NULL); Chain_SetValue(link, clientData); return link; } -ChainLink Blt::Chain_Prepend(Chain chain, ClientData clientData) +ChainLink* Blt::Chain_Prepend(Chain* chain, ClientData clientData) { - ChainLink link = Chain_NewLink(); - Chain_LinkBefore(chain, link, (ChainLink)NULL); + ChainLink* link = Chain_NewLink(); + Chain_LinkBefore(chain, link, NULL); Chain_SetValue(link, clientData); return link; } -int Blt::Chain_IsBefore(ChainLink firstPtr, ChainLink lastPtr) +int Blt::Chain_IsBefore(ChainLink* firstPtr, ChainLink* lastPtr) { - for (ChainLink linkPtr = firstPtr; linkPtr; linkPtr = linkPtr->next) { + for (ChainLink* linkPtr = firstPtr; linkPtr; linkPtr = linkPtr->next) if (linkPtr == lastPtr) return 1; - } + return 0; } diff --git a/src/bltChain.h b/src/bltChain.h index b997baa..8348f9a 100644 --- a/src/bltChain.h +++ b/src/bltChain.h @@ -42,40 +42,40 @@ #define Chain_GetValue(l) ((l)->clientData) #define Chain_FirstValue(c) (((c)->head == NULL) ? NULL : (c)->head->clientData) #define Chain_SetValue(l, v) ((l)->clientData = (ClientData)(v)) -#define Chain_AppendLink(c, l) (Chain_LinkAfter((c), (l), (ChainLink)NULL)) -#define Chain_PrependLink(c, l) (Chain_LinkBefore((c), (l), (ChainLink)NULL)) +#define Chain_AppendLink(c, l) (Chain_LinkAfter((c), (l), (ChainLink*)NULL)) +#define Chain_PrependLink(c, l) (Chain_LinkBefore((c), (l), (ChainLink*)NULL)) namespace Blt { - typedef struct _Chain* Chain; - typedef struct _ChainLink* ChainLink; + typedef struct _Chain Chain; + typedef struct _ChainLink ChainLink; struct _ChainLink { - ChainLink prev; /* Link to the previous link */ - ChainLink next; /* Link to the next link */ + ChainLink* prev; /* Link to the previous link */ + ChainLink* next; /* Link to the next link */ ClientData clientData; /* Pointer to the data object */ }; struct _Chain { - ChainLink head; /* Pointer to first element in chain */ - ChainLink tail; /* Pointer to last element in chain */ + ChainLink* head; /* Pointer to first element in chain */ + ChainLink* tail; /* Pointer to last element in chain */ long nLinks; /* Number of elements in chain */ }; - extern Chain Chain_Create(void); - extern ChainLink Chain_AllocLink(size_t size); - extern void Chain_InitLink(ChainLink link); - extern void Chain_Init(Chain chain); - extern ChainLink Chain_NewLink(void); - extern void Chain_Reset(Chain chain); - extern void Chain_Destroy(Chain chain); - extern void Chain_LinkAfter(Chain chain, ChainLink link, ChainLink after); - extern void Chain_LinkBefore(Chain chain, ChainLink link, ChainLink before); - extern void Chain_UnlinkLink(Chain chain, ChainLink link); - extern void Chain_DeleteLink(Chain chain, ChainLink link); - extern ChainLink Chain_Append(Chain chain, ClientData clientData); - extern ChainLink Chain_Prepend(Chain chain, ClientData clientData); - extern int Chain_IsBefore(ChainLink first, ChainLink last); + extern Chain* Chain_Create(void); + extern ChainLink* Chain_AllocLink(size_t size); + extern void Chain_InitLink(ChainLink* link); + extern void Chain_Init(Chain* chain); + extern ChainLink* Chain_NewLink(void); + extern void Chain_Reset(Chain* chain); + extern void Chain_Destroy(Chain* chain); + extern void Chain_LinkAfter(Chain* chain, ChainLink* link, ChainLink* after); + extern void Chain_LinkBefore(Chain* chain, ChainLink* link,ChainLink* before); + extern void Chain_UnlinkLink(Chain* chain, ChainLink* link); + extern void Chain_DeleteLink(Chain* chain, ChainLink* link); + extern ChainLink* Chain_Append(Chain* chain, ClientData clientData); + extern ChainLink* Chain_Prepend(Chain* chain, ClientData clientData); + extern int Chain_IsBefore(ChainLink* first, ChainLink* last); }; #endif /* _BLT_CHAIN_H */ |