21RAPIDJSON_DIAG_OFF(c++98-compat)
28#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
52#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
60 static_assert(std::is_constructible<Value>::value,
"");
61 static_assert(std::is_default_constructible<Value>::value,
"");
63 static_assert(!std::is_copy_constructible<Value>::value,
"");
65 static_assert(std::is_move_constructible<Value>::value,
"");
68 static_assert(std::is_nothrow_constructible<Value>::value,
"");
69 static_assert(std::is_nothrow_default_constructible<Value>::value,
"");
70 static_assert(!std::is_nothrow_copy_constructible<Value>::value,
"");
71 static_assert(std::is_nothrow_move_constructible<Value>::value,
"");
74 static_assert(std::is_assignable<Value,Value>::value,
"");
76 static_assert(!std::is_copy_assignable<Value>::value,
"");
78 static_assert(std::is_move_assignable<Value>::value,
"");
81 static_assert(std::is_nothrow_assignable<Value, Value>::value,
"");
83 static_assert(!std::is_nothrow_copy_assignable<Value>::value,
"");
85 static_assert(std::is_nothrow_move_assignable<Value>::value,
"");
88 static_assert(std::is_destructible<Value>::value,
"");
90 static_assert(std::is_nothrow_destructible<Value>::value,
"");
101 x.Reserve(4u, allocator);
102 x.PushBack(1, allocator).PushBack(2, allocator).PushBack(3, allocator).PushBack(4, allocator);
136 y =
StringRef(x.GetString(),x.GetStringLength());
139 EXPECT_EQ(y.GetStringLength(),x.GetStringLength());
141 static char mstr[] =
"mutable";
147#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
158 y = std::move(
Value().SetInt(1234));
164template <
typename A,
typename B>
172template <
typename A,
typename B>
183 x.AddMember(
"hello",
"world", allocator)
184 .AddMember(
"t",
Value(
true).Move(), allocator)
185 .AddMember(
"f",
Value(
false).Move(), allocator)
187 .AddMember(
"i", 123, allocator)
188 .AddMember(
"pi", 3.14, allocator)
189 .AddMember(
"a",
Value(
kArrayType).Move().PushBack(1, allocator).PushBack(2, allocator).PushBack(3, allocator), allocator);
193 const char* cc =
"world";
195 char* c = strdup(
"world");
208 y.CopyFrom(x, crtAllocator);
221 y.AddMember(
"t",
false, crtAllocator);
232 x[
"a"][0].Swap(x[
"a"][1]);
234 x[
"a"][0].Swap(x[
"a"][1]);
238 x[
"a"].PushBack(4, allocator);
249template <
typename Value>
261 EXPECT_EQ(v1.GetString(), v2.GetString());
263 v1.SetString(
"bar",
a);
267 EXPECT_NE(v1.GetString(), v2.GetString());
270 v1.SetArray().PushBack(1234,
a);
275 v1.PushBack(
Value().SetString(
"foo",
a),
a);
280 EXPECT_NE(v1[1].GetString(), v2[1].GetString());
441 EXPECT_EQ(5680, z.Set<
int>(5680).Get<
int>());
449 EXPECT_EQ(3333l, z.Set(3333l).Get<
long>());
450 EXPECT_EQ(4444l, z.Set<
long>(4444l).Get<
long>());
496 EXPECT_EQ(2147483648u, z.Get<
unsigned>());
497 EXPECT_EQ(2147483649u, z.Set(2147483649u).Get<
unsigned>());
498 EXPECT_EQ(2147483650u, z.Set<
unsigned>(2147483650u).Get<
unsigned>());
505 EXPECT_EQ(2222ul, z.Get<
unsigned long>());
506 EXPECT_EQ(3333ul, z.Set(3333ul).Get<
unsigned long>());
507 EXPECT_EQ(4444ul, z.Set<
unsigned long>(4444ul).Get<
unsigned long>());
549 z.SetInt64(2147483648u);
554 z.SetInt64(
int64_t(4294967295u) + 1);
559 z.SetInt64(-
int64_t(2147483648u) - 1);
610 z.SetUint64(
uint64_t(4294967295u) + 1);
656 EXPECT_EQ(57.78, z.Set(57.78).Get<
double>());
657 EXPECT_EQ(58.78, z.Set<
double>(58.78).Get<
double>());
693 EXPECT_EQ(57.78f, z.Set(57.78f).Get<
float>());
694 EXPECT_EQ(58.78f, z.Set<
float>(58.78f).Get<
float>());
703#if !(defined(_MSC_VER) && _MSC_VER < 1800)
748 static const char cstr[] =
"World";
752 EXPECT_EQ(x.GetStringLength(),
sizeof(cstr)-1);
754 static char mstr[] =
"Howdy";
759 EXPECT_EQ(x.GetStringLength(),
sizeof(mstr)-1);
760 strncpy(mstr,
"Hello",
sizeof(mstr));
763 const char* pstr = cstr;
768 EXPECT_EQ(x.GetStringLength(),
sizeof(cstr)-1);
779 Value c(x.GetString(), x.GetStringLength(), allocator);
781 EXPECT_EQ(x.GetStringLength(), c.GetStringLength());
784 x.SetString(
"World", 5);
796 z.SetString(
"Hello");
798 z.SetString(
"Hello", 5);
803 z.SetString(
"Hello");
824 w.SetString(
s,
static_cast<SizeType>(strlen(
s)), allocator);
832 EXPECT_STREQ(
"Apple", z.Set<
const char*>(
"Apple").Get<
const char*>());
834#if RAPIDJSON_HAS_STDSTRING
836 std::string str =
"Hello World";
845 EXPECT_EQ(vs0.GetStringLength(), str.size());
849 Value vs1(str, allocator);
853 EXPECT_EQ(vs1.GetStringLength(), str.size());
858 vs0.SetNull().SetString(str, allocator);
861 EXPECT_EQ(vs0.GetStringLength(), str.size());
873 vs0.Set<std::string>(std::string(
"Apple"), allocator);
874 EXPECT_EQ(std::string(
"Apple"), vs0.Get<std::string>());
875 vs0.Set(std::string(
"Orange"), allocator);
876 EXPECT_EQ(std::string(
"Orange"), vs0.Get<std::string>());
885 const char* nullPtr = 0;
902 v.SetString(nullPtr, 0u);
907 v.SetString(nullPtr, 0u, allocator);
918 Value v(nullPtr, 0u, allocator);
924template <
typename T,
typename Allocator>
925static void TestArray(
T& x,
Allocator& allocator) {
930 x.PushBack(v, allocator);
932 x.PushBack(v, allocator);
934 x.PushBack(v, allocator);
936 x.PushBack(v, allocator);
938 x.PushBack(
"foo", allocator);
957#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
961 y2.PushBack(
Value(
true), allocator);
962 y2.PushBack(std::move(
Value(
kArrayType).PushBack(
Value(1), allocator).PushBack(
"foo", allocator)), allocator);
973 typename T::ValueIterator itr = x.Begin();
992 typename T::ConstValueIterator citr =
y.Begin();
1029 for (
int i = 0; i < 10; i++)
1030 x.PushBack(
Value(
kArrayType).PushBack(i, allocator).Move(), allocator);
1033 itr = x.Erase(x.Begin());
1036 for (
int i = 0; i < 9; i++)
1040 itr = x.Erase(x.End() - 1);
1043 for (
int i = 0; i < 8; i++)
1047 itr = x.Erase(x.Begin() + 4);
1050 for (
int i = 0; i < 4; i++)
1052 for (
int i = 4; i < 7; i++)
1057 const unsigned n = 10;
1058 for (
unsigned first = 0; first < n; first++) {
1059 for (
unsigned last = first; last <= n; last++) {
1061 for (
unsigned i = 0; i < n; i++)
1062 x.PushBack(
Value(
kArrayType).PushBack(i, allocator).Move(), allocator);
1064 itr = x.Erase(x.Begin() + first, x.Begin() + last);
1070 size_t removeCount = last - first;
1072 for (
unsigned i = 0; i < first; i++)
1074 for (
unsigned i = first; i < n - removeCount; i++)
1100 TestArray(x, allocator);
1105 for (
int i = 0; i < 10; i++)
1107 x.PushBack(i, allocator);
1112 x.Erase(std::remove(x.Begin(), x.End(), null), x.End());
1114 for (
int i = 0; i < 5; i++)
1129 TestArray(
a, allocator);
1135 a.PushBack(1, allocator);
1151 a.PushBack(1, allocator);
1163 y.PushBack(123, allocator);
1165 Value x(y.GetArray());
1175 y.PushBack(123, allocator);
1176 x.PushBack(y.GetArray(), allocator);
1185#if RAPIDJSON_HAS_CXX11_RANGE_FOR
1190 for (
int i = 0; i < 10; i++)
1191 x.PushBack(i, allocator);
1195 for (
auto& v : x.GetArray()) {
1203 for (
const auto& v :
const_cast<const Value&
>(x).GetArray()) {
1215template <
typename T,
typename Allocator>
1216static void TestObject(
T& x,
Allocator& allocator) {
1220 x.AddMember(
"A",
"Apple", allocator);
1225 x.AddMember(
"B",
"Banana", allocator);
1231 o.AddMember(
"true",
true, allocator);
1232 o.AddMember(
"false",
false, allocator);
1233 o.AddMember(
"int", -1, allocator);
1234 o.AddMember(
"uint", 1u, allocator);
1235 o.AddMember(
"int64",
int64_t(-4294967296), allocator);
1236 o.AddMember(
"uint64",
uint64_t(4294967296), allocator);
1237 o.AddMember(
"double", 3.14, allocator);
1238 o.AddMember(
"string",
"Jelly", allocator);
1255 o.AddMember(n,
"string", allocator);
1259 o.AddMember(
count, o.MemberCount(), allocator);
1263#if RAPIDJSON_HAS_STDSTRING
1267 o.AddMember(
"b", std::string(
"Banana"), allocator);
1271 o.RemoveMember(std::string(
"b"));
1276#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1280 o.AddMember(
Value(
"true"),
Value(
true), allocator);
1281 o.AddMember(
Value(
"false"),
Value(
false).Move(), allocator);
1282 o.AddMember(
Value(
"int").Move(),
Value(-1), allocator);
1283 o.AddMember(
"uint", std::move(
Value().SetUint(1u)), allocator);
1294 const Value C0D(
"C\0D", 3);
1295 name.SetString(C0D.GetString(), 3);
1296 value.SetString(
"CherryD", 7);
1305#if RAPIDJSON_HAS_STDSTRING
1309 name.SetString(
"C\0D");
1316 othername.SetString(
"C\0D");
1332#if RAPIDJSON_HAS_STDSTRING
1334 EXPECT_STREQ(
"Apple", y[std::string(
"A")].GetString());
1348 EXPECT_TRUE(memcmp(itr->name.GetString(),
"C\0D", 4) == 0);
1364 EXPECT_TRUE(memcmp(citr->name.GetString(),
"C\0D", 4) == 0);
1370 itr = x.MemberBegin();
1371 citr = x.MemberBegin();
1385 itr += citr - x.MemberBegin();
1412 const char keys[][2] = {
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j" };
1413 for (
int i = 0; i < 10; i++)
1414 x.AddMember(keys[i],
Value(
kArrayType).PushBack(i, allocator), allocator);
1420 itr = x.EraseMember(x.MemberBegin());
1424 for (; itr != x.MemberEnd(); ++itr) {
1425 size_t i =
static_cast<size_t>((itr - x.MemberBegin())) + 1;
1427 EXPECT_EQ(
static_cast<int>(i), itr->value[0].GetInt());
1431 itr = x.EraseMember(x.MemberEnd() - 1);
1435 for (; itr != x.MemberEnd(); ++itr) {
1436 size_t i =
static_cast<size_t>(itr - x.MemberBegin()) + 1;
1438 EXPECT_EQ(
static_cast<int>(i), itr->value[0].GetInt());
1442 itr = x.EraseMember(x.MemberBegin() + 4);
1446 for (; itr != x.MemberEnd(); ++itr) {
1447 size_t i =
static_cast<size_t>(itr - x.MemberBegin());
1448 i += (i < 4) ? 1 : 2;
1450 EXPECT_EQ(
static_cast<int>(i), itr->value[0].GetInt());
1455 const unsigned n = 10;
1456 for (
unsigned first = 0; first < n; first++) {
1457 for (
unsigned last = first; last <= n; last++) {
1458 x.RemoveAllMembers();
1459 for (
unsigned i = 0; i < n; i++)
1460 x.AddMember(keys[i],
Value(
kArrayType).PushBack(i, allocator), allocator);
1462 itr = x.EraseMember(x.MemberBegin() +
static_cast<int>(first), x.MemberBegin() +
static_cast<int>(last));
1466 EXPECT_EQ(x.MemberBegin() +
static_cast<int>(first), itr);
1468 size_t removeCount = last - first;
1469 EXPECT_EQ(n - removeCount, x.MemberCount());
1470 for (
unsigned i = 0; i < first; i++)
1472 for (
unsigned i = first; i < n - removeCount; i++)
1473 EXPECT_EQ(i + removeCount, x[keys[i+removeCount]][0].GetUint());
1478 x.RemoveAllMembers();
1497 TestObject(x, allocator);
1510 TestObject(o, allocator);
1529 x.RemoveAllMembers();
1544 x.AddMember(
"a",
"apple", allocator);
1545 Value y(x.GetObject());
1552 x.AddMember(
"a",
"apple", allocator);
1554 y.AddMember(
"fruits", x.GetObject(), allocator);
1560#if RAPIDJSON_HAS_CXX11_RANGE_FOR
1565 for (
int i = 0; i < 10; i++) {
1568 x.AddMember(n, i, allocator);
1573 for (
auto& m : x.GetObject()) {
1575 sprintf(
name,
"%d", i);
1584 for (
const auto& m :
const_cast<const Value&
>(x).GetObject()) {
1586 sprintf(
name,
"%d", i);
1602 x.AddMember(
"A",
"Apple", allocator);
1603 x.AddMember(
"B",
"Banana", allocator);
1625 Value number(
static_cast<int>(i * n +
j));
1626 y.PushBack(number, allocator);
1628 x.PushBack(y, allocator);
1634 EXPECT_EQ(
static_cast<int>(i * n +
j), x[i][
j].GetInt());
1645 sprintf(name1,
"%d", i);
1653 sprintf(name2,
"%d",
j);
1655 Value name3(name2,
static_cast<SizeType>(strlen(name2)), allocator);
1656 Value number(
static_cast<int>(i * n +
j));
1657 object.AddMember(name3, number, allocator);
1661 x.AddMember(
name,
object, allocator);
1666 sprintf(name1,
"%d", i);
1670 sprintf(name2,
"%d",
j);
1672 EXPECT_EQ(
static_cast<int>(i * n +
j), x[name1][name2].GetInt());
1680 rapidjson::Document doc;
1682 rapidjson::Value objVal(rapidjson::kObjectType);
1683 objVal.AddMember(
"var1", 123, allocator);
1684 objVal.AddMember(
"var2",
"444", allocator);
1685 objVal.AddMember(
"var3", 555, allocator);
1687 objVal.RemoveMember(
"var3");
1695 V::AllocatorType allocator;
1697 o.AddMember(
"x", 1, allocator);
1700 a.PushBack(1, allocator);
1703static void TestShortStringOptimization(
const char* str) {
1704 const rapidjson::SizeType
len =
static_cast<rapidjson::SizeType
>(strlen(str));
1706 rapidjson::Document doc;
1707 rapidjson::Value val;
1708 val.SetString(str,
len, doc.GetAllocator());
1715 TestShortStringOptimization(
"");
1716 TestShortStringOptimization(
"12345678");
1717 TestShortStringOptimization(
"12345678901");
1718 TestShortStringOptimization(
"123456789012");
1719 TestShortStringOptimization(
"123456789012345");
1720 TestShortStringOptimization(
"1234567890123456");
1727 bool Int(
int) {
return e != 2; }
1728 bool Uint(
unsigned) {
return e != 3; }
1741#define TEST_TERMINATION(e, json)\
1744 EXPECT_FALSE(d.Parse(json).HasParseError()); \
1746 TerminateHandler<e> h;\
1747 EXPECT_FALSE(d.Accept(h));\
1770 return lhs.GetInt() < rhs.GetInt();
1774#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1778 a.PushBack(5, allocator);
1779 a.PushBack(1, allocator);
1780 a.PushBack(3, allocator);
1800 itr2->value.PushBack(itr->value[0],
a);
1801 itr = v.EraseMember(itr);
1809 if (itr->value.Size() == 1)
1810 itr->value = itr->value[0];
1811 MergeDuplicateKey(itr->value,
a);
1814 else if (v.IsArray())
1816 MergeDuplicateKey(*itr,
a);
1845 MergeDuplicateKey(
d,
d.GetAllocator());
C-runtime library allocator.
Helper class for accessing Value of array type.
A document for parsing JSON text as DOM.
Allocator & GetAllocator()
Get the allocator of this document.
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
(Constant) member iterator for a JSON object value
Helper class for accessing Value of object type.
SizeType MemberCount() const
GenericObject AddMember(ValueType &name, ValueType &value, AllocatorType &allocator) const
Default memory allocator used by the parser and DOM.
Concept for allocating, resizing and freeing memory block.
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
#define EXPECT_EQ(val1, val2)
#define EXPECT_NE(val1, val2)
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_NEAR(val1, val2, abs_error)
#define EXPECT_DOUBLE_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
bip::allocator< T, pinnable_mapped_file::segment_manager > allocator
void swap(picojson::value &x, picojson::value &y)
GTEST_API_ bool IsTrue(bool condition)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define T(meth, val, expected)
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
unsigned __int64 uint64_t
bool Key(const char *, SizeType, bool)
bool String(const char *, SizeType, bool)
bool RawNumber(const char *, SizeType, bool)
bool operator()(const Value &lhs, const Value &rhs) const
#define TEST_TERMINATION(e, json)
void TestEqual(const A &a, const B &b)
void TestUnequal(const A &a, const B &b)
yh_object_descriptor object