Skip to content

Commit

Permalink
Support enums with symbols that cannot be used in C++ identifiers (e.…
Browse files Browse the repository at this point in the history
…i. backticks)
  • Loading branch information
ilyabelow committed Feb 8, 2024
1 parent c724d94 commit 9e5e698
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions include/daScript/simulate/bind_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
DAS_BASE_BIND_ENUM_CAST(stripped_enum_name##_DasProxy, #enum_name) \
DAS_BASE_BIND_ENUM_CAST(enum_name, #enum_name)

#define DAS_BASE_BIND_ENUM_BOTH(helper, enum_name, das_enum_name, ...) \
class Enumeration##das_enum_name : public das::Enumeration {\
#define DAS_BASE_BIND_ENUM_BOTH(helper, enum_name, das_enum_name, annotation_name, ...) \
class annotation_name : public das::Enumeration {\
public:\
Enumeration##das_enum_name() : das::Enumeration(#das_enum_name) {\
annotation_name() : das::Enumeration(#das_enum_name) {\
external = true;\
cppName = #enum_name; \
baseType = (das::Type) das::ToBasicType< das::underlying_type< enum_name >::type >::type; \
Expand All @@ -60,13 +60,18 @@ public:\
DAS_BASE_BIND_ENUM_FACTORY(enum_name##_DasProxy, #das_enum_name)

#define DAS_BASE_BIND_ENUM(enum_name, das_enum_name, ...) \
DAS_BASE_BIND_ENUM_BOTH(DAS_BIND_ENUM_QUALIFIED_HELPER, enum_name, das_enum_name, __VA_ARGS__)\
DAS_BASE_BIND_ENUM_BOTH(DAS_BIND_ENUM_QUALIFIED_HELPER, enum_name, das_enum_name, Enumeration##das_enum_name, __VA_ARGS__)\
DAS_BASE_BIND_ENUM_FACTORY(enum_name, #das_enum_name)

#define DAS_BASE_BIND_ENUM_98(enum_name, das_enum_name, ...) \
DAS_BASE_BIND_ENUM_BOTH(DAS_BIND_ENUM_QUALIFIED_HELPER, enum_name, das_enum_name, __VA_ARGS__)\
DAS_BASE_BIND_ENUM_BOTH(DAS_BIND_ENUM_QUALIFIED_HELPER, enum_name, das_enum_name, Enumeration##das_enum_name, __VA_ARGS__)\
DAS_BASE_BIND_ENUM_FACTORY(enum_name, #das_enum_name)\
DAS_BASE_BIND_ENUM_FACTORY(das_enum_name##_DasProxy, #das_enum_name)

#define DAS_BASE_BIND_ENUM_IMPL(enum_name, das_enum_name, ...) \
DAS_BASE_BIND_ENUM_BOTH(DAS_BIND_ENUM_QUALIFIED_HELPER, enum_name, das_enum_name, __VA_ARGS__)
DAS_BASE_BIND_ENUM_BOTH(DAS_BIND_ENUM_QUALIFIED_HELPER, enum_name, das_enum_name, Enumeration##das_enum_name, __VA_ARGS__)

// Use this if `das_enum_name` contains symbols that are not valid in C++ identifiers
#define DAS_BASE_BIND_ENUM_SAFE(enum_name, das_enum_name, safe_enum_name, ...) \
DAS_BASE_BIND_ENUM_BOTH(DAS_BIND_ENUM_QUALIFIED_HELPER, enum_name, das_enum_name, Enumeration##safe_enum_name, __VA_ARGS__)\
DAS_BASE_BIND_ENUM_FACTORY(enum_name, #das_enum_name)

0 comments on commit 9e5e698

Please sign in to comment.