Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
thread_type_selector.h
Go to the documentation of this file.
1// Copyright 2019-2022:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Goby Underwater Autonomy Project Libraries
9// ("The Goby Libraries").
10//
11// The Goby Libraries are free software: you can redistribute them and/or modify
12// them under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// The Goby Libraries are distributed in the hope that they will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with Goby. If not, see <http://www.gnu.org/licenses/>.
23
24#ifndef GOBY_MIDDLEWARE_APPLICATION_DETAIL_THREAD_TYPE_SELECTOR_H
25#define GOBY_MIDDLEWARE_APPLICATION_DETAIL_THREAD_TYPE_SELECTOR_H
26
27#include <memory>
28
29namespace goby
30{
31namespace middleware
32{
33namespace detail
34{
36template <typename ThreadType, typename ThreadConfig, bool has_index, bool has_config>
38{
39};
40
42template <typename ThreadType, typename ThreadConfig>
43struct ThreadTypeSelector<ThreadType, ThreadConfig, false, true>
44{
45 static std::shared_ptr<ThreadType> thread(const ThreadConfig& cfg, int index = -1)
46 {
47 return std::make_shared<ThreadType>(cfg);
48 };
49};
50
52template <typename ThreadType, typename ThreadConfig>
53struct ThreadTypeSelector<ThreadType, ThreadConfig, true, true>
54{
55 static std::shared_ptr<ThreadType> thread(const ThreadConfig& cfg, int index)
56 {
57 return std::make_shared<ThreadType>(cfg, index);
58 };
59};
60
62template <typename ThreadType, typename ThreadConfig>
63struct ThreadTypeSelector<ThreadType, ThreadConfig, false, false>
64{
65 static std::shared_ptr<ThreadType> thread(const ThreadConfig& cfg, int index = -1)
66 {
67 return std::make_shared<ThreadType>();
68 };
69};
70
72template <typename ThreadType, typename ThreadConfig>
73struct ThreadTypeSelector<ThreadType, ThreadConfig, true, false>
74{
75 static std::shared_ptr<ThreadType> thread(const ThreadConfig& cfg, int index)
76 {
77 return std::make_shared<ThreadType>(index);
78 };
79};
80
81} // namespace detail
82} // namespace middleware
83} // namespace goby
84
85#endif
detail namespace with internal helper functions
Definition json.hpp:247
The global namespace for the Goby project.
static std::shared_ptr< ThreadType > thread(const ThreadConfig &cfg, int index=-1)
static std::shared_ptr< ThreadType > thread(const ThreadConfig &cfg, int index=-1)
static std::shared_ptr< ThreadType > thread(const ThreadConfig &cfg, int index)
static std::shared_ptr< ThreadType > thread(const ThreadConfig &cfg, int index)
Selects which constructor to use based on whether the thread is launched with an index or not (that i...