diff options
Diffstat (limited to 'docs/cqueue_api.md')
| -rw-r--r-- | docs/cqueue_api.md | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md index 8bd9f15e..16e87d47 100644 --- a/docs/cqueue_api.md +++ b/docs/cqueue_api.md @@ -1,20 +1,23 @@ # STC [cqueue](../include/stc/cqueue.h): Queue  -The **cqueue** is container adapter that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure. The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The queue pushes the elements on the back of the underlying container and pops them from the front. +The **cqueue** is container that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure. The queue pushes the elements on the back of the underlying container and pops them from the front. See the c++ class [std::queue](https://en.cppreference.com/w/cpp/container/queue) for a functional reference. ## Header file and declaration ```c -#include <stc/cqueue.h> /* includes default underlying implementation header cdeq.h */ - -using_cqueue(X, ctype) +#define i_tag // defaults to i_val name +#define i_val // value: REQUIRED +#define i_cmp // three-way compare two i_valraw* : REQUIRED IF i_valraw is a non-integral type +#define i_valraw // convertion "raw" type - defaults to i_val +#define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy +#define i_valto // convertion func i_val* => i_valraw - defaults to plain copy +#define i_valdel // destroy value func - defaults to empty destruct +#include <stc/cqueue.h> ``` -The macro `using_cqueue()` must be instantiated in the global scope. **cqueue** uses normally -a **cdeq_X** or **clist_X** type as underlying implementation, given as `ctype`. See example below for usage. -`X` is a type tag name and will affect the names of all cqueue types and methods. E.g. declaring -`using_cqueue(i, clist_i)`, `X` should be replaced by `i` in all of the following documentation. +`X` should be replaced by the value of i_tag in all of the following documentation. + ## Methods @@ -54,42 +57,12 @@ cqueue_X_value_t cqueue_X_value_clone(cqueue_X_value_t val); ## Examples ```c +#define i_tag i +#define i_val int #include <stc/cqueue.h> -#include <stdio.h> - -using_cdeq(i, int); -using_cqueue(i, cdeq_i); - -int main() { - cqueue_i Q = cqueue_i_init(); - - // push() and pop() a few. - c_forrange (i, 20) - cqueue_i_push(&Q, i); - - c_forrange (5) - cqueue_i_pop(&Q); - - c_foreach (i, cqueue_i, Q) - printf(" %d", *i.ref); - cqueue_i_del(&Q); -} -``` -Output: -``` -5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 -``` -### Example 2 -Use clist as underlying cqueue implementation. -```c -#include <stc/cqueue.h> -#include <stc/clist.h> #include <stdio.h> -using_clist(i, int); -using_cqueue(i, clist_i); - int main() { cqueue_i Q = cqueue_i_init(); |
