8000 Reorganized polyfills · java64/ArduinoJson@58cb793 · GitHub
[go: up one dir, main page]

Skip to content

Commit 58cb793

Browse files
committed
Reorganized polyfills
1 parent 4592f23 commit 58cb793

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+431
-378
lines changed

src/ArduinoJson.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "ArduinoJson/deserializeJson.hpp"
1010
#include "ArduinoJson/deserializeMsgPack.hpp"
1111

12-
#include "ArduinoJson/Json/Serialization/JsonSerializer.hpp"
12+
#include "ArduinoJson/Json/JsonSerializer.hpp"
1313
#include "ArduinoJson/JsonArrayImpl.hpp"
1414
#include "ArduinoJson/JsonObjectImpl.hpp"
1515
#include "ArduinoJson/JsonVariantImpl.hpp"

src/ArduinoJson/TypeTraits/IsVariant.hpp renamed to src/ArduinoJson/Data/IsVariant.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
#pragma once
66

7-
#include "IsBaseOf.hpp"
7+
#include "../Polyfills/type_traits.hpp"
88

99
namespace ArduinoJson {
1010
namespace Internals {
1111

1212
class JsonVariantTag {};
1313

1414
template <typename T>
15-
struct IsVariant : IsBaseOf<JsonVariantTag, T> {};
16-
}
17-
}
15+
struct IsVariant : is_base_of<JsonVariantTag, T> {};
16+
} // namespace Internals
17+
} // namespace ArduinoJson

src/ArduinoJson/Data/ValueSaver.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
#include "../JsonVariant.hpp"
88
#include "../Memory/JsonBuffer.hpp"
9+
#include "../Polyfills/type_traits.hpp"
910
#include "../Strings/StringTraits.hpp"
10-
#include "../TypeTraits/EnableIf.hpp"
1111

