2 * @file qb/core/Actor.tpp
3 * @brief Template implementation for the Actor class
5 * This file contains the template implementation of the Actor class methods defined
6 * in Actor.h. It provides the actual implementation of event handling, actor creation,
7 * and inter-actor communication mechanisms.
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#include "VirtualCore.h"
26#include "VirtualCore.tpp"
33template <typename _Actor>
35Actor::registerCallback(_Actor &actor) const noexcept {
36 VirtualCore::_handler->registerCallback(actor);
39template <typename _Actor>
41Actor::unregisterCallback(_Actor &actor) const noexcept {
42 VirtualCore::_handler->unregisterCallback(actor.id());
45template <typename _Event, typename _Actor>
47Actor::registerEvent(_Actor &actor) const noexcept {
48 VirtualCore::_handler->registerEvent<_Event>(actor);
51template <typename _Event, typename _Actor>
53Actor::unregisterEvent(_Actor &actor) const noexcept {
54 VirtualCore::_handler->unregisterEvent<_Event>(actor);
57template <typename _Event>
59Actor::unregisterEvent() const noexcept {
60 VirtualCore::_handler->unregisterEvent<_Event>(*this);
63template <typename _Actor, typename... _Args>
65Actor::addRefActor(_Args &&...args) const {
66 return VirtualCore::_handler->template addReferencedActor<_Actor>(
67 std::forward<_Args>(args)...);
70template <typename _Event, typename... _Args>
72Actor::push(ActorId const &dest, _Args &&...args) const noexcept {
73 return VirtualCore::_handler->template push<_Event>(dest, id(),
74 std::forward<_Args>(args)...);
77template <typename _Event, typename... _Args>
79Actor::send(ActorId const &dest, _Args &&...args) const noexcept {
80 VirtualCore::_handler->template send<_Event, _Args...>(dest, id(),
81 std::forward<_Args>(args)...);
84template <typename _Event, typename... _Args>
86Actor::build_event(ActorId const source, _Args &&...args) const noexcept {
87 _Event event{std::forward<_Args>(args)...};
88 VirtualCore::fill_event(event, id(), source);
92template <typename _Required>
94Actor::require_type() const noexcept {
95 broadcast<PingEvent>(type_id<_Required>());
99template <typename... _Types>
101Actor::require() const noexcept {
102 return (require_type<_Types>() && ...);
105template <typename _Event, typename... _Args>
107Actor::broadcast(_Args &&...args) const noexcept {
108 VirtualCore::_handler->template broadcast<_Event, _Args...>(
109 id(), std::forward<_Args>(args)...);
112template <typename Tag>
114Actor::getServiceId(CoreId const index) noexcept {
115 return {VirtualCore::getServices()[type_id<Tag>()], index};
118template <typename _ServiceActor>
120Actor::getService() const noexcept {
121 return VirtualCore::_handler->getService<_ServiceActor>();
124template <typename _Event, typename... _Args>
126Actor::EventBuilder::push(_Args &&...args) noexcept {
127 dest_pipe.push<_Event>(std::forward<_Args>(args)...);
131template <typename Tag>
133Actor::registerIndex() noexcept {
134 return VirtualCore::getServices()[type_id<Tag>()] = ++VirtualCore::_nb_service;