2 * @file qb/core/Main.tpp
3 * @brief Template implementation for the Main class
5 * This file contains the template implementation of the Main class methods and related
6 * classes defined in Main.h. It provides the actual implementation of actor creation,
7 * core initialization, and system configuration functionality.
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.
27#include "VirtualCore.h"
35template <typename _Actor, typename... _Args>
37CoreInitializer::addActor(_Args &&...args) noexcept {
38 ActorId id = ActorId::NotFound;
39 if constexpr (std::is_base_of_v<Service, _Actor>) {
40 if (_registered_services.find(_Actor::ServiceIndex) ==
41 _registered_services.end()) {
42 _registered_services.insert(_Actor::ServiceIndex);
43 id = ActorId(_Actor::ServiceIndex, _index);
45 LOG_CRIT("[Start Sequence] Failed to add Service Actor("
46 << typeid(_Actor).name() << ")"
47 << " in Core(" << _index << ")"
48 << " : Already registered");
52 if (unlikely(_next_id == std::numeric_limits<ServiceId>::max())) {
53 LOG_CRIT("[Start Sequence] Failed to add Actor("
54 << typeid(_Actor).name() << ")"
55 << " in Core(" << _index << ")"
56 << " : Max number of Actors reached");
59 id = ActorId(_next_id++, _index);
61 _actor_factories.push_back(
62 new TActorFactory<_Actor, _Args...>(id, std::forward<_Args>(args)...));
66template <typename _Actor, typename... _Args>
67CoreInitializer::ActorBuilder &
68CoreInitializer::ActorBuilder::addActor(_Args &&...args) noexcept {
70 _initializer.template addActor<_Actor, _Args...>(std::forward<_Args>(args)...);
74 _ret_ids.push_back(id);
78template <typename _Actor, typename... _Args>
80Main::addActor(CoreId const cid, _Args &&...args) {
81 return core(cid).addActor<_Actor>(std::forward<_Args>(args)...);