From 7ff738390e55d57a0f513c467a9da3b08c6902ab Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 29 Oct 2024 01:02:02 -0600 Subject: Add a way to make private object members --- libmisc/include/libmisc/private.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 libmisc/include/libmisc/private.h (limited to 'libmisc/include') 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 + * 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_ */ -- cgit v1.2.3-2-g168b