summaryrefslogtreecommitdiffhomepage
path: root/include/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-04-27 19:07:18 +0200
committerTyge Løvset <[email protected]>2022-04-27 19:07:18 +0200
commitedfcc712b48e2a582bcad1bc5a4102f18154e549 (patch)
tree70ed252f3bfd4e5841a25d802da630b73e58b800 /include/stc
parentdf73eddd7933df7c96269f11e37fc1a96916f747 (diff)
downloadSTC-modified-edfcc712b48e2a582bcad1bc5a4102f18154e549.tar.gz
STC-modified-edfcc712b48e2a582bcad1bc5a4102f18154e549.zip
Final fixes to carc and cbox; Reverted constructor name to make; (similarity to make_shared/make_unique in c++).
Diffstat (limited to 'include/stc')
-rw-r--r--include/stc/carc.h16
-rw-r--r--include/stc/cbox.h29
-rw-r--r--include/stc/template.h9
3 files changed, 37 insertions, 17 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 02b932af..c7c18f53 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -103,14 +103,18 @@ _cx_memb(_from_ptr)(_cx_value* p) {
}
STC_INLINE _cx_self
-_cx_memb(_from)(i_key val) { // c++: std::make_shared<i_key>(val)
+_cx_memb(_make)(_cx_value val) { // c++: std::make_shared<_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;
}
-STC_INLINE i_key _cx_memb(_toraw)(const _cx_self* self) {
+STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self) {
+ return i_keyto(self->get);
+}
+
+STC_INLINE _cx_value _cx_memb(_get)(const _cx_self* self) {
return *self->get;
}
@@ -138,14 +142,16 @@ _cx_memb(_reset)(_cx_self* self) {
}
STC_INLINE void
-_cx_memb(_reset_from)(_cx_self* self, i_key val) {
+_cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
_cx_memb(_drop)(self);
- *self = _cx_memb(_from)(val);
+ *self = _cx_memb(_from_ptr)(p);
}
#if !defined _i_no_clone && !defined _i_no_emplace
STC_INLINE _cx_self
- _cx_memb(_make)(_cx_raw raw) { return _cx_memb(_from)(i_keyfrom(raw)); }
+ _cx_memb(_from)(_cx_raw raw) {
+ return _cx_memb(_make)(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 2d766509..f34888e8 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -86,16 +86,23 @@ STC_INLINE long
_cx_memb(_use_count)(_cx_self box) { return (long)(box.get != NULL); }
STC_INLINE _cx_self
-_cx_memb(_from_ptr)(i_key* p) { return c_make(_cx_self){p}; }
+_cx_memb(_from_ptr)(_cx_value* p) { return c_make(_cx_self){p}; }
STC_INLINE _cx_self
-_cx_memb(_from)(i_key val) { // c++: std::make_unique<i_key>(val)
- _cx_self ptr = {c_alloc(i_key)};
+_cx_memb(_make)(_cx_value val) { // c++: std::make_unique<i_key>(val)
+ _cx_self ptr = {c_alloc(_cx_value)};
*ptr.get = val; return ptr;
}
-STC_INLINE i_key
-_cx_memb(_toraw)(const _cx_self* self) { return *self->get; }
+STC_INLINE _cx_raw
+_cx_memb(_toraw)(const _cx_self* self) {
+ return i_keyto(self->get);
+}
+
+STC_INLINE _cx_value
+_cx_memb(_get)(const _cx_self* self) {
+ return *self->get;
+}
// destructor
STC_INLINE void
@@ -114,17 +121,19 @@ _cx_memb(_reset)(_cx_self* self) {
_cx_memb(_drop)(self); self->get = NULL;
}
-// take ownership of val
+// take ownership of p
STC_INLINE void
-_cx_memb(_reset_from)(_cx_self* self, i_key val) {
- if (self->get) { i_keydrop(self->get); *self->get = val; }
- else self->get = c_new(i_key, val);
+_cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
+ if (self->get) i_keydrop(self->get);
+ self->get = p;
}
#if !defined _i_no_clone
#if !defined _i_no_emplace
STC_INLINE _cx_self
- _cx_memb(_make)(_cx_raw raw) { return _cx_memb(_from)(i_keyfrom(raw)); }
+ _cx_memb(_from)(_cx_raw raw) {
+ return _cx_memb(_make)(i_keyfrom(raw));
+ }
#endif
STC_INLINE _cx_self
_cx_memb(_clone)(_cx_self other) {
diff --git a/include/stc/template.h b/include/stc/template.h
index 2a4a43f1..b0a98d1e 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -114,6 +114,9 @@
#elif defined i_key_arcbox
#define i_key_bind i_key_arcbox
#define i_keyraw c_paste(i_key_arcbox, _value)
+ #define i_keyfrom c_paste(i_key_arcbox, _make)
+ #define i_keyto c_paste(i_key_arcbox, _get)
+ #define i_eq c_paste(i_key_arcbox, _value_eq)
#define _i_no_emplace
#endif
@@ -167,7 +170,7 @@
#define i_keyto c_default_toraw
#endif
#ifndef i_keyclone
- #define i_keyclone(key) i_keyfrom((i_keyto((&(key)))))
+ #define i_keyclone(key) (key)
#endif
#ifndef i_keydrop
#define i_keydrop c_default_drop
@@ -197,6 +200,8 @@
#elif defined i_val_arcbox
#define i_val_bind i_val_arcbox
#define i_valraw c_paste(i_val_arcbox, _value)
+ #define i_valfrom c_paste(i_val_arcbox, _make)
+ #define i_valto c_paste(i_val_arcbox, _get)
#define _i_no_emplace
#endif
@@ -237,7 +242,7 @@
#define i_valto c_default_toraw
#endif
#ifndef i_valclone
- #define i_valclone(val) i_valfrom((i_valto((&(val)))))
+ #define i_valclone(val) (val)
#endif
#ifndef i_valdrop
#define i_valdrop c_default_drop