14
14
15
15
#include " controller_interface/chainable_controller_interface.hpp"
16
16
17
+ #include < fmt/compile.h>
18
+
17
19
#include < vector>
18
20
19
21
#include " controller_interface/helpers.hpp"
@@ -62,12 +64,12 @@ ChainableControllerInterface::export_state_interfaces()
62
64
{
63
65
if (interface.get_prefix_name ().find (get_node ()->get_name ()) != 0 )
64
66
{
65
- std::string error_msg =
66
- " The prefix of the interface ' " + interface. get_prefix_name () +
67
- " ' should begin with the controller's name '" + get_node ()-> get_name () +
68
- " '. This is mandatory for state interfaces. No state interface will be exported. Please "
69
- " correct and recompile the controller with name '" +
70
- get_node ()->get_name () + " ' and try again. " ;
67
+ const std::string error_msg = fmt::format (
68
+ FMT_COMPILE (
69
+ " The prefix of the interface '{}' should begin with the controller's name '{}'. "
70
+ " This is mandatory for state interfaces. No state interface will be exported. "
71
+ " Please correct and recompile the controller with name '{}' and try again. " ),
72
+ interface. get_prefix_name (), get_node ()->get_name (), get_node ()-> get_name ()) ;
71
73
throw std::runtime_error (error_msg);
72
74
}
73
75
auto state_interface = std::make_shared<hardware_interface::StateInterface>(interface);
@@ -78,13 +80,13 @@ ChainableControllerInterface::export_state_interfaces()
78
80
// inform cm by throwing exception
79
81
if (!succ)
80
82
{
81
- std::string error_msg =
82
- " Could not insert StateInterface< " + interface_name +
83
- " > into exported_state_interfaces_ map. Check if you export duplicates. The "
84
- " map returned iterator with interface_name<" +
85
- it-> second -> get_name () +
86
- " >. If its a duplicate adjust exportation of InterfacesDescription so that all the "
87
- " interface names are unique. " ;
83
+ std::string error_msg = fmt::format (
84
+ FMT_COMPILE (
85
+ " Could not insert StateInterface<{} > into exported_state_interfaces_ map. "
86
+ " Check if you export duplicates. The map returned iterator with interface_name<{}>. "
87
+ " If its a duplicate adjust exportation of InterfacesDescription so that all the "
88
+ " interface names are unique. " ),
89
+ interface_name, it-> second -> get_name ()) ;
88
90
exported_state_interfaces_.clear ();
89
91
exported_state_interface_names_.clear ();
90
92
state_interfaces_ptrs_vec.clear ();
@@ -98,14 +100,13 @@ ChainableControllerInterface::export_state_interfaces()
98
100
99
101
if (exported_state_interfaces_.size () != state_interfaces.size ())
100
102
{
101
- std::string error_msg =
102
- " The internal storage for state interface ptrs 'exported_state_interfaces_' variable has "
103
- " size '" +
104
- std::to_string (exported_state_interfaces_.size ()) +
105
- " ', but it is expected to have the size '" + std::to_string (state_interfaces.size ()) +
106
- " ' equal to the number of exported reference interfaces. Please correct and recompile the "
107
- " controller with name '" +
108
- get_node ()->get_name () + " ' and try again." ;
103
+ std::string error_msg = fmt::format (
104
+ FMT_COMPILE (
105
+ " The internal storage for state interface ptrs 'exported_state_interfaces_' variable has "
106
+ " size '{}', but it is expected to have the size '{}' equal to the number of exported "
107
+ " reference interfaces. Please correct and recompile the controller with name '{}' and try "
108
+ " again." ),
109
+ exported_state_interfaces_.size (), state_interfaces.size (), get_node ()->get_name ());
109
110
throw std::runtime_error (error_msg);
110
111
}
111
112
@@ -128,13 +129,12 @@ ChainableControllerInterface::export_reference_interfaces()
128
129
// check if the "reference_interfaces_" variable is resized to number of interfaces
129
130
if (reference_interfaces_.size () != reference_interfaces.size ())
130
131
{
131
- std::string error_msg =
132
- " The internal storage for reference values 'reference_interfaces_' variable has size '" +
133
- std::to_string (reference_interfaces_.size ()) + " ', but it is expected to have the size '" +
134
- std::to_string (reference_interfaces.size ()) +
135
- " ' equal to the number of exported reference interfaces. Please correct and recompile the "
136
- " controller with name '" +
137
- get_node ()->get_name () + " ' and try again." ;
132
+ std::string error_msg = fmt::format (
133
+ FMT_COMPILE (
134
+ " The internal storage for reference values 'reference_interfaces_' variable has size '{}', "
135
+ " but it is expected to have the size '{}' equal to the number of exported reference "
136
+ " interfaces. Please correct and recompile the controller with name '{}' and try again." ),
137
+ reference_interfaces_.size (), reference_interfaces.size (), get_node ()->get_name ());
138
138
throw std::runtime_error (error_msg);
139
139
}
140
140
// END
@@ -145,12 +145,12 @@ ChainableControllerInterface::export_reference_interfaces()
145
145
{
146
146
if (interface.get_prefix_name ().find (get_node ()->get_name ()) != 0 )
147
147
{
148
- std::string error_msg = " The prefix of the interface ' " + interface. get_prefix_name () +
149
- " ' should begin with the controller's name ' " +
150
- get_node ()-> get_name () +
151
- " '. This is mandatory for reference interfaces. Please correct and "
152
- " recompile the controller with name '" +
153
- get_node ()->get_name () + " ' and try again. " ;
148
+ std::string error_msg = fmt::format (
149
+ FMT_COMPILE (
150
+ " The prefix of the interface '{}' should begin with the controller's name '{}'. "
151
+ " This is mandatory for reference interfaces. Please correct and recompile the "
152
+ " controller with name '{}' and try again. " ),
153
+ interface. get_prefix_name (), get_node ()->get_name (), get_node ()-> get_name ()) ;
154
154
throw std::runtime_error (error_msg);
155
155
}
156
156
@@ -164,13 +164,13 @@ ChainableControllerInterface::export_reference_interfaces()
164
164
// inform cm by throwing exception
165
165
if (!succ)
166
166
{
167
- std::string error_msg =
168
- " Could not insert Reference interface< " + interface_name +
169
- " > into reference_interfaces_ map. Check if you export duplicates. The "
170
- " map returned iterator with interface_name<" +
171
- it-> second -> get_name () +
172
- " >. If its a duplicate adjust exportation of InterfacesDescription so that all the "
173
- " interface names are unique. " ;
167
+ std::string error_msg = fmt::format (
168
+ FMT_COMPILE (
169
+ " Could not insert Reference interface<{}> into reference_interfaces_ map. "
170
+ " Check if you export duplicates. The map returned iterator with interface_name<{}>. "
171
+ " If its a duplicate adjust exportation of InterfacesDescription so that all the "
172
+ " interface names are unique. " ),
173
+ interface_name, it-> second -> get_name ()) ;
174
174
reference_interfaces_.clear ();
175
175
exported_reference_interface_names_.clear ();
176
176
reference_interfaces_ptrs_vec.clear ();
@@ -183,14 +183,13 @@ ChainableControllerInterface::export_reference_interfaces()
183
183
184
184
if (exported_reference_interfaces_.size () != ref_interface_size)
185
185
{
186
- std::string error_msg =
187
- " The internal storage for exported reference ptrs 'exported_reference_interfaces_' variable "
188
- " has size '" +
189
- std::to_string (exported_reference_interfaces_.size ()) +
190
- " ', but it is expected to have the size '" + std::to_string (ref_interface_size) +
191
- " ' equal to the number of exported reference interfaces. Please correct and recompile the "
192
- " controller with name '" +
193
- get_node ()->get_name () + " ' and try again." ;
186
+ std::string error_msg = fmt::format (
187
+ FMT_COMPILE (
188
+ " The internal storage for exported reference ptrs 'exported_reference_interfaces_' "
189
+ " variable has size '{}', but it is expected to have the size '{}' equal to the number of "
190
+ " exported reference interfaces. Please correct and recompile the controller with name '{}' "
191
+ " and try again." ),
192
+ exported_reference_interfaces_.size (), ref_interface_size, get_node ()->get_name ());
194
193
throw std::runtime_error (error_msg);
195
194
}
196
195
0 commit comments