From bb8484be936d82f0f01b99ca67a6de1508037e8f Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 19 May 2022 11:22:03 +0200 Subject: Added _toval() in carc and cbox. Added dynamic polymorphism example, shape.c. --- include/stc/carc.h | 3 +++ include/stc/cbox.h | 3 +++ include/stc/template.h | 2 ++ 3 files changed, 8 insertions(+) (limited to 'include') diff --git a/include/stc/carc.h b/include/stc/carc.h index 6c591d2c..e4a69e80 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -115,6 +115,9 @@ STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self) { return i_keyto(self->get); } +STC_INLINE _cx_value _cx_memb(_toval)(const _cx_self* self) + { return *self->get; } + STC_INLINE _cx_self _cx_memb(_move)(_cx_self* self) { _cx_self ptr = *self; self->get = NULL, self->use_count = NULL; diff --git a/include/stc/cbox.h b/include/stc/cbox.h index cb5cada3..73b437d4 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -97,6 +97,9 @@ STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self) { return i_keyto(self->get); } +STC_INLINE _cx_value _cx_memb(_toval)(const _cx_self* self) + { return *self->get; } + // destructor STC_INLINE void _cx_memb(_drop)(_cx_self* self) { if (self->get) { diff --git a/include/stc/template.h b/include/stc/template.h index f55a3354..6af10ace 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -114,6 +114,7 @@ #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, _toval) #define i_eq c_paste(i_key_arcbox, _value_eq) #endif @@ -196,6 +197,7 @@ #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, _toval) #endif #ifdef i_val_bind -- cgit v1.2.3