ControllerDescription.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @date 2022
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <type_traits>
25 
26 #include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
27 
29 {
30  namespace detail::proxy
31  {
32  template <typename, typename = std::void_t<>>
33  struct has_proxy_type : std::false_type
34  {
35  };
36 
37  // Specialization that checks for the presence of 'Proxy' member.
38  template <typename T>
39  struct has_proxy_type<T, std::void_t<typename T::Proxy>> : std::true_type
40  {
41  };
42 
43  // Helper variable template for easier usage.
44  template <typename T>
45  inline constexpr bool has_proxy_type_v = has_proxy_type<T>::value;
46 
47  // Fallback mechanism using std::conditional_t to safely define ProxyType if it exists
48  template <typename T, bool = has_proxy_type_v<T>>
49  struct ProxyType
50  {
51  using type = typename T::Proxy; // If T has a Proxy type, use it
52  };
53 
54  template <typename T>
55  struct ProxyType<T, false>
56  {
57  using type = armarx::control::ConfigurableNJointControllerInterfacePrx; // Fallback type
58  };
59 
60  // Helper to easily get the type
61  template <typename T>
62  using ProxyType_t = typename ProxyType<T>::type;
63 
64  } // namespace detail::proxy
65 
66  namespace detail::ctrl_class_name
67  {
68  // Check for the existence of 'ctrlConfigClassName' member
69  template <typename, typename = std::void_t<>>
70  struct has_ctrl_config_class_name : std::false_type
71  {
72  };
73 
74  template <typename T>
75  struct has_ctrl_config_class_name<T, std::void_t<decltype(T::ctrlConfigClassName)>> :
76  std::true_type
77  {
78  };
79 
80  template <typename T>
82 
83  // Safe ctrlConfigClassName detection with a fallback to 'name'
84  template <typename T, bool = has_ctrl_config_class_name_v<T>>
86  {
87  static constexpr const char* value =
88  T::ctrlConfigClassName; // If T has ctrlConfigClassName, use it
89  };
90 
91  template <typename T>
92  struct CtrlConfigClassName<T, false>
93  {
94  static constexpr const char* value = T::name; // Fallback to 'name'
95  };
96 
97  template <typename T>
98  inline constexpr const char* CtrlConfigClassName_v = CtrlConfigClassName<T>::value;
99 
100  } // namespace detail::ctrl_class_name
101 
102  template <auto T>
104  {
105  // using AronDTO = 'your aron type';
106  // using Proxy = armarx::control::ConfigurableNJointControllerInterfacePrx;
107  };
108 
109 } // namespace armarx::control::client
armarx::control::client::detail::ctrl_class_name::CtrlConfigClassName_v
constexpr const char * CtrlConfigClassName_v
Definition: ControllerDescription.h:98
armarx::control::client
This file is part of ArmarX.
Definition: ComponentPlugin.cpp:20
armarx::control::client::detail::proxy::ProxyType_t
typename ProxyType< T >::type ProxyType_t
Definition: ControllerDescription.h:62
armarx::control::client::ControllerDescription
Definition: ControllerDescription.h:103
armarx::control::client::detail::ctrl_class_name::CtrlConfigClassName::value
static constexpr const char * value
Definition: ControllerDescription.h:87
armarx::control::client::detail::proxy::ProxyType< T, false >::type
armarx::control::ConfigurableNJointControllerInterfacePrx type
Definition: ControllerDescription.h:57
armarx::control::client::detail::ctrl_class_name::has_ctrl_config_class_name
Definition: ControllerDescription.h:70
armarx::control::client::detail::proxy::has_proxy_type
Definition: ControllerDescription.h:33
armarx::control::client::detail::proxy::has_proxy_type_v
constexpr bool has_proxy_type_v
Definition: ControllerDescription.h:45
armarx::control::client::detail::ctrl_class_name::CtrlConfigClassName
Definition: ControllerDescription.h:85
armarx::control::client::detail::proxy::ProxyType::type
typename T::Proxy type
Definition: ControllerDescription.h:51
armarx::meta::void_t
void void_t
Helper for sfinae (is added in c++17)
Definition: TemplateMetaProgramming.h:59
std
Definition: Application.h:66
armarx::control::client::detail::ctrl_class_name::has_ctrl_config_class_name_v
constexpr bool has_ctrl_config_class_name_v
Definition: ControllerDescription.h:81
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::control::client::detail::proxy::ProxyType
Definition: ControllerDescription.h:49