xref: /aosp_15_r20/external/deqp/external/vulkancts/framework/vulkan/vkStrUtil.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Pretty-printing and logging utilities.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vkStrUtil.hpp"
25 
26 #if (DE_OS == DE_OS_WIN32)
27 
28 #define WIN32_LEAN_AND_MEAN
29 #include <windows.h>
30 
31 #endif
32 
33 namespace vk
34 {
35 
36 struct CharPtr
37 {
38     const char *ptr;
39 
CharPtrvk::CharPtr40     CharPtr(const char *ptr_) : ptr(ptr_)
41     {
42     }
43 };
44 
operator <<(std::ostream & str,const CharPtr & ptr)45 std::ostream &operator<<(std::ostream &str, const CharPtr &ptr)
46 {
47     if (!ptr.ptr)
48         return str << "(null)";
49     else
50         return str << '"' << ptr.ptr << '"';
51 }
52 
getCharPtrStr(const char * ptr)53 inline CharPtr getCharPtrStr(const char *ptr)
54 {
55     return CharPtr(ptr);
56 }
57 
58 #if (DE_OS == DE_OS_WIN32)
59 
60 struct WStr
61 {
62     LPCWSTR wstr;
63 
WStrvk::WStr64     WStr(LPCWSTR wstr_) : wstr(wstr_)
65     {
66     }
67 };
68 
operator <<(std::ostream & str,const WStr & wstr)69 std::ostream &operator<<(std::ostream &str, const WStr &wstr)
70 {
71     int len = WideCharToMultiByte(CP_UTF8, 0, wstr.wstr, -1, NULL, 0, 0, 0);
72     if (len < 1)
73         return str << "(null)";
74 
75     std::string result;
76     result.resize(len + 1);
77     WideCharToMultiByte(CP_UTF8, 0, wstr.wstr, -1, &result[0], len, 0, 0);
78 
79     return str << '"' << result << '"';
80 }
81 
getWStr(pt::Win32LPCWSTR pt_wstr)82 inline WStr getWStr(pt::Win32LPCWSTR pt_wstr)
83 {
84     return WStr(static_cast<LPCWSTR>(pt_wstr.internal));
85 }
86 
87 #else
88 
getWStr(pt::Win32LPCWSTR pt_wstr)89 inline CharPtr getWStr(pt::Win32LPCWSTR pt_wstr)
90 {
91     return CharPtr(static_cast<const char *>(pt_wstr.internal));
92 }
93 
94 #endif
95 
96 #include "vkStrUtilImpl.inl"
97 
98 } // namespace vk
99