18#include <yaml-cpp/node/node.h>
19#include <yaml-cpp/node/convert.h>
30 template <
typename _Cp,
bool>
31 class __bit_reference;
37 struct _Bit_reference;
54#if !defined(__linux__) && defined(__llvm__)
55 template <
typename _Cp>
79 inline T
lexicalCast(
const std::string& str, uint32_t base=10) {
85 if(ss.fail() ==
false) {
90 ex << str <<
"\" to typeid: \"" <<
typeid(T).name() <<
"\"";
95 inline MetaStruct::enable_if_t<MetaStruct::is_stl<T>::value and
96 std::is_same<typename T::value_type, bool>::value, T>
97 lexicalCast(
const std::string& str, uint32_t base = 10) =
delete;
100 inline std::string
lexicalCast(
const std::string& str, uint32_t base) {
106 inline bool lexicalCast(
const std::string& str, uint32_t base) {
109 YAML::Node node(YAML::NodeType::Scalar);
116 if(
false == YAML::convert<bool>::decode(node, out)){
118 if(
false == YAML::convert<int>::decode(node, out_int)){
119 SpartaException ex(
"Unable to cast string \"");
120 ex << str <<
"\" to bool";
130 inline uint64_t
lexicalCast(
const std::string& str, uint32_t base) {
132 uint64_t val = std::stoul(str.c_str(),
nullptr, base);
135 catch(std::exception &e) {
136 SpartaException ex(
"Unable to cast string \"");
137 ex << str <<
"\" to uint64_t: " << e.what();
144 inline int64_t
lexicalCast(
const std::string& str, uint32_t base) {
146 int64_t val = std::stol(str.c_str(),
nullptr, base);
149 catch(std::exception &e) {
150 SpartaException ex(
"Unable to cast string \"");
151 ex << str <<
"\" to int64_t: " << e.what();
158 inline uint32_t
lexicalCast(
const std::string& str, uint32_t base) {
161 uint64_t val = std::stoul(str.c_str(),
nullptr, base);
162 if (val > std::numeric_limits<uint32_t>::max()) {
163 throw std::range_error(
"Value " + str +
" is too large to fit into a uint32_t");;
165 return static_cast<uint32_t
>(val);
167 catch(std::exception &e) {
168 SpartaException ex(
"Unable to cast string \"");
169 ex << str <<
"\" to uint32_t: " << e.what();
176 inline int32_t
lexicalCast(
const std::string& str, uint32_t base) {
178 int32_t val = std::stoi(str.c_str(),
nullptr, base);
181 catch(std::exception &e) {
182 SpartaException ex(
"Unable to cast string \"");
183 ex << str <<
"\" to int32_t: " << e.what();
194 return 1 + floor(log10(val));
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Macros for handling exponential backoff.
uint32_t numDecDigits(uint32_t val)
Gets number of decimal digits in a uint32_t.
T lexicalCast(const std::string &str, uint32_t base=10)
Helper type for converting _Bit_reference types into bool types for the purpose of determining how to...