Commit 6ee69155 authored by miloyip's avatar miloyip

Move GenericPointer::kInvalidIndex to rapidjson::kPointerInvalidIndex

It is needed to prevent linking error for gcc/clang
parent bd435f76
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
RAPIDJSON_NAMESPACE_BEGIN RAPIDJSON_NAMESPACE_BEGIN
static const SizeType kPointerInvalidIndex = ~SizeType(0);
template <typename ValueType, typename Allocator = CrtAllocator> template <typename ValueType, typename Allocator = CrtAllocator>
class GenericPointer { class GenericPointer {
public: public:
...@@ -28,11 +30,9 @@ public: ...@@ -28,11 +30,9 @@ public:
struct Token { struct Token {
const Ch* name; const Ch* name;
SizeType length; SizeType length;
SizeType index; //!< A valid index if not equal to kInvalidIndex. SizeType index; //!< A valid index if not equal to kPointerInvalidIndex.
}; };
static const SizeType kInvalidIndex = -1;
GenericPointer() GenericPointer()
: allocator_(), : allocator_(),
ownAllocator_(), ownAllocator_(),
...@@ -150,7 +150,7 @@ public: ...@@ -150,7 +150,7 @@ public:
bool exist = true; bool exist = true;
for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
if (v->GetType() != kObjectType && v->GetType() != kArrayType) { if (v->GetType() != kObjectType && v->GetType() != kArrayType) {
if (t->index == kInvalidIndex) if (t->index == kPointerInvalidIndex)
v->SetObject(); v->SetObject();
else else
v->SetArray(); v->SetArray();
...@@ -170,7 +170,7 @@ public: ...@@ -170,7 +170,7 @@ public:
} }
break; break;
case kArrayType: case kArrayType:
if (t->index == kInvalidIndex) if (t->index == kPointerInvalidIndex)
v->SetArray(); // Change to Array v->SetArray(); // Change to Array
if (t->index >= v->Size()) { if (t->index >= v->Size()) {
v->Reserve(t->index + 1, allocator); v->Reserve(t->index + 1, allocator);
...@@ -207,7 +207,7 @@ public: ...@@ -207,7 +207,7 @@ public:
} }
break; break;
case kArrayType: case kArrayType:
if (t->index == kInvalidIndex || t->index >= v->Size()) if (t->index == kPointerInvalidIndex || t->index >= v->Size())
return 0; return 0;
v = &((*v)[t->index]); v = &((*v)[t->index]);
break; break;
...@@ -307,7 +307,7 @@ private: ...@@ -307,7 +307,7 @@ private:
} }
} }
token.index = isNumber ? n : kInvalidIndex; token.index = isNumber ? n : kPointerInvalidIndex;
} }
RAPIDJSON_ASSERT(name <= nameBuffer_ + length); // Should not overflow buffer RAPIDJSON_ASSERT(name <= nameBuffer_ + length); // Should not overflow buffer
......
...@@ -128,7 +128,7 @@ TEST(Pointer, Parse) { ...@@ -128,7 +128,7 @@ TEST(Pointer, Parse) {
EXPECT_TRUE(p.IsValid()); EXPECT_TRUE(p.IsValid());
EXPECT_EQ(1u, p.GetTokenCount()); EXPECT_EQ(1u, p.GetTokenCount());
EXPECT_STREQ("01", p.GetTokens()[0].name); EXPECT_STREQ("01", p.GetTokens()[0].name);
EXPECT_EQ(Pointer::kInvalidIndex, p.GetTokens()[0].index); EXPECT_EQ(kPointerInvalidIndex, p.GetTokens()[0].index);
} }
if (sizeof(SizeType) == 4) { if (sizeof(SizeType) == 4) {
...@@ -137,7 +137,7 @@ TEST(Pointer, Parse) { ...@@ -137,7 +137,7 @@ TEST(Pointer, Parse) {
EXPECT_TRUE(p.IsValid()); EXPECT_TRUE(p.IsValid());
EXPECT_EQ(1u, p.GetTokenCount()); EXPECT_EQ(1u, p.GetTokenCount());
EXPECT_STREQ("4294967296", p.GetTokens()[0].name); EXPECT_STREQ("4294967296", p.GetTokens()[0].name);
EXPECT_EQ(Pointer::kInvalidIndex, p.GetTokens()[0].index); EXPECT_EQ(kPointerInvalidIndex, p.GetTokens()[0].index);
} }
} }
...@@ -167,7 +167,7 @@ TEST(Pointer, Stringify) { ...@@ -167,7 +167,7 @@ TEST(Pointer, Stringify) {
} }
// Construct a Pointer with static tokens, no dynamic allocation involved. // Construct a Pointer with static tokens, no dynamic allocation involved.
#define NAME(s) { s, sizeof(s) / sizeof(s[0]) - 1, Pointer::kInvalidIndex } #define NAME(s) { s, sizeof(s) / sizeof(s[0]) - 1, kPointerInvalidIndex }
#define INDEX(i) { #i, sizeof(#i) - 1, i } #define INDEX(i) { #i, sizeof(#i) - 1, i }
static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(0) }; // equivalent to "/foo/0" static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(0) }; // equivalent to "/foo/0"
......
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