Flutter Engine
The Flutter Engine
shell
platform
embedder
embedder_struct_macros.h
Go to the documentation of this file.
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_
6
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_
7
8
#include <type_traits>
9
10
// Checks if the given struct contains a member, whether set or not.
11
#define STRUCT_HAS_MEMBER(pointer, member) \
12
((offsetof(std::remove_pointer<decltype(pointer)>::type, member) + \
13
sizeof(pointer->member) <= \
14
pointer->struct_size))
15
16
#define SAFE_ACCESS(pointer, member, default_value) \
17
([=]() { \
18
if (STRUCT_HAS_MEMBER(pointer, member)) { \
19
return pointer->member; \
20
} \
21
return static_cast<decltype(pointer->member)>((default_value)); \
22
})()
23
24
/// Checks if the member exists and is non-null.
25
#define SAFE_EXISTS(pointer, member) \
26
(SAFE_ACCESS(pointer, member, nullptr) != nullptr)
27
28
/// Checks if exactly one of member1 or member2 exists and is non-null.
29
#define SAFE_EXISTS_ONE_OF(pointer, member1, member2) \
30
(SAFE_EXISTS(pointer, member1) != SAFE_EXISTS(pointer, member2))
31
32
#endif
// FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_
Generated on Sun Jun 23 2024 21:55:14 for Flutter Engine by
1.9.4