mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-10 13:01:18 +00:00
Support as<uint8_t>/as<int8_t>.
Fix issue 844/848.
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
#include "yaml-cpp/binary.h"
|
||||
#include "yaml-cpp/node/impl.h"
|
||||
@@ -114,6 +113,31 @@ typename std::enable_if<!std::is_floating_point<T>::value, void>::type
|
||||
inner_encode(const T& rhs, std::stringstream& stream){
|
||||
stream << rhs;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<(std::is_same<T, unsigned char>::value ||
|
||||
std::is_same<T, signed char>::value), bool>::type
|
||||
ConvertStreamTo(std::stringstream& stream, T& rhs) {
|
||||
int num;
|
||||
if ((stream >> std::noskipws >> num) && (stream >> std::ws).eof()) {
|
||||
if (num >= std::numeric_limits<T>::min() &&
|
||||
num <= std::numeric_limits<T>::max()) {
|
||||
rhs = num;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!(std::is_same<T, unsigned char>::value ||
|
||||
std::is_same<T, signed char>::value), bool>::type
|
||||
ConvertStreamTo(std::stringstream& stream, T& rhs) {
|
||||
if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \
|
||||
@@ -137,7 +161,7 @@ inner_encode(const T& rhs, std::stringstream& stream){
|
||||
if ((stream.peek() == '-') && std::is_unsigned<type>::value) { \
|
||||
return false; \
|
||||
} \
|
||||
if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) { \
|
||||
if (conversion::ConvertStreamTo(stream, rhs)) { \
|
||||
return true; \
|
||||
} \
|
||||
if (std::numeric_limits<type>::has_infinity) { \
|
||||
|
Reference in New Issue
Block a user