1212
namespace ArduinoJson {
1313
namespace Internals {
@@ -23,7 +23,7 @@ struct ValueSaver {
2323

2424
template <typename Source>
2525
struct ValueSaver<
26-
Source, typename EnableIf<StringTraits<Source>::should_duplicate>::type> {
26+
Source, typename enable_if<StringTraits<Source>::should_duplicate>::type> {
2727
template <typename Destination>
2828
static bool save(JsonBuffer* buffer, Destination& dest, Source source) {
2929
if (!StringTraits<Source>::is_null(source)) {
@@ -41,7 +41,7 @@ struct ValueSaver<
4141
// const char*, const signed char*, const unsigned char*
4242
template <typename Char>
4343
struct ValueSaver<
44-
Char*, typename EnableIf<!StringTraits<Char*>::should_duplicate>::type> {
44+
Char*, typename enable_if<!StringTraits<Char*>::should_duplicate>::type> {
4545
template <typename Destination>
4646
static bool save(JsonBuffer*, Destination& dest, Char* source) {
4747
dest = reinterpret_cast<const char*>(source);

src/ArduinoJson/DynamicJsonDocument.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class DynamicJsonDocument {
3434

3535
// JsonObject& to<JsonObject>()
3636
template <typename T>
37-
typename Internals::EnableIf<Internals::IsSame<T, JsonObject>::value,
38-
JsonObject&>::type
37+
typename Internals::enable_if<Internals::is_same<T, JsonObject>::value,
38+
JsonObject&>::type
3939
to() {
4040
clear();
4141
JsonObject* object = new (&_buffer) JsonObject(&_buffer);
@@ -46,8 +46,8 @@ class DynamicJsonDocument {
4646

4747
// JsonArray& to<JsonArray>()
4848
template <typename T>
49-
typename Internals::EnableIf<Internals::IsSame<T, JsonArray>::value,
50-
JsonArray&>::type
49+
typename Internals::enable_if<Internals::is_same<T, JsonArray>::value,
50+
JsonArray&>::type
5151
to() {
5252
clear();
5353
JsonArray* array = new (&_buffer) JsonArray(&_buffer);
@@ -58,8 +58,8 @@ class DynamicJsonDocument {
5858

5959
// JsonVariant& to<JsonVariant>()
6060
template <typename T>
61-
typename Internals::EnableIf<Internals::IsSame<T, JsonVariant>::value,
62-
T&>::type
61+
typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value,
62+
T&>::type
6363
to() {
6464
clear();
6565
return _root;

src/ArduinoJson/Json/Encoding.hpp renamed to src/ArduinoJson/Json/EscapeSequence.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace ArduinoJson {
88
namespace Internals {
99

10-
class Encoding {
10+
class EscapeSequence {
1111
public:
1212
// Optimized for code size on a 8-bit AVR
1313
static char escapeChar(char c) {
@@ -33,5 +33,5 @@ class Encoding {
3333
return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0];
3434
}
3535
};
36-
}
37-
}
36+
} // namespace Internals
37+
} // namespace ArduinoJson

src/ArduinoJson/Json/Deserialization/JsonDeserializer.hpp renamed to src/ArduinoJson/Json/JsonDeserializer.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
#pragma once
66

7-
#include "../../DeserializationError.hpp"
8-
#include "../../JsonVariant.hpp"
9-
#include "../../Memory/JsonBuffer.hpp"
10-
#include "../../Reading/Reader.hpp"
11-
#include "../../TypeTraits/IsConst.hpp"
12-
#include "../Encoding.hpp"
7+
#include "../DeserializationError.hpp"
8+
#include "../JsonVariant.hpp"
9+
#include "../Memory/JsonBuffer.hpp"
10+
#include "../Polyfills/type_traits.hpp"
11+
#include "../Reading/Reader.hpp"
12+
#include "./EscapeSequence.hpp"
1313

1414
namespace ArduinoJson {
1515
namespace Internals {
@@ -168,7 +168,8 @@ class JsonDeserializer {
168168
}
169169

170170
DeserializationError parseString(const char **result) {
171-
typename RemoveReference<TWriter>::type::String str = _writer.startString();
171+
typename remove_reference<TWriter>::type::String str =
172+
_writer.startString();
172173

173174
char c = current();
174175
if (c == '\0') return DeserializationError::IncompleteInput;
@@ -188,7 +189,7 @@ class JsonDeserializer {
188189
if (c == '\0') return DeserializationError::IncompleteInput;
189190
if (c == 'u') return DeserializationError::NotSupported;
190191
// replace char
191-
c = Encoding::unescapeChar(c);
192+
c = EscapeSequence::unescapeChar(c);
192193
if (c == '\0') return DeserializationError::InvalidInput;
193194
move();
194195
}

src/ArduinoJson/Json/Serialization/JsonSerializer.hpp renamed to src/ArduinoJson/Json/JsonSerializer.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
#pragma once
66

7-
#include "../../Print/DummyPrint.hpp"
8-
#include "../../Print/DynamicStringBuilder.hpp"
9-
#include "../../Print/StaticStringBuilder.hpp"
7+
#include "../Print/DummyPrint.hpp"
8+
#include "../Print/DynamicStringBuilder.hpp"
9+
#include "../Print/StaticStringBuilder.hpp"
1010
#include "./IndentedPrint.hpp"
1111
#include "./JsonWriter.hpp"
1212
#include "./Prettyfier.hpp"
1313

1414
#if ARDUINOJSON_ENABLE_STD_STREAM
15-
#include "../../Print/StreamPrintAdapter.hpp"
15+
#include "../Print/StreamPrintAdapter.hpp"
1616
#endif
1717

1818
namespace ArduinoJson {
@@ -96,8 +96,8 @@ class JsonSerializer {
9696
} // namespace Internals
9797

9898
template <typename TSource, typename TDestination>
99-
typename Internals::EnableIf<!Internals::StringTraits<TDestination>::has_append,
100-
size_t>::type
99+
typename Internals::enable_if<
100+
!Internals::StringTraits<TDestination>::has_append, size_t>::type
101101
serializeJson(const TSource &source, TDestination &destination) {
102102
Internals::JsonWriter<TDestination> writer(destination);
103103
Internals::JsonSerializer<Internals::JsonWriter<TDestination> >::serialize(
@@ -126,8 +126,8 @@ size_t serializeJson(const TSource &source, char (&buffer)[N]) {
126126
}
127127

128128
template <typename TSource, typename TDestination>
129-
typename Internals::EnableIf<Internals::StringTraits<TDestination>::has_append,
130-
size_t>::type
129+
typename Internals::enable_if<Internals::StringTraits<TDestination>::has_append,
130+
size_t>::type
131131
serializeJson(const TSource &source, TDestination &str) {
132132
Internals::DynamicStringBuilder<TDestination> sb(str);
133133
return serializeJson(source, sb);
@@ -153,16 +153,16 @@ size_t serializeJsonPretty(const TSource &source, char (&buffer)[N]) {
153153
}
154154

155155
template <typename TSource, typename TDestination>
156-
typename Internals::EnableIf<!Internals::StringTraits<TDestination>::has_append,
157-
size_t>::type
156+
typename Internals::enable_if<
157+
!Internals::StringTraits<TDestination>::has_append, size_t>::type
158158
serializeJsonPretty(const TSource &source, TDestination &print) {
159159
Internals::IndentedPrint<TDestination> indentedPrint(print);
160160
return serializeJsonPretty(source, indentedPrint);
161161
}
162162

163163
template <typename TSource, typename TDestination>
164-
typename Internals::EnableIf<Internals::StringTraits<TDestination>::has_append,
165-
size_t>::type
164+
typename Internals::enable_if<Internals::StringTraits<TDestination>::has_append,
165+
size_t>::type
166166
serializeJsonPretty(const TSource &source, TDestination &str) {
167167
Internals::DynamicStringBuilder<TDestination> sb(str);
168168
return serializeJsonPretty(source, sb);

src/ArduinoJson/Json/Serialization/JsonWriter.hpp renamed to src/ArduinoJson/Json/JsonWriter.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#pragma once
66

77
#include <stdint.h>
8-
#include "../../Data/JsonInteger.hpp"
9-
#include "../../Polyfills/attributes.hpp"
10-
#include "../Encoding.hpp"
11-
#include "./FloatParts.hpp"
8+
#include "../Data/JsonInteger.hpp"
9+
#include "../Numbers/FloatParts.hpp"
10+
#include "../Polyfills/attributes.hpp"
11+
#include "./EscapeSequence.hpp"
1212

1313
namespace ArduinoJson {
1414
namespace Internals {
@@ -66,7 +66,7 @@ class JsonWriter {
6666
}
6767

6868
void writeChar(char c) {
69-
char specialChar = Encoding::escapeChar(c);
69+
char specialChar = EscapeSequence::escapeChar(c);
7070
if (specialChar) {
7171
writeRaw('\\');
7272
writeRaw(specialChar);
@@ -77,14 +77,14 @@ class JsonWriter {
7777

7878
template <typename TFloat>
7979
void writeFloat(TFloat value) {
80-
if (isNaN(value)) return writeRaw("NaN");
80+
if (isnan(value)) return writeRaw("NaN");
8181

8282
if (value < 0.0) {
8383
writeRaw('-');
8484
value = -value;
8585
}
8686

87-
if (isInfinity(value)) return writeRaw("Infinity");
87+
if (isinf(value)) return writeRaw("Infinity");
8888

8989
FloatParts<TFloat> parts(value);
9090

src/ArduinoJson/JsonArray.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
#include "Data/ValueSaver.hpp"
1010
#include "JsonVariant.hpp"
1111
#include "Memory/JsonBufferAllocated.hpp"
12+
#include "Polyfills/type_traits.hpp"
1213
#include "Strings/StringTraits.hpp"
13-
#include "TypeTraits/EnableIf.hpp"
14-
#include "TypeTraits/IsArray.hpp"
15-
#include "TypeTraits/IsFloatingPoint.hpp"
16-
#include "TypeTraits/IsSame.hpp"
1714

1815
// Returns the size (in bytes) of an array with n elements.
1916
// Can be very handy to determine the size of a StaticJsonBuffer.
@@ -88,7 +85,8 @@ class JsonArray : public Internals::ReferenceType,
8885
// bool set(size_t index, TValue value, uint8_t decimals);
8986
// TValue = float, double
9087
template <typename T>
91-
typename Internals::EnableIf<Internals::IsFlo 10000 atingPoint<T>::value, bool>::type
88+
typename Internals::enable_if<Internals::is_floating_point<T>::value,
89+
bool>::type
9290
set(size_t index, T value, uint8_t decimals) {
9391
return set_impl<const JsonVariant &>(index, JsonVariant(value, decimals));
9492
}

src/ArduinoJson/JsonObject.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
#include "Data/ValueSaver.hpp"
1010
#include "JsonPair.hpp"
1111
#include "Memory/JsonBufferAllocated.hpp"
12+
#include "Polyfills/type_traits.hpp"
1213
#include "Strings/StringTraits.hpp"
13-
#include "TypeTraits/EnableIf.hpp"
14-
#include "TypeTraits/IsArray.hpp"
15-
#include "TypeTraits/IsFloatingPoint.hpp"
16-
#include "TypeTraits/IsSame.hpp"
1714

1815
// Returns the size (in bytes) of an object with n elements.
1916
// Can be very handy to determine the size of a StaticJsonBuffer.

src/ArduinoJson/JsonObjectSubscript.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "Configuration.hpp"
88
#include "JsonVariantBase.hpp"
9-
#include "TypeTraits/EnableIf.hpp"
9+
#include "Polyfills/type_traits.hpp"
1010

1111
#ifdef _MSC_VER
1212
#pragma warning(push)
@@ -36,7 +36,7 @@ class JsonObjectSubscript
3636
// TValue = bool, char, long, int, short, float, double,
3737
// std::string, String, JsonArray, JsonObject
3838
template <typename TValue>
39-
FORCE_INLINE typename EnableIf<!IsArray<TValue>::value, this_type&>::type
39+
FORCE_INLINE typename enable_if<!is_array<TValue>::value, this_type&>::type
4040
operator=(const TValue& src) {
4141
_object.set(_key, src);
4242
return *this;
@@ -70,7 +70,7 @@ class JsonObjectSubscript
7070
// TValue = bool, char, long, int, short, float, double, RawJson, JsonVariant,
7171
// std::string, String, JsonArray, JsonObject
7272
template <typename TValue>
73-
FORCE_INLINE typename EnableIf<!IsArray<TValue>::value, bool>::type set(
73+
FORCE_INLINE typename enable_if<!is_array<TValue>::value, bool>::type set(
7474
const TValue& value) {
7575
return _object.set(_key, value);
7676
}

0 commit comments

Comments
 (0)
0