VTK  9.7.20260913
vtkWebGPUHelpersPrivate.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef vtkWebGPUHelpersPrivate_h
5#define vtkWebGPUHelpersPrivate_h
6
7#include "vtk_wgpu.h"
8#include <string>
9
10// Helper function for converting WGPUStringView to std::string.
11// This is used internally by WebGPU implementations.
12inline std::string vtkWebGPUStringViewToStdString(WGPUStringView sv)
13{
14 if (sv.length == WGPU_STRLEN)
15 {
16 if (sv.data == nullptr)
17 {
18 return {};
19 }
20 return { sv.data };
21 }
22 return { sv.data, sv.length };
23}
24
25// Helper function for constructing a WGPUStringView that borrows a std::string's
26// storage. The returned view is only valid while the string is alive.
27inline WGPUStringView vtkWebGPUMakeStringView(const std::string& str)
28{
29 return WGPUStringView{ str.data(), str.size() };
30}
31
32#endif
std::string vtkWebGPUStringViewToStdString(WGPUStringView sv)
WGPUStringView vtkWebGPUMakeStringView(const std::string &str)