docs/Writerside/topics/collection.h.md

Fri, 24 Jan 2025 21:12:09 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 24 Jan 2025 21:12:09 +0100
branch
docs/3.1
changeset 1143
0559812df10c
parent 1141
a06a2d27c043
child 1146
151c057faf7c
permissions
-rw-r--r--

assign proper names to the documentation topics

relates to #451

1143
0559812df10c assign proper names to the documentation topics
Mike Becker <universe@uap-core.de>
parents: 1141
diff changeset
1 # Collections
1141
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 Collections in UCX 3 have several common features.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 If you want to implement an own collection data type that uses the same features, you can use the
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 `CX_COLLECTION_BASE` macro at the beginning of your struct to roll out all members a usual UCX collection has.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 ```c
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 struct my_fancy_collection_s {
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 CX_COLLECTION_BASE;
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 struct my_collection_data_s *data;
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 };
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 ```
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 Based on this structure, this header provides some convenience macros for invoking the destructor functions
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 that are part of the basic collection members.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 The idea of having destructor functions within a collection is that you can destroy the collection _and_ the
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 contents with one single function call.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 When you are implementing a collection, you are responsible for invoking the destructors at the right places, e.g.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 when removing (and deleting) elements in the collection, clearing the collection, or - the most prominent case -
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 destroying the collection.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 You can always look at the UCX list and map implementations if you need some inspiration.

mercurial