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
operator <<(std::ostream & str,const CharPtr & ptr)43 std::ostream& operator<< (std::ostream& str, const CharPtr& ptr)
44 {
45 if (!ptr.ptr)
46 return str << "(null)";
47 else
48 return str << '"' << ptr.ptr << '"';
49 }
50
getCharPtrStr(const char * ptr)51 inline CharPtr getCharPtrStr (const char* ptr)
52 {
53 return CharPtr(ptr);
54 }
55
56
57 #if (DE_OS == DE_OS_WIN32)
58
59 struct WStr
60 {
61 LPCWSTR wstr;
62
WStrvk::WStr63 WStr (LPCWSTR wstr_) : wstr(wstr_) {}
64 };
65
operator <<(std::ostream & str,const WStr & wstr)66 std::ostream& operator<< (std::ostream& str, const WStr& wstr)
67 {
68 int len = WideCharToMultiByte(CP_UTF8, 0, wstr.wstr, -1, NULL, 0, 0, 0);
69 if (len < 1)
70 return str << "(null)";
71
72 std::string result;
73 result.resize(len + 1);
74 WideCharToMultiByte(CP_UTF8, 0, wstr.wstr, -1, &result[0], len, 0, 0);
75
76 return str << '"' << result << '"';
77 }
78
getWStr(pt::Win32LPCWSTR pt_wstr)79 inline WStr getWStr (pt::Win32LPCWSTR pt_wstr)
80 {
81 return WStr(static_cast<LPCWSTR>(pt_wstr.internal));
82 }
83
84 #else
85
getWStr(pt::Win32LPCWSTR pt_wstr)86 inline CharPtr getWStr (pt::Win32LPCWSTR pt_wstr)
87 {
88 return CharPtr(static_cast<const char*>(pt_wstr.internal));
89 }
90
91 #endif
92
93
94 #include "vkStrUtilImpl.inl"
95
96 } // vk
97