1
- #ifndef BT_BASIC_TYPES_H
2
- #define BT_BASIC_TYPES_H
1
+ #pragma once
3
2
4
3
#include < iostream>
5
4
#include < vector>
@@ -70,7 +69,7 @@ using StringView = std::string_view;
70
69
*
71
70
* If you have a custom type, you need to implement the corresponding template specialization.
72
71
*/
73
- template <typename T>
72
+ template <typename T> [[nodiscard]]
74
73
inline T convertFromString (StringView /* str*/ )
75
74
{
76
75
auto type_name = BT::demangle (typeid (T));
@@ -145,13 +144,13 @@ inline StringConverter GetAnyFromStringFunctor<void>()
145
144
146
145
// ------------------------------------------------------------------
147
146
148
- template <typename T>
147
+ template <typename T> [[nodiscard]]
149
148
std::string toStr (T value)
150
149
{
151
150
return std::to_string (value);
152
151
}
153
152
154
- std::string toStr (std::string value);
153
+ std::string toStr (const std::string& value);
155
154
156
155
template <>
157
156
std::string toStr<BT::NodeStatus>(BT::NodeStatus status);
@@ -166,17 +165,18 @@ std::ostream& operator<<(std::ostream& os, const BT::NodeStatus& status);
166
165
/* *
167
166
* @brief toStr converts NodeType to string.
168
167
*/
169
- template <>
168
+ template <> [[nodiscard]]
170
169
std::string toStr<BT::NodeType>(BT::NodeType type);
171
170
172
171
std::ostream& operator <<(std::ostream& os, const BT::NodeType& type);
173
172
174
- template <>
173
+ template <> [[nodiscard]]
175
174
std::string toStr<BT::PortDirection>(BT::PortDirection direction);
176
175
177
176
std::ostream& operator <<(std::ostream& os, const BT::PortDirection& type);
178
177
179
178
// Small utility, unless you want to use <boost/algorithm/string.hpp>
179
+ [[nodiscard]]
180
180
std::vector<StringView> splitString (const StringView& strToSplit, char delimeter);
181
181
182
182
template <typename Predicate>
@@ -228,6 +228,7 @@ using Optional = nonstd::expected<T, std::string>;
228
228
* */
229
229
using Result = Expected<std::monostate>;
230
230
231
+ [[nodiscard]]
231
232
bool IsAllowedPortName (StringView str);
232
233
233
234
class PortInfo
@@ -245,15 +246,15 @@ class PortInfo
245
246
_type (direction), _type_info(type_info), _converter(conv)
246
247
{}
247
248
248
- PortDirection direction () const ;
249
+ [[nodiscard]] PortDirection direction () const ;
249
250
250
- const std::type_index& type () const ;
251
+ [[nodiscard]] const std::type_index& type () const ;
251
252
252
- Any parseString (const char * str) const ;
253
+ [[nodiscard]] Any parseString (const char * str) const ;
253
254
254
- Any parseString (const std::string& str) const ;
255
+ [[nodiscard]] Any parseString (const std::string& str) const ;
255
256
256
- template <typename T>
257
+ template <typename T> [[nodiscard]]
257
258
Any parseString (const T&) const
258
259
{
259
260
// avoid compilation errors
@@ -264,16 +265,16 @@ class PortInfo
264
265
265
266
void setDefaultValue (StringView default_value_as_string);
266
267
267
- const std::string& description () const ;
268
+ [[nodiscard]] const std::string& description () const ;
268
269
269
- std::optional<std::string> defaultValue () const ;
270
+ [[nodiscard]] std::optional<std::string> defaultValue () const ;
270
271
271
- bool isStronglyTyped () const
272
+ [[nodiscard]] bool isStronglyTyped () const
272
273
{
273
274
return _type_info != typeid (AnyTypeAllowed);
274
275
}
275
276
276
- const StringConverter& converter () const
277
+ [[nodiscard]] const StringConverter& converter () const
277
278
{
278
279
return _converter;
279
280
}
@@ -286,8 +287,9 @@ class PortInfo
286
287
std::optional<std::string> default_value_;
287
288
};
288
289
289
- template <typename T = PortInfo::AnyTypeAllowed>
290
- std::pair<std::string, PortInfo> CreatePort (PortDirection direction, StringView name,
290
+ template <typename T = PortInfo::AnyTypeAllowed> [[nodiscard]]
291
+ std::pair<std::string, PortInfo> CreatePort (PortDirection direction,
292
+ StringView name,
291
293
StringView description = {})
292
294
{
293
295
auto sname = static_cast <std::string>(name);
@@ -316,28 +318,28 @@ std::pair<std::string, PortInfo> CreatePort(PortDirection direction, StringView
316
318
}
317
319
318
320
// ----------
319
- template <typename T = void >
321
+ template <typename T = void > [[nodiscard]]
320
322
inline std::pair<std::string, PortInfo> InputPort (StringView name,
321
323
StringView description = {})
322
324
{
323
325
return CreatePort<T>(PortDirection::INPUT, name, description);
324
326
}
325
327
326
- template <typename T = void >
328
+ template <typename T = void > [[nodiscard]]
327
329
inline std::pair<std::string, PortInfo> OutputPort (StringView name,
328
330
StringView description = {})
329
331
{
330
332
return CreatePort<T>(PortDirection::OUTPUT, name, description);
331
333
}
332
334
333
- template <typename T = void >
335
+ template <typename T = void > [[nodiscard]]
334
336
inline std::pair<std::string, PortInfo> BidirectionalPort (StringView name,
335
337
StringView description = {})
336
338
{
337
339
return CreatePort<T>(PortDirection::INOUT, name, description);
338
340
}
339
341
// ----------
340
- template <typename T = void >
342
+ template <typename T = void > [[nodiscard]]
341
343
inline std::pair<std::string, PortInfo> InputPort (StringView name, const T& default_value,
342
344
StringView description)
343
345
{
@@ -346,7 +348,7 @@ inline std::pair<std::string, PortInfo> InputPort(StringView name, const T& defa
346
348
return out;
347
349
}
348
350
349
- template <typename T = void >
351
+ template <typename T = void > [[nodiscard]]
350
352
inline std::pair<std::string, PortInfo> BidirectionalPort (StringView name,
351
353
const T& default_value,
352
354
StringView description)
@@ -372,13 +374,13 @@ struct has_static_method_providedPorts<
372
374
{
373
375
};
374
376
375
- template <typename T>
377
+ template <typename T> [[nodiscard]]
376
378
inline PortsList getProvidedPorts (enable_if<has_static_method_providedPorts<T>> = nullptr )
377
379
{
378
380
return T::providedPorts ();
379
381
}
380
382
381
- template <typename T>
383
+ template <typename T> [[nodiscard]]
382
384
inline PortsList
383
385
getProvidedPorts (enable_if_not<has_static_method_providedPorts<T>> = nullptr )
384
386
{
@@ -390,4 +392,3 @@ typedef std::chrono::high_resolution_clock::duration Duration;
390
392
391
393
} // namespace BT
392
394
393
- #endif // BT_BASIC_TYPES_H
0 commit comments