Files
TheRock/rocm-libraries/shared/rocroller/lib/include/rocRoller/Serialization/HasTraits.hpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

167 lines
5.3 KiB
C++

// Copyright Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#pragma once
#include <rocRoller/Serialization/Base.hpp>
#include <cstddef>
namespace rocRoller
{
namespace Serialization
{
template <typename T, T>
struct SameType;
template <typename T, typename IO, typename Context = EmptyContext>
concept CMappedType = requires(T& obj, IO& io, Context& ctx)
{
{MappingTraits<T, IO, Context>::mapping(io, obj, ctx)};
};
template <typename T, typename IO, typename Context = EmptyContext>
concept CEmptyMappedType = requires(T& obj, IO& io)
{
{MappingTraits<T, IO, Context>::mapping(io, obj)};
};
template <typename T, typename IO, typename Context = EmptyContext>
struct has_MappingTraits
{
static const bool value = CMappedType<T, IO, Context>;
};
template <typename T, typename IO, typename Context = EmptyContext>
struct has_EmptyMappingTraits
{
static const bool value
= std::same_as<Context, EmptyContext> && CEmptyMappedType<T, IO, Context>;
};
template <typename T, typename IO, typename Context = EmptyContext>
concept EmptyMappedType = has_EmptyMappingTraits<T, IO, Context>::
value && !has_MappingTraits<T, IO, Context>::value;
template <typename T, typename IO>
class has_EnumTraits
{
using enumeration = void (*)(IO&, T&);
template <typename U>
static uint8_t test(SameType<enumeration, &U::enumeration>*);
template <typename U>
static uint32_t test(...);
public:
static const bool value = sizeof(test<EnumTraits<T, IO>>(nullptr)) == 1;
};
template <typename T, typename IO>
concept EnumType = has_EnumTraits<T, IO>::value;
template <typename T>
concept CHasScalarTraits = requires(T const& cval, T& val, std::string const& string)
{
{
ScalarTraits<T>::output(cval)
} -> std::convertible_to<std::string>;
{ScalarTraits<T>::input(string, val)};
};
template <typename T, typename IO>
class has_SequenceTraits
{
using size = size_t (*)(IO&, T&);
template <typename U>
static uint8_t test(SameType<size, &U::size>*);
template <typename u>
static uint32_t test(...);
public:
static const bool value = sizeof(test<SequenceTraits<T, IO>>(nullptr)) == 1;
};
template <typename T, typename IO>
concept SequenceType = has_SequenceTraits<T, IO>::value;
template <typename T, typename IO>
class has_CustomMappingTraits
{
using inputOne = void (*)(IO&, std::string const&, T&);
using output = void (*)(IO&, T&);
template <typename U>
static uint8_t test(SameType<inputOne, &U::inputOne>*, SameType<output, &U::output>*);
template <typename u>
static uint32_t test(...);
public:
static const bool value
= sizeof(test<CustomMappingTraits<T, IO>>(nullptr, nullptr)) == 1;
};
template <typename T, typename IO>
concept CustomMappingType = has_CustomMappingTraits<T, IO>::value;
template <typename T, typename IO>
struct has_SerializationTraits
{
static const bool value0
= has_EmptyMappingTraits<T, IO>::value || has_MappingTraits<T, IO>::value;
static const bool value1 = has_EnumTraits<T, IO>::value;
static const bool value2 = has_SequenceTraits<T, IO>::value;
static const bool value3 = has_CustomMappingTraits<T, IO>::value;
static const bool value4 = CHasScalarTraits<T>;
static const int count = value0 + value1 + value2 + value3 + value4;
static_assert(count == 0 || count == 1, "Ambiguous serialization!");
static const bool value = value0 || value1 || value2 || value3 || value4;
};
template <typename T, typename IO, typename Context = EmptyContext>
concept SerializableType = has_SerializationTraits<T, IO>::value;
template <typename T, typename IO, typename Context = EmptyContext>
concept ValueType = !has_SerializationTraits<T, IO>::value;
template <typename T>
concept CHasFlowMember = requires
{
// clang-format off
{ T::flow } -> std::convertible_to<bool>;
// clang-format on
};
template <typename T>
struct HasFlowValue
{
static const bool flow = false;
};
template <CHasFlowMember T>
struct HasFlowValue<T>
{
static const bool flow = T::flow;
};
/**
* Concept that will match a type that has a static `flow` member which is true. It will
* not match a type that has no such member, nor will it match if that member is set to
* false. It will also not cause an error if it's tested against a type that has no such
* member.
*/
template <typename T>
concept CHasFlow = HasFlowValue<T>::flow;
} // namespace Serialization
} // namespace rocRoller