Skip to content

Commit a919c92

Browse files
committed
new method for cleanup
1 parent 661c3b2 commit a919c92

6 files changed

Lines changed: 37 additions & 33 deletions

File tree

include/billboard.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
#include "raylib.h"
66

77
typedef struct billboard* Billboard;
8+
typedef const struct billboard* CBillboard;
89

910
Billboard BillboardCreate(Texture sprite, int posX, int posY, int size);
1011
void BillboardDestroy(Billboard* bp);
1112

12-
Texture BillboardGetTexture(const struct billboard* bb);
13+
Texture BillboardGetTexture(CBillboard bb);
1314

14-
int BillboardGetX(const struct billboard* bb);
15-
int BillboardGetY(const struct billboard* bb);
16-
int BillboardGetSize(const struct billboard* bb);
15+
int BillboardGetX(CBillboard bb);
16+
int BillboardGetY(CBillboard bb);
17+
int BillboardGetSize(CBillboard bb);
1718

1819
void BillboardSetX(Billboard bb, int posX);
1920
void BillboardSetY(Billboard bb, int posY);

include/hashmap.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#define HASHMAP_H
55

66
typedef struct hashmap* HashMap;
7+
typedef const struct hashmap* CHashMap;
78
typedef struct hashmapi* HashMapIterator;
9+
typedef const struct hashmapi* CHashMapIterator;
810

911

1012
// Creates a HashMap (hashFunc is the function used fir hashing the key)
@@ -15,22 +17,22 @@ void HashMapDestroy(HashMap* mapp);
1517

1618

1719
// Puts an item in the HashMap, returning whether or not it was successful
18-
bool HashMapPut(HashMap map, void* key, void* value);
20+
bool HashMapPut(CHashMap map, void* key, void* value);
1921

2022
// Returns an item from the HashMap
21-
void* HashMapGet(const struct hashmap* map, void* key);
23+
void* HashMapGet(CHashMap map, void* key);
2224

2325
// Returns whether or not the HashMap contains a value for the given key
24-
bool HashMapContains(const struct hashmap* map, void* key);
26+
bool HashMapContains(CHashMap map, void* key);
2527

2628
// Removes an item from the HashMap, returning whether or not it was successful
27-
bool HashMapRemove(const struct hashmap* map, void* key);
29+
bool HashMapRemove(CHashMap map, void* key);
2830

2931
// Removes an item from the HashMap, returning it
30-
void* HashMapPop(const struct hashmap* map, void* key);
32+
void* HashMapPop(CHashMap map, void* key);
3133

3234
// Prints the map in usual format. printFunc (optional) prints the item correctly)
33-
void HashMapPrint(const struct hashmap* map, bool newline, void (*printFunc) (void* key, void* value));
35+
void HashMapPrint(CHashMap map, bool newline, void (*printFunc) (void* key, void* value));
3436

3537

3638
// Iterating functions
@@ -44,13 +46,13 @@ void HashMapIterDestroy(HashMapIterator* iterp);
4446
bool HashMapIterGoToNext(HashMapIterator iter);
4547

4648
// Returns whether or not its safe to operate in the current element
47-
bool HashMapIterCanOperate(const struct hashmapi* iter);
49+
bool HashMapIterCanOperate(CHashMapIterator iter);
4850

4951
// Returns the current key the iterator is in
50-
void* HashMapIterGetCurrentKey(HashMapIterator iter);
52+
void* HashMapIterGetCurrentKey(CHashMapIterator iter);
5153

5254
// Returns the current value the iterator is in
53-
void* HashMapIterGetCurrentValue(HashMapIterator iter);
55+
void* HashMapIterGetCurrentValue(CHashMapIterator iter);
5456

5557

5658
#endif

include/list.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
// List type. Pointers stored inside the list are not freed when removing them or destroying the list.
77
typedef struct list* List;
8+
typedef const struct list* CList;
89

910
// Creates a List. printFunc (optional) prints an item from the list)
1011
List ListCreate(void (*printFunc) (void* item));
@@ -62,15 +63,15 @@ void ListMoveToEnd(List list);
6263
void* ListGetCurrent(List list);
6364

6465
// Returns whether or not the list has a next element
65-
bool ListHasNext(const struct list* list);
66+
bool ListHasNext(CList list);
6667

6768
// Returns whether or not its safe to operate in the current list node
68-
bool ListCanOperate(const struct list* list);
69+
bool ListCanOperate(CList list);
6970

7071
// Prints the list in the usual format. printFunc (optional) prints the item correctly)
7172
void ListPrint(List list, bool newline, void (*printFunc) (void* item));
7273

7374
// Returns the size of the list
74-
int ListGetSize(const struct list* list);
75+
int ListGetSize(CList list);
7576

7677
#endif

src/billboard.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ void BillboardDestroy(Billboard* bbp) {
3434
*bbp = NULL;
3535
}
3636

