From 669d063e75d1bdb470aa0945389967159b846913 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 15 Oct 2000 09:24:21 +0000 Subject: [PATCH] Added functions taking and returning consts git-svn-id: svn://svn.cc65.org/cc65/trunk@367 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/coll.c | 26 +++++++++++++++++++++++++- src/common/coll.h | 8 +++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/common/coll.c b/src/common/coll.c index 0b36ca463..232438d8a 100644 --- a/src/common/coll.c +++ b/src/common/coll.c @@ -96,7 +96,7 @@ void FreeCollection (Collection* C) -unsigned CollCount (Collection* C) +unsigned CollCount (const Collection* C) /* Return the number of items in the collection */ { return C->Count; @@ -158,6 +158,18 @@ void* CollAt (Collection* C, unsigned Index) +const void* CollConstAt (const Collection* C, unsigned Index) +/* Return the item at the given index */ +{ + /* Check the index */ + PRECONDITION (Index < C->Count); + + /* Return the element */ + return C->Items[Index]; +} + + + void* CollLast (Collection* C) /* Return the last item in a collection */ { @@ -170,6 +182,18 @@ void* CollLast (Collection* C) +const void* CollConstLast (const Collection* C) +/* Return the last item in a collection */ +{ + /* We must have at least one entry */ + PRECONDITION (C->Count > 0); + + /* Return the element */ + return C->Items[C->Count-1]; +} + + + void CollDelete (Collection* C, unsigned Index) /* Remove the item with the given index from the collection. This will not * free the item itself, just the pointer. All items with higher indices diff --git a/src/common/coll.h b/src/common/coll.h index c84e0bbff..ca39b1441 100644 --- a/src/common/coll.h +++ b/src/common/coll.h @@ -81,7 +81,7 @@ Collection* NewCollection (void); void FreeCollection (Collection* C); /* Free a collection */ -unsigned CollCount (Collection* C); +unsigned CollCount (const Collection* C); /* Return the number of items in the collection */ void CollInsert (Collection* C, void* Item, unsigned Index); @@ -93,9 +93,15 @@ void CollAppend (Collection* C, void* Item); void* CollAt (Collection* C, unsigned Index) attribute ((const)); /* Return the item at the given index */ +const void* CollConstAt (const Collection* C, unsigned Index) attribute ((const)); +/* Return the item at the given index */ + void* CollLast (Collection* C); /* Return the last item in a collection */ +const void* CollConstLast (const Collection* C); +/* Return the last item in a collection */ + void CollDelete (Collection* C, unsigned Index); /* Remove the item with the given index from the collection. This will not * free the item itself, just the pointer. All items with higher indices -- 2.39.5