drop JSON_VALUE_USE_INTERNAL_MAP, JSON_USE_SIMPLE_INTERNAL_ALLOCATOR

And remove some old headers.

These were not actually compiling anymore, and there were outstanding,
known bugs, e.g. https://sourceforge.net/p/jsoncpp/bugs/27
This commit is contained in:
Christopher Dunn
2015-02-22 16:38:05 -06:00
parent 6c898441e3
commit 4788764844
13 changed files with 2 additions and 1662 deletions

View File

@@ -7,9 +7,6 @@
#include <json/assertions.h>
#include <json/value.h>
#include <json/writer.h>
#ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
#include "json_batchallocator.h"
#endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <math.h>
#include <sstream>
@@ -117,10 +114,6 @@ static inline void releaseStringValue(char* value) { free(value); }
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
#if !defined(JSON_IS_AMALGAMATION)
#ifdef JSON_VALUE_USE_INTERNAL_MAP
#include "json_internalarray.inl"
#include "json_internalmap.inl"
#endif // JSON_VALUE_USE_INTERNAL_MAP
#include "json_valueiterator.inl"
#endif // if !defined(JSON_IS_AMALGAMATION)
@@ -162,7 +155,6 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
#ifndef JSON_VALUE_USE_INTERNAL_MAP
// Notes: index_ indicates if the string was allocated when
// a string is stored.
@@ -215,8 +207,6 @@ const char* Value::CZString::c_str() const { return cstr_; }
bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
#endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
@@ -244,19 +234,10 @@ Value::Value(ValueType type) {
case stringValue:
value_.string_ = 0;
break;
#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
value_.map_ = new ObjectValues();
break;
#else
case arrayValue:
value_.array_ = arrayAllocator()->newArray();
break;
case objectValue:
value_.map_ = mapAllocator()->newMap();
break;
#endif
case booleanValue:
value_.bool_ = false;
break;
@@ -326,10 +307,6 @@ Value::Value(bool value) {
Value::Value(const Value& other)
: type_(other.type_), allocated_(false)
#ifdef JSON_VALUE_USE_INTERNAL_MAP
,
itemIsUsed_(0)
#endif
,
comments_(0), start_(other.start_), limit_(other.limit_) {
switch (type_) {
@@ -349,19 +326,10 @@ Value::Value(const Value& other)
allocated_ = false;
}
break;
#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
value_.map_ = new ObjectValues(*other.value_.map_);
break;
#else
case arrayValue:
value_.array_ = arrayAllocator()->newArrayCopy(*other.value_.array_);
break;
case objectValue:
value_.map_ = mapAllocator()->newMapCopy(*other.value_.map_);
break;
#endif
default:
JSON_ASSERT_UNREACHABLE;
}
@@ -388,19 +356,10 @@ Value::~Value() {
if (allocated_)
releaseStringValue(value_.string_);
break;
#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
delete value_.map_;
break;
#else
case arrayValue:
arrayAllocator()->destructArray(value_.array_);
break;
case objectValue:
mapAllocator()->destructMap(value_.map_);
break;
#endif
default:
JSON_ASSERT_UNREACHABLE;
}
@@ -460,7 +419,6 @@ bool Value::operator<(const Value& other) const {
return (value_.string_ == 0 && other.value_.string_) ||
(other.value_.string_ && value_.string_ &&
strcmp(value_.string_, other.value_.string_) < 0);
#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue: {
int delta = int(value_.map_->size() - other.value_.map_->size());
@@ -468,12 +426,6 @@ bool Value::operator<(const Value& other) const {
return delta < 0;
return (*value_.map_) < (*other.value_.map_);
}
#else
case arrayValue:
return value_.array_->compare(*(other.value_.array_)) < 0;
case objectValue:
return value_.map_->compare(*(other.value_.map_)) < 0;
#endif
default:
JSON_ASSERT_UNREACHABLE;
}
@@ -509,17 +461,10 @@ bool Value::operator==(const Value& other) const {
return (value_.string_ == other.value_.string_) ||
(other.value_.string_ && value_.string_ &&
strcmp(value_.string_, other.value_.string_) == 0);
#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
return value_.map_->size() == other.value_.map_->size() &&
(*value_.map_) == (*other.value_.map_);
#else
case arrayValue:
return value_.array_->compare(*(other.value_.array_)) == 0;
case objectValue:
return value_.map_->compare(*(other.value_.map_)) == 0;
#endif
default:
JSON_ASSERT_UNREACHABLE;
}
@@ -769,7 +714,6 @@ ArrayIndex Value::size() const {
case booleanValue:
case stringValue:
return 0;
#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue: // size of the array is highest index + 1
if (!value_.map_->empty()) {
ObjectValues::const_iterator itLast = value_.map_->end();
@@ -779,12 +723,6 @@ ArrayIndex Value::size() const {
return 0;
case objectValue:
return ArrayIndex(value_.map_->size());
#else
case arrayValue:
return Int(value_.array_->size());
case objectValue:
return Int(value_.map_->size());
#endif
}
JSON_ASSERT_UNREACHABLE;
return 0; // unreachable;
@@ -806,19 +744,10 @@ void Value::clear() {
start_ = 0;
limit_ = 0;
switch (type_) {
#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
value_.map_->clear();
break;
#else
case arrayValue:
value_.array_->clear();
break;
case objectValue:
value_.map_->clear();
break;
#endif
default:
break;
}
@@ -829,7 +758,6 @@ void Value::resize(ArrayIndex newSize) {
"in Json::Value::resize(): requires arrayValue");
if (type_ == nullValue)
*this = Value(arrayValue);
#ifndef JSON_VALUE_USE_INTERNAL_MAP
ArrayIndex oldSize = size();
if (newSize == 0)
clear();
@@ -841,9 +769,6 @@ void Value::resize(ArrayIndex newSize) {
}
assert(size() == newSize);
}
#else
value_.array_->resize(newSize);
#endif
}
Value& Value::operator[](ArrayIndex index) {
@@ -852,7 +777,6 @@ Value& Value::operator[](ArrayIndex index) {
"in Json::Value::operator[](ArrayIndex): requires arrayValue");
if (type_ == nullValue)
*this = Value(arrayValue);
#ifndef JSON_VALUE_USE_INTERNAL_MAP
CZString key(index);
ObjectValues::iterator it = value_.map_->lower_bound(key);
if (it != value_.map_->end() && (*it).first == key)
@@ -861,9 +785,6 @@ Value& Value::operator[](ArrayIndex index) {
ObjectValues::value_type defaultValue(key, null);
it = value_.map_->insert(it, defaultValue);
return (*it).second;
#else
return value_.array_->resolveReference(index);
#endif
}
Value& Value::operator[](int index) {
@@ -879,16 +800,11 @@ const Value& Value::operator[](ArrayIndex index) const {
"in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
if (type_ == nullValue)
return null;
#ifndef JSON_VALUE_USE_INTERNAL_MAP
CZString key(index);
ObjectValues::const_iterator it = value_.map_->find(key);
if (it == value_.map_->end())
return null;
return (*it).second;
#else
Value* value = value_.array_->find(index);
return value ? *value : null;
#endif
}
const Value& Value::operator[](int index) const {
@@ -905,9 +821,6 @@ Value& Value::operator[](const char* key) {
void Value::initBasic(ValueType type, bool allocated) {
type_ = type;
allocated_ = allocated;
#ifdef JSON_VALUE_USE_INTERNAL_MAP
itemIsUsed_ = 0;
#endif
comments_ = 0;
start_ = 0;
limit_ = 0;
@@ -919,7 +832,6 @@ Value& Value::resolveReference(const char* key, bool isStatic) {
"in Json::Value::resolveReference(): requires objectValue");
if (type_ == nullValue)
*this = Value(objectValue);
#ifndef JSON_VALUE_USE_INTERNAL_MAP
CZString actualKey(
key, isStatic ? CZString::noDuplication : CZString::duplicateOnCopy);
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
@@ -930,9 +842,6 @@ Value& Value::resolveReference(const char* key, bool isStatic) {
it = value_.map_->insert(it, defaultValue);
Value& value = (*it).second;
return value;
#else
return value_.map_->resolveReference(key, isStatic);
#endif
}
Value Value::get(ArrayIndex index, const Value& defaultValue) const {
@@ -948,16 +857,11 @@ const Value& Value::operator[](const char* key) const {
"in Json::Value::operator[](char const*)const: requires objectValue");
if (type_ == nullValue)
return null;
#ifndef JSON_VALUE_USE_INTERNAL_MAP
CZString actualKey(key, CZString::noDuplication);
ObjectValues::const_iterator it = value_.map_->find(actualKey);
if (it == value_.map_->end())
return null;
return (*it).second;
#else
const Value* value = value_.map_->find(key);
return value ? *value : null;
#endif
}
Value& Value::operator[](const std::string& key) {
@@ -998,7 +902,6 @@ bool Value::removeMember(const char* key, Value* removed) {
if (type_ != objectValue) {
return false;
}
#ifndef JSON_VALUE_USE_INTERNAL_MAP
CZString actualKey(key, CZString::noDuplication);
ObjectValues::iterator it = value_.map_->find(actualKey);
if (it == value_.map_->end())
@@ -1006,16 +909,6 @@ bool Value::removeMember(const char* key, Value* removed) {
*removed = it->second;
value_.map_->erase(it);
return true;
#else
Value* value = value_.map_->find(key);
if (value) {
*removed = *value;
value_.map_.remove(key);
return true;
} else {
return false;
}
#endif
}
Value Value::removeMember(const char* key) {
@@ -1037,10 +930,6 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
if (type_ != arrayValue) {
return false;
}
#ifdef JSON_VALUE_USE_INTERNAL_MAP
JSON_FAIL_MESSAGE("removeIndex is not implemented for ValueInternalArray.");
return false;
#else
CZString key(index);
ObjectValues::iterator it = value_.map_->find(key);
if (it == value_.map_->end()) {
@@ -1058,7 +947,6 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
ObjectValues::iterator itLast = value_.map_->find(keyLast);
value_.map_->erase(itLast);
return true;
#endif
}
#ifdef JSON_USE_CPPTL
@@ -1091,19 +979,10 @@ Value::Members Value::getMemberNames() const {
return Value::Members();
Members members;
members.reserve(value_.map_->size());
#ifndef JSON_VALUE_USE_INTERNAL_MAP
ObjectValues::const_iterator it = value_.map_->begin();
ObjectValues::const_iterator itEnd = value_.map_->end();
for (; it != itEnd; ++it)
members.push_back(std::string((*it).first.c_str()));
#else
ValueInternalMap::IteratorState it;
ValueInternalMap::IteratorState itEnd;
value_.map_->makeBeginIterator(it);
value_.map_->makeEndIterator(itEnd);
for (; !ValueInternalMap::equals(it, itEnd); ValueInternalMap::increment(it))
members.push_back(std::string(ValueInternalMap::key(it)));
#endif
return members;
}
//
@@ -1272,28 +1151,11 @@ std::string Value::toStyledString() const {
Value::const_iterator Value::begin() const {
switch (type_) {
#ifdef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
if (value_.array_) {
ValueInternalArray::IteratorState it;
value_.array_->makeBeginIterator(it);
return const_iterator(it);
}
break;
case objectValue:
if (value_.map_) {
ValueInternalMap::IteratorState it;
value_.map_->makeBeginIterator(it);
return const_iterator(it);
}
break;
#else
case arrayValue:
case objectValue:
if (value_.map_)
return const_iterator(value_.map_->begin());
break;
#endif
default:
break;
}
@@ -1302,28 +1164,11 @@ Value::const_iterator Value::begin() const {
Value::const_iterator Value::end() const {
switch (type_) {
#ifdef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
if (value_.array_) {
ValueInternalArray::IteratorState it;
value_.array_->makeEndIterator(it);
return const_iterator(it);
}
break;
case objectValue:
if (value_.map_) {
ValueInternalMap::IteratorState it;
value_.map_->makeEndIterator(it);
return const_iterator(it);
}
break;
#else
case arrayValue:
case objectValue:
if (value_.map_)
return const_iterator(value_.map_->end());
break;
#endif
default:
break;
}
@@ -1332,28 +1177,11 @@ Value::const_iterator Value::end() const {
Value::iterator Value::begin() {
switch (type_) {
#ifdef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
if (value_.array_) {
ValueInternalArray::IteratorState it;
value_.array_->makeBeginIterator(it);
return iterator(it);
}
break;
case objectValue:
if (value_.map_) {
ValueInternalMap::IteratorState it;
value_.map_->makeBeginIterator(it);
return iterator(it);
}
break;
#else
case arrayValue:
case objectValue:
if (value_.map_)
return iterator(value_.map_->begin());
break;
#endif
default:
break;
}
@@ -1362,28 +1190,11 @@ Value::iterator Value::begin() {
Value::iterator Value::end() {
switch (type_) {
#ifdef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
if (value_.array_) {
ValueInternalArray::IteratorState it;
value_.array_->makeEndIterator(it);
return iterator(it);
}
break;
case objectValue:
if (value_.map_) {
ValueInternalMap::IteratorState it;
value_.map_->makeEndIterator(it);
return iterator(it);
}
break;
#else
case arrayValue:
case objectValue:
if (value_.map_)
return iterator(value_.map_->end());
break;
#endif
default:
break;
}