Skip to content

Commit

Permalink
feat: Prevent macros from leaking into user code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tradias committed Apr 7, 2024
1 parent 5dc7945 commit 9314fe5
Show file tree
Hide file tree
Showing 119 changed files with 408 additions and 205 deletions.
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ ForEachMacros:
- foreach
IncludeBlocks: Regroup
IncludeCategories:
# epilogue
- Regex: 'agrpc/detail/epilogue\.hpp'
Priority: 5
SortPriority: 0
CaseSensitive: false
# config
- Regex: 'agrpc/detail/(config|awaitable|asio_macros)\.hpp'
Priority: 4
SortPriority: 0
CaseSensitive: false
# Headers in <> without extension.
- Regex: '<([A-Za-z0-9\Q/-_\E])+>'
Priority: 3
Expand Down
2 changes: 0 additions & 2 deletions example/helper/one_shot_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#ifndef AGRPC_HELPER_ONE_SHOT_ALLOCATOR_HPP
#define AGRPC_HELPER_ONE_SHOT_ALLOCATOR_HPP

#include <agrpc/detail/config.hpp>

#include <cassert>
#include <cstddef>
#include <utility>
Expand Down
1 change: 1 addition & 0 deletions example/snippets/alarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "helper.hpp"

#include <agrpc/asio_grpc.hpp>
#include <boost/asio/bind_allocator.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/use_awaitable.hpp>
Expand Down
5 changes: 4 additions & 1 deletion src/agrpc/alarm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

#include <agrpc/detail/alarm.hpp>
#include <agrpc/detail/asio_forward.hpp>
#include <agrpc/detail/config.hpp>
#include <agrpc/detail/default_completion_token.hpp>
#include <agrpc/detail/grpc_sender.hpp>
#include <agrpc/detail/initiate_sender_implementation.hpp>
#include <agrpc/detail/query_grpc_context.hpp>
#include <agrpc/grpc_executor.hpp>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

