summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-03-15 00:17:08 +0100
committerTyge Løvset <[email protected]>2022-03-15 00:17:08 +0100
commit342484f70998258022c26e6af2926ecc7635bbdd (patch)
tree2055e6fd1adc1a0f61c1456e8e79f021838ab583
parent9f1a51593ae7dd45db46f39ac18901ad175af18e (diff)
downloadSTC-modified-342484f70998258022c26e6af2926ecc7635bbdd.tar.gz
STC-modified-342484f70998258022c26e6af2926ecc7635bbdd.zip
Some docs update, ++.
-rw-r--r--README.md9
-rw-r--r--docs/carc_api.md72
-rw-r--r--include/stc/ccommon.h2
-rw-r--r--include/stc/forward.h4
4 files changed, 47 insertions, 40 deletions
diff --git a/README.md b/README.md
index ec8187c2..5d253987 100644
--- a/README.md
+++ b/README.md
@@ -25,14 +25,14 @@ Note that STC does not use long macro expansions anymore, but relies on one or m
which by the compiler is seen as different code because of macro name substitutions.
- [***ccommon*** - RAII and iterator macros](docs/ccommon_api.md)
-- [***carr2, carr3*** - **2d** and **3d** dynamic **array** type](docs/carray_api.md)
+- [***carc*** - **std::shared_ptr** alike support](docs/carc_api.md)
+- [***carr2/3 - **2d** and **3d** dynamic **array** type](docs/carray_api.md)
- [***cbits*** - **std::bitset** alike type](docs/cbits_api.md)
- [***cbox*** - **std::unique_ptr** alike type](docs/cbox_api.md)
- [***cdeq*** - **std::deque** alike type](docs/cdeq_api.md)
- [***clist*** - **std::forward_list** alike type](docs/clist_api.md)
- [***cmap*** - **std::unordered_map** alike type](docs/cmap_api.md)
- [***cpque*** - **std::priority_queue** alike type](docs/cpque_api.md)
-- [***carc*** - **std::shared_ptr** alike support](docs/carc_api.md)
- [***cqueue*** - **std::queue** alike type](docs/cqueue_api.md)
- [***cset*** - **std::unordered_set** alike type](docs/cset_api.md)
- [***csmap*** - **std::map** sorted map alike type](docs/csmap_api.md)
@@ -94,10 +94,11 @@ int main(void) {
FVec_drop(&vec); // free memory
}
```
-However, a "better" way to write the same is:
+A "better" way to write the same code is:
```c
int main(void) {
- c_auto (FVec, vec) { // RAII
+ c_auto (FVec, vec) // RAII - create and destroy vec
+ {
c_apply(v, FVec_push_back(&vec, v), float, {10.f, 20.f, 30.f});
c_foreach (i, FVec, vec) // generic iteration and element access
diff --git a/docs/carc_api.md b/docs/carc_api.md
index e33bf410..a83bc194 100644
--- a/docs/carc_api.md
+++ b/docs/carc_api.md
@@ -75,7 +75,7 @@ bool carc_X_value_eq(const i_val* x, const i_val* y); // cbox_X_value_c
#define i_type Map
#define i_key_str // strings
#define i_val int
-#define i_keydrop(p) (printf("drop name: %s\n", (p)->str), cstr_drop(p))
+#define i_keydrop(p) (printf(" drop name: %s\n", (p)->str), cstr_drop(p))
#include <stc/csmap.h>
#define i_type Arc // (atomic) ref. counted type
@@ -104,44 +104,50 @@ int main()
Map *map;
map = Stack_push(&stack, Arc_from(Map_init()))->get;
c_apply(v, Map_emplace(map, c_pair(v)), Map_raw, {
- {"Joey", 1990}, {"Mary", 1995}, {"Joanna", 1992}
+ {"Joey", 1990},
+ {"Mary", 1995},
+ {"Joanna", 1992}
});
map = Stack_push(&stack, Arc_from(Map_init()))->get;
c_apply(v, Map_emplace(map, c_pair(v)), Map_raw, {
- {"Rosanna", 2001}, {"Brad", 1999}, {"Jack", 1980}
+ {"Rosanna", 2001},
+ {"Brad", 1999},
+ {"Jack", 1980}
});
// POPULATE the list:
map = List_push_back(&list, Arc_from(Map_init()))->get;
c_apply(v, Map_emplace(map, c_pair(v)), Map_raw, {
- {"Steve", 1979}, {"Rick", 1974}, {"Tracy", 2003}
+ {"Steve", 1979},
+ {"Rick", 1974},
+ {"Tracy", 2003}
});
- // Share two Maps from the stack with the list using emplace (clones the carc):
- List_emplace_back(&list, stack.data[0]);
- List_emplace_back(&list, stack.data[1]);
+ // Share two Maps from the stack with the list by cloning(=sharing) the carc:
+ List_push_back(&list, Arc_clone(stack.data[0]));
+ List_push_back(&list, Arc_clone(stack.data[1]));
- // Clone (deep copy) a Map from the stack to the list
+ // Deep-copy (not share) a Map from the stack to the list
// List will contain two shared and two unshared maps.
map = List_push_back(&list, Arc_from(Map_clone(*stack.data[1].get)))->get;
// Add one more element to the cloned map:
- Map_emplace_or_assign(map, "CLONED", 2021);
+ Map_emplace_or_assign(map, "Cloned", 2022);
// Add one more element to the shared map:
- Map_emplace_or_assign(stack.data[1].get, "SHARED", 2021);
-
+ Map_emplace_or_assign(stack.data[1].get, "Shared", 2022);
puts("STACKS");
c_foreach (i, Stack, stack) {
c_forpair (name, year, Map, *i.ref->get)
- printf(" %s:%d", _.name.str, _.year);
+ printf(" %s:%d", _.name.str, _.year);
puts("");
}
+
puts("LIST");
c_foreach (i, List, list) {
c_forpair (name, year, Map, *i.ref->get)
- printf(" %s:%d", _.name.str, _.year);
+ printf(" %s:%d", _.name.str, _.year);
puts("");
}
}
@@ -150,29 +156,29 @@ int main()
Output:
```
STACKS
- Joanna:1992 Joey:1990 Mary:1995
- Brad:1999 Jack:1980 Rosanna:2001 SHARED:2021
+ Joanna:1992 Joey:1990 Mary:1995
+ Brad:1999 Jack:1980 Rosanna:2001 Shared:2022
LIST
- Rick:1974 Steve:1979 Tracy:2003
- Joanna:1992 Joey:1990 Mary:1995
- Brad:1999 Jack:1980 Rosanna:2001 SHARED:2021
- Brad:1999 CLONED:2021 Jack:1980 Rosanna:2001
+ Rick:1974 Steve:1979 Tracy:2003
+ Joanna:1992 Joey:1990 Mary:1995
+ Brad:1999 Jack:1980 Rosanna:2001 Shared:2022
+ Brad:1999 Cloned:2022 Jack:1980 Rosanna:2001
drop Arc:
-drop name: Rick
-drop name: Tracy
-drop name: Steve
+ drop name: Rick
+ drop name: Tracy
+ drop name: Steve
drop Arc:
-drop name: CLONED
-drop name: Brad
-drop name: Rosanna
-drop name: Jack
+ drop name: Cloned
+ drop name: Brad
+ drop name: Rosanna
+ drop name: Jack
drop Arc:
-drop name: Brad
-drop name: SHARED
-drop name: Rosanna
-drop name: Jack
+ drop name: Brad
+ drop name: Shared
+ drop name: Rosanna
+ drop name: Jack
drop Arc:
-drop name: Joanna
-drop name: Mary
-drop name: Joey
+ drop name: Joanna
+ drop name: Mary
+ drop name: Joey
```
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 52daf837..f3939b16 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -240,6 +240,6 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, size_t slen, cons
# define STC_API static inline
# define STC_DEF static inline
#endif
-#if (c_option(c_implement) || defined(STC_IMPLEMENTATION)) ^ defined(_i_static)
+#if c_option(c_implement) || defined(STC_IMPLEMENTATION) || defined(_i_static)
# define _i_implement
#endif
diff --git a/include/stc/forward.h b/include/stc/forward.h
index e57aedfd..6f450219 100644
--- a/include/stc/forward.h
+++ b/include/stc/forward.h
@@ -30,9 +30,9 @@
#define forward_cdeq(CX, VAL) _c_cdeq_types(CX, VAL)
#define forward_clist(CX, VAL) _c_clist_types(CX, VAL)
#define forward_cmap(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, uint32_t, c_true, c_false)
-#define forward_cmap_big(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, size_t, c_true, c_false)
+#define forward_cmap_huge(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, size_t, c_true, c_false)
#define forward_cset(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, uint32_t, c_false, c_true)
-#define forward_cset_big(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, size_t, c_false, c_true)
+#define forward_cset_huge(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, size_t, c_false, c_true)
#define forward_csmap(CX, KEY, VAL) _c_aatree_types(CX, KEY, VAL, uint32_t, c_true, c_false)
#define forward_csset(CX, KEY) _c_aatree_types(CX, KEY, KEY, uint32_t, c_false, c_true)
#define forward_cbox(CX, VAL) _c_cbox_types(CX, VAL)