From 105dce4477b617ebf2a23fd7e6680569e5da3ddb Mon Sep 17 00:00:00 2001 From: Andrew Cox Date: Sat, 18 Nov 2023 02:16:04 +0000 Subject: [PATCH] Stripped Out More ToASCII Vintage JSON Code This include the ObjectToString template. --- framework/util/CMakeLists.txt | 2 - framework/util/custom_common_to_string.cpp | 48 ------- framework/util/custom_common_to_string.h | 43 ------ framework/util/to_string.cpp | 18 --- framework/util/to_string.h | 154 +-------------------- 5 files changed, 3 insertions(+), 262 deletions(-) delete mode 100644 framework/util/custom_common_to_string.cpp delete mode 100644 framework/util/custom_common_to_string.h diff --git a/framework/util/CMakeLists.txt b/framework/util/CMakeLists.txt index ef3f9e1917..18a536d092 100644 --- a/framework/util/CMakeLists.txt +++ b/framework/util/CMakeLists.txt @@ -96,8 +96,6 @@ target_sources(gfxrecon_util ${CMAKE_CURRENT_LIST_DIR}/to_string.cpp ${CMAKE_CURRENT_LIST_DIR}/options.h ${CMAKE_CURRENT_LIST_DIR}/options.cpp - ${CMAKE_CURRENT_LIST_DIR}/custom_common_to_string.h - ${CMAKE_CURRENT_LIST_DIR}/custom_common_to_string.cpp ${CMAKE_SOURCE_DIR}/framework/generated/generated_vulkan_enum_to_string.h ${CMAKE_SOURCE_DIR}/framework/generated/generated_vulkan_enum_to_string.cpp $<$:${CMAKE_CURRENT_LIST_DIR}/xcb_loader.h> diff --git a/framework/util/custom_common_to_string.cpp b/framework/util/custom_common_to_string.cpp deleted file mode 100644 index e37c5d99d4..0000000000 --- a/framework/util/custom_common_to_string.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -** Copyright (c) 2022 Advanced Micro Devices, Inc. -** -** Permission is hereby granted, free of charge, to any person obtaining a -** copy of this software and associated documentation files (the "Software"), -** to deal in the Software without restriction, including without limitation -** the rights to use, copy, modify, merge, publish, distribute, sublicense, -** and/or sell copies of the Software, and to permit persons to whom the -** Software is furnished to do so, subject to the following conditions: -** -** The above copyright notice and this permission notice shall be included in -** all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -** DEALINGS IN THE SOFTWARE. -*/ - -#include "custom_common_to_string.h" - -#include - -GFXRECON_BEGIN_NAMESPACE(gfxrecon) -GFXRECON_BEGIN_NAMESPACE(util) - -// clang-format off - -template <> -std::string ToString(const SECURITY_ATTRIBUTES& obj, ToStringFlags toStringFlags, uint32_t tabCount, uint32_t tabSize) -{ - return ObjectToString(toStringFlags, tabCount, tabSize, - [&](std::ostringstream& strStrm) - { - FieldToString(strStrm, true, "nLength", toStringFlags, tabCount, tabSize, ToString(obj.nLength, toStringFlags, tabCount, tabSize)); - FieldToString(strStrm, false, "lpSecurityDescriptor", toStringFlags, tabCount, tabSize, Quote(PtrToString(obj.lpSecurityDescriptor))); - FieldToString(strStrm, false, "bInheritHandle", toStringFlags, tabCount, tabSize, ToString(obj.bInheritHandle, toStringFlags, tabCount, tabSize)); - } - ); -} - -// clang-format on - -GFXRECON_END_NAMESPACE(util) -GFXRECON_END_NAMESPACE(gfxrecon) diff --git a/framework/util/custom_common_to_string.h b/framework/util/custom_common_to_string.h deleted file mode 100644 index 5aea075d73..0000000000 --- a/framework/util/custom_common_to_string.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -** Copyright (c) 2022 Advanced Micro Devices, Inc. -** -** Permission is hereby granted, free of charge, to any person obtaining a -** copy of this software and associated documentation files (the "Software"), -** to deal in the Software without restriction, including without limitation -** the rights to use, copy, modify, merge, publish, distribute, sublicense, -** and/or sell copies of the Software, and to permit persons to whom the -** Software is furnished to do so, subject to the following conditions: -** -** The above copyright notice and this permission notice shall be included in -** all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -** DEALINGS IN THE SOFTWARE. -*/ - -#ifndef GFXRECON_CUSTOM_COMMON_TO_STRING_H -#define GFXRECON_CUSTOM_COMMON_TO_STRING_H - -#include "format/platform_types.h" -#include "util/to_string.h" - -#include - -GFXRECON_BEGIN_NAMESPACE(gfxrecon) -GFXRECON_BEGIN_NAMESPACE(util) - -template <> -std::string ToString(const SECURITY_ATTRIBUTES& obj, - ToStringFlags toStringFlags, - uint32_t tabCount, - uint32_t tabSize); - -GFXRECON_END_NAMESPACE(util) -GFXRECON_END_NAMESPACE(gfxrecon) - -#endif // GFXRECON_CUSTOM_COMMON_TO_STRING_H diff --git a/framework/util/to_string.cpp b/framework/util/to_string.cpp index 3762b86bf4..b95f57f351 100644 --- a/framework/util/to_string.cpp +++ b/framework/util/to_string.cpp @@ -36,23 +36,5 @@ std::string uuid_to_string(uint32_t size, const uint8_t* uuid) return stream.str(); } -void FieldToString(std::ostringstream& strStrm, - bool firstField, - const char* fieldName, - ToStringFlags toStringFlags, - uint32_t tabCount, - uint32_t tabSize, - const std::string& fieldString) -{ - if (!firstField) - { - strStrm << ',' << GetNewlineString(toStringFlags); - } - strStrm << GetTabString(toStringFlags, tabCount, tabSize); - strStrm << "\"" << fieldName << "\":"; - strStrm << GetWhitespaceString(toStringFlags); - strStrm << fieldString; -} - GFXRECON_END_NAMESPACE(util) GFXRECON_END_NAMESPACE(gfxrecon) \ No newline at end of file diff --git a/framework/util/to_string.h b/framework/util/to_string.h index 10e20caffc..cd3a18dc48 100644 --- a/framework/util/to_string.h +++ b/framework/util/to_string.h @@ -33,7 +33,6 @@ #include #include #include -#include GFXRECON_BEGIN_NAMESPACE(gfxrecon) GFXRECON_BEGIN_NAMESPACE(util) @@ -97,7 +96,7 @@ inline std::string ToString(const T& obj, /// function specializations since a caller has to explicitly spell out a type /// to call one of them and there is no function resolution based on argument /// types going on. -/// @todo This may not be necessary: try deleting it. +/// @todo This may not be necessary: try deleting it after #1321 lands. template inline std::string ToString(uint32_t apiFlags, ToStringFlags toStringFlags = kToString_Default, @@ -112,27 +111,6 @@ inline std::string ToString(uint32_t apiFlags, return "0"; } -template -inline std::string HandleIdToString(HandleIdType handleId) -{ - std::ostringstream strStrm; - if (handleId) - { - strStrm << "\"0x" << reinterpret_cast(handleId) << "\""; - } - else - { - strStrm << "\"NULL\""; - } - return strStrm.str(); -} - -template <> -inline std::string HandleIdToString(format::HandleId handleId) -{ - return std::to_string(handleId); -} - #if defined(WIN32) inline std::string WCharArrayToString(const wchar_t* pStr) { @@ -160,6 +138,7 @@ inline std::string WCharArrayToString(const wchar_t* pStr) } #endif +/// Widely used in Vulkan and DX12 enum to string functions. template inline std::string BitmaskToString(FlagsType flags) { @@ -185,35 +164,8 @@ inline std::string BitmaskToString(FlagsType flags) return str; } -template -inline std::string PtrToString(PtrType* ptr) -{ - return to_hex_variable_width(reinterpret_cast(ptr)); -} - -template -inline std::string PtrToString(PtrType ptr) -{ - return to_hex_variable_width(ptr); -} - -inline std::string GetNewlineString(ToStringFlags toStringFlags) -{ - return (toStringFlags & kToString_Formatted) ? std::string("\n") : std::string(); -} - -inline std::string GetWhitespaceString(ToStringFlags toStringFlags, uint32_t count = 1) -{ - return (toStringFlags & kToString_Formatted) ? std::string((size_t)count, ' ') : std::string(); -} - -inline std::string -GetTabString(ToStringFlags toStringFlags, uint32_t tabCount, uint32_t tabSize = kToStringDefaultTabSize) -{ - return GetWhitespaceString(toStringFlags, tabCount * tabSize); -} - /// @brief Make a copy of the input string with double quotes at start and end. +/// @note Dead code only used in its unit test. Keep _just in case_? inline std::string Quote(const std::string& str) { std::string quoted{ '"' }; @@ -222,106 +174,6 @@ inline std::string Quote(const std::string& str) return quoted; } -/// @brief Create the opening and closing braces of a JSON object: calling a function -/// to fill out the internal fields of the object. -/// By convention the functions which convert structs will be called ToString and -/// will call FieldToString() to format each field and another ToString, -/// ArrayToString(), etc. to form the nested structure or the immediate value of -/// the field. -/// @deprecated Use the nlohmann JSON library instead. -template -inline std::string -ObjectToString(ToStringFlags toStringFlags, uint32_t& tabCount, uint32_t tabSize, ToStringFunctionType toStringFunction) -{ - std::ostringstream strStrm; - const auto nl = GetNewlineString(toStringFlags); - strStrm << '{'; - strStrm << nl; - ++tabCount; - toStringFunction(strStrm); - --tabCount; - strStrm << nl; - strStrm << GetTabString(toStringFlags, tabCount, tabSize); - strStrm << '}'; - return strStrm.str(); -} - -/// Part of a system for formatting fields of structs and arguments of functions -/// as JSON text strings. -/// @deprecated Use the nlohmann JSON library instead. -void FieldToString(std::ostringstream& strStrm, - bool firstField, - const char* fieldName, - ToStringFlags toStringFlags, - uint32_t tabCount, - uint32_t tabSize, - const std::string& fieldString); - -template -inline std::string ArrayToString(size_t count, - const ObjectType* pObjs, - ToStringFlags toStringFlags, - uint32_t tabCount, - uint32_t tabSize, - ValidateArrayFunctionType validateArrayFunction, - ToStringFunctionType toStringFunction) -{ - if (!(count && validateArrayFunction())) - { - return "null"; - } - - std::ostringstream strStrm; - strStrm << '['; - strStrm << GetNewlineString(toStringFlags); - for (uint32_t i = 0; i < count; ++i) - { - if (i) - { - strStrm << ',' << GetNewlineString(toStringFlags); - } - strStrm << GetTabString(toStringFlags, tabCount + 1, tabSize) << toStringFunction(i); - } - strStrm << GetNewlineString(toStringFlags) << GetTabString(toStringFlags, tabCount, tabSize); - strStrm << ']'; - return strStrm.str(); -} - -template -inline std::string ArrayToString(size_t count, - const T* pObjs, - ToStringFlags toStringFlags = kToString_Default, - uint32_t tabCount = kToStringDefaultTabCount, - uint32_t tabSize = kToStringDefaultTabSize) -{ - return ArrayToString( - count, - pObjs, - toStringFlags, - tabCount, - tabSize, - [&]() { return pObjs != nullptr; }, - [&](size_t i) { return ToString(pObjs[i], toStringFlags, tabCount + 1, tabSize); }); -} - -template -inline std::string EnumArrayToString(size_t count, - const EnumType* pObjs, - util::ToStringFlags toStringFlags = util::kToString_Default, - uint32_t tabCount = kToStringDefaultTabCount, - uint32_t tabSize = kToStringDefaultTabSize) -{ - using namespace util; - return ArrayToString( - count, - pObjs, - toStringFlags, - tabCount, - tabSize, - [&]() { return pObjs != nullptr; }, - [&](size_t i) { return Quote(ToString(pObjs[i])); }); -} - GFXRECON_END_NAMESPACE(util) GFXRECON_END_NAMESPACE(gfxrecon)