Skip to content

Commit

Permalink
remove boost.lexical_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Nov 28, 2017
1 parent 6b5b8af commit 0159a2c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
19 changes: 17 additions & 2 deletions iguana/xml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <algorithm>
#include <functional>
#include <cctype>
#include <boost/lexical_cast.hpp>
#include "reflection.hpp"

#define IGUANA_XML_READER_CHECK_FORWARD if (l > length) return 0; work_ptr += l; length -= l
Expand Down Expand Up @@ -91,11 +90,27 @@ namespace iguana { namespace xml
return l;
}

template<typename T>
constexpr bool is_64_v = std::is_same_v<T, std::int64_t>||std::is_same_v<T, std::uint64_t>;

template <typename T>
inline auto get_value(char const* str, size_t length, T& value)
-> std::enable_if_t<std::is_arithmetic<T>::value>
{
value = boost::lexical_cast<T>(str, length);
using U = std::remove_const_t<std::remove_reference_t<T>>;
if constexpr(std::is_integral_v<U>&&!detail::is_64_v<U>){
value = std::atoi(str);
}
else if constexpr(std::is_floating_point_v<U>){
value = std::atof(str);
}
else if constexpr(detail::is_64_v<U>){
value = std::atoll(str);
}
else{
std::cout<<"don't support the type now"<<std::endl;
throw(std::invalid_argument("don't support the type now"));
}
}

inline void get_value(char const* str, size_t length, std::string& value)
Expand Down
20 changes: 18 additions & 2 deletions iguana/xml17.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,27 @@ namespace iguana::xml {
return l;
}

template<typename T>
constexpr bool is_64_v = std::is_same_v<T, std::int64_t>||std::is_same_v<T, std::uint64_t>;

template <typename T>
auto get_value(char const* str, size_t length, T& value)
inline auto get_value(char const* str, size_t length, T& value)
-> std::enable_if_t<std::is_arithmetic<T>::value>
{
value = boost::lexical_cast<T>(str, length);
using U = std::remove_const_t<std::remove_reference_t<T>>;
if constexpr(std::is_integral_v<U>&&!detail::is_64_v<U>){
value = std::atoi(str);
}
else if constexpr(std::is_floating_point_v<U>){
value = std::atof(str);
}
else if constexpr(detail::is_64_v<U>){
value = std::atoll(str);
}
else{
std::cout<<"don't support the type now"<<std::endl;
throw(std::invalid_argument("don't support the type now"));
}
}

void get_value(char const* str, size_t length, std::string& value)
Expand Down

0 comments on commit 0159a2c

Please sign in to comment.