-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace enum_long by 'enum class' #868
Comments
Switching to strongly-typed enum classes already pays off. Background: vAmiga utilizes multiple so-called register change recorders to maintain pending register changes. A struct RegChangeRecorder : public util::SortedRingBuffer<RegChange, capacity>
struct RegChange : Serializable
{
u32 addr;
u16 value;
u16 accessor;
} With the benefit of strongly typed enum classes, the compiler now complains that I use the RegChange recorders inconsistently. I.e., Agnus stores enums of type I introduced enum RegChangeID : i32
{
SET_NONE,
…
SET_INTREQ,
SET_INTENA,
SET_BPLCON0_AGNUS,
SET_BPLCON0_DENISE,
…
} TODO: Trash the |
Accomplished. My old work-around to access enums on the Swift side is no longer needed: /* The following macros 'enum_<type>' provide a way to make enumerations
* easily accessible in Swift. All macros have two definitions, one for the
* Swift side and one for the C side. Please note that the type mapping for
* enum_long differs on both sides. On the Swift side, enums of this type are
* mapped to 'long enums' to make them accessible via the Swift standard type
* 'Int'. On the C side all enums are mapped to 'enum-less longs' to make them
* easily serializable.
*/
#if defined(__SWIFT__)
// Definition for Swift
#define enum_generic(_name, _type) \
typedef enum __attribute__((enum_extensibility(open))) _name : _type _name; \
enum _name : _type
// #define enum_long(_name) enum_generic(_name, long)
#define enum_i8(_name) enum_generic(_name, i8)
#else
// Definition for C
#define enum_generic(_name, _type) \
typedef _type _name; \
enum : _type
// #define enum_long(_name) enum_generic(_name, long)
#define enum_i8(_name) enum_generic(_name, i8)
#endif enum classes are mapped perfectly out of the box. |
Background: For most enum-like types, vAmiga defines a C-style enum together with a xxxEnum class that allows some kind of reflection support. The xxxEnum classes are utilizes at various places both on the C++ side and the Swift side to translate textual descriptions (e.g. those coming from RetroShell command) into enums and vice versa. A type declaration typically looks like this:
Starting with vAmiga 3.3, Swift/C++ interoperability will be enabled, that is, Swift understands C++ syntax. Thus, we can replace the enum part by this:
Pros:
The text was updated successfully, but these errors were encountered: