Commit 23b49aab authored by Dominik Charousset's avatar Dominik Charousset

implemented serialization of floating point numbers

parent 429872ba
......@@ -28,8 +28,10 @@
\******************************************************************************/
#include <string>
#include <cstdint>
#include <cstring>
#include <sstream>
#include <iterator>
#include <exception>
#include <stdexcept>
......@@ -51,13 +53,6 @@ inline void range_check(iterator begin, iterator end, size_t read_size) {
}
}
// @returns the next iterator position
template<typename T>
iterator read(iterator, iterator, T&,
typename enable_if<std::is_floating_point<T>::value>::type* = 0) {
throw std::logic_error("read floating point not implemented yet");
}
template<typename T>
iterator read(iterator begin, iterator end, T& storage,
typename enable_if<std::is_integral<T>::value>::type* = 0) {
......@@ -90,6 +85,18 @@ iterator read_unicode_string(iterator begin, iterator end, StringType& str) {
return begin;
}
// @returns the next iterator position
template<typename T>
iterator read(iterator begin, iterator end, T& value,
typename enable_if<std::is_floating_point<T>::value>::type* = 0) {
// floating points are written as strings
std::string str;
auto result = read_unicode_string<char>(begin, end, str);
std::istringstream iss(str);
iss >> value;
return result;
}
iterator read(iterator begin, iterator end, std::u16string& storage) {
// char16_t is guaranteed to has *at least* 16 bytes,
// but not to have *exactly* 16 bytes; thus use uint16_t
......
......@@ -69,10 +69,11 @@ class binary_writer {
}
template<typename T>
void operator()(const T&,
void operator()(const T& value,
typename enable_if<std::is_floating_point<T>::value>::type* = 0) {
throw std::logic_error("binary_serializer::write_floating_point "
"not implemented yet");
// write floating points as strings
std::string str = std::to_string(value);
(*this)(str);
}
void operator()(const std::string& str) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment