mirror of
https://github.com/USCiLab/cereal.git
synced 2025-09-21 20:59:31 +02:00
Removed some (but not all) of the line endings I accidentally added while in VS.
Fixed a bunch of issues related to compiling unittests on VS. Having a problem linking against boost unit tests, so can't run the tests yet.
This commit is contained in:
parent
66c9bc3647
commit
da03627ff1
@ -106,16 +106,26 @@ namespace cereal
|
||||
void saveValue(double d) { itsWriter.Double(d); }
|
||||
void saveValue(std::string const & s) { itsWriter.String(s.c_str(), static_cast<rapidjson::SizeType>( s.size() )); }
|
||||
void saveValue(char const * s) { itsWriter.String(s); }
|
||||
#ifdef _MSC_VER
|
||||
template <class T> inline
|
||||
typename std::enable_if<sizeof(T) == sizeof(std::uint32_t), void>::type
|
||||
saveLong(T lu){ saveValue( static_cast<std::uint32_t>( lu ) ); }
|
||||
template <class T> inline
|
||||
typename std::enable_if<sizeof(T) != sizeof(std::uint32_t), void>::type
|
||||
saveLong(T lu){ saveValue( static_cast<std::uint64_t>( lu ) ); }
|
||||
|
||||
void saveValue( unsigned long lu ){ saveLong( lu ); };
|
||||
#endif
|
||||
|
||||
//! Save exotic arithmetic types as binary
|
||||
template<class T>
|
||||
typename std::enable_if<std::is_arithmetic<T>::value &&
|
||||
(sizeof(T) >= sizeof(long double) || sizeof(T) >= sizeof(long long)), void>::type
|
||||
saveValue(T const & t)
|
||||
{
|
||||
auto base64string = base64::encode( reinterpret_cast<const unsigned char *>( &t ), sizeof(T) );
|
||||
saveValue( base64string );
|
||||
}
|
||||
typename std::enable_if<std::is_arithmetic<T>::value &&
|
||||
(sizeof(T) >= sizeof(long double) || sizeof(T) >= sizeof(long long)), void>::type
|
||||
saveValue(T const & t)
|
||||
{
|
||||
auto base64string = base64::encode( reinterpret_cast<const unsigned char *>( &t ), sizeof(T) );
|
||||
saveValue( base64string );
|
||||
}
|
||||
|
||||
//! Write the name of the upcoming node and prepare object/array state
|
||||
/*! Since writeName is called for every value that is output, regardless of
|
||||
@ -358,7 +368,7 @@ namespace cereal
|
||||
};
|
||||
|
||||
//! Loads the size for a SizeTag
|
||||
void loadSize(size_t & size)
|
||||
void loadSize(size_type & size)
|
||||
{
|
||||
size = (itsValueStack.rbegin() + 1)->value().Size();
|
||||
}
|
||||
|
652
include/cereal/external/rapidjson/writer.h
vendored
652
include/cereal/external/rapidjson/writer.h
vendored
@ -1,326 +1,326 @@
|
||||
#ifndef RAPIDJSON_WRITER_H_
|
||||
#define RAPIDJSON_WRITER_H_
|
||||
|
||||
#include "rapidjson.h"
|
||||
#include "internal/stack.h"
|
||||
#include "internal/strfunc.h"
|
||||
#include <cstdio> // snprintf() or _sprintf_s()
|
||||
#include <new> // placement new
|
||||
#include <limits>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4127) // conditional expression is constant
|
||||
#endif
|
||||
|
||||
namespace rapidjson {
|
||||
|
||||
//! JSON writer
|
||||
/*! Writer implements the concept Handler.
|
||||
It generates JSON text by events to an output stream.
|
||||
|
||||
User may programmatically calls the functions of a writer to generate JSON text.
|
||||
|
||||
On the other side, a writer can also be passed to objects that generates events,
|
||||
|
||||
for example Reader::Parse() and Document::Accept().
|
||||
|
||||
\tparam Stream Type of ouptut stream.
|
||||
\tparam Encoding Encoding of both source strings and output.
|
||||
\implements Handler
|
||||
*/
|
||||
template<typename Stream, typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<> >
|
||||
class Writer {
|
||||
public:
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
Writer(Stream& stream, int precision = 20, Allocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) :
|
||||
stream_(stream), level_stack_(allocator, levelDepth * sizeof(Level))
|
||||
{
|
||||
#if _MSC_VER
|
||||
(void) sprintf_s(double_format, sizeof(double_format), "%%0.%dg", precision);
|
||||
(void) sprintf_s( long_double_format, sizeof( long_double_format ), "%%0.%dLg", precision );
|
||||
#else
|
||||
(void) snprintf(double_format, sizeof(double_format), "%%0.%dg", precision);
|
||||
(void) snprintf( long_double_format, sizeof( long_double_format ), "%%0.%dLg", precision );
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
protected:
|
||||
char double_format[32];
|
||||
char long_double_format[32];
|
||||
public:
|
||||
|
||||
//@name Implementation of Handler
|
||||
//@{
|
||||
|
||||
Writer& Null() { Prefix(kNullType); WriteNull(); return *this; }
|
||||
Writer& Bool(bool b) { Prefix(b ? kTrueType : kFalseType); WriteBool(b); return *this; }
|
||||
Writer& Int(int i) { Prefix(kNumberType); WriteInt(i); return *this; }
|
||||
Writer& Uint(unsigned u) { Prefix(kNumberType); WriteUint(u); return *this; }
|
||||
Writer& Int64(int64_t i64) { Prefix(kNumberType); WriteInt64(i64); return *this; }
|
||||
Writer& Uint64(uint64_t u64) { Prefix(kNumberType); WriteUint64(u64); return *this; }
|
||||
Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; }
|
||||
Writer& LongDouble(long double d) { Prefix(kNumberType); WriteLongDouble(d); return *this; }
|
||||
Writer& LongLong(long long d) { Prefix(kNumberType); WriteLongLong(d); return *this; }
|
||||
Writer& ULongLong(unsigned long long d) { Prefix(kNumberType); WriteULongLong(d); return *this; }
|
||||
|
||||
Writer& String(const Ch* str, SizeType length, bool copy = false) {
|
||||
(void)copy;
|
||||
Prefix(kStringType);
|
||||
WriteString(str, length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Writer& StartObject() {
|
||||
Prefix(kObjectType);
|
||||
new (level_stack_.template Push<Level>()) Level(false);
|
||||
WriteStartObject();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Writer& EndObject(SizeType memberCount = 0) {
|
||||
(void)memberCount;
|
||||
RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
|
||||
RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray);
|
||||
level_stack_.template Pop<Level>(1);
|
||||
WriteEndObject();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Writer& StartArray() {
|
||||
Prefix(kArrayType);
|
||||
new (level_stack_.template Push<Level>()) Level(true);
|
||||
WriteStartArray();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Writer& EndArray(SizeType elementCount = 0) {
|
||||
(void)elementCount;
|
||||
RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
|
||||
RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray);
|
||||
level_stack_.template Pop<Level>(1);
|
||||
WriteEndArray();
|
||||
return *this;
|
||||
}
|
||||
//@}
|
||||
|
||||
//! Simpler but slower overload.
|
||||
Writer& String(const Ch* str) { return String(str, internal::StrLen(str)); }
|
||||
|
||||
protected:
|
||||
//! Information for each nested level
|
||||
struct Level {
|
||||
Level(bool inArray_) : inArray(inArray_), valueCount(0) {}
|
||||
bool inArray; //!< true if in array, otherwise in object
|
||||
size_t valueCount; //!< number of values in this level
|
||||
};
|
||||
|
||||
static const size_t kDefaultLevelDepth = 32;
|
||||
|
||||
void WriteNull() {
|
||||
stream_.Put('n'); stream_.Put('u'); stream_.Put('l'); stream_.Put('l');
|
||||
}
|
||||
|
||||
void WriteBool(bool b) {
|
||||
if (b) {
|
||||
stream_.Put('t'); stream_.Put('r'); stream_.Put('u'); stream_.Put('e');
|
||||
}
|
||||
else {
|
||||
stream_.Put('f'); stream_.Put('a'); stream_.Put('l'); stream_.Put('s'); stream_.Put('e');
|
||||
}
|
||||
}
|
||||
|
||||
void WriteInt(int i) {
|
||||
if (i < 0) {
|
||||
stream_.Put('-');
|
||||
i = -i;
|
||||
}
|
||||
WriteUint((unsigned)i);
|
||||
}
|
||||
|
||||
void WriteUint(unsigned u) {
|
||||
char buffer[10];
|
||||
char *p = buffer;
|
||||
do {
|
||||
*p++ = (u % 10) + '0';
|
||||
u /= 10;
|
||||
} while (u > 0);
|
||||
|
||||
do {
|
||||
--p;
|
||||
stream_.Put(*p);
|
||||
} while (p != buffer);
|
||||
}
|
||||
|
||||
void WriteInt64(int64_t i64) {
|
||||
if (i64 < 0) {
|
||||
stream_.Put('-');
|
||||
i64 = -i64;
|
||||
}
|
||||
WriteUint64((uint64_t)i64);
|
||||
}
|
||||
|
||||
void WriteUint64(uint64_t u64) {
|
||||
char buffer[20];
|
||||
char *p = buffer;
|
||||
do {
|
||||
*p++ = char(u64 % 10) + '0';
|
||||
u64 /= 10;
|
||||
} while (u64 > 0);
|
||||
|
||||
do {
|
||||
--p;
|
||||
stream_.Put(*p);
|
||||
} while (p != buffer);
|
||||
}
|
||||
|
||||
// cereal Temporary until constexpr support is added in RTM
|
||||
#ifdef _MSC_VER
|
||||
template <class Ch>
|
||||
bool characterOk( Ch c )
|
||||
{
|
||||
return c < 256;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool characterOk<char>( Ch )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
template<class Ch>
|
||||
typename std::enable_if < std::numeric_limits<Ch>::max() < 265, bool>::type
|
||||
characterOk( Ch c )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class Ch>
|
||||
typename std::enable_if<std::numeric_limits<Ch>::max() >= 265, bool>::type
|
||||
characterOk(Ch c)
|
||||
{ return c < 256; }
|
||||
#endif
|
||||
|
||||
//! \todo Optimization with custom double-to-string converter.
|
||||
void WriteDouble(double d) {
|
||||
char buffer[100];
|
||||
#if _MSC_VER
|
||||
int ret = sprintf_s(buffer, sizeof(buffer), double_format, d);
|
||||
#else
|
||||
int ret = snprintf(buffer, sizeof(buffer), double_format, d);
|
||||
#endif
|
||||
RAPIDJSON_ASSERT(ret >= 1);
|
||||
for (int i = 0; i < ret; i++)
|
||||
stream_.Put(buffer[i]);
|
||||
}
|
||||
|
||||
void WriteLongDouble(long double d) {
|
||||
char buffer[256];
|
||||
#if _MSC_VER
|
||||
int ret = sprintf_s(buffer, sizeof(buffer), long_double_format, d);
|
||||
#else
|
||||
int ret = snprintf(buffer, sizeof(buffer), long_double_format, d);
|
||||
#endif
|
||||
RAPIDJSON_ASSERT(ret >= 1);
|
||||
for (int i = 0; i < ret; i++)
|
||||
stream_.Put(buffer[i]);
|
||||
}
|
||||
|
||||
void WriteLongLong(long long d) {
|
||||
char buffer[256];
|
||||
#if _MSC_VER
|
||||
int ret = sprintf_s(buffer, sizeof(buffer), "%lld", d);
|
||||
#else
|
||||
int ret = snprintf(buffer, sizeof(buffer), "%lld", d);
|
||||
#endif
|
||||
RAPIDJSON_ASSERT(ret >= 1);
|
||||
for (int i = 0; i < ret; i++)
|
||||
stream_.Put(buffer[i]);
|
||||
}
|
||||
|
||||
void WriteULongLong(unsigned long long d) {
|
||||
char buffer[256];
|
||||
#if _MSC_VER
|
||||
int ret = sprintf_s(buffer, sizeof(buffer), "%llu", d);
|
||||
#else
|
||||
int ret = snprintf(buffer, sizeof(buffer), "%llu", d);
|
||||
#endif
|
||||
RAPIDJSON_ASSERT(ret >= 1);
|
||||
for (int i = 0; i < ret; i++)
|
||||
stream_.Put(buffer[i]);
|
||||
}
|
||||
|
||||
void WriteString(const Ch* str, SizeType length) {
|
||||
static const char hexDigits[] = "0123456789ABCDEF";
|
||||
static const char escape[256] = {
|
||||
#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
//0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
|
||||
'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
|
||||
0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20
|
||||
Z16, Z16, // 30~4F
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50
|
||||
Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF
|
||||
#undef Z16
|
||||
};
|
||||
|
||||
stream_.Put('\"');
|
||||
for (const Ch* p = str; p != str + length; ++p) {
|
||||
if ((sizeof(Ch) == 1 || characterOk(*p)) && escape[(unsigned char)*p]) {
|
||||
//if ((sizeof(Ch) == 1 || *p < 256) && escape[(unsigned char)*p]) {
|
||||
stream_.Put('\\');
|
||||
stream_.Put(escape[(unsigned char)*p]);
|
||||
if (escape[(unsigned char)*p] == 'u') {
|
||||
stream_.Put('0');
|
||||
stream_.Put('0');
|
||||
stream_.Put(hexDigits[(*p) >> 4]);
|
||||
stream_.Put(hexDigits[(*p) & 0xF]);
|
||||
}
|
||||
}
|
||||
else
|
||||
stream_.Put(*p);
|
||||
}
|
||||
stream_.Put('\"');
|
||||
}
|
||||
|
||||
void WriteStartObject() { stream_.Put('{'); }
|
||||
void WriteEndObject() { stream_.Put('}'); }
|
||||
void WriteStartArray() { stream_.Put('['); }
|
||||
void WriteEndArray() { stream_.Put(']'); }
|
||||
|
||||
void Prefix(Type type) {
|
||||
(void)type;
|
||||
if (level_stack_.GetSize() != 0) { // this value is not at root
|
||||
Level* level = level_stack_.template Top<Level>();
|
||||
if (level->valueCount > 0) {
|
||||
if (level->inArray)
|
||||
stream_.Put(','); // add comma if it is not the first element in array
|
||||
else // in object
|
||||
stream_.Put((level->valueCount % 2 == 0) ? ',' : ':');
|
||||
}
|
||||
if (!level->inArray && level->valueCount % 2 == 0)
|
||||
RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
|
||||
level->valueCount++;
|
||||
}
|
||||
else
|
||||
RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType);
|
||||
}
|
||||
|
||||
Stream& stream_;
|
||||
internal::Stack<Allocator> level_stack_;
|
||||
|
||||
private:
|
||||
// Prohibit assignment for VC C4512 warning
|
||||
Writer& operator=(const Writer& w);
|
||||
};
|
||||
|
||||
} // namespace rapidjson
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // RAPIDJSON_RAPIDJSON_H_
|
||||
#ifndef RAPIDJSON_WRITER_H_
|
||||
#define RAPIDJSON_WRITER_H_
|
||||
|
||||
#include "rapidjson.h"
|
||||
#include "internal/stack.h"
|
||||
#include "internal/strfunc.h"
|
||||
#include <cstdio> // snprintf() or _sprintf_s()
|
||||
#include <new> // placement new
|
||||
#include <limits>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4127) // conditional expression is constant
|
||||
#endif
|
||||
|
||||
namespace rapidjson {
|
||||
|
||||
//! JSON writer
|
||||
/*! Writer implements the concept Handler.
|
||||
It generates JSON text by events to an output stream.
|
||||
|
||||
User may programmatically calls the functions of a writer to generate JSON text.
|
||||
|
||||
On the other side, a writer can also be passed to objects that generates events,
|
||||
|
||||
for example Reader::Parse() and Document::Accept().
|
||||
|
||||
\tparam Stream Type of ouptut stream.
|
||||
\tparam Encoding Encoding of both source strings and output.
|
||||
\implements Handler
|
||||
*/
|
||||
template<typename Stream, typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<> >
|
||||
class Writer {
|
||||
public:
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
Writer(Stream& stream, int precision = 20, Allocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) :
|
||||
stream_(stream), level_stack_(allocator, levelDepth * sizeof(Level))
|
||||
{
|
||||
#if _MSC_VER
|
||||
(void) sprintf_s(double_format, sizeof(double_format), "%%0.%dg", precision);
|
||||
(void) sprintf_s( long_double_format, sizeof( long_double_format ), "%%0.%dLg", precision );
|
||||
#else
|
||||
(void) snprintf(double_format, sizeof(double_format), "%%0.%dg", precision);
|
||||
(void) snprintf( long_double_format, sizeof( long_double_format ), "%%0.%dLg", precision );
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
protected:
|
||||
char double_format[32];
|
||||
char long_double_format[32];
|
||||
public:
|
||||
|
||||
//@name Implementation of Handler
|
||||
//@{
|
||||
|
||||
Writer& Null() { Prefix(kNullType); WriteNull(); return *this; }
|
||||
Writer& Bool(bool b) { Prefix(b ? kTrueType : kFalseType); WriteBool(b); return *this; }
|
||||
Writer& Int(int i) { Prefix(kNumberType); WriteInt(i); return *this; }
|
||||
Writer& Uint(unsigned u) { Prefix(kNumberType); WriteUint(u); return *this; }
|
||||
Writer& Int64(int64_t i64) { Prefix(kNumberType); WriteInt64(i64); return *this; }
|
||||
Writer& Uint64(uint64_t u64) { Prefix(kNumberType); WriteUint64(u64); return *this; }
|
||||
Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; }
|
||||
Writer& LongDouble(long double d) { Prefix(kNumberType); WriteLongDouble(d); return *this; }
|
||||
Writer& LongLong(long long d) { Prefix(kNumberType); WriteLongLong(d); return *this; }
|
||||
Writer& ULongLong(unsigned long long d) { Prefix(kNumberType); WriteULongLong(d); return *this; }
|
||||
|
||||
Writer& String(const Ch* str, SizeType length, bool copy = false) {
|
||||
(void)copy;
|
||||
Prefix(kStringType);
|
||||
WriteString(str, length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Writer& StartObject() {
|
||||
Prefix(kObjectType);
|
||||
new (level_stack_.template Push<Level>()) Level(false);
|
||||
WriteStartObject();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Writer& EndObject(SizeType memberCount = 0) {
|
||||
(void)memberCount;
|
||||
RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
|
||||
RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray);
|
||||
level_stack_.template Pop<Level>(1);
|
||||
WriteEndObject();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Writer& StartArray() {
|
||||
Prefix(kArrayType);
|
||||
new (level_stack_.template Push<Level>()) Level(true);
|
||||
WriteStartArray();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Writer& EndArray(SizeType elementCount = 0) {
|
||||
(void)elementCount;
|
||||
RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
|
||||
RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray);
|
||||
level_stack_.template Pop<Level>(1);
|
||||
WriteEndArray();
|
||||
return *this;
|
||||
}
|
||||
//@}
|
||||
|
||||
//! Simpler but slower overload.
|
||||
Writer& String(const Ch* str) { return String(str, internal::StrLen(str)); }
|
||||
|
||||
protected:
|
||||
//! Information for each nested level
|
||||
struct Level {
|
||||
Level(bool inArray_) : inArray(inArray_), valueCount(0) {}
|
||||
bool inArray; //!< true if in array, otherwise in object
|
||||
size_t valueCount; //!< number of values in this level
|
||||
};
|
||||
|
||||
static const size_t kDefaultLevelDepth = 32;
|
||||
|
||||
void WriteNull() {
|
||||
stream_.Put('n'); stream_.Put('u'); stream_.Put('l'); stream_.Put('l');
|
||||
}
|
||||
|
||||
void WriteBool(bool b) {
|
||||
if (b) {
|
||||
stream_.Put('t'); stream_.Put('r'); stream_.Put('u'); stream_.Put('e');
|
||||
}
|
||||
else {
|
||||
stream_.Put('f'); stream_.Put('a'); stream_.Put('l'); stream_.Put('s'); stream_.Put('e');
|
||||
}
|
||||
}
|
||||
|
||||
void WriteInt(int i) {
|
||||
if (i < 0) {
|
||||
stream_.Put('-');
|
||||
i = -i;
|
||||
}
|
||||
WriteUint((unsigned)i);
|
||||
}
|
||||
|
||||
void WriteUint(unsigned u) {
|
||||
char buffer[10];
|
||||
char *p = buffer;
|
||||
do {
|
||||
*p++ = (u % 10) + '0';
|
||||
u /= 10;
|
||||
} while (u > 0);
|
||||
|
||||
do {
|
||||
--p;
|
||||
stream_.Put(*p);
|
||||
} while (p != buffer);
|
||||
}
|
||||
|
||||
void WriteInt64(int64_t i64) {
|
||||
if (i64 < 0) {
|
||||
stream_.Put('-');
|
||||
i64 = -i64;
|
||||
}
|
||||
WriteUint64((uint64_t)i64);
|
||||
}
|
||||
|
||||
void WriteUint64(uint64_t u64) {
|
||||
char buffer[20];
|
||||
char *p = buffer;
|
||||
do {
|
||||
*p++ = char(u64 % 10) + '0';
|
||||
u64 /= 10;
|
||||
} while (u64 > 0);
|
||||
|
||||
do {
|
||||
--p;
|
||||
stream_.Put(*p);
|
||||
} while (p != buffer);
|
||||
}
|
||||
|
||||
// cereal Temporary until constexpr support is added in RTM
|
||||
#ifdef _MSC_VER
|
||||
template <class Ch>
|
||||
bool characterOk( Ch c )
|
||||
{
|
||||
return c < 256;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool characterOk<char>( Ch )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
template<class Ch>
|
||||
typename std::enable_if < std::numeric_limits<Ch>::max() < 265, bool>::type
|
||||
characterOk( Ch c )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class Ch>
|
||||
typename std::enable_if<std::numeric_limits<Ch>::max() >= 265, bool>::type
|
||||
characterOk(Ch c)
|
||||
{ return c < 256; }
|
||||
#endif
|
||||
|
||||
//! \todo Optimization with custom double-to-string converter.
|
||||
void WriteDouble(double d) {
|
||||
char buffer[100];
|
||||
#if _MSC_VER
|
||||
int ret = sprintf_s(buffer, sizeof(buffer), double_format, d);
|
||||
#else
|
||||
int ret = snprintf(buffer, sizeof(buffer), double_format, d);
|
||||
#endif
|
||||
RAPIDJSON_ASSERT(ret >= 1);
|
||||
for (int i = 0; i < ret; i++)
|
||||
stream_.Put(buffer[i]);
|
||||
}
|
||||
|
||||
void WriteLongDouble(long double d) {
|
||||
char buffer[256];
|
||||
#if _MSC_VER
|
||||
int ret = sprintf_s(buffer, sizeof(buffer), long_double_format, d);
|
||||
#else
|
||||
int ret = snprintf(buffer, sizeof(buffer), long_double_format, d);
|
||||
#endif
|
||||
RAPIDJSON_ASSERT(ret >= 1);
|
||||
for (int i = 0; i < ret; i++)
|
||||
stream_.Put(buffer[i]);
|
||||
}
|
||||
|
||||
void WriteLongLong(long long d) {
|
||||
char buffer[256];
|
||||
#if _MSC_VER
|
||||
int ret = sprintf_s(buffer, sizeof(buffer), "%lld", d);
|
||||
#else
|
||||
int ret = snprintf(buffer, sizeof(buffer), "%lld", d);
|
||||
#endif
|
||||
RAPIDJSON_ASSERT(ret >= 1);
|
||||
for (int i = 0; i < ret; i++)
|
||||
stream_.Put(buffer[i]);
|
||||
}
|
||||
|
||||
void WriteULongLong(unsigned long long d) {
|
||||
char buffer[256];
|
||||
#if _MSC_VER
|
||||
int ret = sprintf_s(buffer, sizeof(buffer), "%llu", d);
|
||||
#else
|
||||
int ret = snprintf(buffer, sizeof(buffer), "%llu", d);
|
||||
#endif
|
||||
RAPIDJSON_ASSERT(ret >= 1);
|
||||
for (int i = 0; i < ret; i++)
|
||||
stream_.Put(buffer[i]);
|
||||
}
|
||||
|
||||
void WriteString(const Ch* str, SizeType length) {
|
||||
static const char hexDigits[] = "0123456789ABCDEF";
|
||||
static const char escape[256] = {
|
||||
#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
//0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
|
||||
'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
|
||||
0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20
|
||||
Z16, Z16, // 30~4F
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50
|
||||
Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF
|
||||
#undef Z16
|
||||
};
|
||||
|
||||
stream_.Put('\"');
|
||||
for (const Ch* p = str; p != str + length; ++p) {
|
||||
if ((sizeof(Ch) == 1 || characterOk(*p)) && escape[(unsigned char)*p]) {
|
||||
//if ((sizeof(Ch) == 1 || *p < 256) && escape[(unsigned char)*p]) {
|
||||
stream_.Put('\\');
|
||||
stream_.Put(escape[(unsigned char)*p]);
|
||||
if (escape[(unsigned char)*p] == 'u') {
|
||||
stream_.Put('0');
|
||||
stream_.Put('0');
|
||||
stream_.Put(hexDigits[(*p) >> 4]);
|
||||
stream_.Put(hexDigits[(*p) & 0xF]);
|
||||
}
|
||||
}
|
||||
else
|
||||
stream_.Put(*p);
|
||||
}
|
||||
stream_.Put('\"');
|
||||
}
|
||||
|
||||
void WriteStartObject() { stream_.Put('{'); }
|
||||
void WriteEndObject() { stream_.Put('}'); }
|
||||
void WriteStartArray() { stream_.Put('['); }
|
||||
void WriteEndArray() { stream_.Put(']'); }
|
||||
|
||||
void Prefix(Type type) {
|
||||
(void)type;
|
||||
if (level_stack_.GetSize() != 0) { // this value is not at root
|
||||
Level* level = level_stack_.template Top<Level>();
|
||||
if (level->valueCount > 0) {
|
||||
if (level->inArray)
|
||||
stream_.Put(','); // add comma if it is not the first element in array
|
||||
else // in object
|
||||
stream_.Put((level->valueCount % 2 == 0) ? ',' : ':');
|
||||
}
|
||||
if (!level->inArray && level->valueCount % 2 == 0)
|
||||
RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
|
||||
level->valueCount++;
|
||||
}
|
||||
else
|
||||
RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType);
|
||||
}
|
||||
|
||||
Stream& stream_;
|
||||
internal::Stack<Allocator> level_stack_;
|
||||
|
||||
private:
|
||||
// Prohibit assignment for VC C4512 warning
|
||||
Writer& operator=(const Writer& w);
|
||||
};
|
||||
|
||||
} // namespace rapidjson
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // RAPIDJSON_RAPIDJSON_H_
|
||||
|
@ -57,7 +57,7 @@ namespace cereal
|
||||
ar( _CEREAL_NVP("type", bitset_detail::type::ulong) );
|
||||
ar( _CEREAL_NVP("data", b) );
|
||||
}
|
||||
catch( std::overflow_error const & e )
|
||||
catch( std::overflow_error const & )
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -65,7 +65,7 @@ namespace cereal
|
||||
ar( _CEREAL_NVP("type", bitset_detail::type::ullong) );
|
||||
ar( _CEREAL_NVP("data", b) );
|
||||
}
|
||||
catch( std::overflow_error const & e )
|
||||
catch( std::overflow_error const & )
|
||||
{
|
||||
ar( _CEREAL_NVP("type", bitset_detail::type::string) );
|
||||
ar( _CEREAL_NVP("data", bits.to_string()) );
|
||||
|
@ -52,7 +52,7 @@ namespace cereal
|
||||
size_type size;
|
||||
ar( make_size_tag( size ) );
|
||||
|
||||
deque.resize( size );
|
||||
deque.resize( static_cast<size_t>( size ) );
|
||||
|
||||
for( auto & i : deque )
|
||||
ar( i );
|
||||
|
@ -58,7 +58,7 @@ namespace cereal
|
||||
size_type size;
|
||||
ar( make_size_tag( size ) );
|
||||
|
||||
forward_list.resize( size );
|
||||
forward_list.resize( static_cast<size_t>( size ) );
|
||||
|
||||
for( auto & i : forward_list )
|
||||
ar( i );
|
||||
|
@ -52,7 +52,7 @@ namespace cereal
|
||||
size_type size;
|
||||
ar( make_size_tag( size ) );
|
||||
|
||||
list.resize( size );
|
||||
list.resize( static_cast<size_t>( size ) );
|
||||
|
||||
for( auto & i : list )
|
||||
ar( i );
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include <cereal/details/polymorphic_impl.hpp>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define CONSTEXPR
|
||||
#define CONSTEXPR
|
||||
#else
|
||||
#define CONSTEXPR constexpr
|
||||
#endif
|
||||
@ -128,7 +128,7 @@ namespace cereal
|
||||
default constructors, but on clang/gcc this will return false. So we also need to check for that here.
|
||||
@internal */
|
||||
template<class Archive, class T> inline
|
||||
typename std::enable_if<(std::is_default_constructible<T>::value
|
||||
typename std::enable_if<(std::is_default_constructible<T>::value
|
||||
|| traits::has_load_and_allocate<T, Archive>::value)
|
||||
&& !std::is_abstract<T>::value, bool>::type
|
||||
serialize_wrapper(Archive & ar, std::shared_ptr<T> & ptr, std::uint32_t const nameid)
|
||||
@ -146,7 +146,7 @@ namespace cereal
|
||||
using the derived class serialize function
|
||||
@internal */
|
||||
template<class Archive, class T, class D> inline
|
||||
typename std::enable_if<(std::is_default_constructible<T>::value
|
||||
typename std::enable_if<(std::is_default_constructible<T>::value
|
||||
|| traits::has_load_and_allocate<T, Archive>::value)
|
||||
&& !std::is_abstract<T>::value, bool>::type
|
||||
serialize_wrapper(Archive & ar, std::unique_ptr<T, D> & ptr, std::uint32_t const nameid)
|
||||
@ -166,7 +166,7 @@ namespace cereal
|
||||
this was a polymorphic type serialized by its proper pointer type
|
||||
@internal */
|
||||
template<class Archive, class T> inline
|
||||
typename std::enable_if<(!std::is_default_constructible<T>::value
|
||||
typename std::enable_if<(!std::is_default_constructible<T>::value
|
||||
&& !traits::has_load_and_allocate<T, Archive>::value)
|
||||
|| std::is_abstract<T>::value, bool>::type
|
||||
serialize_wrapper(Archive &, std::shared_ptr<T> &, std::uint32_t const nameid)
|
||||
|
@ -55,7 +55,7 @@ namespace cereal
|
||||
ar( make_size_tag( size ) );
|
||||
|
||||
map.clear();
|
||||
map.reserve( size );
|
||||
map.reserve( static_cast<std::size_t>( size ) );
|
||||
|
||||
for( size_type i = 0; i < size; ++i )
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ namespace cereal
|
||||
ar( make_size_tag( size ) );
|
||||
|
||||
set.clear();
|
||||
set.reserve( size );
|
||||
set.reserve( static_cast<std::size_t>( size ) );
|
||||
|
||||
for( size_type i = 0; i < size; ++i )
|
||||
{
|
||||
|
@ -54,8 +54,8 @@ namespace cereal
|
||||
size_type vectorSize;
|
||||
ar( make_size_tag( vectorSize ) );
|
||||
|
||||
vector.resize( vectorSize );
|
||||
ar( binary_data( vector.data(), vectorSize * sizeof(T) ) );
|
||||
vector.resize( static_cast<std::size_t>( vectorSize ) );
|
||||
ar( binary_data( vector.data(), static_cast<std::size_t>( vectorSize ) * sizeof(T) ) );
|
||||
}
|
||||
|
||||
//! Serialization for non-arithmetic (and bool) vector types
|
||||
|
@ -217,6 +217,6 @@ int main()
|
||||
// std::cout << cereal::traits::has_load_and_allocate<A, cereal::JSONInputArchive>::value << std::endl;
|
||||
// ar( ptr );
|
||||
//}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
5850
unittests.cpp
5850
unittests.cpp
File diff suppressed because it is too large
Load Diff
@ -66,7 +66,7 @@
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_54;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@ -74,7 +74,7 @@
|
||||
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_54;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@ -89,6 +89,7 @@
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>libboost_unit_test_framework-vc120-mt-gd-1_55.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@ -113,6 +114,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>libboost_unit_test_framework-vc120-mt-1_55.lib;libboost_test_exec_monitor-vc120-mt-1_55.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
Loading…
x
Reference in New Issue
Block a user