vppinfra: add vec_foreach_pointer macro 31/39331/2
authorDamjan Marion <damarion@cisco.com>
Sun, 6 Aug 2023 18:41:40 +0000 (20:41 +0200)
committerFlorin Coras <florin.coras@gmail.com>
Mon, 7 Aug 2023 17:33:25 +0000 (17:33 +0000)
works with vectors of pointers...

Type: improvement
Change-Id: I530653978fcf981be299cf42a1133be000d74d0c
Signed-off-by: Damjan Marion <damarion@cisco.com>
.clang-format
src/vppinfra/vec_bootstrap.h

index 0680770..050505b 100644 (file)
@@ -18,6 +18,7 @@ ForEachMacros:
   - 'vec_foreach_backwards'
   - 'vec_foreach_index'
   - 'vec_foreach_index_backwards'
+  - 'vec_foreach_pointer'
   - 'vlib_foreach_rx_tx'
   - 'foreach_vlib_main'
   - 'foreach_set_bit_index'
index 006d167..5c827d4 100644 (file)
@@ -238,6 +238,10 @@ _vec_set_len (void *v, uword len, uword elt_sz)
   if (v)                                                                      \
     for ((var) = vec_len ((v)) - 1; (var) >= 0; (var)--)
 
+#define vec_foreach_pointer(e, v)                                             \
+  for (typeof (**v) **__ep = (v), *(e) = *__ep; __ep - (v) < vec_len (v);     \
+       __ep++, (e) = *__ep)
+
 #endif /* included_clib_vec_bootstrap_h */
 
 /*