qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
Pipe.tpp
1/**
2 * @file qb/core/Pipe.tpp
3 * @brief Template implementation for the Pipe class
4 *
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.
8 *
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
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
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.
22 * @ingroup Core
23 */
24
25#ifndef QB_PROXYPIPE_TPL
26#define QB_PROXYPIPE_TPL
27
28namespace qb {
29
30template <typename T, typename... _Args>
31T &
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>();
36 data.dest = dest;
37 data.source = source;
38 if constexpr (std::is_base_of_v<ServiceEvent, T>) {
39 data.forward = source;
40 std::swap(data.id, data.service_event_id);
41 }
42
43 data.bucket_size = BUCKET_SIZE;
44 return data;
45}
46
47template <typename T, typename... _Args>
48T &
49Pipe::allocated_push(std::size_t size, _Args &&...args) const noexcept {
50 size += sizeof(T);
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)...));
54
55 data.id = data.template type_to_id<T>();
56 data.dest = dest;
57 data.source = source;
58 if constexpr (std::is_base_of_v<ServiceEvent, T>) {
59 data.forward = source;
60 std::swap(data.id, data.service_event_id);
61 }
62
63 data.bucket_size = static_cast<uint16_t>(size);
64 return data;
65}
66
67} // namespace qb
68
69#endif // QB_PROXYPIPE_TPL