20#ifndef WG14_RESULT_STATUS_CODE_H
21#define WG14_RESULT_STATUS_CODE_H
32#pragma warning(disable : 4996)
37#define STATUS_CODE_WITH_PAYLOAD(name) \
38 struct WG14_RESULT_PREFIX(status_code_with_payload_##name)
44#define STATUS_CODE_WITH_PAYLOAD_DECLARE(T, name) \
45 struct WG14_RESULT_PREFIX(status_code_with_payload_##name) \
47 WG14_RESULT_PREFIX(status_code_untyped) base; \
50 WG14_RESULT_INLINE struct WG14_RESULT_PREFIX( \
51 status_code_with_payload_##name) \
52 WG14_RESULT_PREFIX(status_code_with_payload_##name##_make)(T val) \
54 struct WG14_RESULT_PREFIX(status_code_with_payload_##name) \
55 ret = {{&name##_domain}, val}; \
59#define STATUS_CODE_WITH_PAYLOAD_MAKE(name, ...) \
60 WG14_RESULT_PREFIX(status_code_with_payload_##name##_make)(__VA_ARGS__)
96 struct WG14_RESULT_PREFIX(status_code_domain_vtable_message_args) args;
97 memset(&args, 0,
sizeof(args));
108 return WG14_RESULT_PREFIX(status_code_domain_string_ref_from_static_string)(
144 struct WG14_RESULT_PREFIX(status_code_domain_vtable_payload_info_args)
146 memset(&args, 0,
sizeof(args));
147 args.domain = r->domain;
161 WG14_RESULT_PREFIX(status_code_erased_destroy)(dest);
172#define status_code_is_empty(...) \
173 WG14_RESULT_PREFIX(status_code_is_empty)(&(__VA_ARGS__).base)
175#define status_code_is_success(...) \
176 WG14_RESULT_PREFIX(status_code_is_success)(&(__VA_ARGS__).base)
178#define status_code_is_failure(...) \
179 WG14_RESULT_PREFIX(status_code_is_failure)(&(__VA_ARGS__).base)
183#define status_code_message(...) \
184 WG14_RESULT_PREFIX(status_code_message)(&(__VA_ARGS__).base)
190#define status_code_strictly_equivalent(primary, secondary) \
191 WG14_RESULT_PREFIX(status_code_strictly_equivalent) \
192 (&(primary).base, &(secondary).base)
194#define status_code_destroy(...) \
196 typedef WG14_RESULT_TYPEOF_UNQUAL(*(__VA_ARGS__)) \
197 WG14_RESULT_PREFIX(_code_type_); \
198 WG14_RESULT_PREFIX(_code_type_) * WG14_RESULT_PREFIX(_code_ptr_) = \
199 (WG14_RESULT_PREFIX(_code_type_) *) (&(*(__VA_ARGS__))); \
200 if(WG14_RESULT_PREFIX(_code_ptr_)->base.domain != WG14_RESULT_NULLPTR && \
201 WG14_RESULT_PREFIX(_code_ptr_)->base.domain->vptr->erased_destroy != \
202 WG14_RESULT_NULLPTR) \
204 typedef WG14_RESULT_TYPEOF(WG14_RESULT_PREFIX(_code_ptr_)->value) \
205 WG14_RESULT_PREFIX(_value_type_); \
206 const WG14_RESULT_PREFIX(status_code_domain_payload_info_t) \
207 WG14_RESULT_PREFIX(_info_) = \
208 STATUS_CODE_DOMAIN_PAYLOAD_INFO_INIT(WG14_RESULT_PREFIX(_value_type_)); \
209 WG14_RESULT_VTABLE_INVOKE_API( \
210 WG14_RESULT_PREFIX(_code_ptr_)->base.domain, erased_destroy, \
211 &WG14_RESULT_PREFIX(_code_ptr_)->base, WG14_RESULT_PREFIX(_info_)); \
212 WG14_RESULT_PREFIX(_code_ptr_)->base.domain = WG14_RESULT_NULLPTR; \
215#if !defined(_MSC_VER) || defined(__clang__)
217#pragma GCC diagnostic push
218#pragma GCC diagnostic ignored "-Wpedantic"
221#define status_code_clone(dest, src) \
223 typedef WG14_RESULT_TYPEOF(*(dest)) WG14_RESULT_PREFIX(_dest_code_type_); \
224 typedef WG14_RESULT_TYPEOF(*(src)) WG14_RESULT_PREFIX(_src_code_type_); \
225 WG14_RESULT_PREFIX(_dest_code_type_) * \
226 WG14_RESULT_PREFIX(_dest_code_ptr_) = \
227 (WG14_RESULT_PREFIX(_dest_code_type_) *) (&(*(dest))); \
228 WG14_RESULT_PREFIX(_src_code_type_) * WG14_RESULT_PREFIX(_src_code_ptr_) = \
229 (WG14_RESULT_PREFIX(_src_code_type_) *) (&(*(src))); \
230 typedef WG14_RESULT_TYPEOF(WG14_RESULT_PREFIX(_dest_code_ptr_)->value) \
231 WG14_RESULT_PREFIX(_dest_value_type_); \
232 status_code_destroy(_dest_code_ptr_); \
233 int WG14_RESULT_PREFIX(ret) = 0; \
234 if(WG14_RESULT_PREFIX(_src_code_ptr_)->base.domain != WG14_RESULT_NULLPTR) \
236 const WG14_RESULT_PREFIX(status_code_domain_payload_info_t) \
237 WG14_RESULT_PREFIX(_info_) = STATUS_CODE_DOMAIN_PAYLOAD_INFO_INIT( \
238 WG14_RESULT_PREFIX(_dest_value_type_)); \
239 WG14_RESULT_PREFIX(ret) = WG14_RESULT_VTABLE_INVOKE_API( \
240 WG14_RESULT_PREFIX(_src_code_ptr_)->base.domain, erased_copy, \
241 &WG14_RESULT_PREFIX(_dest_code_ptr_)->base, \
242 &WG14_RESULT_PREFIX(_src_code_ptr_)->base, WG14_RESULT_PREFIX(_info_)); \
244 WG14_RESULT_PREFIX(ret); \
247#pragma GCC diagnostic pop
#define WG14_RESULT_NULLPTR
#define WG14_RESULT_INLINE
#define WG14_RESULT_ABORTF(...)
#define status_code_is_empty(...)
True if the status code is empty (convenience macro)
#define status_code_is_failure(...)
True if the status code is a failure (convenience macro)
#define status_code_message(...)
Retrieves the message of the status code (convenience macro). Make sure you call status_code_domain_s...
#define status_code_is_success(...)
True if the status code is a success (convenience macro)
#define status_code_strictly_equivalent(primary, secondary)
True if the status codes are strictly semantically equivalent (convenience macro)....
#define WG14_RESULT_VTABLE_INVOKE_API(domain, name,...)
Type of a payload info of a domain.
Type of a string ref of a domain.
Type of an untyped status code.