1 #ifndef BT_BASIC_TYPES_H 2 #define BT_BASIC_TYPES_H 7 #include <unordered_map> 8 #include <unordered_set> 70 std::cerr <<
"You (maybe indirectly) called BT::convertFromString() for type [" 71 << type_name <<
"], but I can't find the template specialization.\n" 74 throw LogicError(std::string(
"You didn't implement the template specialization of " 75 "convertFromString for this type: ") +
80 std::string convertFromString<std::string>(StringView str);
83 const char* convertFromString<const char*>(StringView str);
104 std::vector<int> convertFromString<std::vector<int>>(StringView str);
107 std::vector<double> convertFromString<std::vector<double>>(StringView str);
126 template <
typename T>
129 return [](StringView str) {
return Any(convertFromString<T>(str)); };
140 template <
typename T>
146 std::string
toStr(std::string value);
172 std::vector<StringView>
splitString(
const StringView& strToSplit,
char delimeter);
174 template <
typename Predicate>
175 using enable_if =
typename std::enable_if<Predicate::value>::type*;
177 template <
typename Predicate>
196 template <
typename T>
225 _type(direction), _info(nullptr)
229 StringConverter conv) :
230 _type(direction), _info(&type_info), _converter(conv)
235 const std::type_info* type()
const;
237 Any parseString(
const char* str)
const;
239 Any parseString(
const std::string& str)
const;
241 template <
typename T>
248 void setDescription(StringView description);
250 void setDefaultValue(StringView default_value_as_string);
252 const std::string& description()
const;
254 const std::string& defaultValue()
const;
264 template <
typename T =
void>
266 StringView description = {})
268 auto sname =
static_cast<std::string
>(name);
269 if (ReservedPortNames.count(sname) != 0)
271 throw std::runtime_error(
"A port can not use a reserved name. See ReservedPortNames");
274 std::pair<std::string, PortInfo> out;
276 if (std::is_same<T, void>::value)
282 out = {sname,
PortInfo(direction,
typeid(T), GetAnyFromStringFunctor<T>())};
284 if (!description.empty())
292 template <
typename T =
void>
293 inline std::pair<std::string, PortInfo>
InputPort(StringView name,
294 StringView description = {})
299 template <
typename T =
void>
300 inline std::pair<std::string, PortInfo>
OutputPort(StringView name,
301 StringView description = {})
306 template <
typename T =
void>
308 StringView description = {})
313 template <
typename T =
void>
314 inline std::pair<std::string, PortInfo>
InputPort(StringView name,
const T& default_value,
315 StringView description)
318 out.second.setDefaultValue(
BT::toStr(default_value));
322 template <
typename T =
void>
324 const T& default_value,
325 StringView description)
328 out.second.setDefaultValue(
BT::toStr(default_value));
333 typedef std::unordered_map<std::string, PortInfo>
PortsList;
335 template <
typename T,
typename =
void>
340 template <
typename T>
343 std::is_same<decltype(T::providedPorts()), PortsList>::value>::type>
348 template <
typename T>
351 return T::providedPorts();
354 template <
typename T>
361 typedef std::chrono::high_resolution_clock::time_point
TimePoint;
362 typedef std::chrono::high_resolution_clock::duration
Duration;
366 #endif // BT_BASIC_TYPES_H
typename std::enable_if< Predicate::value >::type * enable_if
NodeStatus convertFromString< NodeStatus >(StringView str)
PortDirection convertFromString< PortDirection >(StringView str)
std::pair< std::string, PortInfo > InputPort(StringView name, StringView description={})
StringConverter _converter
float convertFromString< float >(StringView str)
const std::type_info * _info
std::chrono::high_resolution_clock::time_point TimePoint
std::pair< std::string, PortInfo > BidirectionalPort(StringView name, StringView description={})
std::string toStr(T value)
std::string default_value_
Any parseString(const T &) const
long convertFromString< long >(StringView str)
bool StatusCompleted(const NodeStatus &status)
std::ostream & operator<<(std::ostream &os, const BT::NodeStatus &status)
const std::unordered_set< std::string > ReservedPortNames
std::vector< StringView > splitString(const StringView &strToSplit, char delimeter)
std::string demangle(char const *name)
StringConverter GetAnyFromStringFunctor()
nonstd::string_view StringView
unsigned convertFromString< unsigned >(StringView str)
NodeType convertFromString< NodeType >(StringView str)
bool convertFromString< bool >(StringView str)
std::unordered_map< std::string, PortInfo > PortsList
std::pair< std::string, PortInfo > OutputPort(StringView name, StringView description={})
StringConverter GetAnyFromStringFunctor< void >()
nonstd::expected< T, std::string > Optional
int convertFromString< int >(StringView str)
std::function< Any(StringView)> StringConverter
PortInfo(PortDirection direction, const std::type_info &type_info, StringConverter conv)
void setDescription(StringView description)
NodeType
Enumerates the possible types of nodes.
std::unordered_map< const std::type_info *, StringConverter > StringConvertersMap
std::basic_string< CharT, Traits > to_string(basic_string_view< CharT, Traits > v)
PortsList getProvidedPorts(enable_if< has_static_method_providedPorts< T >>=nullptr)
std::chrono::high_resolution_clock::duration Duration
std::pair< std::string, PortInfo > CreatePort(PortDirection direction, StringView name, StringView description={})
double convertFromString< double >(StringView str)
unsigned long convertFromString< unsigned long >(StringView str)
typename std::enable_if<!Predicate::value >::type * enable_if_not
Point3D convertFromString(StringView key)
PortInfo(PortDirection direction=PortDirection::INOUT)