Skip to content

Commit

Permalink
Replace ARDUINOJSON_USE_ARDUINO_STRING by ARDUINOJSON_ENABLE_STD_STRI…
Browse files Browse the repository at this point in the history
…NG and ARDUINOJSON_ENABLE_ARDUINO_STRING
  • Loading branch information
bblanchon committed Oct 29, 2016
1 parent 73654b9 commit 0e14313
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Expand Up @@ -4,23 +4,28 @@ ArduinoJson: change log
HEAD
----

* Increased default nesting limit to 50 when compiled for a computer (issue #349)
* Removed `ArduinoJson::String`
* Templatized all functions using `String` or `std::string`
* Replaced `ARDUINOJSON_USE_ARDUINO_STRING` by `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_ARDUINO_STRING`
* Increased default nesting limit to 50 when compiled for a computer (issue #349)

**BREAKING CHANGE**:
**BREAKING CHANGES**:

The non-template function `JsonObject::get()` and `JsonArray.get()` have been removed. This means that you need to explicitely tell the type you expect in return.

Old code:

```c++
#define ARDUINOJSON_USE_ARDUINO_STRING 0
JsonVariant value1 = myObject.get("myKey");
JsonVariant value2 = myArray.get(0);
```
New code:
```c++
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
#define ARDUINOJSON_ENABLE_STD_STRING 1
JsonVariant value1 = myObject.get<JsonVariant>("myKey");
JsonVariant value2 = myArray.get<JsonVariant>(0);
```
Expand Down
22 changes: 16 additions & 6 deletions include/ArduinoJson/Configuration.hpp
Expand Up @@ -22,12 +22,17 @@
#define ARDUINOJSON_USE_INT64 0
#endif

// arduino has its own implementation of String to replace std::string
#ifndef ARDUINOJSON_USE_ARDUINO_STRING
#define ARDUINOJSON_USE_ARDUINO_STRING 1
// Arduino has its own implementation of String to replace std::string
#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
#endif

// arduino doesn't support STL stream
// Arduino doesn't have std::string
#ifndef ARDUINOJSON_ENABLE_STD_STRING
#define ARDUINOJSON_ENABLE_STD_STRING 1
#endif

// Arduino doesn't support STL stream
#ifndef ARDUINOJSON_ENABLE_STD_STREAM
#define ARDUINOJSON_ENABLE_STD_STREAM 0
#endif
Expand Down Expand Up @@ -73,8 +78,13 @@
#endif

// on a computer, we can use std::string
#ifndef ARDUINOJSON_USE_ARDUINO_STRING
#define ARDUINOJSON_USE_ARDUINO_STRING 0
#ifndef ARDUINOJSON_ENABLE_STD_STRING
#define ARDUINOJSON_ENABLE_STD_STRING 1
#endif

// on a computer, there is no reason to beleive Arduino String is available
#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
#endif

// on a computer, we can assume that the STL is there
Expand Down
14 changes: 7 additions & 7 deletions include/ArduinoJson/JsonString.hpp
Expand Up @@ -9,9 +9,11 @@

#include "Configuration.hpp"

#if ARDUINOJSON_USE_ARDUINO_STRING
#if ARDUINOJSON_ENABLE_ARDUINO_STRING
#include <WString.h>
#else
#endif

#if ARDUINOJSON_ENABLE_STD_STRING
#include <string>
#endif

Expand Down Expand Up @@ -102,22 +104,20 @@ class StandardJsonString {
static const bool should_copy = true;
};

#if ARDUINOJSON_USE_ARDUINO_STRING

#if ARDUINOJSON_ENABLE_ARDUINO_STRING
template <>
class JsonString<String> : public StandardJsonString<String> {
public:
JsonString(const String& str) : StandardJsonString(str) {}
};
#endif

#else

#if ARDUINOJSON_ENABLE_STD_STRING
template <>
class JsonString<std::string> : public StandardJsonString<std::string> {
public:
JsonString(const std::string& str) : StandardJsonString(str) {}
};

#endif

template <typename TString>
Expand Down

0 comments on commit 0e14313

Please sign in to comment.