diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-29 01:02:02 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-29 01:40:02 -0600 |
commit | 7ff738390e55d57a0f513c467a9da3b08c6902ab (patch) | |
tree | 384bd03462a9790c9c747b895cf5de0677659db7 /libmisc/include | |
parent | affe77a2b068a9de236f0d7703092dbfafacff5e (diff) |
Add a way to make private object members
Diffstat (limited to 'libmisc/include')
-rw-r--r-- | libmisc/include/libmisc/private.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libmisc/include/libmisc/private.h b/libmisc/include/libmisc/private.h new file mode 100644 index 0000000..0eb8c42 --- /dev/null +++ b/libmisc/include/libmisc/private.h @@ -0,0 +1,37 @@ +/* libmisc/private.h - Utilities to hide struct fields + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBMISC_CPPUTIL_H_ +#define _LIBMISC_CPPUTIL_H_ + +/* primitive utilities */ + +#define _SECOND(a, b, ...) b + +#define _CAT(a, b) a ## b +#define _CAT2(a, b) _CAT(a, b) +#define _EAT(...) +#define _EXPAND(...) __VA_ARGS__ + +/* conditionals */ + +#define _T xxTxx +#define _F xxFxx + +#define _SENTINEL() bogus, _T /* a magic sentinel value */ +#define _IS_SENTINEL(...) _SECOND(__VA_ARGS__, _F) + +#define _IF(cond) _CAT(_IF__, cond) /* _IF(cond)(then)(else) */ +#define _IF__xxTxx(...) __VA_ARGS__ _EAT +#define _IF__xxFxx(...) _EXPAND + +/* high-level functionality */ + +#define YES _SENTINEL() +#define BEGIN_PRIVATE(name) _IF(_IS_SENTINEL(IMPLEMENTATION_FOR_##name))()(struct {) +#define END_PRIVATE(name) _IF(_IS_SENTINEL(IMPLEMENTATION_FOR_##name))()(} _CAT2(_HIDDEN_, __COUNTER__);) + +#endif /* _LIBMISC_CPPUTIL_H_ */ |