Fixed IntelliSense errors in Visual Micro (issue #483)

This commit is contained in:
Benoit Blanchon
2017-05-28 15:33:03 +02:00
parent 574c00c096
commit c955049207
15 changed files with 51 additions and 153 deletions

View File

@ -1,6 +1,11 @@
ArduinoJson: change log
=======================
HEAD
----
* Fixed IntelliSense errors in Visual Micro (issue #483)
v5.10.0
-------

View File

@ -20,9 +20,8 @@ inline bool ArduinoJson::Internals::JsonParser<TReader, TWriter>::eat(
}
template <typename TReader, typename TWriter>
inline bool
ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseAnythingTo(
JsonVariant *destination) {
inline bool ArduinoJson::Internals::JsonParser<
TReader, TWriter>::parseAnythingTo(JsonVariant *destination) {
if (_nestingLimit == 0) return false;
_nestingLimit--;
bool success = parseAnythingToUnsafe(destination);
@ -31,9 +30,8 @@ ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseAnythingTo(
}
template <typename TReader, typename TWriter>
inline bool
ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseAnythingToUnsafe(
JsonVariant *destination) {
inline bool ArduinoJson::Internals::JsonParser<
TReader, TWriter>::parseAnythingToUnsafe(JsonVariant *destination) {
skipSpacesAndComments(_reader);
switch (_reader.current()) {

View File

@ -17,8 +17,8 @@ class StringWriter {
public:
String(TChar** ptr) : _writePtr(ptr), _startPtr(*ptr) {}
void append(TChar c) {
*(*_writePtr)++ = c;
void append(char c) {
*(*_writePtr)++ = TChar(c);
}
const char* c_str() const {

View File

@ -98,7 +98,7 @@ class DynamicJsonBufferBase
private:
DynamicJsonBufferBase* _parent;
char* _start;
int _length;
size_t _length;
};
String startString() {

View File

@ -107,13 +107,13 @@ inline const JsonArraySubscript JsonArray::operator[](size_t index) const {
}
template <typename TImplem>
inline JsonArraySubscript JsonVariantBase<TImplem>::operator[](int index) {
inline JsonArraySubscript JsonVariantBase<TImplem>::operator[](size_t index) {
return as<JsonArray>()[index];
}
template <typename TImplem>
inline const JsonArraySubscript JsonVariantBase<TImplem>::operator[](
int index) const {
size_t index) const {
return as<JsonArray>()[index];
}

View File

@ -52,7 +52,7 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
JsonVariant(bool value) {
using namespace Internals;
_type = JSON_BOOLEAN;
_content.asInteger = static_cast<JsonInteger>(value);
_content.asInteger = static_cast<JsonUInt>(value);
}
// Create a JsonVariant containing a floating point value.

View File

@ -78,8 +78,8 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
// Mimics an array.
// Returns the element at specified index if the variant is an array.
// Returns JsonVariant::invalid() if the variant is not an array.
FORCE_INLINE const JsonArraySubscript operator[](int index) const;
FORCE_INLINE JsonArraySubscript operator[](int index);
FORCE_INLINE const JsonArraySubscript operator[](size_t index) const;
FORCE_INLINE JsonArraySubscript operator[](size_t index);
// Mimics an object.
// Returns the value associated with the specified key if the variant is

View File

@ -56,16 +56,16 @@ inline T JsonVariant::variantAsInteger() const {
return 0;
case JSON_POSITIVE_INTEGER:
case JSON_BOOLEAN:
return static_cast<T>(_content.asInteger);
return T(_content.asInteger);
case JSON_NEGATIVE_INTEGER:
return static_cast<T>(_content.asInteger * -1);
return T(~_content.asInteger + 1);
case JSON_STRING:
case JSON_UNPARSED:
if (!_content.asString) return 0;
if (!strcmp("true", _content.asString)) return 1;
return Polyfills::parseInteger<T>(_content.asString);
default:
return static_cast<T>(_content.asFloat);
return T(_content.asFloat);
}
}
@ -117,7 +117,8 @@ inline bool JsonVariant::variantIsInteger() const {
inline bool JsonVariant::variantIsFloat() const {
using namespace Internals;
return _type == JSON_FLOAT || _type == JSON_POSITIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER ||
return _type == JSON_FLOAT || _type == JSON_POSITIVE_INTEGER ||
_type == JSON_NEGATIVE_INTEGER ||
(_type == JSON_UNPARSED && Polyfills::isFloat(_content.asString));
}

View File

@ -7,126 +7,16 @@
#pragma once
// If Visual Studo
#if defined(_MSC_VER)
#include <float.h>
#include <limits>
namespace ArduinoJson {
namespace Polyfills {
template <typename T>
bool isNaN(T x) {
return _isnan(x) != 0;
return x != x;
}
template <typename T>
bool isInfinity(T x) {
return !_finite(x);
}
template <typename T>
T nan() {
return std::numeric_limits<T>::quiet_NaN();
}
template <typename T>
T inf() {
return std::numeric_limits<T>::infinity();
return x != 0.0 && x * 2 == x;
}
}
}
#else
#include <math.h>
// GCC warning: "conversion to 'float' from 'double' may alter its value"
#ifdef __GNUC__
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic push
#endif
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
#pragma GCC diagnostic ignored "-Wfloat-conversion"
#else
#pragma GCC diagnostic ignored "-Wconversion"
#endif
#endif
// Workaround for libs that #undef isnan or isinf
// https://bblanchon.github.io/ArduinoJson//issues/284
#if !defined(isnan) || !defined(isinf)
namespace std {}
#endif
namespace ArduinoJson {
namespace Polyfills {
template <typename T>
bool isNaN(T x) {
// Workaround for libs that #undef isnan
// https://bblanchon.github.io/ArduinoJson//issues/284
#ifndef isnan
using namespace std;
#endif
return isnan(x);
}
#if defined(_GLIBCXX_HAVE_ISNANL) && _GLIBCXX_HAVE_ISNANL
template <>
inline bool isNaN<double>(double x) {
return isnanl(x);
}
#endif
#if defined(_GLIBCXX_HAVE_ISNANF) && _GLIBCXX_HAVE_ISNANF
template <>
inline bool isNaN<float>(float x) {
return isnanf(x);
}
#endif
template <typename T>
bool isInfinity(T x) {
// Workaround for libs that #undef isinf
// https://bblanchon.github.io/ArduinoJson//issues/284
#ifndef isinf
using namespace std;
#endif
return isinf(x);
}
#if defined(_GLIBCXX_HAVE_ISINFL) && _GLIBCXX_HAVE_ISINFL
template <>
inline bool isInfinity<double>(double x) {
return isinfl(x);
}
#endif
#if defined(_GLIBCXX_HAVE_ISINFF) && _GLIBCXX_HAVE_ISINFF
template <>
inline bool isInfinity<float>(float x) {
return isinff(x);
}
#endif
template <typename T>
T nan() {
return static_cast<T>(NAN);
}
template <typename T>
T inf() {
return static_cast<T>(INFINITY);
}
#if defined(__GNUC__)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic pop
#endif
#endif
}
}
#endif

View File

@ -30,11 +30,11 @@ T parseInteger(const char *s) {
}
while (isdigit(*s)) {
result = static_cast<T>(result * 10 + (*s - '0'));
result = T(result * 10 + T(*s - '0'));
s++;
}
return negative_result ? static_cast<T>(result * -1) : result;
return negative_result ? T(~result + 1) : result;
}
}
}

View File

@ -28,7 +28,7 @@ class StaticStringBuilder {
char *begin = p;
while (p < end && *s) *p++ = *s++;
*p = '\0';
return p - begin;
return size_t(p - begin);
}
private:

View File

@ -23,12 +23,12 @@ struct CharPointerTraits {
++_ptr;
}
TChar current() const {
return _ptr[0];
char current() const {
return char(_ptr[0]);
}
TChar next() const {
return _ptr[1];
char next() const {
return char(_ptr[1]);
}
};

View File

@ -43,11 +43,13 @@ struct FloatTraits<T, 8 /*64bits*/> {
}
static T nan() {
return Polyfills::nan<T>();
uint64_t x = uint64_t(0x7ff8) << 48;
return *reinterpret_cast<T*>(&x);
}
static T inf() {
return Polyfills::inf<T>();
uint64_t x = uint64_t(0x7ff0) << 48;
return *reinterpret_cast<T*>(&x);
}
};
#endif
@ -73,11 +75,13 @@ struct FloatTraits<T, 4 /*32bits*/> {
}
static T nan() {
return Polyfills::nan<T>();
uint32_t x = 0x7fc00000;
return *reinterpret_cast<T*>(&x);
}
static T inf() {
return Polyfills::inf<T>();
uint32_t x = 0x7f800000;
return *reinterpret_cast<T*>(&x);
}
};
}

View File

@ -87,7 +87,7 @@ TEST_CASE("Gbathree") {
REQUIRE(3 == array.size());
for (int i = 0; i < 3; i++) {
for (size_t i = 0; i < 3; i++) {
REQUIRE(50 == array[i]);
}
}
@ -112,11 +112,11 @@ TEST_CASE("Gbathree") {
REQUIRE(array.success());
REQUIRE(4 == array.size());
for (int i = 0; i < 4; i++) {
for (size_t i = 0; i < 4; i++) {
JsonArray& nestedArray = array[i];
REQUIRE(4 == nestedArray.size());
for (int j = 0; j < 4; j++) {
for (size_t j = 0; j < 4; j++) {
REQUIRE(34 == nestedArray[j]);
}
}
@ -130,7 +130,7 @@ TEST_CASE("Gbathree") {
REQUIRE(4 == array.size());
for (int i = 0; i < 4; i++) {
for (size_t i = 0; i < 4; i++) {
REQUIRE(2 == array[i]);
}
}
@ -143,7 +143,7 @@ TEST_CASE("Gbathree") {
REQUIRE(4 == array.size());
for (int i = 0; i < 4; i++) {
for (size_t i = 0; i < 4; i++) {
REQUIRE(2 == array[i]);
}
}
@ -155,12 +155,12 @@ TEST_CASE("Gbathree") {
REQUIRE(array.success());
REQUIRE(4 == array.size());
for (int i = 0; i < 4; i++) {
for (size_t i = 0; i < 4; i++) {
JsonArray& nestedArray = array[i];
REQUIRE(4 == nestedArray.size());
for (int j = 0; j < 4; j++) {
for (size_t j = 0; j < 4; j++) {
REQUIRE(15 == nestedArray[j]);
}
}
@ -173,11 +173,11 @@ TEST_CASE("Gbathree") {
REQUIRE(array.success());
REQUIRE(4 == array.size());
for (int i = 0; i < 4; i++) {
for (size_t i = 0; i < 4; i++) {
JsonArray& nestedArray = array[i];
REQUIRE(4 == nestedArray.size());
for (int j = 0; j < 4; j++) {
for (size_t j = 0; j < 4; j++) {
REQUIRE(15 == nestedArray[j]);
}
}
@ -191,7 +191,7 @@ TEST_CASE("Gbathree") {
REQUIRE(4 == array.size());
for (int i = 0; i < 4; i++) {
for (size_t i = 0; i < 4; i++) {
REQUIRE(2 == array[i]);
}
}
@ -204,7 +204,7 @@ TEST_CASE("Gbathree") {
REQUIRE(4 == array.size());
for (int i = 0; i < 4; i++) {
for (size_t i = 0; i < 4; i++) {
REQUIRE(2 == array[i]);
}
}

View File

@ -23,7 +23,7 @@ TEST_CASE("JsonVariant::operator[]") {
REQUIRE(std::string("element at index 1") == var[1]);
REQUIRE(std::string("element at index 0") ==
var[static_cast<unsigned char>(0)]); // issue #381
REQUIRE_FALSE(var[-1].success());
REQUIRE_FALSE(var[666].success());
REQUIRE_FALSE(var[3].success());
REQUIRE_FALSE(var["0"].success());
}