Skip to content

Commit

Permalink
Add Variant debug browser (for convinient value observe value in a de…
Browse files Browse the repository at this point in the history
…bugger)
  • Loading branch information
SergeyRyabinin committed Feb 26, 2024
1 parent f483a55 commit a3bcf58
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions include/aws/crt/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ namespace Aws
static const bool value = ContainsType<T, Ts...>();
};
} // namespace Checker
#if defined(DEBUG_BUILD)
namespace VariantDebug
{
template <typename... Ts> class VariantDebugBrowser
{
public:
VariantDebugBrowser(char *storage) { InitTuple<0, Ts...>(storage); }
std::tuple<typename std::add_pointer<Ts>::type...> as_tuple;

private:
template <short Index, typename First, typename Second, typename... Rest>
void InitTuple(char *storage)
{
First *value = reinterpret_cast<First *>(storage);
std::get<Index>(as_tuple) = value;
InitTuple<Index + 1, Second, Rest...>(storage);
}

template <short Index, typename Last> void InitTuple(char *storage)
{
Last *value = reinterpret_cast<Last *>(storage);
std::get<Index>(as_tuple) = value;
}
};
} // namespace VariantDebug
#endif /* defined(DEBUG_BUILD) */
} // namespace VariantDetail

template <std::size_t Index, typename... Ts> class VariantAlternative;
Expand Down Expand Up @@ -366,6 +392,9 @@ namespace Aws

alignas(VariantDetail::ParameterPackSize::AlignAsPack<Ts...>()) char m_storage[STORAGE_SIZE];
VariantDetail::Index::VariantIndex m_index = -1;
#if defined(DEBUG_BUILD)
VariantDetail::VariantDebug::VariantDebugBrowser<Ts...> browser = m_storage;
#endif /* defined(DEBUG_BUILD) */

void Destroy()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ if(AWS_WARNINGS_ARE_ERRORS)
endif()
endif()

target_compile_definitions(${TEST_BINARY_NAME} PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD>)

add_custom_command(TARGET ${TEST_BINARY_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/resources $<TARGET_FILE_DIR:${TEST_BINARY_NAME}>)

0 comments on commit a3bcf58

Please sign in to comment.