summaryrefslogtreecommitdiffhomepage
path: root/include/stc/csptr.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/stc/csptr.h')
-rw-r--r--include/stc/csptr.h94
1 files changed, 37 insertions, 57 deletions
diff --git a/include/stc/csptr.h b/include/stc/csptr.h
index 4f183498..1729235e 100644
--- a/include/stc/csptr.h
+++ b/include/stc/csptr.h
@@ -68,112 +68,92 @@ typedef long atomic_count_t;
}
#endif
-#define forward_csptr(X, Value) _csptr_types(csptr_##X, Value)
+#define forward_csptr(X, i_VAL) _csptr_types(csptr_##X, i_VAL)
#define csptr_null {NULL, NULL}
-#define using_csptr(...) c_MACRO_OVERLOAD(using_csptr, __VA_ARGS__)
-
-#define using_csptr_2(X, Value) \
- using_csptr_3(X, Value, c_default_compare)
-#define using_csptr_3(X, Value, valueCompare) \
- using_csptr_4(X, Value, valueCompare, c_default_del)
-#define using_csptr_4(X, Value, valueCompare, valueDel) \
- _c_using_csptr(csptr_##X, Value, valueCompare, valueDel, c_true)
-#define using_csptr_5(X, Value, valueCompare, valueDel, defTypes) \
- _c_using_csptr(csptr_##X, Value, valueCompare, valueDel, defTypes)
-
-#define _csptr_types(CX, Value) \
- typedef Value CX##_value_t; \
-\
- typedef struct { \
- CX##_value_t* get; \
- atomic_count_t* use_count; \
- } CX
-
-#define _c_using_csptr(CX, Value, valueCompare, valueDel, defTypes) \
- defTypes( _csptr_types(CX, Value); ) \
- struct CX##_rep_ {atomic_count_t cnt; CX##_value_t val;}; \
+ defTypes( _csptr_types(Self, i_VAL); ) \
+ struct cx_memb(_rep_) {atomic_count_t cnt; cx_value_t val; }; \
\
- STC_INLINE CX \
- CX##_init() { return c_make(CX){NULL, NULL}; } \
+ STC_INLINE Self \
+ cx_memb(_init)() { return c_make(Self){NULL, NULL}; } \
\
STC_INLINE atomic_count_t \
- CX##_use_count(CX ptr) { return ptr.use_count ? *ptr.use_count : 0; } \
+ cx_memb(_use_count)(Self ptr) { return ptr.use_count ? *ptr.use_count : 0; } \
\
- STC_INLINE CX \
- CX##_from(CX##_value_t* p) { \
- CX ptr = {p}; \
+ STC_INLINE Self \
+ cx_memb(_from)(cx_value_t* p) { \
+ Self ptr = {p}; \
if (p) *(ptr.use_count = c_new(atomic_count_t)) = 1; \
return ptr; \
} \
\
- STC_INLINE CX \
- CX##_make(CX##_value_t val) { \
- CX ptr; struct CX##_rep_ *rep = c_new(struct CX##_rep_); \
+ STC_INLINE Self \
+ cx_memb(_make)(cx_value_t val) { \
+ Self ptr; struct cx_memb(_rep_) *rep = c_new(struct cx_memb(_rep_)); \
*(ptr.use_count = &rep->cnt) = 1; \
*(ptr.get = &rep->val) = val; \
return ptr; \
} \
\
- STC_INLINE CX \
- CX##_clone(CX ptr) { \
+ STC_INLINE Self \
+ cx_memb(_clone)(Self ptr) { \
if (ptr.use_count) c_atomic_increment(ptr.use_count); \
return ptr; \
} \
\
- STC_INLINE CX \
- CX##_move(CX* self) { \
- CX ptr = *self; \
+ STC_INLINE Self \
+ cx_memb(_move)(Self* self) { \
+ Self ptr = *self; \
self->get = NULL, self->use_count = NULL; \
return ptr; \
} \
\
STC_INLINE void \
- CX##_del(CX* self) { \
+ cx_memb(_del)(Self* self) { \
if (self->use_count && c_atomic_decrement(self->use_count) == 0) { \
- valueDel(self->get); \
- if (self->get != &((struct CX##_rep_*)self->use_count)->val) c_free(self->get); \
+ i_VALDEL(self->get); \
+ if (self->get != &((struct cx_memb(_rep_)*)self->use_count)->val) c_free(self->get); \
c_free(self->use_count); \
} \
} \
\
STC_INLINE void \
- CX##_reset(CX* self) { \
- CX##_del(self); \
+ cx_memb(_reset)(Self* self) { \
+ cx_memb(_del)(self); \
self->use_count = NULL, self->get = NULL; \
} \
\
- STC_INLINE CX##_value_t* \
- CX##_reset_with(CX* self, CX##_value_t* p) { \
- CX##_del(self); \
- *self = CX##_from(p); \
+ STC_INLINE cx_value_t* \
+ cx_memb(_reset_with)(Self* self, cx_value_t* p) { \
+ cx_memb(_del)(self); \
+ *self = cx_memb(_from)(p); \
return self->get; \
} \
\
- STC_INLINE CX##_value_t* \
- CX##_reset_make(CX* self, CX##_value_t val) { \
- CX##_del(self); \
- *self = CX##_make(val); \
+ STC_INLINE cx_value_t* \
+ cx_memb(_reset_make)(Self* self, cx_value_t val) { \
+ cx_memb(_del)(self); \
+ *self = cx_memb(_make)(val); \
return self->get; \
} \
\
- STC_INLINE CX##_value_t* \
- CX##_copy(CX* self, CX ptr) { \
- CX##_del(self); \
+ STC_INLINE cx_value_t* \
+ cx_memb(_copy)(Self* self, Self ptr) { \
+ cx_memb(_del)(self); \
*self = ptr; \
if (self->use_count) c_atomic_increment(self->use_count); \
return self->get; \
} \
\
STC_INLINE int \
- CX##_compare(const CX* x, const CX* y) { \
- return valueCompare(x->get, y->get); \
+ cx_memb(_compare)(const Self* x, const Self* y) { \
+ return i_CMP(x->get, y->get); \
} \
\
STC_INLINE bool \
- CX##_equals(const CX* x, const CX* y) { \
- return valueCompare(x->get, y->get) == 0; \
+ cx_memb(_equals)(const Self* x, const Self* y) { \
+ return i_CMP(x->get, y->get) == 0; \
} \
struct stc_trailing_semicolon