Asterisk - The Open Source Telephony Project  18.5.0
AstObj2 Containers

Containers are data structures meant to store several objects, and perform various operations on them. Internally, objects are stored in lists, hash tables or other data structures depending on the needs.

Operations on container include:

struct ao2_container *c = ... // our container
struct ao2_iterator i;
void *o;
while ((o = ao2_iterator_next(&i))) {
... do something on o ...
ao2_ref(o, -1);
}
The difference with the callback is that the control
on how to iterate is left to us.

- \b ao2_ref(c, -1)
dropping a reference to a container destroys it, very simple!

Containers are ao2 objects themselves, and this is why their implementation is simple too.

Before declaring containers, we need to declare the types of the arguments passed to the constructor - in turn, this requires to define callback and hash functions and their arguments.