/**
Expand Down Expand Up @@ -175,4 +176,6 @@ using Alarm = agrpc::BasicAlarm<agrpc::GrpcExecutor>;

AGRPC_NAMESPACE_END

#include <agrpc/detail/epilogue.hpp>

#endif // AGRPC_AGRPC_ALARM_HPP
5 changes: 4 additions & 1 deletion src/agrpc/client_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#include <agrpc/detail/asio_forward.hpp>
#include <agrpc/detail/client_rpc_base.hpp>
#include <agrpc/detail/client_rpc_sender.hpp>
#include <agrpc/detail/config.hpp>
#include <agrpc/detail/default_completion_token.hpp>
#include <agrpc/detail/forward.hpp>
#include <agrpc/detail/initiate_sender_implementation.hpp>
#include <agrpc/detail/name.hpp>
#include <agrpc/detail/rpc_type.hpp>
#include <agrpc/grpc_executor.hpp>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down Expand Up @@ -1179,4 +1180,6 @@ using GenericStreamingClientRPC = agrpc::ClientRPC<agrpc::ClientRPCType::GENERIC

AGRPC_NAMESPACE_END

#include <agrpc/detail/epilogue.hpp>

#endif // AGRPC_AGRPC_CLIENT_RPC_HPP
2 changes: 2 additions & 0 deletions src/agrpc/default_server_rpc_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ struct DefaultServerRPCTraits

AGRPC_NAMESPACE_END

#include <agrpc/detail/epilogue.hpp>

#endif // AGRPC_AGRPC_DEFAULT_SERVER_RPC_TRAITS_HPP
4 changes: 3 additions & 1 deletion src/agrpc/detail/alarm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#ifndef AGRPC_DETAIL_ALARM_HPP
#define AGRPC_DETAIL_ALARM_HPP

#include <agrpc/detail/config.hpp>
#include <agrpc/detail/forward.hpp>
#include <agrpc/detail/grpc_sender.hpp>
#include <agrpc/detail/sender_implementation.hpp>

#include <agrpc/detail/asio_macros.hpp>
#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
4 changes: 2 additions & 2 deletions src/agrpc/detail/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#ifndef AGRPC_DETAIL_ALGORITHM_HPP
#define AGRPC_DETAIL_ALGORITHM_HPP

#include <agrpc/detail/config.hpp>

#include <iterator>
#include <utility>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
3 changes: 2 additions & 1 deletion src/agrpc/detail/allocate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
#ifndef AGRPC_DETAIL_ALLOCATE_HPP
#define AGRPC_DETAIL_ALLOCATE_HPP

#include <agrpc/detail/config.hpp>
#include <agrpc/detail/utility.hpp>

#include <memory>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
3 changes: 2 additions & 1 deletion src/agrpc/detail/allocate_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#include <agrpc/detail/allocate.hpp>
#include <agrpc/detail/allocation_type.hpp>
#include <agrpc/detail/association.hpp>
#include <agrpc/detail/config.hpp>
#include <agrpc/detail/grpc_context_implementation.hpp>
#include <agrpc/detail/utility.hpp>
#include <agrpc/grpc_context.hpp>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
50 changes: 8 additions & 42 deletions src/agrpc/detail/asio_forward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
#ifndef AGRPC_DETAIL_ASIO_FORWARD_HPP
#define AGRPC_DETAIL_ASIO_FORWARD_HPP

#include <agrpc/detail/config.hpp>
#include <agrpc/detail/asio_macros.hpp>

#ifdef AGRPC_STANDALONE_ASIO
//
#include <asio/version.hpp>
//
#include <asio/associated_allocator.hpp>
#include <asio/associated_executor.hpp>
#include <asio/async_result.hpp>
Expand All @@ -35,32 +32,15 @@
#include <asio/query.hpp>
#include <asio/system_executor.hpp>

#if (ASIO_VERSION >= 101900)
#ifdef AGRPC_ASIO_HAS_CANCELLATION_SLOT
#include <asio/associated_cancellation_slot.hpp>
#include <asio/bind_cancellation_slot.hpp>

#define AGRPC_ASIO_HAS_CANCELLATION_SLOT
#endif

#if (ASIO_VERSION >= 102201)
#include <asio/bind_allocator.hpp>

#define AGRPC_ASIO_HAS_BIND_ALLOCATOR
#endif

#if (ASIO_VERSION >= 102400)
#define AGRPC_ASIO_HAS_NEW_SPAWN
#endif

#if (ASIO_VERSION >= 102700)
#ifdef AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR
#include <asio/associated_immediate_executor.hpp>

#define AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR
#endif
#elif defined(AGRPC_BOOST_ASIO)
//
#include <boost/version.hpp>
//
#include <boost/asio/associated_allocator.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/async_result.hpp>
Expand All @@ -75,34 +55,20 @@
#include <boost/asio/query.hpp>
#include <boost/asio/system_executor.hpp>

#if (BOOST_VERSION >= 107700)
#ifdef AGRPC_ASIO_HAS_CANCELLATION_SLOT
#include <boost/asio/associated_cancellation_slot.hpp>
#include <boost/asio/bind_cancellation_slot.hpp>

#define AGRPC_ASIO_HAS_CANCELLATION_SLOT
#endif

#if (BOOST_VERSION >= 107900)
#include <boost/asio/bind_allocator.hpp>

#define AGRPC_ASIO_HAS_BIND_ALLOCATOR
#endif

#if (BOOST_VERSION >= 108000)
#define AGRPC_ASIO_HAS_NEW_SPAWN
#endif

#if (BOOST_VERSION >= 108200)
#ifdef AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR
#include <boost/asio/associated_immediate_executor.hpp>

#define AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR
#endif
#endif

#if defined(AGRPC_UNIFEX) || defined(AGRPC_STDEXEC)
#else
#include <system_error>
#endif

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

#ifdef AGRPC_STANDALONE_ASIO
Expand Down
48 changes: 48 additions & 0 deletions src/agrpc/detail/asio_macros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2023 Dennis Hezel
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#if !defined(AGRPC_ASIO_HAS_CANCELLATION_SLOT) && !defined(AGRPC_ASIO_HAS_NEW_SPAWN) && \
!defined(AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR)

#ifdef AGRPC_STANDALONE_ASIO // standalone Asio
#include <asio/version.hpp>

#if (ASIO_VERSION >= 101900)
#define AGRPC_ASIO_HAS_CANCELLATION_SLOT
#endif

#if (ASIO_VERSION >= 102400)
#define AGRPC_ASIO_HAS_NEW_SPAWN
#endif

#if (ASIO_VERSION >= 102700)
#define AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR
#endif
#elif defined(AGRPC_BOOST_ASIO) // Boost.Asio
#include <boost/version.hpp>

#if (BOOST_VERSION >= 107700)
#define AGRPC_ASIO_HAS_CANCELLATION_SLOT
#endif

#if (BOOST_VERSION >= 108000)
#define AGRPC_ASIO_HAS_NEW_SPAWN
#endif

#if (BOOST_VERSION >= 108200)
#define AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR
#endif
#endif

#endif
4 changes: 3 additions & 1 deletion src/agrpc/detail/asio_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#define AGRPC_DETAIL_ASIO_UTILS_HPP

#include <agrpc/detail/asio_forward.hpp>
#include <agrpc/detail/config.hpp>
#include <agrpc/detail/execution.hpp>

#include <agrpc/detail/asio_macros.hpp>
#include <agrpc/detail/config.hpp>

#if defined(AGRPC_STANDALONE_ASIO) || defined(AGRPC_BOOST_ASIO)

AGRPC_NAMESPACE_BEGIN()
Expand Down
3 changes: 2 additions & 1 deletion src/agrpc/detail/association_asio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
#define AGRPC_DETAIL_ASSOCIATION_ASIO_HPP

#include <agrpc/detail/asio_utils.hpp>
#include <agrpc/detail/config.hpp>
#include <agrpc/detail/execution.hpp>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
3 changes: 2 additions & 1 deletion src/agrpc/detail/association_execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
#ifndef AGRPC_DETAIL_ASSOCIATION_EXECUTION_HPP
#define AGRPC_DETAIL_ASSOCIATION_EXECUTION_HPP

#include <agrpc/detail/config.hpp>
#include <agrpc/detail/execution.hpp>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
4 changes: 3 additions & 1 deletion src/agrpc/detail/atomic_bool_stop_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
#define AGRPC_DETAIL_ATOMIC_BOOL_STOP_CONTEXT_HPP

#include <agrpc/detail/association.hpp>
#include <agrpc/detail/config.hpp>
#include <agrpc/detail/execution.hpp>
#include <agrpc/detail/forward.hpp>
#include <agrpc/detail/stop_callback_lifetime.hpp>

#include <atomic>

#include <agrpc/detail/asio_macros.hpp>
#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
3 changes: 2 additions & 1 deletion src/agrpc/detail/atomic_intrusive_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#ifndef AGRPC_DETAIL_ATOMIC_INTRUSIVE_QUEUE_HPP
#define AGRPC_DETAIL_ATOMIC_INTRUSIVE_QUEUE_HPP

#include <agrpc/detail/config.hpp>
#include <agrpc/detail/intrusive_queue.hpp>

#include <atomic>
#include <utility>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
5 changes: 2 additions & 3 deletions src/agrpc/detail/awaitable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef AGRPC_DETAIL_AWAITABLE_HPP
#define AGRPC_DETAIL_AWAITABLE_HPP
#ifndef AGRPC_ASIO_HAS_CO_AWAIT

#ifdef AGRPC_STANDALONE_ASIO
#include <asio/use_awaitable.hpp>
Expand All @@ -33,4 +32,4 @@
#endif
#endif

#endif // AGRPC_DETAIL_AWAITABLE_HPP
#endif
3 changes: 2 additions & 1 deletion src/agrpc/detail/backoff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#ifndef AGRPC_DETAIL_BACKOFF_HPP
#define AGRPC_DETAIL_BACKOFF_HPP

#include <agrpc/detail/config.hpp>
#include <agrpc/detail/math.hpp>

#include <chrono>
#include <cstdint>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
3 changes: 2 additions & 1 deletion src/agrpc/detail/basic_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <agrpc/detail/allocation_type.hpp>
#include <agrpc/detail/association.hpp>
#include <agrpc/detail/config.hpp>
#include <agrpc/detail/deallocate_on_complete.hpp>
#include <agrpc/detail/execution.hpp>
#include <agrpc/detail/forward.hpp>
Expand All @@ -30,6 +29,8 @@
#include <agrpc/detail/utility.hpp>
#include <agrpc/grpc_context.hpp>

#include <agrpc/detail/config.hpp>

AGRPC_NAMESPACE_BEGIN()

namespace detail
Expand Down
Loading

0 comments on commit 9314fe5

Please sign in to comment.