Go to the documentation of this file.
34 return value ?
"true" :
"false";
38 std::string toStr<std::string>(
const std::string& value)
116 return std::string(str.data(), str.size());
123 auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
124 if(ec != std::errc())
134 unsigned long result = 0;
135 auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
136 if(ec != std::errc())
143 template <
typename T>
147 if(res < std::numeric_limits<T>::lowest() || res > std::numeric_limits<T>::max())
150 StrCat(
"Value out of bound when converting [", str,
"] to integer"));
158 return ConvertWithBoundCheck<int8_t>(str);
164 return ConvertWithBoundCheck<int16_t>(str);
170 return ConvertWithBoundCheck<int32_t>(str);
176 return ConvertWithBoundCheck<uint8_t>(str);
182 return ConvertWithBoundCheck<uint16_t>(str);
188 return ConvertWithBoundCheck<uint32_t>(str);
197 std::string old_locale = setlocale(LC_NUMERIC,
nullptr);
198 setlocale(LC_NUMERIC,
"C");
199 double val = std::stod(str.data());
200 setlocale(LC_NUMERIC, old_locale.c_str());
207 std::string old_locale = setlocale(LC_NUMERIC,
nullptr);
208 setlocale(LC_NUMERIC,
"C");
209 float val = std::stof(str.data());
210 setlocale(LC_NUMERIC, old_locale.c_str());
215 std::vector<int> convertFromString<std::vector<int>>(
StringView str)
218 std::vector<int> output;
219 output.reserve(parts.size());
222 output.push_back(convertFromString<int>(part));
228 std::vector<double> convertFromString<std::vector<double>>(
StringView str)
231 std::vector<double> output;
232 output.reserve(parts.size());
241 std::vector<std::string> convertFromString<std::vector<std::string>>(
StringView str)
244 std::vector<std::string> output;
245 output.reserve(parts.size());
248 output.push_back(convertFromString<std::string>(part));
267 else if(str.size() == 4)
269 if(str ==
"true" || str ==
"TRUE" || str ==
"True")
274 else if(str.size() == 5)
276 if(str ==
"false" || str ==
"FALSE" || str ==
"False")
281 throw RuntimeError(
"convertFromString(): invalid bool conversion");
298 throw RuntimeError(std::string(
"Cannot convert this to NodeStatus: ") +
299 static_cast<std::string
>(str));
307 if(str ==
"Condition")
311 if(str ==
"Decorator")
321 if(str ==
"Input" || str ==
"INPUT")
323 if(str ==
"Output" || str ==
"OUTPUT")
325 if(str ==
"InOut" || str ==
"INOUT")
327 throw RuntimeError(std::string(
"Cannot convert this to PortDirection: ") +
328 static_cast<std::string
>(str));
351 std::vector<StringView> splitted_strings;
352 splitted_strings.reserve(4);
355 while(pos < strToSplit.size())
357 size_t new_pos = strToSplit.find_first_of(delimeter, pos);
358 if(new_pos == std::string::npos)
360 new_pos = strToSplit.size();
362 const auto sv =
StringView{ &strToSplit.data()[pos], new_pos - pos };
363 splitted_strings.push_back(sv);
366 return splitted_strings;
428 const char first_char = str.data()[0];
429 if(!std::isalpha(first_char))
452 return str ==
"name" || str ==
"ID" || str ==
"_autoremap";
461 throw std::runtime_error(res.error());
473 return nonstd::make_unexpected(
"toJsonString failed");
478 return str.size() >= prefix.size() &&
479 strncmp(str.data(), prefix.data(), prefix.size()) == 0;
484 return str.size() >= 1 && str[0] == prefix;
void setDescription(StringView description)
const std::string & typeName() const
int32_t convertFromString< int32_t >(StringView str)
uint64_t convertFromString< uint64_t >(StringView str)
NodeType
Enumerates the possible types of nodes.
Expected< std::string > toJsonString(const Any &value)
std::string toStr< bool >(const bool &value)
const std::string & defaultValueString() const
const Any & defaultValue() const
nonstd::expected< T, std::string > Expected
std::string_view StringView
bool IsReservedAttribute(StringView str)
namespace for Niels Lohmann
StringConverter converter_
uint16_t convertFromString< uint16_t >(StringView str)
std::type_index type_info_
int64_t convertFromString< int64_t >(StringView str)
float convertFromString< float >(StringView str)
std::string toStr< NodeType >(const NodeType &type)
static const char * json_text
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
int8_t convertFromString< int8_t >(StringView str)
Any convertFromJSON(StringView json_text, std::type_index type)
convertFromJSON will parse a json string and use JsonExporter to convert its content to a given type....
bool convertFromString< bool >(StringView str)
std::ostream & operator<<(std::ostream &os, const BT::NodeStatus &status)
static const std::array< std::string, 4 > PostCondNames
std::vector< StringView > splitString(const StringView &strToSplit, char delimeter)
NodeType convertFromString< NodeType >(StringView str)
static JsonExporter & get()
uint32_t convertFromString< uint32_t >(StringView str)
const std::type_index & type() const
bool IsAllowedPortName(StringView str)
PortDirection direction() const
bool StartWith(StringView str, StringView prefix)
basic_json<> json
default specialization
static const std::array< std::string, 4 > PreCondNames
std::string toStr< PortDirection >(const PortDirection &direction)
double convertFromString< double >(StringView str)
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
std::string default_value_str_
T ConvertWithBoundCheck(StringView str)
PortDirection convertFromString< PortDirection >(StringView str)
ExpectedEntry fromJson(const nlohmann::json &source) const
fromJson will return an Entry (value wrappedn in Any + TypeInfo) from a json source....
NodeStatus convertFromString< NodeStatus >(StringView str)
Any parseString(const char *str) const
std::string toStr< NodeStatus >(const NodeStatus &status)
int16_t convertFromString< int16_t >(StringView str)
const std::string & description() const
std::string toStr(const T &value)
toStr is the reverse operation of convertFromString.
uint8_t convertFromString< uint8_t >(StringView str)