Derive-C
Loading...
Searching...
No Matches
ref.h File Reference

Go to the source code of this file.

Macros

#define DC_TRAIT_REFERENCABLE(SELF)
 The reference trait. For some objects references do not need to be the size of pointers.
#define DC_TRAIT_REFERENCABLE_BY_PTR(SELF)
#define DC_TRAIT_REFERENCABLE_SINGLETON(SELF, INSTANCE)

Macro Definition Documentation

◆ DC_TRAIT_REFERENCABLE

#define DC_TRAIT_REFERENCABLE ( SELF)
Value:
DC_STATIC_ASSERT(sizeof(NS(SELF, ref)) <= sizeof(SELF*), \
"Reference type must be at most pointer sized"); \
DC_REQUIRE_METHOD(SELF*, NS(SELF, ref), deref, (NS(SELF, ref)))
#define SELF
Definition def.h:52
#define NS(pre, post)
Definition namespace.h:14
#define DC_REQUIRE_TYPE(obj, name)
Definition require.h:25

The reference trait. For some objects references do not need to be the size of pointers.

  • For singletons an empty struct is sufficient
  • For a small (global) pool of objects, a smaller index can be used.

These are convertable to pointers for ease of use, but use less storage when stored.

Definition at line 13 of file ref.h.

13#define DC_TRAIT_REFERENCABLE(SELF) \
14 DC_REQUIRE_TYPE(SELF, ref); \
15 DC_STATIC_ASSERT(sizeof(NS(SELF, ref)) <= sizeof(SELF*), \
16 "Reference type must be at most pointer sized"); \
17 DC_REQUIRE_METHOD(SELF*, NS(SELF, ref), deref, (NS(SELF, ref)))

◆ DC_TRAIT_REFERENCABLE_BY_PTR

#define DC_TRAIT_REFERENCABLE_BY_PTR ( SELF)
Value:
typedef SELF* NS(SELF, ref); \
DC_PUBLIC static SELF* NS(NS(SELF, ref), deref)(NS(SELF, ref) ref) { return ref; } \
DC_TRAIT_REFERENCABLE(SELF)
#define DC_PUBLIC
Definition namespace.h:25

Definition at line 19 of file ref.h.

19#define DC_TRAIT_REFERENCABLE_BY_PTR(SELF) \
20 typedef SELF* NS(SELF, ref); \
21 DC_PUBLIC static SELF* NS(NS(SELF, ref), deref)(NS(SELF, ref) ref) { return ref; } \
22 DC_TRAIT_REFERENCABLE(SELF)

◆ DC_TRAIT_REFERENCABLE_SINGLETON

#define DC_TRAIT_REFERENCABLE_SINGLETON ( SELF,
INSTANCE )
Value:
DC_ZERO_SIZED(NS(SELF, ref)); \
DC_PUBLIC static NS(SELF, ref) NS(SELF, get_ref)() { return (NS(SELF, ref)){}; } \
DC_PUBLIC static SELF* NS(NS(SELF, ref), deref)(NS(SELF, ref) /*ref*/) { return &INSTANCE; } \
DC_TRAIT_REFERENCABLE(SELF)
#define DC_ZERO_SIZED(TYPE)
Zero sized types are useful as markers (e.g. for gdb printing, or to replace debug info structs.
Definition zerosized.h:11

Definition at line 24 of file ref.h.

24#define DC_TRAIT_REFERENCABLE_SINGLETON(SELF, INSTANCE) \
25 DC_ZERO_SIZED(NS(SELF, ref)); \
26 DC_PUBLIC static NS(SELF, ref) NS(SELF, get_ref)() { return (NS(SELF, ref)){}; } \
27 DC_PUBLIC static SELF* NS(NS(SELF, ref), deref)(NS(SELF, ref) /*ref*/) { return &INSTANCE; } \
28 DC_TRAIT_REFERENCABLE(SELF)