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);
97 std::vector<int> convertFromString<std::vector<int>>(StringView str);
100 std::vector<double> convertFromString<std::vector<double>>(StringView str);
121 template <
typename T>
inline 124 return [](StringView str){
return Any(convertFromString<T>(str)); };
135 template <
typename T>
141 std::string
toStr(std::string value);
143 template<> std::string toStr<BT::NodeStatus>(
BT::NodeStatus status);
155 template<> std::string toStr<BT::NodeType>(
BT::NodeType type);
165 std::vector<StringView>
splitString(
const StringView& strToSplit,
char delimeter);
167 template <
typename Predicate>
168 using enable_if =
typename std::enable_if< Predicate::value >::type*;
170 template <
typename Predicate>
190 template <
typename T>
using Optional = nonstd::expected<T, std::string>;
217 _type(direction), _info(nullptr) {}
220 const std::type_info& type_info,
221 StringConverter conv):
229 const std::type_info* type()
const;
231 Any parseString(
const char *str)
const;
233 Any parseString(
const std::string& str)
const;
235 template <
typename T>
242 void setDescription(StringView description);
244 void setDefaultValue(StringView default_value_as_string);
246 const std::string& description()
const;
248 const std::string& defaultValue()
const;
259 template <
typename T =
void>
262 StringView description = {})
264 std::pair<std::string,PortInfo> out;
266 if( std::is_same<T, void>::value)
268 out = {
static_cast<std::string
>(name),
PortInfo(direction) };
271 out = {
static_cast<std::string
>(name),
PortInfo(direction,
typeid(T),
272 GetAnyFromStringFunctor<T>() ) };
274 if( !description.empty() )
282 template <
typename T =
void>
inline 283 std::pair<std::string,PortInfo>
InputPort(StringView name, StringView description = {})
288 template <
typename T =
void>
inline 289 std::pair<std::string,PortInfo>
OutputPort(StringView name, StringView description = {})
294 template <
typename T =
void>
inline 300 template <
typename T =
void>
inline 301 std::pair<std::string,PortInfo>
InputPort(StringView name,
const T& default_value, StringView description)
304 out.second.setDefaultValue(
BT::toStr(default_value) );
308 template <
typename T =
void>
inline 309 std::pair<std::string,PortInfo>
BidirectionalPort(StringView name,
const T& default_value, StringView description)
312 out.second.setDefaultValue(
BT::toStr(default_value) );
317 typedef std::unordered_map<std::string, PortInfo>
PortsList;
319 template <
typename T,
typename =
void>
322 template <
typename T>
324 typename
std::
enable_if<std::is_same<decltype(T::providedPorts()), PortsList>::value>::type>
327 template <
typename T>
inline 330 return T::providedPorts();
333 template <
typename T>
inline 339 typedef std::chrono::high_resolution_clock::time_point
TimePoint;
340 typedef std::chrono::high_resolution_clock::duration
Duration;
345 #endif // BT_BASIC_TYPES_H
NodeStatus convertFromString< NodeStatus >(StringView str)
PortDirection convertFromString< PortDirection >(StringView str)
StringConverter _converter
float convertFromString< float >(StringView str)
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_
long convertFromString< long >(StringView str)
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)
const char * convertFromString< const char * >(StringView str)
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)
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)
unsigned long convertFromString< unsigned long >(StringView str)
PortInfo(PortDirection direction=PortDirection::INOUT)