summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-09-23 08:13:46 +0200
committerTyge Løvset <[email protected]>2021-09-23 08:13:46 +0200
commit7b5ad58d20dcf3561662a294183fceab0d0ee73c (patch)
tree6a3dec1ac0f65a886c1287c1468bb1bf705d92f0
parent6b0cee466ec405a8b8051da56fc63ed3e2930846 (diff)
downloadSTC-modified-7b5ad58d20dcf3561662a294183fceab0d0ee73c.tar.gz
STC-modified-7b5ad58d20dcf3561662a294183fceab0d0ee73c.zip
Some more documentation in README.md.
Added support for i_del template arg/define for destroy function. For maps, i_keydel / i_valdel is still required and error is given if i_del is defined.
-rw-r--r--README.md6
-rw-r--r--docs/carray_api.md3
-rw-r--r--docs/cvec_api.md2
-rw-r--r--include/stc/template.h11
-rw-r--r--tests/test_new_list.c12
-rw-r--r--tests/test_new_pque.c6
6 files changed, 29 insertions, 11 deletions
diff --git a/README.md b/README.md
index 4fd34197..48ad3533 100644
--- a/README.md
+++ b/README.md
@@ -272,7 +272,11 @@ c_autovar (cstr s = cstr_lit("a string literal"), cstr_del(&s)) // cstr_lit() f
```
This is made possible because the type configuration may be given an optional
conversion/"rawvalue"-type as template parameter, along with a back and forth conversion
-methods to the container value type. By default, *rawvalue has the same type as value*.
+methods to the container value type.
+
+Hence, `i_val x = ..., y = i_valfrom(i_valto(&x))` works as a *clone* function, where the output of
+`i_valto()` is type `i_valraw`. Function `i_valfrom()` is a *clone* function when `i_valraw/i_valto` is
+undefined (i_valraw defaults to `i_val`). Same for `i_key`.
Rawvalues are also beneficial for **find()** and *map insertions*. The **emplace()** methods constructs
*cstr*-objects from the rawvalues, but only when required:
diff --git a/docs/carray_api.md b/docs/carray_api.md
index 5a86240f..b567d8aa 100644
--- a/docs/carray_api.md
+++ b/docs/carray_api.md
@@ -11,7 +11,8 @@ See the c++ class [boost::multi_array](https://www.boost.org/doc/libs/release/li
```c
#define i_tag // defaults to i_val name
#define i_val // value: REQUIRED
-#define i_valfrom // clone func i_val => i_val - defaults to plain copy
+#define i_valfrom // func Raw => i_val - defaults to plain copy
+#define i_valto // func i_val => Raw - defaults to plain copy
#define i_valdel // destroy value func - defaults to empty destruct
#include <stc/carr2.h> // or <stc/carr3.h>
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index 294d3a59..3b1ff265 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -23,6 +23,8 @@ See the c++ class [std::vector](https://en.cppreference.com/w/cpp/container/vect
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
+`i_del` may be defined instead of `i_valdel` (or `i_keydel`) for all non-map containers.
+
## Methods
```c
diff --git a/include/stc/template.h b/include/stc/template.h
index efb6f2f8..c207ae56 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -104,6 +104,14 @@
#define i_valraw const char*
#endif
+#if defined i_del && defined i_isset
+ #define i_keydel i_del
+#elif defined i_del && !defined i_key
+ #define i_valdel i_del
+#elif defined i_del
+ #error i_del not supported for maps, define i_keydel / i_valdel instead.
+#endif
+
#ifdef i_key
#ifndef i_val
#define i_val i_key
@@ -131,6 +139,8 @@
#ifndef i_keydel
#define i_keydel c_default_del
#endif
+#elif defined i_keydel || defined i_keyfrom || defined i_keyraw || defined i_hash || defined i_equ
+ #warning i_key-related definitions without i_key are ignored.
#endif
#ifndef i_tag
@@ -160,6 +170,7 @@
#undef i_imp
#undef i_fwd
#undef i_cmp
+#undef i_del
#undef i_equ
#undef i_hash
#undef i_val
diff --git a/tests/test_new_list.c b/tests/test_new_list.c
index f0983b76..a38936b0 100644
--- a/tests/test_new_list.c
+++ b/tests/test_new_list.c
@@ -1,5 +1,5 @@
-#include "cstr.h"
-#include "forward.h"
+#include <stc/cstr.h>
+#include <stc/forward.h>
forward_clist(i32, int);
forward_clist(pnt, struct Point);
@@ -12,7 +12,7 @@ struct MyStruct {
#define F_tag i32
#define i_val int
-#include "clist.h"
+#include <stc/clist.h>
struct Point { int x, y; } typedef Point;
int point_compare(const Point* a, const Point* b) {
@@ -22,13 +22,13 @@ int point_compare(const Point* a, const Point* b) {
#define F_tag pnt
#define i_val Point
#define i_cmp point_compare
-#include "clist.h"
+#include <stc/clist.h>
#define i_val float
-#include "clist.h"
+#include <stc/clist.h>
#define i_val_str
-#include "clist.h"
+#include <stc/clist.h>
int main()
diff --git a/tests/test_new_pque.c b/tests/test_new_pque.c
index b9750c44..1fb90123 100644
--- a/tests/test_new_pque.c
+++ b/tests/test_new_pque.c
@@ -8,10 +8,10 @@ struct MyStruct {
};
#define i_val int
-#include "cstack.h"
+#include <stc/cstack.h>
#define i_val int
-#include "cpque.h"
+#include <stc/cpque.h>
struct Point { int x, y; } typedef Point;
@@ -22,7 +22,7 @@ int Point_cmp(const Point* a, const Point* b) {
#define F_tag pnt // F: was forward declared.
#define i_val Point
#define i_cmp Point_cmp
-#include "cpque.h"
+#include <stc/cpque.h>
#include <stdio.h>