forked from bblanchon/ArduinoJson
Fixed build when another lib does #undef isnan
(issue #284)
This commit is contained in:
@ -1,6 +1,11 @@
|
|||||||
ArduinoJson: change log
|
ArduinoJson: change log
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
HEAD
|
||||||
|
----
|
||||||
|
|
||||||
|
* Fixed build when another lib does `#undef isnan` (issue #284)
|
||||||
|
|
||||||
v5.6.1
|
v5.6.1
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -8,8 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../Polyfills/attributes.hpp"
|
#include "../Polyfills/attributes.hpp"
|
||||||
#include "../Polyfills/isInfinity.hpp"
|
#include "../Polyfills/math.hpp"
|
||||||
#include "../Polyfills/isNaN.hpp"
|
|
||||||
#include "../Polyfills/normalize.hpp"
|
#include "../Polyfills/normalize.hpp"
|
||||||
#include "../Print.hpp"
|
#include "../Print.hpp"
|
||||||
#include "Encoding.hpp"
|
#include "Encoding.hpp"
|
||||||
@ -33,18 +32,34 @@ class JsonWriter {
|
|||||||
// Returns the number of bytes sent to the Print implementation.
|
// Returns the number of bytes sent to the Print implementation.
|
||||||
// This is very handy for implementations of printTo() that must return the
|
// This is very handy for implementations of printTo() that must return the
|
||||||
// number of bytes written.
|
// number of bytes written.
|
||||||
size_t bytesWritten() const { return _length; }
|
size_t bytesWritten() const {
|
||||||
|
return _length;
|
||||||
|
}
|
||||||
|
|
||||||
void beginArray() { writeRaw('['); }
|
void beginArray() {
|
||||||
void endArray() { writeRaw(']'); }
|
writeRaw('[');
|
||||||
|
}
|
||||||
|
void endArray() {
|
||||||
|
writeRaw(']');
|
||||||
|
}
|
||||||
|
|
||||||
void beginObject() { writeRaw('{'); }
|
void beginObject() {
|
||||||
void endObject() { writeRaw('}'); }
|
writeRaw('{');
|
||||||
|
}
|
||||||
|
void endObject() {
|
||||||
|
writeRaw('}');
|
||||||
|
}
|
||||||
|
|
||||||
void writeColon() { writeRaw(':'); }
|
void writeColon() {
|
||||||
void writeComma() { writeRaw(','); }
|
writeRaw(':');
|
||||||
|
}
|
||||||
|
void writeComma() {
|
||||||
|
writeRaw(',');
|
||||||
|
}
|
||||||
|
|
||||||
void writeBoolean(bool value) { writeRaw(value ? "true" : "false"); }
|
void writeBoolean(bool value) {
|
||||||
|
writeRaw(value ? "true" : "false");
|
||||||
|
}
|
||||||
|
|
||||||
void writeString(const char *value) {
|
void writeString(const char *value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@ -132,8 +147,12 @@ class JsonWriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeRaw(const char *s) { _length += _sink.print(s); }
|
void writeRaw(const char *s) {
|
||||||
void writeRaw(char c) { _length += _sink.write(c); }
|
_length += _sink.print(s);
|
||||||
|
}
|
||||||
|
void writeRaw(char c) {
|
||||||
|
_length += _sink.write(c);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Print &_sink;
|
Print &_sink;
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
// Copyright Benoit Blanchon 2014-2016
|
|
||||||
// MIT License
|
|
||||||
//
|
|
||||||
// Arduino JSON library
|
|
||||||
// https://github.com/bblanchon/ArduinoJson
|
|
||||||
// If you like this project, please add a star!
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// If Visual Studo <= 2012
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
|
||||||
#include <float.h>
|
|
||||||
#else
|
|
||||||
#include <math.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
namespace ArduinoJson {
|
|
||||||
namespace Polyfills {
|
|
||||||
|
|
||||||
// If Visual Studo <= 2012
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
bool isNaN(T x) {
|
|
||||||
return _isnan(x) != 0;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
bool isNaN(T x) {
|
|
||||||
return isnan(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
#endif
|
|
@ -9,10 +9,26 @@
|
|||||||
|
|
||||||
// If Visual Studo <= 2012
|
// If Visual Studo <= 2012
|
||||||
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
||||||
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
|
namespace ArduinoJson {
|
||||||
|
namespace Polyfills {
|
||||||
|
template <typename T>
|
||||||
|
bool isNaN(T x) {
|
||||||
|
return _isnan(x) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool isInfinity(T x) {
|
||||||
|
return !_finite(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
// GCC warning: "conversion to 'float' from 'double' may alter its value"
|
// GCC warning: "conversion to 'float' from 'double' may alter its value"
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
@ -26,40 +42,42 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Workaround for libs that #undef isnan or isinf
|
||||||
|
// https://github.com/bblanchon/ArduinoJson/issues/284
|
||||||
|
#if !defined(isnan) || !defined(isinf)
|
||||||
|
namespace std {}
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace ArduinoJson {
|
namespace ArduinoJson {
|
||||||
namespace Polyfills {
|
namespace Polyfills {
|
||||||
|
|
||||||
// If Visual Studo <= 2012
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool isInfinity(T x) {
|
bool isNaN(T x) {
|
||||||
return !_finite(x);
|
// Workaround for libs that #undef isnan
|
||||||
|
// https://github.com/bblanchon/ArduinoJson/issues/284
|
||||||
|
#ifndef isnan
|
||||||
|
using namespace std;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return isnan(x);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool isInfinity(T x) {
|
bool isInfinity(T x) {
|
||||||
|
// Workaround for libs that #undef isinf
|
||||||
|
// https://github.com/bblanchon/ArduinoJson/issues/284
|
||||||
|
#ifndef isinf
|
||||||
|
using namespace std;
|
||||||
|
#endif
|
||||||
|
|
||||||
return isinf(x);
|
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
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
Reference in New Issue
Block a user