Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ArrayShortcuts.hpp Source File

ArrayShortcuts.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <ArduinoJson/Polyfills/attributes.hpp>
00008 #include <ArduinoJson/Polyfills/type_traits.hpp>
00009 
00010 namespace ARDUINOJSON_NAMESPACE {
00011 // Forward declarations.
00012 template <typename>
00013 class ElementProxy;
00014 
00015 template <typename TArray>
00016 class ArrayShortcuts {
00017  public:
00018   // Returns the element at specified index if the variant is an array.
00019   FORCE_INLINE ElementProxy<TArray> operator[](size_t index) const;
00020 
00021   FORCE_INLINE ObjectRef createNestedObject() const;
00022 
00023   FORCE_INLINE ArrayRef createNestedArray() const;
00024 
00025   // Adds the specified value at the end of the array.
00026   //
00027   // bool add(TValue);
00028   // TValue = bool, long, int, short, float, double, serialized, VariantRef,
00029   //          std::string, String, ObjectRef
00030   template <typename T>
00031   FORCE_INLINE bool add(const T &value) const {
00032     return impl()->addElement().set(value);
00033   }
00034   //
00035   // bool add(TValue);
00036   // TValue = char*, const char*, const __FlashStringHelper*
00037   template <typename T>
00038   FORCE_INLINE bool add(T *value) const {
00039     return impl()->addElement().set(value);
00040   }
00041 
00042  private:
00043   const TArray *impl() const {
00044     return static_cast<const TArray *>(this);
00045   }
00046 };
00047 }  // namespace ARDUINOJSON_NAMESPACE