summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mesa/program/hash_table.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mesa/program/hash_table.h b/src/mesa/program/hash_table.h
index e95fc4982ec..eed2e55dc29 100644
--- a/src/mesa/program/hash_table.h
+++ b/src/mesa/program/hash_table.h
@@ -198,6 +198,11 @@ string_to_uint_map_dtor(struct string_to_uint_map *);
#ifdef __cplusplus
}
+struct string_map_iterate_wrapper_closure {
+ void (*callback)(const char *key, unsigned value, void *closure);
+ void *closure;
+};
+
/**
* Map from a string (name) to an unsigned integer value
*
@@ -229,6 +234,24 @@ public:
}
/**
+ * Runs a passed callback for the hash
+ */
+ void iterate(void (*func)(const char *, unsigned, void *), void *closure)
+ {
+ struct string_map_iterate_wrapper_closure *wrapper;
+
+ wrapper = (struct string_map_iterate_wrapper_closure *)
+ malloc(sizeof(struct string_map_iterate_wrapper_closure));
+ if (wrapper == NULL)
+ return;
+
+ wrapper->callback = func;
+ wrapper->closure = closure;
+
+ hash_table_call_foreach(this->ht, subtract_one_wrapper, wrapper);
+ }
+
+ /**
* Get the value associated with a particular key
*
* \return
@@ -281,6 +304,17 @@ private:
free((char *)key);
}
+ static void subtract_one_wrapper(const void *key, void *data, void *closure)
+ {
+ struct string_map_iterate_wrapper_closure *wrapper =
+ (struct string_map_iterate_wrapper_closure *) closure;
+ unsigned value = (intptr_t) data;
+
+ value -= 1;
+
+ wrapper->callback((const char *) key, value, wrapper->closure);
+ }
+
struct hash_table *ht;
};