Move GenericPointer::kInvalidIndex to rapidjson::kPointerInvalidIndex

It is needed to prevent linking error for gcc/clang
This commit is contained in:
miloyip 2015-04-11 14:48:33 +08:00
parent bd435f76ab
commit 6ee691550f
2 changed files with 10 additions and 10 deletions

View File

@ -19,6 +19,8 @@
RAPIDJSON_NAMESPACE_BEGIN
static const SizeType kPointerInvalidIndex = ~SizeType(0);
template <typename ValueType, typename Allocator = CrtAllocator>
class GenericPointer {
public:
@ -28,11 +30,9 @@ public:
struct Token {
const Ch* name;
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()
: allocator_(),
ownAllocator_(),
@ -150,7 +150,7 @@ public:
bool exist = true;
for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
if (v->GetType() != kObjectType && v->GetType() != kArrayType) {
if (t->index == kInvalidIndex)
if (t->index == kPointerInvalidIndex)
v->SetObject();
else
v->SetArray();
@ -170,7 +170,7 @@ public:
}
break;
case kArrayType:
if (t->index == kInvalidIndex)
if (t->index == kPointerInvalidIndex)
v->SetArray(); // Change to Array
if (t->index >= v->Size()) {
v->Reserve(t->index + 1, allocator);
@ -207,7 +207,7 @@ public:
}
break;
case kArrayType:
if (t->index == kInvalidIndex || t->index >= v->Size())
if (t->index == kPointerInvalidIndex || t->index >= v->Size())
return 0;
v = &((*v)[t->index]);
break;
@ -307,7 +307,7 @@ private:
}
}
token.index = isNumber ? n : kInvalidIndex;
token.index = isNumber ? n : kPointerInvalidIndex;
}
RAPIDJSON_ASSERT(name <= nameBuffer_ + length); // Should not overflow buffer

View File

@ -128,7 +128,7 @@ TEST(Pointer, Parse) {
EXPECT_TRUE(p.IsValid());
EXPECT_EQ(1u, p.GetTokenCount());
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) {
@ -137,7 +137,7 @@ TEST(Pointer, Parse) {
EXPECT_TRUE(p.IsValid());
EXPECT_EQ(1u, p.GetTokenCount());
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) {
}
// 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 }
static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(0) }; // equivalent to "/foo/0"