8000 Fixed IntelliSense errors in Visual Micro (issue #483) · trinhduc/ArduinoJson@c955049 · GitHub
[go: up one dir, main page]

Skip to content

Commit c955049

Browse files
committed
Fixed IntelliSense errors in Visual Micro (issue bblanchon#483)
1 parent 574c00c commit c955049

File tree

15 files changed

+51
-153
lines changed

15 files changed

+51
-153
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
ArduinoJson: change log
22
=======================
33

4+
HEAD
5+
----
6+
7+
* Fixed IntelliSense errors in Visual Micro (issue #483)
8+
49
v5.10.0
510
-------
611

src/ArduinoJson/Deserialization/JsonParserImpl.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ inline bool ArduinoJson::Internals::JsonParser<TReader, TWriter>::eat(
2020
}
2121

2222
template <typename TReader, typename TWriter>
23-
inline bool
24-
ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseAnythingTo(
25-
JsonVariant *destination) {
23+
inline bool ArduinoJson::Internals::JsonParser<
24+
TReader, TWriter>::parseAnythingTo(JsonVariant *destination) {
2625
if (_nestingLimit == 0) return false;
2726
_nestingLimit--;
2827
bool success = parseAnythingToUnsafe(destination);
@@ -31,9 +30,8 @@ ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseAnythingTo(
3130
}
3231

3332
template <typename TReader, typename TWriter>
34-
inline bool
35-
ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseAnythingToUnsafe(
36-
JsonVariant *destination) {
33+
inline bool ArduinoJson::Internals::JsonParser<
34+
TReader, TWriter>::parseAnythingToUnsafe(JsonVariant *destination) {
3735
skipSpacesAndComments(_reader);
3836

3937
switch (_reader.current()) {

src/ArduinoJson/Deserialization/StringWriter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class StringWriter {
1717
public:
1818
String(TChar** ptr) : _writePtr(ptr), _startPtr(*ptr) {}
1919

20-
void append(TChar c) {
21-
*(*_writePtr)++ = c;
20+
void append(char c) {
21+
*(*_writePtr)++ = TChar(c);
2222
}
2323

2424
const char* c_str() const {

src/ArduinoJson/DynamicJsonBuffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class DynamicJsonBufferBase
9898
private:
9999
DynamicJsonBufferBase* _parent;
100100
char* _start;
101-
int _length;
101+
size_t _length;
102102
};
103103

104104
String startString() {

src/ArduinoJson/JsonArraySubscript.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ inline const JsonArraySubscript JsonArray::operator[](size_t index) const {
107107
}
108108

109109
template <typename TImplem>
110-
inline JsonArraySubscript JsonVariantBase<TImplem>::operator[](int index) {
110+
inline JsonArraySubscript JsonVariantBase<TImplem>::operator[](size_t index) {
111111
return as<JsonArray>()[index];
112112
}
113113

114114
template <typename TImplem>
115115
inline const JsonArraySubscript JsonVariantBase<TImplem>::operator[](
116-
int index) const {
116+
size_t index) const {
117117
return as<JsonArray>()[index];
118118
}
119119

src/ArduinoJson/JsonVariant.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
5252
JsonVariant(bool value) {
5353
using namespace Internals;
5454
_type = JSON_BOOLEAN;
55-
_content.asInteger = static_cast<JsonInteger>(value);
55+
_content.asInteger = static_cast<JsonUInt>(value);
5656
}
5757

5858
// Create a JsonVariant containing a floating point value.

src/ArduinoJson/JsonVariantBase.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
7878
// Mimics an array.
7979
// Returns the element at specified index if the variant is an array.
8080
// Returns JsonVariant::invalid() if the variant is not an array.
81-
FORCE_INLINE const JsonArraySubscript operator[](int index) const;
82-
FORCE_INLINE JsonArraySubscript operator[](int index);
81+
FORCE_INLINE const JsonArraySubscript operator[](size_t index) const;
82+
FORCE_INLINE JsonArraySubscript operator[](size_t index);
8383

8484
// Mimics an object.
8585
// Returns the value associated with the specified key if the variant is

src/ArduinoJson/JsonVariantImpl.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ inline T JsonVariant::variantAsInteger() const {
5656
return 0;
5757
case JSON_POSITIVE_INTEGER:
5858
case JSON_BOOLEAN:
59-
return static_cast<T>(_content.asInteger);
59+
return T(_content.asInteger);
6060
case JSON_NEGATIVE_INTEGER:
61-
return static_cast<T>(_content.asInteger * -1);
61+
return T(~_content.asInteger + 1);
6262
case JSON_STRING:
6363
case JSON_UNPARSED:
6464
if (!_content.asString) return 0;
6565
if (!strcmp("true", _content.asString)) return 1;
6666
return Polyfills::parseInteger<T>(_content.asString);
6767
default:
68-
return static_cast<T>(_content.asFloat);
68+
return T(_content.asFloat);
6969
}
7070
}
7171

@@ -117,7 +117,8 @@ inline bool JsonVariant::variantIsInteger() const {
117117
inline bool JsonVariant::variantIsFloat() const {
118118
using namespace Internals;
119119

120-
return _type == JSON_FLOAT || _type == JSON_POSITIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER ||
120+
return _type == JSON_FLOAT || _type == JSON_POSITIVE_INTEGER ||
121+
_type == JSON_NEGATIVE_INTEGER ||
121122
(_type == JSON_UNPARSED && Polyfills::isFloat(_content.asString));
122123
}
123124

src/ArduinoJson/Polyfills/math.hpp

Lines changed: 2 additions & 112 deletions
76
Original file line numberDiff line numberDiff line change
@@ -7,126 +7,16 @@
77

88
#pragma once
99

10-
// If Visual Studo
11-
#if defined(_MSC_VER)
12-
13-
#include <float.h>
14-
#include <limits>
15-
16-
namespace ArduinoJson {
17-
namespace Polyfills {
18-
template <typename T>
19-
bool isNaN(T x) {
20-
return _isnan(x) != 0;
21-
}
22-
23-
template <typename T>
24-
bool isInfinity(T x) {
25-
return !_finite(x);
26-
}
27-
28-
template <typename T>
29-
T nan() {
30-
return std::numeric_limits<T>::quiet_NaN();
31-
}
32-
33-
template <typename T>
34-
T inf() {
35-
return std::numeric_limits<T>::infinity();
36-
}
37-
}
38-
}
39-
40-
#else
41-
42-
#include <math.h>
43-
44-
// GCC warning: "conversion to 'float' from 'double' may alter its value"
45-
#ifdef __GNUC__
46-
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
47-
#pragma GCC diagnostic push
48-
#endif
49-
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
50-
#pragma GCC diagnostic ignored "-Wfloat-conversion"
51-
#else
52-
#pragma GCC diagnostic ignored "-Wconversion"
53-
#endif
54-
#endif
55-
56-
// Workaround for libs that #undef isnan or isinf
57-
// https://bblanchon.github.io/ArduinoJson//issues/284
58-
#if !defined(isnan) || !defined(isinf)
59-
namespace std {}
60-
#endif
61-
6210
namespace ArduinoJson {
6311
namespace Polyfills {
64-
6512
template <typename T>
6613
bool isNaN(T x) {
67-
// Workaround for libs that #undef isnan
68-
// https://bblanchon.github.io/ArduinoJson//issues/284
69-
#ifndef isnan
70-
using namespace std;
71-
#endif
72-
73-
return isnan(x);
14+
return x != x;
7415
}
7516

-
#if defined(_GLIBCXX_HAVE_ISNANL) && _GLIBCXX_HAVE_ISNANL
77-
template <>
78-
inline bool isNaN<double>(double x) {
79-
return isnanl(x);
80-
}
81-
#endif
82-
83-
#if defined(_GLIBCXX_HAVE_ISNANF) && _GLIBCXX_HAVE_ISNANF
84-
template <>
85-
inline bool isNaN<float>(float x) {
86-
return isnanf(x);
87-
}
88-
#endif
89-
9017
template <typename T>
9118
bool isInfinity(T x) {
92-
// Workaround for libs that #undef isinf
93-
// https://bblanchon.github.io/ArduinoJson//issues/284
94-
#ifndef isinf
95-
using namespace std;
96-
#endif
97-
98-
return isinf(x);
19+
return x != 0.0 && x * 2 == x;
9920
}
100-
101-
#if defined(_GLIBCXX_HAVE_ISINFL) && _GLIBCXX_HAVE_ISINFL
102-
template <>
103-
inline bool isInfinity<double>(double x) {
104-
return isinfl(x);
105-
}
106-
#endif
107-
108-
#if defined(_GLIBCXX_HAVE_ISINFF) && _GLIBCXX_HAVE_ISINFF
109-
template <>
110-
inline bool isInfinity<float>(float x) {
111-
return isinff(x);
112-
}
113-
#endif
114-
115-
template <typename T>
116-
T nan() {
117-
return static_cast<T>(NAN);
118-
}
119-
120-
template <typename T>
121-
T inf() {
122-
return static_cast<T>(INFINITY);
123-
}
124-
125-
#if defined(__GNUC__)
126-
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
127-
#pragma GCC diagnostic pop
128-
#endif
129-
#endif
13021
}
13122
}
132-
#endif

src/ArduinoJson/Polyfills/parseInteger.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ T parseInteger(const char *s) {
3030
}
3131

3232
while (isdigit(*s)) {
33-
result = static_cast<T>(result * 10 + (*s - '0'));
33+
result = T(result * 10 + T(*s - '0'));
3434
s++;
3535
}
3636

37-
return negative_result ? static_cast<T>(result * -1) : result;
37+
return negative_result ? T(~result + 1) : result;
3838
}
3939
}
4040
}

src/ArduinoJson/Serialization/StaticStringBuilder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class StaticStringBuilder {
2828
char *begin = p;
2929
while (p < end && *s) *p++ = *s++;
3030
*p = '\0';
31-
return p - begin;
31+
return size_t(p - begin);
3232
}
3333

3434
private:

src/ArduinoJson/StringTraits/CharPointer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ struct CharPointerTraits {
2323
++_ptr;
2424
}
2525

26-
TChar current() const {
27-
return _ptr[0];
26+
char current() const {
27+
return char(_ptr[0]);
2828
}
2929

30-
TChar next() const {
31-
return _ptr[1];
30+
char next() const {
31+
return char(_ptr[1]);
3232
}
3333
};
3434

src/ArduinoJson/TypeTraits/FloatTraits.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ struct FloatTraits<T, 8 /*64bits*/> {
4343
}
4444

4545
static T nan() {
46-
return Polyfills::nan<T>();
46+
uint64_t x = uint64_t(0x7ff8) << 48;
47+
return *reinterpret_cast<T*>(&x);
4748
}
4849

4950
static T inf() {
50-
return Polyfills::inf<T>();
51+
uint64_t x = uint64_t(0x7ff0) << 48;
52+
return *reinterpret_cast<T*>(&x);
5153
}
5254
};
5355
#endif
@@ -73,11 +75,13 @@ struct FloatTraits<T, 4 /*32bits*/> {
7375
}
7476

7577
static T nan() {
76-
return Polyfills::nan<T>();
78+
uint32_t x = 0x7fc00000;
79+
return *reinterpret_cast<T*>(&x);
7780
}
7881

7982
static T inf() {
80-
return Polyfills::inf<T>();
83+
uint32_t x = 0x7f800000;
84+
return *reinterpret_cast<T*>(&x);
8185
}
8286
};
8387
}

0 commit comments

Comments
 (0)
0