| 1 |
#if 0 |
| 2 |
DEF PLATFORM_UNIX = 0 |
| 3 |
DEF PLATFORM_WIN = 0 |
| 4 |
DEF X11 = 0 |
| 5 |
DEF M_32 = 0 |
| 6 |
#endif |
| 7 |
|
| 8 |
|
| 9 |
#include <cstdarg> |
| 10 |
#include <cstdint> |
| 11 |
#include <cstdlib> |
| 12 |
#include <ostream> |
| 13 |
#include <new> |
| 14 |
|
| 15 |
#if (defined(PLATFORM_WIN) || defined(M_32)) |
| 16 |
enum class BarType : uint32_t { |
| 17 |
A, |
| 18 |
B, |
| 19 |
C, |
| 20 |
}; |
| 21 |
#endif |
| 22 |
|
| 23 |
#if (defined(PLATFORM_UNIX) && defined(X11)) |
| 24 |
enum class FooType : uint32_t { |
| 25 |
A, |
| 26 |
B, |
| 27 |
C, |
| 28 |
}; |
| 29 |
#endif |
| 30 |
|
| 31 |
#if (defined(PLATFORM_UNIX) && defined(X11)) |
| 32 |
struct FooHandle { |
| 33 |
FooType ty; |
| 34 |
int32_t x; |
| 35 |
float y; |
| 36 |
|
| 37 |
bool operator==(const FooHandle& other) const { |
| 38 |
return ty == other.ty && |
| 39 |
x == other.x && |
| 40 |
y == other.y; |
| 41 |
} |
| 42 |
bool operator!=(const FooHandle& other) const { |
| 43 |
return ty != other.ty || |
| 44 |
x != other.x || |
| 45 |
y != other.y; |
| 46 |
} |
| 47 |
}; |
| 48 |
#endif |
| 49 |
|
| 50 |
union C { |
| 51 |
enum class Tag : uint8_t { |
| 52 |
C1, |
| 53 |
C2, |
| 54 |
#if defined(PLATFORM_WIN) |
| 55 |
C3, |
| 56 |
#endif |
| 57 |
#if defined(PLATFORM_UNIX) |
| 58 |
C5, |
| 59 |
#endif |
| 60 |
}; |
| 61 |
|
| 62 |
#if defined(PLATFORM_UNIX) |
| 63 |
struct C5_Body { |
| 64 |
Tag tag; |
| 65 |
int32_t int_; |
| 66 |
|
| 67 |
bool operator==(const C5_Body& other) const { |
| 68 |
return int_ == other.int_; |
| 69 |
} |
| 70 |
bool operator!=(const C5_Body& other) const { |
| 71 |
return int_ != other.int_; |
| 72 |
} |
| 73 |
}; |
| 74 |
#endif |
| 75 |
|
| 76 |
struct { |
| 77 |
Tag tag; |
| 78 |
}; |
| 79 |
#if defined(PLATFORM_UNIX) |
| 80 |
C5_Body c5; |
| 81 |
#endif |
| 82 |
|
| 83 |
static C C1() { |
| 84 |
C result; |
| 85 |
result.tag = Tag::C1; |
| 86 |
return result; |
| 87 |
} |
| 88 |
|
| 89 |
bool IsC1() const { |
| 90 |
return tag == Tag::C1; |
| 91 |
} |
| 92 |
|
| 93 |
static C C2() { |
| 94 |
C result; |
| 95 |
result.tag = Tag::C2; |
| 96 |
return result; |
| 97 |
} |
| 98 |
|
| 99 |
bool IsC2() const { |
| 100 |
return tag == Tag::C2; |
| 101 |
} |
| 102 |
|
| 103 |
#if defined(PLATFORM_WIN) |
| 104 |
static C C3() { |
| 105 |
C result; |
| 106 |
result.tag = Tag::C3; |
| 107 |
return result; |
| 108 |
} |
| 109 |
|
| 110 |
bool IsC3() const { |
| 111 |
return tag == Tag::C3; |
| 112 |
} |
| 113 |
#endif |
| 114 |
|
| 115 |
#if defined(PLATFORM_UNIX) |
| 116 |
static C C5(const int32_t &int_) { |
| 117 |
C result; |
| 118 |
::new (&result.c5.int_) (int32_t)(int_); |
| 119 |
result.tag = Tag::C5; |
| 120 |
return result; |
| 121 |
} |
| 122 |
|
| 123 |
bool IsC5() const { |
| 124 |
return tag == Tag::C5; |
| 125 |
} |
| 126 |
#endif |
| 127 |
|
| 128 |
bool operator==(const C& other) const { |
| 129 |
if (tag != other.tag) { |
| 130 |
return false; |
| 131 |
} |
| 132 |
switch (tag) { |
| 133 |
#if defined(PLATFORM_UNIX) |
| 134 |
case Tag::C5: return c5 == other.c5; |
| 135 |
#endif |
| 136 |
default: break; |
| 137 |
} |
| 138 |
return true; |
| 139 |
} |
| 140 |
|
| 141 |
bool operator!=(const C& other) const { |
| 142 |
return !(*this == other); |
| 143 |
} |
| 144 |
|
| 145 |
private: |
| 146 |
C() { |
| 147 |
|
| 148 |
} |
| 149 |
public: |
| 150 |
|
| 151 |
|
| 152 |
~C() { |
| 153 |
switch (tag) { |
| 154 |
#if defined(PLATFORM_UNIX) |
| 155 |
case Tag::C5: c5.~C5_Body(); break; |
| 156 |
#endif |
| 157 |
default: break; |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
C(const C& other) |
| 162 |
: tag(other.tag) { |
| 163 |
switch (tag) { |
| 164 |
#if defined(PLATFORM_UNIX) |
| 165 |
case Tag::C5: ::new (&c5) (C5_Body)(other.c5); break; |
| 166 |
#endif |
| 167 |
default: break; |
| 168 |
} |
| 169 |
} |
| 170 |
C& operator=(const C& other) { |
| 171 |
if (this != &other) { |
| 172 |
this->~C(); |
| 173 |
new (this) C(other); |
| 174 |
} |
| 175 |
return *this; |
| 176 |
} |
| 177 |
}; |
| 178 |
|
| 179 |
#if (defined(PLATFORM_WIN) || defined(M_32)) |
| 180 |
struct BarHandle { |
| 181 |
BarType ty; |
| 182 |
int32_t x; |
| 183 |
float y; |
| 184 |
|
| 185 |
bool operator==(const BarHandle& other) const { |
| 186 |
return ty == other.ty && |
| 187 |
x == other.x && |
| 188 |
y == other.y; |
| 189 |
} |
| 190 |
bool operator!=(const BarHandle& other) const { |
| 191 |
return ty != other.ty || |
| 192 |
x != other.x || |
| 193 |
y != other.y; |
| 194 |
} |
| 195 |
}; |
| 196 |
#endif |
| 197 |
|
| 198 |
struct ConditionalField { |
| 199 |
#if defined(X11) |
| 200 |
int32_t field |
| 201 |
#endif |
| 202 |
; |
| 203 |
}; |
| 204 |
|
| 205 |
extern "C" { |
| 206 |
|
| 207 |
#if (defined(PLATFORM_UNIX) && defined(X11)) |
| 208 |
void root(FooHandle a, C c); |
| 209 |
#endif |
| 210 |
|
| 211 |
#if (defined(PLATFORM_WIN) || defined(M_32)) |
| 212 |
void root(BarHandle a, C c); |
| 213 |
#endif |
| 214 |
|
| 215 |
void cond(ConditionalField a); |
| 216 |
|
| 217 |
} // extern "C" |