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 namespace vk
27 {
28
29 struct CharPtr
30 {
31 const char* ptr;
32
CharPtrvk::CharPtr33 CharPtr (const char* ptr_) : ptr(ptr_) {}
34 };
35
operator <<(std::ostream & str,const CharPtr & ptr)36 std::ostream& operator<< (std::ostream& str, const CharPtr& ptr)
37 {
38 if (!ptr.ptr)
39 return str << "(null)";
40 else
41 return str << '"' << ptr.ptr << '"';
42 }
43
getCharPtrStr(const char * ptr)44 inline CharPtr getCharPtrStr (const char* ptr)
45 {
46 return CharPtr(ptr);
47 }
48
49
50 #if (DE_OS == DE_OS_WIN32)
51
52 #define WIN32_LEAN_AND_MEAN
53 #include <windows.h>
54
55 struct WStr
56 {
57 LPCWSTR wstr;
58
WStrvk::WStr59 WStr (LPCWSTR wstr_) : wstr(wstr_) {}
60 };
61
operator <<(std::ostream & str,const WStr & wstr)62 std::ostream& operator<< (std::ostream& str, const WStr& wstr)
63 {
64 int len = WideCharToMultiByte(CP_UTF8, 0, wstr.wstr, -1, NULL, 0, 0, 0);
65 if (len < 1)
66 return str << "(null)";
67
68 std::string result;
69 result.resize(len + 1);
70 WideCharToMultiByte(CP_UTF8, 0, wstr.wstr, -1, &result[0], len, 0, 0);
71
72 return str << '"' << result << '"';
73 }
74
getWStr(pt::Win32LPCWSTR pt_wstr)75 inline WStr getWStr (pt::Win32LPCWSTR pt_wstr)
76 {
77 return WStr(static_cast<LPCWSTR>(pt_wstr.internal));
78 }
79
80 #else
81
getWStr(pt::Win32LPCWSTR pt_wstr)82 inline CharPtr getWStr (pt::Win32LPCWSTR pt_wstr)
83 {
84 return CharPtr(static_cast<const char*>(pt_wstr.internal));
85 }
86
87 #endif
88
89
90 #include "vkStrUtilImpl.inl"
91
92 } // vk
93