2 * @file qb/core/Pipe.tpp
3 * @brief Template implementation for the Pipe class
5 * This file contains the template implementation of the Pipe class methods defined
6 * in Pipe.h. It provides the actual implementation of event construction and pushing
7 * through the communication channel between actors.
9 * @author qb - C++ Actor Framework
10 * @copyright Copyright (c) 2011-2025 qb - isndev (cpp.actor)
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
25#ifndef QB_PROXYPIPE_TPL
26#define QB_PROXYPIPE_TPL
30template <typename T, typename... _Args>
32Pipe::push(_Args &&...args) const noexcept {
33 constexpr std::size_t BUCKET_SIZE = allocator::getItemSize<T, EventBucket>();
34 auto &data = pipe->template allocate_back<T>(std::forward<_Args>(args)...);
35 data.id = data.template type_to_id<T>();
38 if constexpr (std::is_base_of_v<ServiceEvent, T>) {
39 data.forward = source;
40 std::swap(data.id, data.service_event_id);
43 data.bucket_size = BUCKET_SIZE;
47template <typename T, typename... _Args>
49Pipe::allocated_push(std::size_t size, _Args &&...args) const noexcept {
51 size = size / sizeof(EventBucket) + static_cast<bool>(size % sizeof(EventBucket));
52 auto &data = *(new (reinterpret_cast<T *>(pipe->allocate_back(size)))
53 T(std::forward<_Args>(args)...));
55 data.id = data.template type_to_id<T>();
58 if constexpr (std::is_base_of_v<ServiceEvent, T>) {
59 data.forward = source;
60 std::swap(data.id, data.service_event_id);
63 data.bucket_size = static_cast<uint16_t>(size);
69#endif // QB_PROXYPIPE_TPL