1 #ifndef BT_BASIC_TYPES_H 2 #define BT_BASIC_TYPES_H 7 #include <unordered_map> 8 #include <unordered_set> 60 template <
typename T>
inline 65 std::cerr <<
"You (maybe indirectly) called BT::convertFromString() for type [" <<
66 type_name <<
"], but I can't find the template specialization.\n" << std::endl;
68 throw LogicError(std::string(
"You didn't implement the template specialization of " 69 "convertFromString for this type: ") + type_name );
73 std::string convertFromString<std::string>(StringView
str);
88 std::vector<int> convertFromString<std::vector<int>>(StringView
str);
91 std::vector<double> convertFromString<std::vector<double>>(StringView
str);
112 template <
typename T>
inline 115 return [](StringView
str){
return Any(convertFromString<T>(
str)); };
126 template <
typename T>
132 std::string
toStr(std::string value);
134 template<> std::string toStr<BT::NodeStatus>(
BT::NodeStatus status);
146 template<> std::string toStr<BT::NodeType>(
BT::NodeType type);
156 std::vector<StringView>
splitString(
const StringView& strToSplit,
char delimeter);
158 template <
typename Predicate>
159 using enable_if =
typename std::enable_if< Predicate::value >::type*;
161 template <
typename Predicate>
181 template <
typename T>
using Optional = nonstd::expected<T, std::string>;
208 _type(direction), _info(nullptr) {}
211 const std::type_info& type_info,
212 StringConverter conv):
220 const std::type_info* type()
const;
222 Any parseString(
const char *
str)
const;
224 Any parseString(
const std::string& str)
const;
226 template <
typename T>
233 void setDescription(StringView description);
235 void setDefaultValue(StringView default_value_as_string);
237 const std::string& description()
const;
239 const std::string& defaultValue()
const;
250 template <
typename T =
void>
253 StringView description = {})
255 std::pair<std::string,PortInfo> out;
257 if( std::is_same<T, void>::value)
259 out = {name.to_string(),
PortInfo(direction) };
262 out = {name.to_string(),
PortInfo(direction,
typeid(T),
263 GetAnyFromStringFunctor<T>() ) };
265 if( !description.empty() )
273 template <
typename T =
void>
inline 274 std::pair<std::string,PortInfo>
InputPort(StringView name, StringView description = {})
279 template <
typename T =
void>
inline 280 std::pair<std::string,PortInfo>
OutputPort(StringView name, StringView description = {})
285 template <
typename T =
void>
inline 291 template <
typename T =
void>
inline 292 std::pair<std::string,PortInfo>
InputPort(StringView name,
const T& default_value, StringView description)
295 out.second.setDefaultValue(
BT::toStr(default_value) );
299 template <
typename T =
void>
inline 300 std::pair<std::string,PortInfo>
OutputPort(StringView name,
const T& default_value, StringView description)
303 out.second.setDefaultValue(
BT::toStr(default_value) );
307 template <
typename T =
void>
inline 308 std::pair<std::string,PortInfo>
BidirectionalPort(StringView name,
const T& default_value, StringView description)
311 out.second.setDefaultValue(
BT::toStr(default_value) );
316 typedef std::unordered_map<std::string, PortInfo>
PortsList;
318 template <
typename T,
typename =
void>
321 template <
typename T>
323 typename
std::
enable_if<std::is_same<decltype(T::providedPorts()), PortsList>::value>::type>
326 template <
typename T>
inline 329 return T::providedPorts();
332 template <
typename T>
inline 338 typedef std::chrono::high_resolution_clock::time_point
TimePoint;
339 typedef std::chrono::high_resolution_clock::duration
Duration;
344 #endif // BT_BASIC_TYPES_H
NodeStatus convertFromString< NodeStatus >(StringView str)
PortDirection convertFromString< PortDirection >(StringView str)
StringConverter _converter
const std::type_info * _info
std::chrono::high_resolution_clock::time_point TimePoint
Position2D convertFromString(StringView str)
std::pair< std::string, PortInfo > BidirectionalPort(StringView name, StringView description={})
std::string toStr(T value)
std::string default_value_
std::ostream & operator<<(std::ostream &os, const BT::NodeStatus &status)
std::pair< std::string, PortInfo > OutputPort(StringView name, StringView description={})
std::vector< StringView > splitString(const StringView &strToSplit, char delimeter)
std::string demangle(char const *name)
Any parseString(const T &) const
StringConverter GetAnyFromStringFunctor()
nonstd::string_view StringView
PortsList getProvidedPorts(enable_if< has_static_method_providedPorts< T > >=nullptr)
unsigned convertFromString< unsigned >(StringView str)
NodeType convertFromString< NodeType >(StringView str)
bool convertFromString< bool >(StringView str)
const char * convertFromString< const char * >(StringView str)
typename std::enable_if< Predicate::value >::type * enable_if
std::unordered_map< std::string, PortInfo > PortsList
StringConverter GetAnyFromStringFunctor< void >()
std::pair< std::string, PortInfo > CreatePort(PortDirection direction, StringView name, StringView description={})
nonstd::expected< T, std::string > Optional
int convertFromString< int >(StringView str)
std::function< Any(StringView)> StringConverter
typename std::enable_if< !Predicate::value >::type * enable_if_not
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)
std::pair< std::string, PortInfo > InputPort(StringView name, StringView description={})
std::chrono::high_resolution_clock::duration Duration
double convertFromString< double >(StringView str)
PortInfo(PortDirection direction=PortDirection::INOUT)