37-
Texture BillboardGetTexture(const struct billboard* bb) {
37+
Texture BillboardGetTexture(CBillboard bb) {
3838
assert(bb != NULL);
3939

4040
return bb->sprite;
4141
}
4242

43-
int BillboardGetX(const struct billboard* bb) {
43+
int BillboardGetX(CBillboard bb) {
4444
assert(bb != NULL);
4545

4646
return bb->posX;
4747
}
4848

49-
int BillboardGetY(const struct billboard* bb) {
49+
int BillboardGetY(CBillboard bb) {
5050
assert(bb != NULL);
5151

5252
return bb->posY;
5353
}
5454

55-
int BillboardGetSize(const struct billboard* bb) {
55+
int BillboardGetSize(CBillboard bb) {
5656
assert(bb != NULL);
5757

5858
return bb->size;

src/hashmap.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void HashMapDestroy(HashMap* mapp) {
7474

7575

7676
// Puts an item in the HashMap, returning whether or not it was successful
77-
bool HashMapPut(HashMap map, void* key, void* value) {
77+
bool HashMapPut(CHashMap map, void* key, void* value) {
7878
assert(map != NULL);
7979
assert(key != NULL);
8080

@@ -118,7 +118,7 @@ bool HashMapPut(HashMap map, void* key, void* value) {
118118
}
119119

120120
// Returns an item from the HashMap
121-
void* HashMapGet(const struct hashmap* map, void* key) {
121+
void* HashMapGet(CHashMap map, void* key) {
122122
assert(map != NULL);
123123
assert(key != NULL);
124124

@@ -148,14 +148,14 @@ void* HashMapGet(const struct hashmap* map, void* key) {
148148
}
149149

150150
// Returns whether or not the HashMap contains a value for the given key
151-
bool HashMapContains(const struct hashmap* map, void* key) {
151+
bool HashMapContains(CHashMap map, void* key) {
152152
assert(map != NULL);
153153

154154
return HashMapGet(map, key) != NULL;
155155
}
156156

157157
// Removes an item from the HashMap, returning whether or not it was successful
158-
bool HashMapRemove(const struct hashmap* map, void* key) {
158+
bool HashMapRemove(CHashMap map, void* key) {
159159
assert(map != NULL);
160160

161161
// Get list index
@@ -187,7 +187,7 @@ bool HashMapRemove(const struct hashmap* map, void* key) {
187187
}
188188

189189
// Removes an item from the HashMap, returning it
190-
void* HashMapPop(const struct hashmap* map, void* key) {
190+
void* HashMapPop(CHashMap map, void* key) {
191191
assert(map != NULL);
192192

193193
// Get list index
@@ -219,7 +219,7 @@ void* HashMapPop(const struct hashmap* map, void* key) {
219219
}
220220

221221
// Prints the map in usual format. printFunc (optional) prints the item correctly)
222-
void HashMapPrint(const struct hashmap* map, bool newline, void (*printFunc) (void* key, void* value)) {
222+
void HashMapPrint(CHashMap map, bool newline, void (*printFunc) (void* key, void* value)) {
223223
assert(map != NULL);
224224

225225
if (printFunc == NULL) {
@@ -291,7 +291,7 @@ bool HashMapIterGoToNext(HashMapIterator iter) {
291291
return false;
292292
}
293293

294-
List currentList = iter->map->values[iter->currIdxList];
294+
CList currentList = iter->map->values[iter->currIdxList];
295295

296296
// If is at end of current list, go to next
297297
if (++iter->currIdxKey >= ListGetSize(currentList)) {
@@ -304,7 +304,7 @@ bool HashMapIterGoToNext(HashMapIterator iter) {
304304
}
305305

306306
// Returns whether or not its safe to operate in the current element
307-
bool HashMapIterCanOperate(const struct hashmapi* iter) {
307+
bool HashMapIterCanOperate(CHashMapIterator iter) {
308308
assert(iter != NULL);
309309
assert(iter->map != NULL);
310310

@@ -313,15 +313,15 @@ bool HashMapIterCanOperate(const struct hashmapi* iter) {
313313
}
314314

315315
// Returns the current key the iterator is in
316-
void* HashMapIterGetCurrentKey(HashMapIterator iter) {
316+
void* HashMapIterGetCurrentKey(CHashMapIterator iter) {
317317
assert(iter != NULL);
318318
assert(iter->map != NULL);
319319

320320
return HashMapIterCanOperate(iter) ? ((HashMapElement) ListGet(iter->map->values[iter->currIdxList], iter->currIdxKey))->key : NULL;
321321
}
322322

323323
// Returns the current value the iterator is in
324-
void* HashMapIterGetCurrentValue(HashMapIterator iter) {
324+
void* HashMapIterGetCurrentValue(CHashMapIterator iter) {
325325
assert(iter != NULL);
326326
assert(iter->map != NULL);
327327

src/linkedlist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,14 @@ void* ListGetCurrent(List list) {
398398
}
399399

400400
// Returns whether or not the list has a next element
401-
bool ListHasNext(const struct list* list) {
401+
bool ListHasNext(CList list) {
402402
assert(list != NULL);
403403

404404
return list->currentNode->nextNode != NULL;
405405
}
406406

407407
// Returns whether or not its safe to operate in the current list node
408-
bool ListCanOperate(const struct list* list) {
408+
bool ListCanOperate(CList list) {
409409
assert(list != NULL);
410410

411411
return list->currentNode != NULL;
@@ -449,7 +449,7 @@ void ListPrint(List list, bool newline, void (*printFunc) (void* item)) {
449449
}
450450
}
451451

452-
int ListGetSize(const struct list* list) {
452+
int ListGetSize(CList list) {
453453
assert(list != NULL);
454454

455455
return list->size;

0 commit comments

Comments
 (0)