summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-08-11 17:58:15 +0200
committerTyge Løvset <[email protected]>2022-08-11 17:58:15 +0200
commit5cf6b762012168be51b32a1a85ab2bc33504f020 (patch)
tree9fd59787a0d33d23196b77cecbd31ef5d44e103a /include
parent9831e8d6ee6772a4f9899cf9e3d36e3de47bbaf5 (diff)
downloadSTC-modified-5cf6b762012168be51b32a1a85ab2bc33504f020.tar.gz
STC-modified-5cf6b762012168be51b32a1a85ab2bc33504f020.zip
Fixed issue with cbox / carc. Minor update some examples.
Diffstat (limited to 'include')
-rw-r--r--include/stc/carc.h17
-rw-r--r--include/stc/cbox.h11
-rw-r--r--include/stc/template.h5
3 files changed, 22 insertions, 11 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 57f00899..62b33bed 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -34,18 +34,18 @@ void Person_drop(Person* p) {
c_drop(cstr, &p->name, &p->last);
}
-#define i_tag person
+#define i_type ArcPers
#define i_key Person
#define i_keydrop Person_drop
#define i_opt c_no_cmp
#include <stc/carc.h>
int main() {
- carc_person p = carc_person_make(Person_new("John", "Smiths"));
- carc_person q = carc_person_clone(p); // share the pointer
+ ArcPers p = ArcPers_from(Person_new("John", "Smiths"));
+ ArcPers q = ArcPers_clone(p); // share the pointer
printf("%s %s. uses: %" PRIuMAX "\n", cstr_str(&q.get->name), cstr_str(&q.get->last), *q.use_count);
- c_drop(carc_person, &p, &q);
+ c_drop(ArcPers, &p, &q);
}
*/
#include "ccommon.h"
@@ -104,13 +104,16 @@ STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) {
}
// c++: std::make_shared<_cx_value>(val)
-STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) {
+STC_INLINE _cx_self _cx_memb(_from)(_cx_value val) {
_cx_self ptr;
_cx_carc_rep *rep = c_alloc(_cx_carc_rep);
*(ptr.use_count = &rep->counter) = 1;
*(ptr.get = &rep->value) = val;
return ptr;
}
+// [deprecated]
+STC_INLINE _cx_self _cx_memb(_make)(_cx_value val)
+ { return _cx_memb(_from)(val); }
STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self)
{ return i_keyto(self->get); }
@@ -144,8 +147,8 @@ STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
}
#if !defined _i_no_clone && !defined _i_no_emplace
- STC_INLINE _cx_self _cx_memb(_from)(_cx_raw raw)
- { return _cx_memb(_make)(i_keyfrom(raw)); }
+ STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw)
+ { return _cx_memb(_from)(i_keyfrom(raw)); }
#endif // !_i_no_clone
// does not use i_keyclone, so OK to always define.
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index c3a9dd02..467dd645 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -48,7 +48,7 @@ void Person_drop(Person* p) {
int main() {
c_auto (PBox, p, q)
{
- p = PBox_make(Person_from("John Smiths", "[email protected]"));
+ p = PBox_from(Person_from("John Smiths", "[email protected]"));
q = PBox_clone(p);
cstr_assign(&q.get->name, "Joe Smiths");
@@ -89,10 +89,13 @@ STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p)
{ return c_make(_cx_self){p}; }
// c++: std::make_unique<i_key>(val)
-STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) {
+STC_INLINE _cx_self _cx_memb(_from)(_cx_value val) {
_cx_self ptr = {c_alloc(_cx_value)};
*ptr.get = val; return ptr;
}
+// [deprecated]
+STC_INLINE _cx_self _cx_memb(_make)(_cx_value val)
+ { return _cx_memb(_from)(val); }
STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self)
{ return i_keyto(self->get); }
@@ -128,8 +131,8 @@ STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
#if !defined _i_no_clone
#if !defined _i_no_emplace
- STC_INLINE _cx_self _cx_memb(_from)(_cx_raw raw)
- { return _cx_memb(_make)(i_keyfrom(raw)); }
+ STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw)
+ { return _cx_memb(_from)(i_keyfrom(raw)); }
#endif
STC_INLINE _cx_self _cx_memb(_clone)(_cx_self other) {
if (!other.get)
diff --git a/include/stc/template.h b/include/stc/template.h
index ac9d5b5e..eeccc39e 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -109,6 +109,7 @@
#endif
#elif defined i_key_arcbox
#define i_key_bind i_key_arcbox
+ #define i_keyfrom c_paste(i_key_arcbox, _from)
#define i_keyraw c_paste(i_key_arcbox, _value)
#define i_keyto c_paste(i_key_arcbox, _toval)
#define i_eq c_paste(i_key_arcbox, _value_eq)
@@ -199,6 +200,7 @@
#define i_valto cstr_sv
#elif defined i_val_arcbox
#define i_val_bind i_val_arcbox
+ #define i_valfrom c_paste(i_val_arcbox, _from)
#define i_valraw c_paste(i_val_arcbox, _value)
#define i_valto c_paste(i_val_arcbox, _toval)
#endif
@@ -216,6 +218,9 @@
#endif
#endif
+#ifndef i_val
+ #error "i_val* must be defined for maps"
+#endif
#if defined i_valraw ^ defined i_valto
#error "both i_valto and i_valraw must be defined, if any"
#elif defined i_valfrom && !defined i_valraw