diff --git a/sources.cmake b/sources.cmake index 927d453..4c67bce 100644 --- a/sources.cmake +++ b/sources.cmake @@ -29,6 +29,7 @@ dplx_target_sources(deeppack dp/fwd dp/indefinite_range dp/layout_descriptor + dp/macros dp/object_def dp/tuple_def diff --git a/src/dplx/dp/macros.hpp b/src/dplx/dp/macros.hpp new file mode 100644 index 0000000..73fea13 --- /dev/null +++ b/src/dplx/dp/macros.hpp @@ -0,0 +1,31 @@ + +// Copyright Henrik Steffen Gaßmann 2021. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#pragma once + +#include + +// NOLINTBEGIN(modernize-macro-to-enum) +// NOLINTBEGIN(cppcoreguidelines-macro-usage) + +#define DPLX_DP_DECLARE_CODEC_SIMPLE(_fq_type) \ + template <> \ + class dplx::dp::codec<_fq_type> \ + { \ + using value_type = _fq_type; \ + \ + public: \ + static auto size_of(emit_context &ctx, _fq_type const &value) noexcept \ + -> std::uint64_t; \ + static auto encode(emit_context &ctx, _fq_type const &value) noexcept \ + -> result; \ + static auto decode(parse_context &ctx, _fq_type &outValue) noexcept \ + -> result; \ + } + +// NOLINTEND(cppcoreguidelines-macro-usage) +// NOLINTEND(modernize-macro-to-enum) diff --git a/src/dplx/dp/macros.test.cpp b/src/dplx/dp/macros.test.cpp new file mode 100644 index 0000000..1023a69 --- /dev/null +++ b/src/dplx/dp/macros.test.cpp @@ -0,0 +1,24 @@ + +// Copyright Henrik Steffen Gaßmann 2021. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#include + +namespace dp_tests +{ + +namespace +{ + +class custom_type +{ +}; + +} // namespace + +} // namespace dp_tests + +DPLX_DP_DECLARE_CODEC_SIMPLE(dp_tests::custom_type);