Skip to content

Commit

Permalink
Merge 4cb1099 into 3beb37e
Browse files Browse the repository at this point in the history
  • Loading branch information
neheb committed Apr 11, 2020
2 parents 3beb37e + 4cb1099 commit 8d78a6d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 54 deletions.
16 changes: 9 additions & 7 deletions include/json/assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@

// @todo <= add detail about condition in exception
#define JSON_ASSERT(condition) \
{ \
do { \
if (!(condition)) { \
Json::throwLogicError("assert json failed"); \
} \
}
} while(0)

#define JSON_FAIL_MESSAGE(message) \
{ \
do { \
OStringStream oss; \
oss << message; \
Json::throwLogicError(oss.str()); \
abort(); \
}
} while(0)

#else // JSON_USE_EXCEPTION

Expand All @@ -52,8 +52,10 @@
#endif

#define JSON_ASSERT_MESSAGE(condition, message) \
if (!(condition)) { \
JSON_FAIL_MESSAGE(message); \
}
do { \
if (!(condition)) { \
JSON_FAIL_MESSAGE(message); \
} \
} while(0)

#endif // JSON_ASSERTIONS_H_INCLUDED
22 changes: 11 additions & 11 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ enum PrecisionType {
*/
class JSON_API StaticString {
public:
explicit StaticString(const char* czstring) : c_str_(czstring) {}
JSONCPP_OP_EXPLICIT StaticString(const char* czstring) : c_str_(czstring) {}

operator const char*() const { return c_str_; }

Expand Down Expand Up @@ -263,10 +263,10 @@ class JSON_API Value {
CZString(ArrayIndex index);
CZString(char const* str, unsigned length, DuplicationPolicy allocate);
CZString(CZString const& other);
CZString(CZString&& other);
CZString(CZString&& other) JSONCPP_NOEXCEPT;
~CZString();
CZString& operator=(const CZString& other);
CZString& operator=(CZString&& other);
CZString& operator=(CZString&& other) JSONCPP_NOEXCEPT;

bool operator<(CZString const& other) const;
bool operator==(CZString const& other) const;
Expand Down Expand Up @@ -343,13 +343,13 @@ class JSON_API Value {
Value(const String& value);
Value(bool value);
Value(const Value& other);
Value(Value&& other);
Value(Value&& other) JSONCPP_NOEXCEPT;
~Value();

/// \note Overwrite existing comments. To preserve comments, use
/// #swapPayload().
Value& operator=(const Value& other);
Value& operator=(Value&& other);
Value& operator=(Value&& other) JSONCPP_NOEXCEPT;

/// Swap everything.
void swap(Value& other);
Expand Down Expand Up @@ -634,9 +634,9 @@ class JSON_API Value {
public:
Comments() = default;
Comments(const Comments& that);
Comments(Comments&& that);
Comments(Comments&& that) JSONCPP_NOEXCEPT;
Comments& operator=(const Comments& that);
Comments& operator=(Comments&& that);
Comments& operator=(Comments&& that) JSONCPP_NOEXCEPT;
bool has(CommentPlacement slot) const;
String get(CommentPlacement slot) const;
void set(CommentPlacement slot, String comment);
Expand Down Expand Up @@ -810,7 +810,7 @@ class JSON_API ValueIteratorBase {
// For some reason, BORLAND needs these at the end, rather
// than earlier. No idea why.
ValueIteratorBase();
explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
JSONCPP_OP_EXPLICIT ValueIteratorBase(const Value::ObjectValues::iterator& current);
};

/** \brief const iterator for object and array value.
Expand All @@ -833,7 +833,7 @@ class JSON_API ValueConstIterator : public ValueIteratorBase {
private:
/*! \internal Use by Value to create an iterator.
*/
explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
JSONCPP_OP_EXPLICIT ValueConstIterator(const Value::ObjectValues::iterator& current);

public:
SelfType& operator=(const ValueIteratorBase& other);
Expand Down Expand Up @@ -879,13 +879,13 @@ class JSON_API ValueIterator : public ValueIteratorBase {
using SelfType = ValueIterator;

ValueIterator();
explicit ValueIterator(const ValueConstIterator& other);
JSONCPP_NORETURN JSONCPP_OP_EXPLICIT ValueIterator(const ValueConstIterator& other);
ValueIterator(const ValueIterator& other);

private:
/*! \internal Use by Value to create an iterator.
*/
explicit ValueIterator(const Value::ObjectValues::iterator& current);
JSONCPP_OP_EXPLICIT ValueIterator(const Value::ObjectValues::iterator& current);

public:
SelfType& operator=(const SelfType& other);
Expand Down
4 changes: 2 additions & 2 deletions src/jsontestrunner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ static void printValueTree(FILE* fout, Json::Value& value,
Json::Value::Members members(value.getMemberNames());
std::sort(members.begin(), members.end());
Json::String suffix = *(path.end() - 1) == '.' ? "" : ".";
for (auto name : members) {
printValueTree(fout, value[name], path + suffix + name);
for (const auto& name : members) {
printValueTree(fout, value[name], path + suffix.append(name));
}
} break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ class OurReader {
String message;
};

explicit OurReader(OurFeatures const& features);
JSONCPP_OP_EXPLICIT OurReader(OurFeatures const& features);
bool parse(const char* beginDoc, const char* endDoc, Value& root,
bool collectComments = true);
String getFormattedErrorMessages() const;
Expand Down
12 changes: 6 additions & 6 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Value::CZString::CZString(const CZString& other) {
storage_.length_ = other.storage_.length_;
}

Value::CZString::CZString(CZString&& other)
Value::CZString::CZString(CZString&& other) JSONCPP_NOEXCEPT
: cstr_(other.cstr_), index_(other.index_) {
other.cstr_ = nullptr;
}
Expand All @@ -278,7 +278,7 @@ Value::CZString& Value::CZString::operator=(const CZString& other) {
return *this;
}

Value::CZString& Value::CZString::operator=(CZString&& other) {
Value::CZString& Value::CZString::operator=(CZString&& other) JSONCPP_NOEXCEPT {
cstr_ = other.cstr_;
index_ = other.index_;
other.cstr_ = nullptr;
Expand Down Expand Up @@ -426,7 +426,7 @@ Value::Value(const Value& other) {
dupMeta(other);
}

Value::Value(Value&& other) {
Value::Value(Value&& other) JSONCPP_NOEXCEPT {
initBasic(nullValue);
swap(other);
}
Expand All @@ -441,7 +441,7 @@ Value& Value::operator=(const Value& other) {
return *this;
}

Value& Value::operator=(Value&& other) {
Value& Value::operator=(Value&& other) JSONCPP_NOEXCEPT {
other.swap(*this);
return *this;
}
Expand Down Expand Up @@ -1366,14 +1366,14 @@ bool Value::isObject() const { return type() == objectValue; }
Value::Comments::Comments(const Comments& that)
: ptr_{cloneUnique(that.ptr_)} {}

Value::Comments::Comments(Comments&& that) : ptr_{std::move(that.ptr_)} {}
Value::Comments::Comments(Comments&& that) JSONCPP_NOEXCEPT : ptr_{std::move(that.ptr_)} {}

Value::Comments& Value::Comments::operator=(const Comments& that) {
ptr_ = cloneUnique(that.ptr_);
return *this;
}

Value::Comments& Value::Comments::operator=(Comments&& that) {
Value::Comments& Value::Comments::operator=(Comments&& that) JSONCPP_NOEXCEPT {
ptr_ = std::move(that.ptr_);
return *this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/test_lib_json/jsontest.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
/// The predicate may do other assertions and be a member function of the
/// fixture.
#define JSONTEST_ASSERT_PRED(expr) \
{ \
do { \
JsonTest::PredicateContext _minitest_Context = { \
result_->predicateId_, __FILE__, __LINE__, #expr, NULL, NULL}; \
result_->predicateStackTail_->next_ = &_minitest_Context; \
result_->predicateId_ += 1; \
result_->predicateStackTail_ = &_minitest_Context; \
(expr); \
result_->popPredicateContext(); \
}
} while(0)

/// \brief Asserts that two values are equals.
#define JSONTEST_ASSERT_EQUAL(expected, actual) \
Expand All @@ -230,7 +230,7 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,

/// \brief Asserts that a given expression throws an exception
#define JSONTEST_ASSERT_THROWS(expr) \
{ \
do { \
bool _threw = false; \
try { \
expr; \
Expand All @@ -240,7 +240,7 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
if (!_threw) \
result_->addFailure(__FILE__, __LINE__, \
"expected exception thrown: " #expr); \
}
} while(0)

/// \brief Begin a fixture test case.
#define JSONTEST_FIXTURE(FixtureType, name) \
Expand Down

0 comments on commit 8d78a6d

Please sign in to comment.