Skip to content

Commit bb7a96b

Browse files
committed
fix(platform): avoid macro-prone platform factory names
1 parent bbab69b commit bb7a96b

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

include/vix/ui/platform/Platform.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,42 +103,45 @@ namespace vix::ui
103103
*
104104
* @return Web platform.
105105
*/
106-
[[nodiscard]] static Platform web() noexcept;
106+
[[nodiscard]] static Platform web_platform_descriptor() noexcept;
107107

108108
/**
109109
* @brief Create a Linux platform descriptor.
110110
*
111+
* The name intentionally avoids `linux` because some toolchains expose
112+
* it as a preprocessor macro.
113+
*
111114
* @return Linux platform.
112115
*/
113-
[[nodiscard]] static Platform linux() noexcept;
116+
[[nodiscard]] static Platform linux_platform() noexcept;
114117

115118
/**
116119
* @brief Create a Windows platform descriptor.
117120
*
118121
* @return Windows platform.
119122
*/
120-
[[nodiscard]] static Platform windows() noexcept;
123+
[[nodiscard]] static Platform windows_platform() noexcept;
121124

122125
/**
123126
* @brief Create a macOS platform descriptor.
124127
*
125128
* @return macOS platform.
126129
*/
127-
[[nodiscard]] static Platform macos() noexcept;
130+
[[nodiscard]] static Platform macos_platform() noexcept;
128131

129132
/**
130133
* @brief Create an Android platform descriptor.
131134
*
132135
* @return Android platform.
133136
*/
134-
[[nodiscard]] static Platform android() noexcept;
137+
[[nodiscard]] static Platform android_platform() noexcept;
135138

136139
/**
137140
* @brief Create an iOS platform descriptor.
138141
*
139142
* @return iOS platform.
140143
*/
141-
[[nodiscard]] static Platform ios() noexcept;
144+
[[nodiscard]] static Platform ios_platform() noexcept;
142145

143146
/**
144147
* @brief Get the concrete platform kind.

src/platform/Platform.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,32 @@ namespace vix::ui
112112
#endif
113113
}
114114

115-
Platform Platform::web() noexcept
115+
Platform Platform::web_platform_descriptor() noexcept
116116
{
117117
return Platform(PlatformKind::Web);
118118
}
119119

120-
Platform Platform::linux() noexcept
120+
Platform Platform::linux_platform() noexcept
121121
{
122122
return Platform(PlatformKind::Linux);
123123
}
124124

125-
Platform Platform::windows() noexcept
125+
Platform Platform::windows_platform() noexcept
126126
{
127127
return Platform(PlatformKind::Windows);
128128
}
129129

130-
Platform Platform::macos() noexcept
130+
Platform Platform::macos_platform() noexcept
131131
{
132132
return Platform(PlatformKind::MacOS);
133133
}
134134

135-
Platform Platform::android() noexcept
135+
Platform Platform::android_platform() noexcept
136136
{
137137
return Platform(PlatformKind::Android);
138138
}
139139

140-
Platform Platform::ios() noexcept
140+
Platform Platform::ios_platform() noexcept
141141
{
142142
return Platform(PlatformKind::IOS);
143143
}

tests/shell/app_shell_test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ static void test_platform_family_to_string()
4747

4848
static void test_platform_desktop()
4949
{
50-
Platform linux = Platform::linux();
51-
Platform windows = Platform::windows();
52-
Platform macos = Platform::macos();
50+
Platform linux = Platform::linux_platform();
51+
Platform windows = Platform::windows_platform();
52+
Platform macos = Platform::macos_platform();
5353

5454
assert(linux.known());
5555
assert(windows.known());
@@ -70,8 +70,8 @@ static void test_platform_desktop()
7070

7171
static void test_platform_mobile()
7272
{
73-
Platform android = Platform::android();
74-
Platform ios = Platform::ios();
73+
Platform android = Platform::android_platform();
74+
Platform ios = Platform::ios_platform();
7575

7676
assert(android.known());
7777
assert(ios.known());
@@ -88,7 +88,7 @@ static void test_platform_mobile()
8888

8989
static void test_platform_web()
9090
{
91-
Platform web = Platform::web();
91+
Platform web = Platform::web_platform_descriptor();
9292

9393
assert(web.known());
9494
assert(web.web_platform());
@@ -152,7 +152,7 @@ static void test_shell_config_setters()
152152
.set_url("http://localhost:3000")
153153
.set_host("0.0.0.0")
154154
.set_port(9090)
155-
.set_platform(Platform::web())
155+
.set_platform(Platform::web_platform_descriptor())
156156
.set_width(1280)
157157
.set_height(720)
158158
.set_resizable(false)
@@ -454,7 +454,7 @@ static void test_app_shell_restart()
454454
static void test_app_shell_platform()
455455
{
456456
ShellConfig config;
457-
config.set_platform(Platform::web());
457+
config.set_platform(Platform::web_platform_descriptor());
458458

459459
AppShell shell(config);
460460

0 commit comments

Comments
 (0)