]> git.sur5r.net Git - cc65/blobdiff - src/common/coll.h
Merge remote-tracking branch 'upstream/master' into a5200
[cc65] / src / common / coll.h
index 503b9bbdd09c2709023de1d1c9be2895a514fa64..b0a64557ddafd9bc8c5b873f4e3385c7857bca0b 100644 (file)
@@ -1,12 +1,12 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 coll.h                                   */
+/*                                  coll.h                                   */
 /*                                                                           */
-/*                       Collection (dynamic array)                         */
+/*                        Collection (dynamic array)                         */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2010, Ullrich von Bassewitz                                      */
+/* (C) 2000-2011, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -46,7 +46,7 @@
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
 /* An array of pointers that grows if needed */
 typedef struct Collection Collection;
 struct Collection {
-    unsigned                   Count;          /* Number of items in the list */
-    unsigned                   Size;           /* Size of allocated array */
-    void**             Items;          /* Array with dynamic size */
+    unsigned            Count;          /* Number of items in the list */
+    unsigned            Size;           /* Size of allocated array */
+    void**              Items;          /* Array with dynamic size */
 };
 
 /* An empty collection */
 extern const Collection EmptyCollection;
 
 /* Initializer for static collections */
-#define STATIC_COLLECTION_INITIALIZER  { 0, 0, 0 }
+#define STATIC_COLLECTION_INITIALIZER   { 0, 0, 0 }
 
 /* Initializer for auto collections */
 #define AUTO_COLLECTION_INITIALIZER     EmptyCollection
@@ -71,7 +71,7 @@ extern const Collection EmptyCollection;
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -103,7 +103,7 @@ INLINE unsigned CollCount (const Collection* C)
     return C->Count;
 }
 #else
-#  define CollCount(C) (C)->Count
+#  define CollCount(C)  (C)->Count
 #endif
 
 void CollInsert (Collection* C, void* Item, unsigned Index);
@@ -122,7 +122,7 @@ void CollAppend (Collection* C, void* Item);
 #endif
 
 #if defined(HAVE_INLINE)
-INLINE void* CollAt (Collection* C, unsigned Index)
+INLINE void* CollAt (const Collection* C, unsigned Index)
 /* Return the item at the given index */
 {
     /* Check the index */
@@ -132,19 +132,19 @@ INLINE void* CollAt (Collection* C, unsigned Index)
     return C->Items[Index];
 }
 #else
-void* CollAt (Collection* C, unsigned Index);
+void* CollAt (const Collection* C, unsigned Index);
 /* Return the item at the given index */
 #endif
 
 #if defined(HAVE_INLINE)
-INLINE void* CollAtUnchecked (Collection* C, unsigned Index)
+INLINE void* CollAtUnchecked (const Collection* C, unsigned Index)
 /* Return the item at the given index */
 {
     /* Return the element */
     return C->Items[Index];
 }
 #else
-#  define CollAtUnchecked(C, Index)    ((C)->Items[(Index)])
+#  define CollAtUnchecked(C, Index)     ((C)->Items[(Index)])
 #endif
 
 #if defined(HAVE_INLINE)
@@ -237,7 +237,7 @@ INLINE void CollDeleteAll (Collection* C)
     C->Count = 0;
 }
 #else
-#  define CollDeleteAll(C)     ((C)->Count = 0)
+#  define CollDeleteAll(C)      ((C)->Count = 0)
 #endif
 
 #if defined(HAVE_INLINE)
@@ -259,6 +259,13 @@ void CollReplace (Collection* C, void* Item, unsigned Index);
  */
 #endif
 
+void CollReplaceExpand (Collection* C, void* Item, unsigned Index);
+/* If Index is a valid index for the collection, replace the item at this
+ * position by the one passed. If the collection is too small, expand it,
+ * filling unused pointers with NULL, then add the new item at the given
+ * position.
+ */
+
 void CollMove (Collection* C, unsigned OldIndex, unsigned NewIndex);
 /* Move an item from one position in the collection to another. OldIndex
  * is the current position of the item, NewIndex is the new index after
@@ -274,9 +281,15 @@ void CollMoveMultiple (Collection* C, unsigned Start, unsigned Count, unsigned T
  * to higher indices.
  */
 
+void CollTransfer (Collection* Dest, const Collection* Source);
+/* Transfer all items from Source to Dest. Anything already in Dest is left
+ * untouched. The items in Source are not changed and are therefore in both
+ * Collections on return.
+ */
+
 void CollSort (Collection* C,
-              int (*Compare) (void*, const void*, const void*),
-              void* Data);
+               int (*Compare) (void*, const void*, const void*),
+               void* Data);
 /* Sort the collection using the given compare function. The data pointer is
  * passed as *first* element to the compare function, it's not used by the
  * sort function itself. The other two pointer passed to the Compare function
@@ -288,7 +301,3 @@ void CollSort (Collection* C,
 /* End of coll.h */
 
 #endif
-
-
-
-