From 6a304af8192d3fe9eeabe91d19dafc9109fd2220 Mon Sep 17 00:00:00 2001 From: gakamath Date: Wed, 28 Dec 2022 11:37:16 +0530 Subject: [PATCH] Changing 'enum' to 'enum class' Fix for Visual Studio warning - Warning C26812: Enum type is unscoped. Prefer enum class over enum Signed-off-by: ganeshkamath89 --- include/json/reader.h | 2 +- include/json/value.h | 24 +- src/lib_json/json_reader.cpp | 256 ++++++++++---------- src/lib_json/json_value.cpp | 440 ++++++++++++++++++----------------- src/lib_json/json_writer.cpp | 136 +++++------ 5 files changed, 442 insertions(+), 416 deletions(-) diff --git a/include/json/reader.h b/include/json/reader.h index 46975d8..c323933 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -156,7 +156,7 @@ public: bool good() const; private: - enum TokenType { + enum class TokenType { tokenEndOfStream = 0, tokenObjectBegin, tokenObjectEnd, diff --git a/include/json/value.h b/include/json/value.h index 15c517e..712a0ba 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -105,7 +105,7 @@ JSONCPP_NORETURN void throwLogicError(String const& msg); /** \brief Type of the value held by a Value object. */ -enum ValueType { +enum class ValueType { nullValue = 0, ///< 'null' value intValue, ///< signed integer value uintValue, ///< unsigned integer value @@ -116,7 +116,7 @@ enum ValueType { objectValue ///< object value (collection of name/value pairs). }; -enum CommentPlacement { +enum class CommentPlacement { commentBefore = 0, ///< a comment placed on the line before a value commentAfterOnSameLine, ///< a comment just after a value on the same line commentAfter, ///< a comment on the line after a value (only make sense for @@ -126,7 +126,7 @@ enum CommentPlacement { /** \brief Type of precision for formatting of real values. */ -enum PrecisionType { +enum class PrecisionType { significantDigits = 0, ///< we set max number of significant digits in string decimalPlaces ///< we set max number of digits after "." in string }; @@ -260,7 +260,11 @@ private: #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION class CZString { public: - enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy }; + enum class DuplicationPolicy { + noDuplication = 0, + duplicate, + duplicateOnCopy + }; CZString(ArrayIndex index); CZString(char const* str, unsigned length, DuplicationPolicy allocate); CZString(CZString const& other); @@ -313,7 +317,7 @@ public: * Json::Value obj_value(Json::objectValue); // {} * \endcode */ - Value(ValueType type = nullValue); + Value(ValueType type = ValueType::nullValue); Value(Int value); Value(UInt value); #if defined(JSON_HAS_INT64) @@ -644,7 +648,7 @@ private: void set(CommentPlacement slot, String comment); private: - using Array = std::array; + using Array = std::array; std::unique_ptr ptr_; }; Comments comments_; @@ -698,10 +702,14 @@ public: PathArgument(String key); private: - enum Kind { kindNone = 0, kindIndex, kindKey }; + enum class Kind { + kindNone = 0, + kindIndex, + kindKey + }; String key_; ArrayIndex index_{}; - Kind kind_{kindNone}; + Kind kind_{Kind::kindNone}; }; /** \brief Experimental and untested: represents a "path" to access a node. diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 1ac5e81..93bf17a 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -131,12 +131,12 @@ bool Reader::parse(const char* beginDoc, const char* endDoc, Value& root, Token token; skipCommentTokens(token); if (collectComments_ && !commentsBefore_.empty()) - root.setComment(commentsBefore_, commentAfter); + root.setComment(commentsBefore_, CommentPlacement::commentAfter); if (features_.strictRoot_) { if (!root.isArray() && !root.isObject()) { // Set error location to start of doc, ideally should be first token found // in doc - token.type_ = tokenError; + token.type_ = TokenType::tokenError; token.start_ = beginDoc; token.end_ = endDoc; addError( @@ -161,46 +161,46 @@ bool Reader::readValue() { bool successful = true; if (collectComments_ && !commentsBefore_.empty()) { - currentValue().setComment(commentsBefore_, commentBefore); + currentValue().setComment(commentsBefore_, CommentPlacement::commentBefore); commentsBefore_.clear(); } switch (token.type_) { - case tokenObjectBegin: + case TokenType::tokenObjectBegin: successful = readObject(token); currentValue().setOffsetLimit(current_ - begin_); break; - case tokenArrayBegin: + case TokenType::tokenArrayBegin: successful = readArray(token); currentValue().setOffsetLimit(current_ - begin_); break; - case tokenNumber: + case TokenType::tokenNumber: successful = decodeNumber(token); break; - case tokenString: + case TokenType::tokenString: successful = decodeString(token); break; - case tokenTrue: { + case TokenType::tokenTrue: { Value v(true); currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenFalse: { + case TokenType::tokenFalse: { Value v(false); currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenNull: { + case TokenType::tokenNull: { Value v; currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenArraySeparator: - case tokenObjectEnd: - case tokenArrayEnd: + case TokenType::tokenArraySeparator: + case TokenType::tokenObjectEnd: + case TokenType::tokenArrayEnd: if (features_.allowDroppedNullPlaceholders_) { // "Un-read" the current token and mark the current value as a null // token. @@ -210,7 +210,8 @@ bool Reader::readValue() { currentValue().setOffsetStart(current_ - begin_ - 1); currentValue().setOffsetLimit(current_ - begin_); break; - } // Else, fall through... + } + [[fallthrough]]; // Else, fall through... default: currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); @@ -229,7 +230,7 @@ void Reader::skipCommentTokens(Token& token) { if (features_.allowComments_) { do { readToken(token); - } while (token.type_ == tokenComment); + } while (token.type_ == TokenType::tokenComment); } else { readToken(token); } @@ -242,23 +243,23 @@ bool Reader::readToken(Token& token) { bool ok = true; switch (c) { case '{': - token.type_ = tokenObjectBegin; + token.type_ = TokenType::tokenObjectBegin; break; case '}': - token.type_ = tokenObjectEnd; + token.type_ = TokenType::tokenObjectEnd; break; case '[': - token.type_ = tokenArrayBegin; + token.type_ = TokenType::tokenArrayBegin; break; case ']': - token.type_ = tokenArrayEnd; + token.type_ = TokenType::tokenArrayEnd; break; case '"': - token.type_ = tokenString; + token.type_ = TokenType::tokenString; ok = readString(); break; case '/': - token.type_ = tokenComment; + token.type_ = TokenType::tokenComment; ok = readComment(); break; case '0': @@ -272,36 +273,36 @@ bool Reader::readToken(Token& token) { case '8': case '9': case '-': - token.type_ = tokenNumber; + token.type_ = TokenType::tokenNumber; readNumber(); break; case 't': - token.type_ = tokenTrue; + token.type_ = TokenType::tokenTrue; ok = match("rue", 3); break; case 'f': - token.type_ = tokenFalse; + token.type_ = TokenType::tokenFalse; ok = match("alse", 4); break; case 'n': - token.type_ = tokenNull; + token.type_ = TokenType::tokenNull; ok = match("ull", 3); break; case ',': - token.type_ = tokenArraySeparator; + token.type_ = TokenType::tokenArraySeparator; break; case ':': - token.type_ = tokenMemberSeparator; + token.type_ = TokenType::tokenMemberSeparator; break; case 0: - token.type_ = tokenEndOfStream; + token.type_ = TokenType::tokenEndOfStream; break; default: ok = false; break; } if (!ok) - token.type_ = tokenError; + token.type_ = TokenType::tokenError; token.end_ = current_; return ok; } @@ -339,10 +340,10 @@ bool Reader::readComment() { return false; if (collectComments_) { - CommentPlacement placement = commentBefore; + CommentPlacement placement = CommentPlacement::commentBefore; if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) { if (c != '*' || !containsNewLine(commentBegin, current_)) - placement = commentAfterOnSameLine; + placement = CommentPlacement::commentAfterOnSameLine; } addComment(commentBegin, current_, placement); @@ -373,7 +374,7 @@ void Reader::addComment(Location begin, Location end, CommentPlacement placement) { assert(collectComments_); const String& normalized = normalizeEOL(begin, end); - if (placement == commentAfterOnSameLine) { + if (placement == CommentPlacement::commentAfterOnSameLine) { assert(lastValue_ != nullptr); lastValue_->setComment(normalized, placement); } else { @@ -443,61 +444,61 @@ bool Reader::readString() { bool Reader::readObject(Token& token) { Token tokenName; String name; - Value init(objectValue); + Value init(ValueType::objectValue); currentValue().swapPayload(init); currentValue().setOffsetStart(token.start_ - begin_); while (readToken(tokenName)) { bool initialTokenOk = true; - while (tokenName.type_ == tokenComment && initialTokenOk) + while (tokenName.type_ == TokenType::tokenComment && initialTokenOk) initialTokenOk = readToken(tokenName); if (!initialTokenOk) break; - if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object + if (tokenName.type_ == TokenType::tokenObjectEnd && name.empty()) // empty object return true; name.clear(); - if (tokenName.type_ == tokenString) { + if (tokenName.type_ == TokenType::tokenString) { if (!decodeString(tokenName, name)) - return recoverFromError(tokenObjectEnd); - } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { + return recoverFromError(TokenType::tokenObjectEnd); + } else if (tokenName.type_ == TokenType::tokenNumber && features_.allowNumericKeys_) { Value numberName; if (!decodeNumber(tokenName, numberName)) - return recoverFromError(tokenObjectEnd); + return recoverFromError(TokenType::tokenObjectEnd); name = numberName.asString(); } else { break; } Token colon; - if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { + if (!readToken(colon) || colon.type_ != TokenType::tokenMemberSeparator) { return addErrorAndRecover("Missing ':' after object member name", colon, - tokenObjectEnd); + TokenType::tokenObjectEnd); } Value& value = currentValue()[name]; nodes_.push(&value); bool ok = readValue(); nodes_.pop(); if (!ok) // error already set - return recoverFromError(tokenObjectEnd); + return recoverFromError(TokenType::tokenObjectEnd); Token comma; if (!readToken(comma) || - (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && - comma.type_ != tokenComment)) { + (comma.type_ != TokenType::tokenObjectEnd && comma.type_ != TokenType::tokenArraySeparator && + comma.type_ != TokenType::tokenComment)) { return addErrorAndRecover("Missing ',' or '}' in object declaration", - comma, tokenObjectEnd); + comma, TokenType::tokenObjectEnd); } bool finalizeTokenOk = true; - while (comma.type_ == tokenComment && finalizeTokenOk) + while (comma.type_ == TokenType::tokenComment && finalizeTokenOk) finalizeTokenOk = readToken(comma); - if (comma.type_ == tokenObjectEnd) + if (comma.type_ == TokenType::tokenObjectEnd) return true; } return addErrorAndRecover("Missing '}' or object member name", tokenName, - tokenObjectEnd); + TokenType::tokenObjectEnd); } bool Reader::readArray(Token& token) { - Value init(arrayValue); + Value init(ValueType::arrayValue); currentValue().swapPayload(init); currentValue().setOffsetStart(token.start_ - begin_); skipSpaces(); @@ -514,21 +515,21 @@ bool Reader::readArray(Token& token) { bool ok = readValue(); nodes_.pop(); if (!ok) // error already set - return recoverFromError(tokenArrayEnd); + return recoverFromError(TokenType::tokenArrayEnd); Token currentToken; // Accept Comment after last item in the array. ok = readToken(currentToken); - while (currentToken.type_ == tokenComment && ok) { + while (currentToken.type_ == TokenType::tokenComment && ok) { ok = readToken(currentToken); } - bool badTokenType = (currentToken.type_ != tokenArraySeparator && - currentToken.type_ != tokenArrayEnd); + bool badTokenType = (currentToken.type_ != TokenType::tokenArraySeparator && + currentToken.type_ != TokenType::tokenArrayEnd); if (!ok || badTokenType) { return addErrorAndRecover("Missing ',' or ']' in array declaration", - currentToken, tokenArrayEnd); + currentToken, TokenType::tokenArrayEnd); } - if (currentToken.type_ == tokenArrayEnd) + if (currentToken.type_ == TokenType::tokenArrayEnd) break; } return true; @@ -744,7 +745,7 @@ bool Reader::recoverFromError(TokenType skipUntilToken) { for (;;) { if (!readToken(skip)) errors_.resize(errorCount); // discard errors caused by recovery - if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream) + if (skip.type_ == skipUntilToken || skip.type_ == TokenType::tokenEndOfStream) break; } errors_.resize(errorCount); @@ -830,7 +831,7 @@ bool Reader::pushError(const Value& value, const String& message) { if (value.getOffsetStart() > length || value.getOffsetLimit() > length) return false; Token token; - token.type_ = tokenError; + token.type_ = TokenType::tokenError; token.start_ = begin_ + value.getOffsetStart(); token.end_ = begin_ + value.getOffsetLimit(); ErrorInfo info; @@ -848,7 +849,7 @@ bool Reader::pushError(const Value& value, const String& message, extra.getOffsetLimit() > length) return false; Token token; - token.type_ = tokenError; + token.type_ = TokenType::tokenError; token.start_ = begin_ + value.getOffsetStart(); token.end_ = begin_ + value.getOffsetLimit(); ErrorInfo info; @@ -906,7 +907,7 @@ private: OurReader(OurReader const&); // no impl void operator=(OurReader const&); // no impl - enum TokenType { + enum class TokenType { tokenEndOfStream = 0, tokenObjectBegin, tokenObjectEnd, @@ -1031,17 +1032,17 @@ bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root, nodes_.pop(); Token token; skipCommentTokens(token); - if (features_.failIfExtra_ && (token.type_ != tokenEndOfStream)) { + if (features_.failIfExtra_ && (token.type_ != TokenType::tokenEndOfStream)) { addError("Extra non-whitespace after JSON value.", token); return false; } if (collectComments_ && !commentsBefore_.empty()) - root.setComment(commentsBefore_, commentAfter); + root.setComment(commentsBefore_, CommentPlacement::commentAfter); if (features_.strictRoot_) { if (!root.isArray() && !root.isObject()) { // Set error location to start of doc, ideally should be first token found // in doc - token.type_ = tokenError; + token.type_ = TokenType::tokenError; token.start_ = beginDoc; token.end_ = endDoc; addError( @@ -1062,64 +1063,64 @@ bool OurReader::readValue() { bool successful = true; if (collectComments_ && !commentsBefore_.empty()) { - currentValue().setComment(commentsBefore_, commentBefore); + currentValue().setComment(commentsBefore_, CommentPlacement::commentBefore); commentsBefore_.clear(); } switch (token.type_) { - case tokenObjectBegin: + case TokenType::tokenObjectBegin: successful = readObject(token); currentValue().setOffsetLimit(current_ - begin_); break; - case tokenArrayBegin: + case TokenType::tokenArrayBegin: successful = readArray(token); currentValue().setOffsetLimit(current_ - begin_); break; - case tokenNumber: + case TokenType::tokenNumber: successful = decodeNumber(token); break; - case tokenString: + case TokenType::tokenString: successful = decodeString(token); break; - case tokenTrue: { + case TokenType::tokenTrue: { Value v(true); currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenFalse: { + case TokenType::tokenFalse: { Value v(false); currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenNull: { + case TokenType::tokenNull: { Value v; currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenNaN: { + case TokenType::tokenNaN: { Value v(std::numeric_limits::quiet_NaN()); currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenPosInf: { + case TokenType::tokenPosInf: { Value v(std::numeric_limits::infinity()); currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenNegInf: { + case TokenType::tokenNegInf: { Value v(-std::numeric_limits::infinity()); currentValue().swapPayload(v); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); } break; - case tokenArraySeparator: - case tokenObjectEnd: - case tokenArrayEnd: + case TokenType::tokenArraySeparator: + case TokenType::tokenObjectEnd: + case TokenType::tokenArrayEnd: if (features_.allowDroppedNullPlaceholders_) { // "Un-read" the current token and mark the current value as a null // token. @@ -1129,7 +1130,8 @@ bool OurReader::readValue() { currentValue().setOffsetStart(current_ - begin_ - 1); currentValue().setOffsetLimit(current_ - begin_); break; - } // else, fall through ... + } + [[fallthrough]]; // Else, fall through... default: currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); @@ -1149,7 +1151,7 @@ void OurReader::skipCommentTokens(Token& token) { if (features_.allowComments_) { do { readToken(token); - } while (token.type_ == tokenComment); + } while (token.type_ == TokenType::tokenComment); } else { readToken(token); } @@ -1162,24 +1164,24 @@ bool OurReader::readToken(Token& token) { bool ok = true; switch (c) { case '{': - token.type_ = tokenObjectBegin; + token.type_ = TokenType::tokenObjectBegin; break; case '}': - token.type_ = tokenObjectEnd; + token.type_ = TokenType::tokenObjectEnd; break; case '[': - token.type_ = tokenArrayBegin; + token.type_ = TokenType::tokenArrayBegin; break; case ']': - token.type_ = tokenArrayEnd; + token.type_ = TokenType::tokenArrayEnd; break; case '"': - token.type_ = tokenString; + token.type_ = TokenType::tokenString; ok = readString(); break; case '\'': if (features_.allowSingleQuotes_) { - token.type_ = tokenString; + token.type_ = TokenType::tokenString; ok = readStringSingleQuote(); } else { // If we don't allow single quotes, this is a failure case. @@ -1187,7 +1189,7 @@ bool OurReader::readToken(Token& token) { } break; case '/': - token.type_ = tokenComment; + token.type_ = TokenType::tokenComment; ok = readComment(); break; case '0': @@ -1200,40 +1202,40 @@ bool OurReader::readToken(Token& token) { case '7': case '8': case '9': - token.type_ = tokenNumber; + token.type_ = TokenType::tokenNumber; readNumber(false); break; case '-': if (readNumber(true)) { - token.type_ = tokenNumber; + token.type_ = TokenType::tokenNumber; } else { - token.type_ = tokenNegInf; + token.type_ = TokenType::tokenNegInf; ok = features_.allowSpecialFloats_ && match("nfinity", 7); } break; case '+': if (readNumber(true)) { - token.type_ = tokenNumber; + token.type_ = TokenType::tokenNumber; } else { - token.type_ = tokenPosInf; + token.type_ = TokenType::tokenPosInf; ok = features_.allowSpecialFloats_ && match("nfinity", 7); } break; case 't': - token.type_ = tokenTrue; + token.type_ = TokenType::tokenTrue; ok = match("rue", 3); break; case 'f': - token.type_ = tokenFalse; + token.type_ = TokenType::tokenFalse; ok = match("alse", 4); break; case 'n': - token.type_ = tokenNull; + token.type_ = TokenType::tokenNull; ok = match("ull", 3); break; case 'N': if (features_.allowSpecialFloats_) { - token.type_ = tokenNaN; + token.type_ = TokenType::tokenNaN; ok = match("aN", 2); } else { ok = false; @@ -1241,27 +1243,27 @@ bool OurReader::readToken(Token& token) { break; case 'I': if (features_.allowSpecialFloats_) { - token.type_ = tokenPosInf; + token.type_ = TokenType::tokenPosInf; ok = match("nfinity", 7); } else { ok = false; } break; case ',': - token.type_ = tokenArraySeparator; + token.type_ = TokenType::tokenArraySeparator; break; case ':': - token.type_ = tokenMemberSeparator; + token.type_ = TokenType::tokenMemberSeparator; break; case 0: - token.type_ = tokenEndOfStream; + token.type_ = TokenType::tokenEndOfStream; break; default: ok = false; break; } if (!ok) - token.type_ = tokenError; + token.type_ = TokenType::tokenError; token.end_ = current_; return ok; } @@ -1315,12 +1317,12 @@ bool OurReader::readComment() { return false; if (collectComments_) { - CommentPlacement placement = commentBefore; + CommentPlacement placement = CommentPlacement::commentBefore; if (!lastValueHasAComment_) { if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) { if (isCppStyleComment || !cStyleWithEmbeddedNewline) { - placement = commentAfterOnSameLine; + placement = CommentPlacement::commentAfterOnSameLine; lastValueHasAComment_ = true; } } @@ -1355,7 +1357,7 @@ void OurReader::addComment(Location begin, Location end, CommentPlacement placement) { assert(collectComments_); const String& normalized = normalizeEOL(begin, end); - if (placement == commentAfterOnSameLine) { + if (placement == CommentPlacement::commentAfterOnSameLine) { assert(lastValue_ != nullptr); lastValue_->setComment(normalized, placement); } else { @@ -1446,27 +1448,27 @@ bool OurReader::readStringSingleQuote() { bool OurReader::readObject(Token& token) { Token tokenName; String name; - Value init(objectValue); + Value init(ValueType::objectValue); currentValue().swapPayload(init); currentValue().setOffsetStart(token.start_ - begin_); while (readToken(tokenName)) { bool initialTokenOk = true; - while (tokenName.type_ == tokenComment && initialTokenOk) + while (tokenName.type_ == TokenType::tokenComment && initialTokenOk) initialTokenOk = readToken(tokenName); if (!initialTokenOk) break; - if (tokenName.type_ == tokenObjectEnd && + if (tokenName.type_ == TokenType::tokenObjectEnd && (name.empty() || features_.allowTrailingCommas_)) // empty object or trailing comma return true; name.clear(); - if (tokenName.type_ == tokenString) { + if (tokenName.type_ == TokenType::tokenString) { if (!decodeString(tokenName, name)) - return recoverFromError(tokenObjectEnd); - } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { + return recoverFromError(TokenType::tokenObjectEnd); + } else if (tokenName.type_ == TokenType::tokenNumber && features_.allowNumericKeys_) { Value numberName; if (!decodeNumber(tokenName, numberName)) - return recoverFromError(tokenObjectEnd); + return recoverFromError(TokenType::tokenObjectEnd); name = numberName.asString(); } else { break; @@ -1475,40 +1477,40 @@ bool OurReader::readObject(Token& token) { throwRuntimeError("keylength >= 2^30"); if (features_.rejectDupKeys_ && currentValue().isMember(name)) { String msg = "Duplicate key: '" + name + "'"; - return addErrorAndRecover(msg, tokenName, tokenObjectEnd); + return addErrorAndRecover(msg, tokenName, TokenType::tokenObjectEnd); } Token colon; - if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { + if (!readToken(colon) || colon.type_ != TokenType::tokenMemberSeparator) { return addErrorAndRecover("Missing ':' after object member name", colon, - tokenObjectEnd); + TokenType::tokenObjectEnd); } Value& value = currentValue()[name]; nodes_.push(&value); bool ok = readValue(); nodes_.pop(); if (!ok) // error already set - return recoverFromError(tokenObjectEnd); + return recoverFromError(TokenType::tokenObjectEnd); Token comma; if (!readToken(comma) || - (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && - comma.type_ != tokenComment)) { + (comma.type_ != TokenType::tokenObjectEnd && comma.type_ != TokenType::tokenArraySeparator && + comma.type_ != TokenType::tokenComment)) { return addErrorAndRecover("Missing ',' or '}' in object declaration", - comma, tokenObjectEnd); + comma, TokenType::tokenObjectEnd); } bool finalizeTokenOk = true; - while (comma.type_ == tokenComment && finalizeTokenOk) + while (comma.type_ == TokenType::tokenComment && finalizeTokenOk) finalizeTokenOk = readToken(comma); - if (comma.type_ == tokenObjectEnd) + if (comma.type_ == TokenType::tokenObjectEnd) return true; } return addErrorAndRecover("Missing '}' or object member name", tokenName, - tokenObjectEnd); + TokenType::tokenObjectEnd); } bool OurReader::readArray(Token& token) { - Value init(arrayValue); + Value init(ValueType::arrayValue); currentValue().swapPayload(init); currentValue().setOffsetStart(token.start_ - begin_); int index = 0; @@ -1529,21 +1531,21 @@ bool OurReader::readArray(Token& token) { bool ok = readValue(); nodes_.pop(); if (!ok) // error already set - return recoverFromError(tokenArrayEnd); + return recoverFromError(TokenType::tokenArrayEnd); Token currentToken; // Accept Comment after last item in the array. ok = readToken(currentToken); - while (currentToken.type_ == tokenComment && ok) { + while (currentToken.type_ == TokenType::tokenComment && ok) { ok = readToken(currentToken); } - bool badTokenType = (currentToken.type_ != tokenArraySeparator && - currentToken.type_ != tokenArrayEnd); + bool badTokenType = (currentToken.type_ != TokenType::tokenArraySeparator && + currentToken.type_ != TokenType::tokenArrayEnd); if (!ok || badTokenType) { return addErrorAndRecover("Missing ',' or ']' in array declaration", - currentToken, tokenArrayEnd); + currentToken, TokenType::tokenArrayEnd); } - if (currentToken.type_ == tokenArrayEnd) + if (currentToken.type_ == TokenType::tokenArrayEnd) break; } return true; @@ -1796,7 +1798,7 @@ bool OurReader::recoverFromError(TokenType skipUntilToken) { for (;;) { if (!readToken(skip)) errors_.resize(errorCount); // discard errors caused by recovery - if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream) + if (skip.type_ == skipUntilToken || skip.type_ == TokenType::tokenEndOfStream) break; } errors_.resize(errorCount); diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index aa2b744..5fabc2d 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -239,21 +239,21 @@ Value::CZString::CZString(char const* str, unsigned length, DuplicationPolicy allocate) : cstr_(str) { // allocate != duplicate - storage_.policy_ = allocate & 0x3; + storage_.policy_ = (size_t)(allocate) & 0x3; storage_.length_ = length & 0x3FFFFFFF; } Value::CZString::CZString(const CZString& other) { - cstr_ = (other.storage_.policy_ != noDuplication && other.cstr_ != nullptr + cstr_ = (other.storage_.policy_ != (size_t)DuplicationPolicy::noDuplication && other.cstr_ != nullptr ? duplicateStringValue(other.cstr_, other.storage_.length_) : other.cstr_); storage_.policy_ = static_cast( other.cstr_ ? (static_cast(other.storage_.policy_) == - noDuplication - ? noDuplication - : duplicate) + DuplicationPolicy::noDuplication + ? DuplicationPolicy::noDuplication + : DuplicationPolicy::duplicate) : static_cast(other.storage_.policy_)) & 3U; storage_.length_ = other.storage_.length_; @@ -265,7 +265,7 @@ Value::CZString::CZString(CZString&& other) noexcept } Value::CZString::~CZString() { - if (cstr_ && storage_.policy_ == duplicate) { + if (cstr_ && storage_.policy_ == (size_t)DuplicationPolicy::duplicate) { releaseStringValue(const_cast(cstr_), storage_.length_ + 1U); // +1 for null terminating // character for sake of @@ -329,7 +329,7 @@ ArrayIndex Value::CZString::index() const { return index_; } const char* Value::CZString::data() const { return cstr_; } unsigned Value::CZString::length() const { return storage_.length_; } bool Value::CZString::isStaticString() const { - return storage_.policy_ == noDuplication; + return storage_.policy_ == (size_t)DuplicationPolicy::noDuplication; } // ////////////////////////////////////////////////////////////////// @@ -348,24 +348,24 @@ Value::Value(ValueType type) { static char const emptyString[] = ""; initBasic(type); switch (type) { - case nullValue: + case ValueType::nullValue: break; - case intValue: - case uintValue: + case ValueType::intValue: + case ValueType::uintValue: value_.int_ = 0; break; - case realValue: + case ValueType::realValue: value_.real_ = 0.0; break; - case stringValue: + case ValueType::stringValue: // allocated_ == false, so this is safe. value_.string_ = const_cast(static_cast(emptyString)); break; - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: value_.map_ = new ObjectValues(); break; - case booleanValue: + case ValueType::booleanValue: value_.bool_ = false; break; default: @@ -374,32 +374,32 @@ Value::Value(ValueType type) { } Value::Value(Int value) { - initBasic(intValue); + initBasic(ValueType::intValue); value_.int_ = value; } Value::Value(UInt value) { - initBasic(uintValue); + initBasic(ValueType::uintValue); value_.uint_ = value; } #if defined(JSON_HAS_INT64) Value::Value(Int64 value) { - initBasic(intValue); + initBasic(ValueType::intValue); value_.int_ = value; } Value::Value(UInt64 value) { - initBasic(uintValue); + initBasic(ValueType::uintValue); value_.uint_ = value; } #endif // defined(JSON_HAS_INT64) Value::Value(double value) { - initBasic(realValue); + initBasic(ValueType::realValue); value_.real_ = value; } Value::Value(const char* value) { - initBasic(stringValue, true); + initBasic(ValueType::stringValue, true); JSON_ASSERT_MESSAGE(value != nullptr, "Null Value Passed to Value Constructor"); value_.string_ = duplicateAndPrefixStringValue( @@ -407,24 +407,24 @@ Value::Value(const char* value) { } Value::Value(const char* begin, const char* end) { - initBasic(stringValue, true); + initBasic(ValueType::stringValue, true); value_.string_ = duplicateAndPrefixStringValue(begin, static_cast(end - begin)); } Value::Value(const String& value) { - initBasic(stringValue, true); + initBasic(ValueType::stringValue, true); value_.string_ = duplicateAndPrefixStringValue( value.data(), static_cast(value.length())); } Value::Value(const StaticString& value) { - initBasic(stringValue); + initBasic(ValueType::stringValue); value_.string_ = const_cast(value.c_str()); } Value::Value(bool value) { - initBasic(booleanValue); + initBasic(ValueType::booleanValue); value_.bool_ = value; } @@ -434,7 +434,7 @@ Value::Value(const Value& other) { } Value::Value(Value&& other) noexcept { - initBasic(nullValue); + initBasic(ValueType::nullValue); swap(other); } @@ -488,21 +488,21 @@ int Value::compare(const Value& other) const { } bool Value::operator<(const Value& other) const { - int typeDelta = type() - other.type(); + int typeDelta = (size_t)type() - (size_t)other.type(); if (typeDelta) return typeDelta < 0; switch (type()) { - case nullValue: + case ValueType::nullValue: return false; - case intValue: + case ValueType::intValue: return value_.int_ < other.value_.int_; - case uintValue: + case ValueType::uintValue: return value_.uint_ < other.value_.uint_; - case realValue: + case ValueType::realValue: return value_.real_ < other.value_.real_; - case booleanValue: + case ValueType::booleanValue: return value_.bool_ < other.value_.bool_; - case stringValue: { + case ValueType::stringValue: { if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) { return other.value_.string_ != nullptr; } @@ -523,8 +523,8 @@ bool Value::operator<(const Value& other) const { return false; return (this_len < other_len); } - case arrayValue: - case objectValue: { + case ValueType::arrayValue: + case ValueType::objectValue: { auto thisSize = value_.map_->size(); auto otherSize = other.value_.map_->size(); if (thisSize != otherSize) @@ -547,17 +547,17 @@ bool Value::operator==(const Value& other) const { if (type() != other.type()) return false; switch (type()) { - case nullValue: + case ValueType::nullValue: return true; - case intValue: + case ValueType::intValue: return value_.int_ == other.value_.int_; - case uintValue: + case ValueType::uintValue: return value_.uint_ == other.value_.uint_; - case realValue: + case ValueType::realValue: return value_.real_ == other.value_.real_; - case booleanValue: + case ValueType::booleanValue: return value_.bool_ == other.value_.bool_; - case stringValue: { + case ValueType::stringValue: { if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) { return (value_.string_ == other.value_.string_); } @@ -575,8 +575,8 @@ bool Value::operator==(const Value& other) const { int comp = memcmp(this_str, other_str, this_len); return comp == 0; } - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: return value_.map_->size() == other.value_.map_->size() && (*value_.map_) == (*other.value_.map_); default: @@ -588,7 +588,7 @@ bool Value::operator==(const Value& other) const { bool Value::operator!=(const Value& other) const { return !(*this == other); } const char* Value::asCString() const { - JSON_ASSERT_MESSAGE(type() == stringValue, + JSON_ASSERT_MESSAGE(type() == ValueType::stringValue, "in Json::Value::asCString(): requires stringValue"); if (value_.string_ == nullptr) return nullptr; @@ -614,7 +614,7 @@ unsigned Value::getCStringLength() const { #endif bool Value::getString(char const** begin, char const** end) const { - if (type() != stringValue) + if (type() != ValueType::stringValue) return false; if (value_.string_ == nullptr) return false; @@ -627,9 +627,9 @@ bool Value::getString(char const** begin, char const** end) const { String Value::asString() const { switch (type()) { - case nullValue: + case ValueType::nullValue: return ""; - case stringValue: { + case ValueType::stringValue: { if (value_.string_ == nullptr) return ""; unsigned this_len; @@ -638,13 +638,13 @@ String Value::asString() const { &this_str); return String(this_str, this_len); } - case booleanValue: + case ValueType::booleanValue: return value_.bool_ ? "true" : "false"; - case intValue: + case ValueType::intValue: return valueToString(value_.int_); - case uintValue: + case ValueType::uintValue: return valueToString(value_.uint_); - case realValue: + case ValueType::realValue: return valueToString(value_.real_); default: JSON_FAIL_MESSAGE("Type is not convertible to string"); @@ -653,19 +653,19 @@ String Value::asString() const { Value::Int Value::asInt() const { switch (type()) { - case intValue: + case ValueType::intValue: JSON_ASSERT_MESSAGE(isInt(), "LargestInt out of Int range"); return Int(value_.int_); - case uintValue: + case ValueType::uintValue: JSON_ASSERT_MESSAGE(isInt(), "LargestUInt out of Int range"); return Int(value_.uint_); - case realValue: + case ValueType::realValue: JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt, maxInt), "double out of Int range"); return Int(value_.real_); - case nullValue: + case ValueType::nullValue: return 0; - case booleanValue: + case ValueType::booleanValue: return value_.bool_ ? 1 : 0; default: break; @@ -675,19 +675,19 @@ Value::Int Value::asInt() const { Value::UInt Value::asUInt() const { switch (type()) { - case intValue: + case ValueType::intValue: JSON_ASSERT_MESSAGE(isUInt(), "LargestInt out of UInt range"); return UInt(value_.int_); - case uintValue: + case ValueType::uintValue: JSON_ASSERT_MESSAGE(isUInt(), "LargestUInt out of UInt range"); return UInt(value_.uint_); - case realValue: + case ValueType::realValue: JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt), "double out of UInt range"); return UInt(value_.real_); - case nullValue: + case ValueType::nullValue: return 0; - case booleanValue: + case ValueType::booleanValue: return value_.bool_ ? 1 : 0; default: break; @@ -699,18 +699,18 @@ Value::UInt Value::asUInt() const { Value::Int64 Value::asInt64() const { switch (type()) { - case intValue: + case ValueType::intValue: return Int64(value_.int_); - case uintValue: + case ValueType::uintValue: JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range"); return Int64(value_.uint_); - case realValue: + case ValueType::realValue: JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64), "double out of Int64 range"); return Int64(value_.real_); - case nullValue: + case ValueType::nullValue: return 0; - case booleanValue: + case ValueType::booleanValue: return value_.bool_ ? 1 : 0; default: break; @@ -720,18 +720,18 @@ Value::Int64 Value::asInt64() const { Value::UInt64 Value::asUInt64() const { switch (type()) { - case intValue: + case ValueType::intValue: JSON_ASSERT_MESSAGE(isUInt64(), "LargestInt out of UInt64 range"); return UInt64(value_.int_); - case uintValue: + case ValueType::uintValue: return UInt64(value_.uint_); - case realValue: + case ValueType::realValue: JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt64), "double out of UInt64 range"); return UInt64(value_.real_); - case nullValue: + case ValueType::nullValue: return 0; - case booleanValue: + case ValueType::booleanValue: return value_.bool_ ? 1 : 0; default: break; @@ -758,19 +758,19 @@ LargestUInt Value::asLargestUInt() const { double Value::asDouble() const { switch (type()) { - case intValue: + case ValueType::intValue: return static_cast(value_.int_); - case uintValue: + case ValueType::uintValue: #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) return static_cast(value_.uint_); #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) return integerToDouble(value_.uint_); #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - case realValue: + case ValueType::realValue: return value_.real_; - case nullValue: + case ValueType::nullValue: return 0.0; - case booleanValue: + case ValueType::booleanValue: return value_.bool_ ? 1.0 : 0.0; default: break; @@ -780,20 +780,20 @@ double Value::asDouble() const { float Value::asFloat() const { switch (type()) { - case intValue: + case ValueType::intValue: return static_cast(value_.int_); - case uintValue: + case ValueType::uintValue: #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) return static_cast(value_.uint_); #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) // This can fail (silently?) if the value is bigger than MAX_FLOAT. return static_cast(integerToDouble(value_.uint_)); #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - case realValue: + case ValueType::realValue: return static_cast(value_.real_); - case nullValue: + case ValueType::nullValue: return 0.0; - case booleanValue: + case ValueType::booleanValue: return value_.bool_ ? 1.0F : 0.0F; default: break; @@ -803,15 +803,15 @@ float Value::asFloat() const { bool Value::asBool() const { switch (type()) { - case booleanValue: + case ValueType::booleanValue: return value_.bool_; - case nullValue: + case ValueType::nullValue: return false; - case intValue: + case ValueType::intValue: return value_.int_ != 0; - case uintValue: + case ValueType::uintValue: return value_.uint_ != 0; - case realValue: { + case ValueType::realValue: { // According to JavaScript language zero or NaN is regarded as false const auto value_classification = std::fpclassify(value_.real_); return value_classification != FP_ZERO && value_classification != FP_NAN; @@ -824,32 +824,37 @@ bool Value::asBool() const { bool Value::isConvertibleTo(ValueType other) const { switch (other) { - case nullValue: + case ValueType::nullValue: return (isNumeric() && asDouble() == 0.0) || - (type() == booleanValue && !value_.bool_) || - (type() == stringValue && asString().empty()) || - (type() == arrayValue && value_.map_->empty()) || - (type() == objectValue && value_.map_->empty()) || - type() == nullValue; - case intValue: + (type() == ValueType::booleanValue && !value_.bool_) || + (type() == ValueType::stringValue && asString().empty()) || + (type() == ValueType::arrayValue && value_.map_->empty()) || + (type() == ValueType::objectValue && value_.map_->empty()) || + type() == ValueType::nullValue; + case ValueType::intValue: return isInt() || - (type() == realValue && InRange(value_.real_, minInt, maxInt)) || - type() == booleanValue || type() == nullValue; - case uintValue: + (type() == ValueType::realValue && + InRange(value_.real_, minInt, maxInt)) || + type() == ValueType::booleanValue || type() == ValueType::nullValue; + case ValueType::uintValue: return isUInt() || - (type() == realValue && InRange(value_.real_, 0, maxUInt)) || - type() == booleanValue || type() == nullValue; - case realValue: - return isNumeric() || type() == booleanValue || type() == nullValue; - case booleanValue: - return isNumeric() || type() == booleanValue || type() == nullValue; - case stringValue: - return isNumeric() || type() == booleanValue || type() == stringValue || - type() == nullValue; - case arrayValue: - return type() == arrayValue || type() == nullValue; - case objectValue: - return type() == objectValue || type() == nullValue; + (type() == ValueType::realValue && + InRange(value_.real_, 0, maxUInt)) || + type() == ValueType::booleanValue || type() == ValueType::nullValue; + case ValueType::realValue: + return isNumeric() || type() == ValueType::booleanValue || + type() == ValueType::nullValue; + case ValueType::booleanValue: + return isNumeric() || type() == ValueType::booleanValue || + type() == ValueType::nullValue; + case ValueType::stringValue: + return isNumeric() || type() == ValueType::booleanValue || + type() == ValueType::stringValue || + type() == ValueType::nullValue; + case ValueType::arrayValue: + return type() == ValueType::arrayValue || type() == ValueType::nullValue; + case ValueType::objectValue: + return type() == ValueType::objectValue || type() == ValueType::nullValue; } JSON_ASSERT_UNREACHABLE; return false; @@ -858,21 +863,21 @@ bool Value::isConvertibleTo(ValueType other) const { /// Number of values in array or object ArrayIndex Value::size() const { switch (type()) { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: - case stringValue: + case ValueType::nullValue: + case ValueType::intValue: + case ValueType::uintValue: + case ValueType::realValue: + case ValueType::booleanValue: + case ValueType::stringValue: return 0; - case arrayValue: // size of the array is highest index + 1 + case ValueType::arrayValue: // size of the array is highest index + 1 if (!value_.map_->empty()) { ObjectValues::const_iterator itLast = value_.map_->end(); --itLast; return (*itLast).first.index() + 1; } return 0; - case objectValue: + case ValueType::objectValue: return ArrayIndex(value_.map_->size()); } JSON_ASSERT_UNREACHABLE; @@ -888,14 +893,15 @@ bool Value::empty() const { Value::operator bool() const { return !isNull(); } void Value::clear() { - JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue || - type() == objectValue, + JSON_ASSERT_MESSAGE(type() == ValueType::nullValue || + type() == ValueType::arrayValue || + type() == ValueType::objectValue, "in Json::Value::clear(): requires complex value"); start_ = 0; limit_ = 0; switch (type()) { - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: value_.map_->clear(); break; default: @@ -904,10 +910,11 @@ void Value::clear() { } void Value::resize(ArrayIndex newSize) { - JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue, + JSON_ASSERT_MESSAGE(type() == ValueType::nullValue || + type() == ValueType::arrayValue, "in Json::Value::resize(): requires arrayValue"); - if (type() == nullValue) - *this = Value(arrayValue); + if (type() == ValueType::nullValue) + *this = Value(ValueType::arrayValue); ArrayIndex oldSize = size(); if (newSize == 0) clear(); @@ -924,10 +931,10 @@ void Value::resize(ArrayIndex newSize) { Value& Value::operator[](ArrayIndex index) { JSON_ASSERT_MESSAGE( - type() == nullValue || type() == arrayValue, + type() == ValueType::nullValue || type() == ValueType::arrayValue, "in Json::Value::operator[](ArrayIndex): requires arrayValue"); - if (type() == nullValue) - *this = Value(arrayValue); + if (type() == ValueType::nullValue) + *this = Value(ValueType::arrayValue); CZString key(index); auto it = value_.map_->lower_bound(key); if (it != value_.map_->end() && (*it).first == key) @@ -947,9 +954,9 @@ Value& Value::operator[](int index) { const Value& Value::operator[](ArrayIndex index) const { JSON_ASSERT_MESSAGE( - type() == nullValue || type() == arrayValue, + type() == ValueType::nullValue || type() == ValueType::arrayValue, "in Json::Value::operator[](ArrayIndex)const: requires arrayValue"); - if (type() == nullValue) + if (type() == ValueType::nullValue) return nullSingleton(); CZString key(index); ObjectValues::const_iterator it = value_.map_->find(key); @@ -977,14 +984,14 @@ void Value::dupPayload(const Value& other) { setType(other.type()); setIsAllocated(false); switch (type()) { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: + case ValueType::nullValue: + case ValueType::intValue: + case ValueType::uintValue: + case ValueType::realValue: + case ValueType::booleanValue: value_ = other.value_; break; - case stringValue: + case ValueType::stringValue: if (other.value_.string_ && other.isAllocated()) { unsigned len; char const* str; @@ -996,8 +1003,8 @@ void Value::dupPayload(const Value& other) { value_.string_ = other.value_.string_; } break; - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: value_.map_ = new ObjectValues(*other.value_.map_); break; default: @@ -1007,18 +1014,18 @@ void Value::dupPayload(const Value& other) { void Value::releasePayload() { switch (type()) { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: + case ValueType::nullValue: + case ValueType::intValue: + case ValueType::uintValue: + case ValueType::realValue: + case ValueType::booleanValue: break; - case stringValue: + case ValueType::stringValue: if (isAllocated()) releasePrefixedStringValue(value_.string_); break; - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: delete value_.map_; break; default: @@ -1037,12 +1044,12 @@ void Value::dupMeta(const Value& other) { // @param key is null-terminated. Value& Value::resolveReference(const char* key) { JSON_ASSERT_MESSAGE( - type() == nullValue || type() == objectValue, + type() == ValueType::nullValue || type() == ValueType::objectValue, "in Json::Value::resolveReference(): requires objectValue"); - if (type() == nullValue) - *this = Value(objectValue); + if (type() == ValueType::nullValue) + *this = Value(ValueType::objectValue); CZString actualKey(key, static_cast(strlen(key)), - CZString::noDuplication); // NOTE! + CZString::DuplicationPolicy::noDuplication); // NOTE! auto it = value_.map_->lower_bound(actualKey); if (it != value_.map_->end() && (*it).first == actualKey) return (*it).second; @@ -1056,12 +1063,12 @@ Value& Value::resolveReference(const char* key) { // @param key is not null-terminated. Value& Value::resolveReference(char const* key, char const* end) { JSON_ASSERT_MESSAGE( - type() == nullValue || type() == objectValue, + type() == ValueType::nullValue || type() == ValueType::objectValue, "in Json::Value::resolveReference(key, end): requires objectValue"); - if (type() == nullValue) - *this = Value(objectValue); + if (type() == ValueType::nullValue) + *this = Value(ValueType::objectValue); CZString actualKey(key, static_cast(end - key), - CZString::duplicateOnCopy); + CZString::DuplicationPolicy::duplicateOnCopy); auto it = value_.map_->lower_bound(actualKey); if (it != value_.map_->end() && (*it).first == actualKey) return (*it).second; @@ -1080,20 +1087,22 @@ Value Value::get(ArrayIndex index, const Value& defaultValue) const { bool Value::isValidIndex(ArrayIndex index) const { return index < size(); } Value const* Value::find(char const* begin, char const* end) const { - JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue, + JSON_ASSERT_MESSAGE(type() == ValueType::nullValue || + type() == ValueType::objectValue, "in Json::Value::find(begin, end): requires " "objectValue or nullValue"); - if (type() == nullValue) + if (type() == ValueType::nullValue) return nullptr; CZString actualKey(begin, static_cast(end - begin), - CZString::noDuplication); + CZString::DuplicationPolicy::noDuplication); ObjectValues::const_iterator it = value_.map_->find(actualKey); if (it == value_.map_->end()) return nullptr; return &(*it).second; } Value* Value::demand(char const* begin, char const* end) { - JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue, + JSON_ASSERT_MESSAGE(type() == ValueType::nullValue || + type() == ValueType::objectValue, "in Json::Value::demand(begin, end): requires " "objectValue or nullValue"); return &resolveReference(begin, end); @@ -1126,10 +1135,11 @@ Value& Value::operator[](const StaticString& key) { Value& Value::append(const Value& value) { return append(Value(value)); } Value& Value::append(Value&& value) { - JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue, + JSON_ASSERT_MESSAGE(type() == ValueType::nullValue || + type() == ValueType::arrayValue, "in Json::Value::append: requires arrayValue"); - if (type() == nullValue) { - *this = Value(arrayValue); + if (type() == ValueType::nullValue) { + *this = Value(ValueType::arrayValue); } return this->value_.map_->emplace(size(), std::move(value)).first->second; } @@ -1139,7 +1149,8 @@ bool Value::insert(ArrayIndex index, const Value& newValue) { } bool Value::insert(ArrayIndex index, Value&& newValue) { - JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue, + JSON_ASSERT_MESSAGE(type() == ValueType::nullValue || + type() == ValueType::arrayValue, "in Json::Value::insert: requires arrayValue"); ArrayIndex length = size(); if (index > length) { @@ -1165,11 +1176,11 @@ Value Value::get(String const& key, Value const& defaultValue) const { } bool Value::removeMember(const char* begin, const char* end, Value* removed) { - if (type() != objectValue) { + if (type() != ValueType::objectValue) { return false; } CZString actualKey(begin, static_cast(end - begin), - CZString::noDuplication); + CZString::DuplicationPolicy::noDuplication); auto it = value_.map_->find(actualKey); if (it == value_.map_->end()) return false; @@ -1185,18 +1196,19 @@ bool Value::removeMember(String const& key, Value* removed) { return removeMember(key.data(), key.data() + key.length(), removed); } void Value::removeMember(const char* key) { - JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue, + JSON_ASSERT_MESSAGE(type() == ValueType::nullValue || + type() == ValueType::objectValue, "in Json::Value::removeMember(): requires objectValue"); - if (type() == nullValue) + if (type() == ValueType::nullValue) return; - CZString actualKey(key, unsigned(strlen(key)), CZString::noDuplication); + CZString actualKey(key, unsigned(strlen(key)), CZString::DuplicationPolicy::noDuplication); value_.map_->erase(actualKey); } void Value::removeMember(const String& key) { removeMember(key.c_str()); } bool Value::removeIndex(ArrayIndex index, Value* removed) { - if (type() != arrayValue) { + if (type() != ValueType::arrayValue) { return false; } CZString key(index); @@ -1232,9 +1244,9 @@ bool Value::isMember(String const& key) const { Value::Members Value::getMemberNames() const { JSON_ASSERT_MESSAGE( - type() == nullValue || type() == objectValue, + type() == ValueType::nullValue || type() == ValueType::objectValue, "in Json::Value::getMemberNames(), value must be objectValue"); - if (type() == nullValue) + if (type() == ValueType::nullValue) return Value::Members(); Members members; members.reserve(value_.map_->size()); @@ -1251,21 +1263,21 @@ static bool IsIntegral(double d) { return modf(d, &integral_part) == 0.0; } -bool Value::isNull() const { return type() == nullValue; } +bool Value::isNull() const { return type() == ValueType::nullValue; } -bool Value::isBool() const { return type() == booleanValue; } +bool Value::isBool() const { return type() == ValueType::booleanValue; } bool Value::isInt() const { switch (type()) { - case intValue: + case ValueType::intValue: #if defined(JSON_HAS_INT64) return value_.int_ >= minInt && value_.int_ <= maxInt; #else return true; #endif - case uintValue: + case ValueType::uintValue: return value_.uint_ <= UInt(maxInt); - case realValue: + case ValueType::realValue: return value_.real_ >= minInt && value_.real_ <= maxInt && IsIntegral(value_.real_); default: @@ -1276,19 +1288,19 @@ bool Value::isInt() const { bool Value::isUInt() const { switch (type()) { - case intValue: + case ValueType::intValue: #if defined(JSON_HAS_INT64) return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt); #else return value_.int_ >= 0; #endif - case uintValue: + case ValueType::uintValue: #if defined(JSON_HAS_INT64) return value_.uint_ <= maxUInt; #else return true; #endif - case realValue: + case ValueType::realValue: return value_.real_ >= 0 && value_.real_ <= maxUInt && IsIntegral(value_.real_); default: @@ -1300,11 +1312,11 @@ bool Value::isUInt() const { bool Value::isInt64() const { #if defined(JSON_HAS_INT64) switch (type()) { - case intValue: + case ValueType::intValue: return true; - case uintValue: + case ValueType::uintValue: return value_.uint_ <= UInt64(maxInt64); - case realValue: + case ValueType::realValue: // Note that maxInt64 (= 2^63 - 1) is not exactly representable as a // double, so double(maxInt64) will be rounded up to 2^63. Therefore we // require the value to be strictly less than the limit. @@ -1320,11 +1332,11 @@ bool Value::isInt64() const { bool Value::isUInt64() const { #if defined(JSON_HAS_INT64) switch (type()) { - case intValue: + case ValueType::intValue: return value_.int_ >= 0; - case uintValue: + case ValueType::uintValue: return true; - case realValue: + case ValueType::realValue: // Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a // double, so double(maxUInt64) will be rounded up to 2^64. Therefore we // require the value to be strictly less than the limit. @@ -1339,10 +1351,10 @@ bool Value::isUInt64() const { bool Value::isIntegral() const { switch (type()) { - case intValue: - case uintValue: + case ValueType::intValue: + case ValueType::uintValue: return true; - case realValue: + case ValueType::realValue: #if defined(JSON_HAS_INT64) // Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a // double, so double(maxUInt64) will be rounded up to 2^64. Therefore we @@ -1360,16 +1372,17 @@ bool Value::isIntegral() const { } bool Value::isDouble() const { - return type() == intValue || type() == uintValue || type() == realValue; + return type() == ValueType::intValue || type() == ValueType::uintValue || + type() == ValueType::realValue; } bool Value::isNumeric() const { return isDouble(); } -bool Value::isString() const { return type() == stringValue; } +bool Value::isString() const { return type() == ValueType::stringValue; } -bool Value::isArray() const { return type() == arrayValue; } +bool Value::isArray() const { return type() == ValueType::arrayValue; } -bool Value::isObject() const { return type() == objectValue; } +bool Value::isObject() const { return type() == ValueType::objectValue; } Value::Comments::Comments(const Comments& that) : ptr_{cloneUnique(that.ptr_)} {} @@ -1388,13 +1401,13 @@ Value::Comments& Value::Comments::operator=(Comments&& that) noexcept { } bool Value::Comments::has(CommentPlacement slot) const { - return ptr_ && !(*ptr_)[slot].empty(); + return ptr_ && !(*ptr_)[(size_t)slot].empty(); } String Value::Comments::get(CommentPlacement slot) const { if (!ptr_) return {}; - return (*ptr_)[slot]; + return (*ptr_)[(size_t)slot]; } void Value::Comments::set(CommentPlacement slot, String comment) { @@ -1402,7 +1415,7 @@ void Value::Comments::set(CommentPlacement slot, String comment) { return; if (!ptr_) ptr_ = std::unique_ptr(new Array()); - (*ptr_)[slot] = std::move(comment); + (*ptr_)[(size_t)slot] = std::move(comment); } void Value::setComment(String comment, CommentPlacement placement) { @@ -1436,7 +1449,7 @@ ptrdiff_t Value::getOffsetLimit() const { return limit_; } String Value::toStyledString() const { StreamWriterBuilder builder; - String out = this->hasComment(commentBefore) ? "\n" : ""; + String out = this->hasComment(CommentPlacement::commentBefore) ? "\n" : ""; out += Json::writeString(builder, *this); out += '\n'; @@ -1445,8 +1458,8 @@ String Value::toStyledString() const { Value::const_iterator Value::begin() const { switch (type()) { - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: if (value_.map_) return const_iterator(value_.map_->begin()); break; @@ -1458,8 +1471,8 @@ Value::const_iterator Value::begin() const { Value::const_iterator Value::end() const { switch (type()) { - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: if (value_.map_) return const_iterator(value_.map_->end()); break; @@ -1471,8 +1484,8 @@ Value::const_iterator Value::end() const { Value::iterator Value::begin() { switch (type()) { - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: if (value_.map_) return iterator(value_.map_->begin()); break; @@ -1484,8 +1497,8 @@ Value::iterator Value::begin() { Value::iterator Value::end() { switch (type()) { - case arrayValue: - case objectValue: + case ValueType::arrayValue: + case ValueType::objectValue: if (value_.map_) return iterator(value_.map_->end()); break; @@ -1501,11 +1514,12 @@ Value::iterator Value::end() { PathArgument::PathArgument() = default; PathArgument::PathArgument(ArrayIndex index) - : index_(index), kind_(kindIndex) {} + : index_(index), kind_(Kind::kindIndex) {} -PathArgument::PathArgument(const char* key) : key_(key), kind_(kindKey) {} +PathArgument::PathArgument(const char* key) : key_(key), kind_(Kind::kindKey) {} -PathArgument::PathArgument(String key) : key_(std::move(key)), kind_(kindKey) {} +PathArgument::PathArgument(String key) + : key_(std::move(key)), kind_(Kind::kindKey) {} // class Path // ////////////////////////////////////////////////////////////////// @@ -1531,7 +1545,7 @@ void Path::makePath(const String& path, const InArgs& in) { if (*current == '[') { ++current; if (*current == '%') - addPathInArg(path, in, itInArg, PathArgument::kindIndex); + addPathInArg(path, in, itInArg, PathArgument::Kind::kindIndex); else { ArrayIndex index = 0; for (; current != end && *current >= '0' && *current <= '9'; ++current) @@ -1541,7 +1555,7 @@ void Path::makePath(const String& path, const InArgs& in) { if (current == end || *++current != ']') invalidPath(path, int(current - path.c_str())); } else if (*current == '%') { - addPathInArg(path, in, itInArg, PathArgument::kindKey); + addPathInArg(path, in, itInArg, PathArgument::Kind::kindKey); ++current; } else if (*current == '.' || *current == ']') { ++current; @@ -1573,13 +1587,13 @@ void Path::invalidPath(const String& /*path*/, int /*location*/) { const Value& Path::resolve(const Value& root) const { const Value* node = &root; for (const auto& arg : args_) { - if (arg.kind_ == PathArgument::kindIndex) { + if (arg.kind_ == PathArgument::Kind::kindIndex) { if (!node->isArray() || !node->isValidIndex(arg.index_)) { // Error: unable to resolve path (array value expected at position... ) return Value::nullSingleton(); } node = &((*node)[arg.index_]); - } else if (arg.kind_ == PathArgument::kindKey) { + } else if (arg.kind_ == PathArgument::Kind::kindKey) { if (!node->isObject()) { // Error: unable to resolve path (object value expected at position...) return Value::nullSingleton(); @@ -1598,11 +1612,11 @@ const Value& Path::resolve(const Value& root) const { Value Path::resolve(const Value& root, const Value& defaultValue) const { const Value* node = &root; for (const auto& arg : args_) { - if (arg.kind_ == PathArgument::kindIndex) { + if (arg.kind_ == PathArgument::Kind::kindIndex) { if (!node->isArray() || !node->isValidIndex(arg.index_)) return defaultValue; node = &((*node)[arg.index_]); - } else if (arg.kind_ == PathArgument::kindKey) { + } else if (arg.kind_ == PathArgument::Kind::kindKey) { if (!node->isObject()) return defaultValue; node = &((*node)[arg.key_]); @@ -1616,12 +1630,12 @@ Value Path::resolve(const Value& root, const Value& defaultValue) const { Value& Path::make(Value& root) const { Value* node = &root; for (const auto& arg : args_) { - if (arg.kind_ == PathArgument::kindIndex) { + if (arg.kind_ == PathArgument::Kind::kindIndex) { if (!node->isArray()) { // Error: node is not an array at position ... } node = &((*node)[arg.index_]); - } else if (arg.kind_ == PathArgument::kindKey) { + } else if (arg.kind_ == PathArgument::Kind::kindKey) { if (!node->isObject()) { // Error: node is not an object at position... } diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 0dd160e..4e75486 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -380,20 +380,20 @@ String FastWriter::write(const Value& root) { void FastWriter::writeValue(const Value& value) { switch (value.type()) { - case nullValue: + case ValueType::nullValue: if (!dropNullPlaceholders_) document_ += "null"; break; - case intValue: + case ValueType::intValue: document_ += valueToString(value.asLargestInt()); break; - case uintValue: + case ValueType::uintValue: document_ += valueToString(value.asLargestUInt()); break; - case realValue: + case ValueType::realValue: document_ += valueToString(value.asDouble()); break; - case stringValue: { + case ValueType::stringValue: { // Is NULL possible for value.string_? No. char const* str; char const* end; @@ -402,10 +402,10 @@ void FastWriter::writeValue(const Value& value) { document_ += valueToQuotedStringN(str, static_cast(end - str)); break; } - case booleanValue: + case ValueType::booleanValue: document_ += valueToString(value.asBool()); break; - case arrayValue: { + case ValueType::arrayValue: { document_ += '['; ArrayIndex size = value.size(); for (ArrayIndex index = 0; index < size; ++index) { @@ -415,7 +415,7 @@ void FastWriter::writeValue(const Value& value) { } document_ += ']'; } break; - case objectValue: { + case ValueType::objectValue: { Value::Members members(value.getMemberNames()); document_ += '{'; for (auto it = members.begin(); it != members.end(); ++it) { @@ -449,19 +449,19 @@ String StyledWriter::write(const Value& root) { void StyledWriter::writeValue(const Value& value) { switch (value.type()) { - case nullValue: + case ValueType::nullValue: pushValue("null"); break; - case intValue: + case ValueType::intValue: pushValue(valueToString(value.asLargestInt())); break; - case uintValue: + case ValueType::uintValue: pushValue(valueToString(value.asLargestUInt())); break; - case realValue: + case ValueType::realValue: pushValue(valueToString(value.asDouble())); break; - case stringValue: { + case ValueType::stringValue: { // Is NULL possible for value.string_? No. char const* str; char const* end; @@ -472,13 +472,13 @@ void StyledWriter::writeValue(const Value& value) { pushValue(""); break; } - case booleanValue: + case ValueType::booleanValue: pushValue(valueToString(value.asBool())); break; - case arrayValue: + case ValueType::arrayValue: writeArrayValue(value); break; - case objectValue: { + case ValueType::objectValue: { Value::Members members(value.getMemberNames()); if (members.empty()) pushValue("{}"); @@ -608,12 +608,12 @@ void StyledWriter::unindent() { } void StyledWriter::writeCommentBeforeValue(const Value& root) { - if (!root.hasComment(commentBefore)) + if (!root.hasComment(CommentPlacement::commentBefore)) return; document_ += '\n'; writeIndent(); - const String& comment = root.getComment(commentBefore); + const String& comment = root.getComment(CommentPlacement::commentBefore); String::const_iterator iter = comment.begin(); while (iter != comment.end()) { document_ += *iter; @@ -627,20 +627,21 @@ void StyledWriter::writeCommentBeforeValue(const Value& root) { } void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) { - if (root.hasComment(commentAfterOnSameLine)) - document_ += " " + root.getComment(commentAfterOnSameLine); + if (root.hasComment(CommentPlacement::commentAfterOnSameLine)) + document_ += + " " + root.getComment(CommentPlacement::commentAfterOnSameLine); - if (root.hasComment(commentAfter)) { + if (root.hasComment(CommentPlacement::commentAfter)) { document_ += '\n'; - document_ += root.getComment(commentAfter); + document_ += root.getComment(CommentPlacement::commentAfter); document_ += '\n'; } } bool StyledWriter::hasCommentForValue(const Value& value) { - return value.hasComment(commentBefore) || - value.hasComment(commentAfterOnSameLine) || - value.hasComment(commentAfter); + return value.hasComment(CommentPlacement::commentBefore) || + value.hasComment(CommentPlacement::commentAfterOnSameLine) || + value.hasComment(CommentPlacement::commentAfter); } // Class StyledStreamWriter @@ -667,19 +668,19 @@ void StyledStreamWriter::write(OStream& out, const Value& root) { void StyledStreamWriter::writeValue(const Value& value) { switch (value.type()) { - case nullValue: + case ValueType::nullValue: pushValue("null"); break; - case intValue: + case ValueType::intValue: pushValue(valueToString(value.asLargestInt())); break; - case uintValue: + case ValueType::uintValue: pushValue(valueToString(value.asLargestUInt())); break; - case realValue: + case ValueType::realValue: pushValue(valueToString(value.asDouble())); break; - case stringValue: { + case ValueType::stringValue: { // Is NULL possible for value.string_? No. char const* str; char const* end; @@ -690,13 +691,13 @@ void StyledStreamWriter::writeValue(const Value& value) { pushValue(""); break; } - case booleanValue: + case ValueType::booleanValue: pushValue(valueToString(value.asBool())); break; - case arrayValue: + case ValueType::arrayValue: writeArrayValue(value); break; - case objectValue: { + case ValueType::objectValue: { Value::Members members(value.getMemberNames()); if (members.empty()) pushValue("{}"); @@ -828,12 +829,12 @@ void StyledStreamWriter::unindent() { } void StyledStreamWriter::writeCommentBeforeValue(const Value& root) { - if (!root.hasComment(commentBefore)) + if (!root.hasComment(CommentPlacement::commentBefore)) return; if (!indented_) writeIndent(); - const String& comment = root.getComment(commentBefore); + const String& comment = root.getComment(CommentPlacement::commentBefore); String::const_iterator iter = comment.begin(); while (iter != comment.end()) { *document_ << *iter; @@ -846,20 +847,21 @@ void StyledStreamWriter::writeCommentBeforeValue(const Value& root) { } void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) { - if (root.hasComment(commentAfterOnSameLine)) - *document_ << ' ' << root.getComment(commentAfterOnSameLine); + if (root.hasComment(CommentPlacement::commentAfterOnSameLine)) + *document_ << ' ' + << root.getComment(CommentPlacement::commentAfterOnSameLine); - if (root.hasComment(commentAfter)) { + if (root.hasComment(CommentPlacement::commentAfter)) { writeIndent(); - *document_ << root.getComment(commentAfter); + *document_ << root.getComment(CommentPlacement::commentAfter); } indented_ = false; } bool StyledStreamWriter::hasCommentForValue(const Value& value) { - return value.hasComment(commentBefore) || - value.hasComment(commentAfterOnSameLine) || - value.hasComment(commentAfter); + return value.hasComment(CommentPlacement::commentBefore) || + value.hasComment(CommentPlacement::commentAfterOnSameLine) || + value.hasComment(CommentPlacement::commentAfter); } ////////////////////////// @@ -868,7 +870,7 @@ bool StyledStreamWriter::hasCommentForValue(const Value& value) { /// Scoped enums are not available until C++11. struct CommentStyle { /// Decide whether to write comments. - enum Enum { + enum class Enum { None, ///< Drop all comments. Most, ///< Recover odd behavior of previous versions (not implemented yet). All ///< Keep all comments. @@ -940,20 +942,20 @@ int BuiltStyledStreamWriter::write(Value const& root, OStream* sout) { } void BuiltStyledStreamWriter::writeValue(Value const& value) { switch (value.type()) { - case nullValue: + case ValueType::nullValue: pushValue(nullSymbol_); break; - case intValue: + case ValueType::intValue: pushValue(valueToString(value.asLargestInt())); break; - case uintValue: + case ValueType::uintValue: pushValue(valueToString(value.asLargestUInt())); break; - case realValue: + case ValueType::realValue: pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_, precisionType_)); break; - case stringValue: { + case ValueType::stringValue: { // Is NULL is possible for value.string_? No. char const* str; char const* end; @@ -965,13 +967,13 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) { pushValue(""); break; } - case booleanValue: + case ValueType::booleanValue: pushValue(valueToString(value.asBool())); break; - case arrayValue: + case ValueType::arrayValue: writeArrayValue(value); break; - case objectValue: { + case ValueType::objectValue: { Value::Members members(value.getMemberNames()); if (members.empty()) pushValue("{}"); @@ -1006,7 +1008,7 @@ void BuiltStyledStreamWriter::writeArrayValue(Value const& value) { if (size == 0) pushValue("[]"); else { - bool isMultiLine = (cs_ == CommentStyle::All) || isMultilineArray(value); + bool isMultiLine = (cs_ == CommentStyle::Enum::All) || isMultilineArray(value); if (isMultiLine) { writeWithIndent("["); indent(); @@ -1112,14 +1114,14 @@ void BuiltStyledStreamWriter::unindent() { } void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) { - if (cs_ == CommentStyle::None) + if (cs_ == CommentStyle::Enum::None) return; - if (!root.hasComment(commentBefore)) + if (!root.hasComment(CommentPlacement::commentBefore)) return; if (!indented_) writeIndent(); - const String& comment = root.getComment(commentBefore); + const String& comment = root.getComment(CommentPlacement::commentBefore); String::const_iterator iter = comment.begin(); while (iter != comment.end()) { *sout_ << *iter; @@ -1133,22 +1135,22 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) { void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine( Value const& root) { - if (cs_ == CommentStyle::None) + if (cs_ == CommentStyle::Enum::None) return; - if (root.hasComment(commentAfterOnSameLine)) - *sout_ << " " + root.getComment(commentAfterOnSameLine); + if (root.hasComment(CommentPlacement::commentAfterOnSameLine)) + *sout_ << " " + root.getComment(CommentPlacement::commentAfterOnSameLine); - if (root.hasComment(commentAfter)) { + if (root.hasComment(CommentPlacement::commentAfter)) { writeIndent(); - *sout_ << root.getComment(commentAfter); + *sout_ << root.getComment(CommentPlacement::commentAfter); } } // static bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) { - return value.hasComment(commentBefore) || - value.hasComment(commentAfterOnSameLine) || - value.hasComment(commentAfter); + return value.hasComment(CommentPlacement::commentBefore) || + value.hasComment(CommentPlacement::commentAfterOnSameLine) || + value.hasComment(CommentPlacement::commentAfter); } /////////////// @@ -1168,15 +1170,15 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const { const bool usf = settings_["useSpecialFloats"].asBool(); const bool emitUTF8 = settings_["emitUTF8"].asBool(); unsigned int pre = settings_["precision"].asUInt(); - CommentStyle::Enum cs = CommentStyle::All; + CommentStyle::Enum cs = CommentStyle::Enum::All; if (cs_str == "All") { - cs = CommentStyle::All; + cs = CommentStyle::Enum::All; } else if (cs_str == "None") { - cs = CommentStyle::None; + cs = CommentStyle::Enum::None; } else { throwRuntimeError("commentStyle must be 'All' or 'None'"); } - PrecisionType precisionType(significantDigits); + PrecisionType precisionType(PrecisionType::significantDigits); if (pt_str == "significant") { precisionType = PrecisionType::significantDigits; } else if (pt_str == "decimal") {