Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Configuration.hpp Source File

Configuration.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #if __cplusplus >= 201103L
00008 #define ARDUINOJSON_HAS_LONG_LONG 1
00009 #define ARDUINOJSON_HAS_NULLPTR 1
00010 #define ARDUINOJSON_HAS_RVALUE_REFERENCES 1
00011 #else
00012 #define ARDUINOJSON_HAS_LONG_LONG 0
00013 #define ARDUINOJSON_HAS_NULLPTR 0
00014 #define ARDUINOJSON_HAS_RVALUE_REFERENCES 0
00015 #endif
00016 
00017 #if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG
00018 #define ARDUINOJSON_HAS_INT64 1
00019 #else
00020 #define ARDUINOJSON_HAS_INT64 0
00021 #endif
00022 
00023 // Small or big machine?
00024 #ifndef ARDUINOJSON_EMBEDDED_MODE
00025 #if defined(ARDUINO)                /* Arduino*/                 \
00026     || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \
00027     || defined(__XC)                /* MPLAB XC compiler */      \
00028     || defined(__ARMCC_VERSION)     /* Keil ARM Compiler */      \
00029     || defined(__AVR)               /* Atmel AVR8/GNU C Compiler */
00030 #define ARDUINOJSON_EMBEDDED_MODE 1
00031 #else
00032 #define ARDUINOJSON_EMBEDDED_MODE 0
00033 #endif
00034 #endif
00035 
00036 // Auto enable std::stream if the right headers are here and no conflicting
00037 // macro is defined
00038 #if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include)
00039 #if __has_include(<istream>) && \
00040     __has_include(<ostream>) && \
00041     !defined(min) && \
00042     !defined(max)
00043 #define ARDUINOJSON_ENABLE_STD_STREAM 1
00044 #else
00045 #define ARDUINOJSON_ENABLE_STD_STREAM 0
00046 #endif
00047 #endif
00048 
00049 // Auto enable std::string if the right header is here and no conflicting
00050 // macro is defined
00051 #if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include)
00052 #if __has_include(<string>) && !defined(min) && !defined(max)
00053 #define ARDUINOJSON_ENABLE_STD_STRING 1
00054 #else
00055 #define ARDUINOJSON_ENABLE_STD_STRING 0
00056 #endif
00057 #endif
00058 
00059 #if ARDUINOJSON_EMBEDDED_MODE
00060 
00061 // Store floats by default to reduce the memory usage (issue #134)
00062 #ifndef ARDUINOJSON_USE_DOUBLE
00063 #define ARDUINOJSON_USE_DOUBLE 0
00064 #endif
00065 
00066 // Store longs by default, because they usually match the size of a float.
00067 #ifndef ARDUINOJSON_USE_LONG_LONG
00068 #define ARDUINOJSON_USE_LONG_LONG 0
00069 #endif
00070 
00071 // Embedded systems usually don't have std::string
00072 #ifndef ARDUINOJSON_ENABLE_STD_STRING
00073 #define ARDUINOJSON_ENABLE_STD_STRING 0
00074 #endif
00075 
00076 // Embedded systems usually don't have std::stream
00077 #ifndef ARDUINOJSON_ENABLE_STD_STREAM
00078 #define ARDUINOJSON_ENABLE_STD_STREAM 0
00079 #endif
00080 
00081 // Limit nesting as the stack is likely to be small
00082 #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT
00083 #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10
00084 #endif
00085 
00086 // Number of bits to store the pointer to next node
00087 // (saves RAM but limits the number of values in a document)
00088 #ifndef ARDUINOJSON_SLOT_OFFSET_SIZE
00089 #if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 2
00090 // Address space == 16-bit => max 127 values
00091 #define ARDUINOJSON_SLOT_OFFSET_SIZE 1
00092 #else
00093 // Address space > 16-bit => max 32767 values
00094 #define ARDUINOJSON_SLOT_OFFSET_SIZE 2
00095 #endif
00096 #endif
00097 
00098 #else  // ARDUINOJSON_EMBEDDED_MODE
00099 
00100 // On a computer we have plenty of memory so we can use doubles
00101 #ifndef ARDUINOJSON_USE_DOUBLE
00102 #define ARDUINOJSON_USE_DOUBLE 1
00103 #endif
00104 
00105 // Use long long when available
00106 #ifndef ARDUINOJSON_USE_LONG_LONG
00107 #if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64
00108 #define ARDUINOJSON_USE_LONG_LONG 1
00109 #else
00110 #define ARDUINOJSON_USE_LONG_LONG 0
00111 #endif
00112 #endif
00113 
00114 // On a computer, we can use std::string
00115 #ifndef ARDUINOJSON_ENABLE_STD_STRING
00116 #define ARDUINOJSON_ENABLE_STD_STRING 1
00117 #endif
00118 
00119 // On a computer, we can assume std::stream
00120 #ifndef ARDUINOJSON_ENABLE_STD_STREAM
00121 #define ARDUINOJSON_ENABLE_STD_STREAM 1
00122 #endif
00123 
00124 // On a computer, the stack is large so we can increase nesting limit
00125 #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT
00126 #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50
00127 #endif
00128 
00129 // Number of bits to store the pointer to next node
00130 #ifndef ARDUINOJSON_SLOT_OFFSET_SIZE
00131 #define ARDUINOJSON_SLOT_OFFSET_SIZE 4
00132 #endif
00133 
00134 #endif  // ARDUINOJSON_EMBEDDED_MODE
00135 
00136 #ifdef ARDUINO
00137 
00138 #include <Arduino.h>
00139 
00140 // Enable support for Arduino's String class
00141 #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
00142 #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
00143 #endif
00144 
00145 // Enable support for Arduino's Stream class
00146 #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
00147 #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1
00148 #endif
00149 
00150 // Enable support for Arduino's Print class
00151 #ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT
00152 #define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1
00153 #endif
00154 
00155 #else  // ARDUINO
00156 
00157 // Disable support for Arduino's String class
00158 #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
00159 #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
00160 #endif
00161 
00162 // Disable support for Arduino's Stream class
00163 #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
00164 #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0
00165 #endif
00166 
00167 // Disable support for Arduino's Print class
00168 #ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT
00169 #define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0
00170 #endif
00171 
00172 #endif  // ARDUINO
00173 
00174 #ifndef ARDUINOJSON_ENABLE_PROGMEM
00175 #if defined(PROGMEM) && defined(pgm_read_byte) && defined(pgm_read_dword) && \
00176     defined(pgm_read_ptr) && defined(pgm_read_float)
00177 #define ARDUINOJSON_ENABLE_PROGMEM 1
00178 #else
00179 #define ARDUINOJSON_ENABLE_PROGMEM 0
00180 #endif
00181 #endif
00182 
00183 // Convert unicode escape sequence (\u0123) to UTF-8
00184 #ifndef ARDUINOJSON_DECODE_UNICODE
00185 #define ARDUINOJSON_DECODE_UNICODE 1
00186 #endif
00187 
00188 // Ignore comments in input
00189 #ifndef ARDUINOJSON_ENABLE_COMMENTS
00190 #define ARDUINOJSON_ENABLE_COMMENTS 0
00191 #endif
00192 
00193 // Support NaN in JSON
00194 #ifndef ARDUINOJSON_ENABLE_NAN
00195 #define ARDUINOJSON_ENABLE_NAN 0
00196 #endif
00197 
00198 // Support Infinity in JSON
00199 #ifndef ARDUINOJSON_ENABLE_INFINITY
00200 #define ARDUINOJSON_ENABLE_INFINITY 0
00201 #endif
00202 
00203 // Control the exponentiation threshold for big numbers
00204 // CAUTION: cannot be more that 1e9 !!!!
00205 #ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD
00206 #define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7
00207 #endif
00208 
00209 // Control the exponentiation threshold for small numbers
00210 #ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD
00211 #define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5
00212 #endif
00213 
00214 #ifndef ARDUINOJSON_LITTLE_ENDIAN
00215 #if defined(_MSC_VER) ||                                                      \
00216     (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
00217     defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64)
00218 #define ARDUINOJSON_LITTLE_ENDIAN 1
00219 #else
00220 #define ARDUINOJSON_LITTLE_ENDIAN 0
00221 #endif
00222 #endif
00223 
00224 #ifndef ARDUINOJSON_ENABLE_ALIGNMENT
00225 #if defined(__AVR)
00226 #define ARDUINOJSON_ENABLE_ALIGNMENT 0
00227 #else
00228 #define ARDUINOJSON_ENABLE_ALIGNMENT 1
00229 #endif
00230 #endif
00231 
00232 #ifndef ARDUINOJSON_TAB
00233 #define ARDUINOJSON_TAB "  "
00234 #endif
00235 
00236 #ifndef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
00237 #define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1
00238 #endif
00239 
00240 #ifndef ARDUINOJSON_STRING_BUFFER_SIZE
00241 #define ARDUINOJSON_STRING_BUFFER_SIZE 32
00242 #endif
00243 
00244 #ifndef ARDUINOJSON_DEBUG
00245 #ifdef __PLATFORMIO_BUILD_DEBUG__
00246 #define ARDUINOJSON_DEBUG 1
00247 #else
00248 #define ARDUINOJSON_DEBUG 0
00249 #endif
00250 #endif
00251 
00252 #if ARDUINOJSON_HAS_NULLPTR && defined(nullptr)
00253 #error nullptr is defined as a macro. Remove the faulty #define or #undef nullptr
00254 // See https://github.com/bblanchon/ArduinoJson/issues/1355
00255 #endif