diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/carc.h | 75 | ||||
| -rw-r--r-- | include/stc/cbox.h | 86 | ||||
| -rw-r--r-- | include/stc/template.h | 2 |
3 files changed, 69 insertions, 94 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h index 245ba708..6c591d2c 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -90,44 +90,38 @@ _cx_deftypes(_c_carc_types, _cx_self, i_key); #endif
_cx_carc_rep { long counter; i_key value; };
-STC_INLINE _cx_self
-_cx_memb(_init)(void) { return c_make(_cx_self){NULL, NULL}; }
+STC_INLINE _cx_self _cx_memb(_init)(void)
+ { return c_make(_cx_self){NULL, NULL}; }
-STC_INLINE long
-_cx_memb(_use_count)(_cx_self ptr) { return ptr.use_count ? *ptr.use_count : 0; }
+STC_INLINE long _cx_memb(_use_count)(_cx_self ptr)
+ { return ptr.use_count ? *ptr.use_count : 0; }
-STC_INLINE _cx_self
-_cx_memb(_from_ptr)(_cx_value* p) {
+STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) {
_cx_self ptr = {p};
- if (p) *(ptr.use_count = c_alloc(long)) = 1;
+ if (p)
+ *(ptr.use_count = c_alloc(long)) = 1;
return ptr;
}
-STC_INLINE _cx_self
-_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);
+// c++: std::make_shared<_cx_value>(val)
+STC_INLINE _cx_self _cx_memb(_make)(_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 _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;
-}
+STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self)
+ { return i_keyto(self->get); }
-STC_INLINE _cx_self
-_cx_memb(_move)(_cx_self* self) {
+STC_INLINE _cx_self _cx_memb(_move)(_cx_self* self) {
_cx_self ptr = *self;
self->get = NULL, self->use_count = NULL;
return ptr;
}
-STC_INLINE void
-_cx_memb(_drop)(_cx_self* self) {
+STC_INLINE void _cx_memb(_drop)(_cx_self* self) {
if (self->use_count && _i_atomic_dec_and_test(self->use_count)) {
i_keydrop(self->get);
if ((char *)self->get != (char *)self->use_count + offsetof(_cx_carc_rep, value))
@@ -136,47 +130,42 @@ _cx_memb(_drop)(_cx_self* self) { }
}
-STC_INLINE void
-_cx_memb(_reset)(_cx_self* self) {
+STC_INLINE void _cx_memb(_reset)(_cx_self* self) {
_cx_memb(_drop)(self);
self->use_count = NULL, self->get = NULL;
}
-STC_INLINE void
-_cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
+STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
_cx_memb(_drop)(self);
*self = _cx_memb(_from_ptr)(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(_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.
-STC_INLINE _cx_self
-_cx_memb(_clone)(_cx_self ptr) {
- if (ptr.use_count) _i_atomic_inc(ptr.use_count);
+STC_INLINE _cx_self _cx_memb(_clone)(_cx_self ptr) {
+ if (ptr.use_count)
+ _i_atomic_inc(ptr.use_count);
return ptr;
}
-STC_INLINE void
-_cx_memb(_copy)(_cx_self* self, _cx_self ptr) {
- if (ptr.use_count) _i_atomic_inc(ptr.use_count);
+STC_INLINE void _cx_memb(_copy)(_cx_self* self, _cx_self ptr) {
+ if (ptr.use_count)
+ _i_atomic_inc(ptr.use_count);
_cx_memb(_drop)(self);
*self = ptr;
}
-STC_INLINE void
-_cx_memb(_take)(_cx_self* self, _cx_self ptr) {
- if (self->get != ptr.get) _cx_memb(_drop)(self);
+STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self ptr) {
+ if (self->get != ptr.get)
+ _cx_memb(_drop)(self);
*self = ptr;
}
-STC_INLINE uint64_t
-_cx_memb(_value_hash)(const _cx_value* x) {
+STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) {
#if c_option(c_no_cmp)
return c_default_hash(&x);
#else
@@ -185,8 +174,7 @@ _cx_memb(_value_hash)(const _cx_value* x) { #endif
}
-STC_INLINE int
-_cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
+STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return c_default_cmp(&x, &y);
#else
@@ -195,8 +183,7 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { #endif
}
-STC_INLINE bool
-_cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
+STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return x == y;
#else
diff --git a/include/stc/cbox.h b/include/stc/cbox.h index b4b583fa..cb5cada3 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -79,86 +79,78 @@ _cx_deftypes(_c_cbox_types, _cx_self, i_key); #endif
// constructors (takes ownsership)
-STC_INLINE _cx_self
-_cx_memb(_init)(void) { return c_make(_cx_self){NULL}; }
+STC_INLINE _cx_self _cx_memb(_init)(void)
+ { return c_make(_cx_self){NULL}; }
-STC_INLINE long
-_cx_memb(_use_count)(_cx_self box) { return (long)(box.get != NULL); }
+STC_INLINE long _cx_memb(_use_count)(_cx_self box)
+ { return (long)(box.get != NULL); }
-STC_INLINE _cx_self
-_cx_memb(_from_ptr)(_cx_value* p) { return c_make(_cx_self){p}; }
+STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p)
+ { return c_make(_cx_self){p}; }
-STC_INLINE _cx_self
-_cx_memb(_make)(_cx_value val) { // c++: std::make_unique<i_key>(val)
+// c++: std::make_unique<i_key>(val)
+STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) {
_cx_self ptr = {c_alloc(_cx_value)};
*ptr.get = val; return ptr;
}
-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;
-}
+STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self)
+ { return i_keyto(self->get); }
// destructor
-STC_INLINE void
-_cx_memb(_drop)(_cx_self* self) {
- if (self->get) { i_keydrop(self->get); c_free(self->get); }
+STC_INLINE void _cx_memb(_drop)(_cx_self* self) {
+ if (self->get) {
+ i_keydrop(self->get);
+ c_free(self->get);
+ }
}
-STC_INLINE _cx_self
-_cx_memb(_move)(_cx_self* self) {
- _cx_self ptr = *self; self->get = NULL;
+STC_INLINE _cx_self _cx_memb(_move)(_cx_self* self) {
+ _cx_self ptr = *self;
+ self->get = NULL;
return ptr;
}
-STC_INLINE void
-_cx_memb(_reset)(_cx_self* self) {
- _cx_memb(_drop)(self); self->get = NULL;
+STC_INLINE void _cx_memb(_reset)(_cx_self* self) {
+ _cx_memb(_drop)(self);
+ self->get = NULL;
}
// take ownership of p
-STC_INLINE void
-_cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
- if (self->get) i_keydrop(self->get);
+STC_INLINE void _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(_from)(_cx_raw raw) {
- return _cx_memb(_make)(i_keyfrom(raw));
- }
+ STC_INLINE _cx_self _cx_memb(_from)(_cx_raw raw)
+ { return _cx_memb(_make)(i_keyfrom(raw)); }
#endif
- STC_INLINE _cx_self
- _cx_memb(_clone)(_cx_self other) {
- if (!other.get) return other;
+ STC_INLINE _cx_self _cx_memb(_clone)(_cx_self other) {
+ if (!other.get)
+ return other;
_cx_self out = {c_alloc(i_key)};
*out.get = i_keyclone(*other.get);
return out;
}
- STC_INLINE void
- _cx_memb(_copy)(_cx_self* self, _cx_self other) {
- if (self->get == other.get) return;
+ STC_INLINE void _cx_memb(_copy)(_cx_self* self, _cx_self other) {
+ if (self->get == other.get)
+ return;
_cx_memb(_drop)(self);
*self = _cx_memb(_clone)(other);
}
#endif // !_i_no_clone
-STC_INLINE void
-_cx_memb(_take)(_cx_self* self, _cx_self other) {
- if (other.get != self->get) _cx_memb(_drop)(self);
+STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self other) {
+ if (other.get != self->get)
+ _cx_memb(_drop)(self);
*self = other;
}
-STC_INLINE uint64_t
-_cx_memb(_value_hash)(const _cx_value* x) {
+STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) {
#if c_option(c_no_cmp)
return c_default_hash(&x);
#else
@@ -167,8 +159,7 @@ _cx_memb(_value_hash)(const _cx_value* x) { #endif
}
-STC_INLINE int
-_cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
+STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return c_default_cmp(&x, &y);
#else
@@ -177,8 +168,7 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { #endif
}
-STC_INLINE bool
-_cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
+STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return x == y;
#else
diff --git a/include/stc/template.h b/include/stc/template.h index f5e77238..f55a3354 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -114,7 +114,6 @@ #elif defined i_key_arcbox
#define i_key_bind i_key_arcbox
#define i_keyraw c_paste(i_key_arcbox, _value)
- #define i_keyto c_paste(i_key_arcbox, _get)
#define i_eq c_paste(i_key_arcbox, _value_eq)
#endif
@@ -197,7 +196,6 @@ #elif defined i_val_arcbox
#define i_val_bind i_val_arcbox
#define i_valraw c_paste(i_val_arcbox, _value)
- #define i_valto c_paste(i_val_arcbox, _get)
#endif
#ifdef i_val_bind
|
