Goby3  3.1.5a
2024.05.23
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 
29 namespace goby
30 {
31 namespace middleware
32 {
33 namespace detail
34 {
36 template <typename ThreadType, typename ThreadConfig, bool has_index, bool has_config>
38 {
39 };
40 
42 template <typename ThreadType, typename ThreadConfig>
43 struct 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 
52 template <typename ThreadType, typename ThreadConfig>
53 struct 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 
62 template <typename ThreadType, typename ThreadConfig>
63 struct 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 
72 template <typename ThreadType, typename ThreadConfig>
73 struct 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
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
detail
detail namespace with internal helper functions
Definition: json.hpp:246
goby::middleware::detail::ThreadTypeSelector< ThreadType, ThreadConfig, false, false >::thread
static std::shared_ptr< ThreadType > thread(const ThreadConfig &cfg, int index=-1)
Definition: thread_type_selector.h:65
goby::middleware::detail::ThreadTypeSelector
Selects which constructor to use based on whether the thread is launched with an index or not (that i...
Definition: thread_type_selector.h:37
goby::middleware::detail::ThreadTypeSelector< ThreadType, ThreadConfig, false, true >::thread
static std::shared_ptr< ThreadType > thread(const ThreadConfig &cfg, int index=-1)
Definition: thread_type_selector.h:45
goby::middleware::detail::ThreadTypeSelector< ThreadType, ThreadConfig, true, true >::thread
static std::shared_ptr< ThreadType > thread(const ThreadConfig &cfg, int index)
Definition: thread_type_selector.h:55
goby::middleware::detail::ThreadTypeSelector< ThreadType, ThreadConfig, true, false >::thread
static std::shared_ptr< ThreadType > thread(const ThreadConfig &cfg, int index)
Definition: thread_type_selector.h:75