source: rtos_arduino/trunk/arduino_lib/libraries/ArduinoJson/include/ArduinoJson/JsonObjectSubscript.hpp@ 209

Last change on this file since 209 was 209, checked in by ertl-honda, 8 years ago

BlueMix用のフィアルを追加

File size: 2.4 KB
Line 
1// Copyright Benoit Blanchon 2014-2016
2// MIT License
3//
4// Arduino JSON library
5// https://github.com/bblanchon/ArduinoJson
6// If you like this project, please add a star!
7
8#pragma once
9
10#include "Configuration.hpp"
11#include "JsonVariantBase.hpp"
12#include "TypeTraits/EnableIf.hpp"
13
14#ifdef _MSC_VER
15#pragma warning(push)
16#pragma warning(disable : 4522)
17#endif
18
19namespace ArduinoJson {
20
21template <typename TKey>
22class JsonObjectSubscript : public JsonVariantBase<JsonObjectSubscript<TKey> > {
23 public:
24 FORCE_INLINE JsonObjectSubscript(JsonObject& object, TKey key)
25 : _object(object), _key(key) {}
26
27 JsonObjectSubscript<TKey>& operator=(const JsonObjectSubscript<TKey>& src) {
28 _object.set<const JsonVariant&>(_key, src);
29 return *this;
30 }
31
32 template <typename T>
33 typename TypeTraits::EnableIf<JsonObject::CanSet<T&>::value,
34 JsonObjectSubscript<TKey> >::type&
35 operator=(const T& src) {
36 _object.set<T&>(_key, const_cast<T&>(src));
37 return *this;
38 }
39
40 template <typename T>
41 typename TypeTraits::EnableIf<JsonObject::CanSet<T>::value,
42 JsonObjectSubscript<TKey> >::type&
43 operator=(T src) {
44 _object.set<T>(_key, src);
45 return *this;
46 }
47
48 FORCE_INLINE bool success() const { return _object.containsKey(_key); }
49
50 FORCE_INLINE operator JsonVariant() const { return _object.get(_key); }
51
52 template <typename TValue>
53 FORCE_INLINE TValue as() const {
54 return _object.get<TValue>(_key);
55 }
56
57 template <typename TValue>
58 FORCE_INLINE bool is() const {
59 return _object.is<TValue>(_key);
60 }
61
62 template <typename TValue>
63 FORCE_INLINE bool set(TValue value) {
64 return _object.set<TValue>(_key, value);
65 }
66
67 template <typename TValue>
68 FORCE_INLINE bool set(TValue value, uint8_t decimals) {
69 return _object.set(_key, value, decimals);
70 }
71
72 FORCE_INLINE JsonVariant get() { return _object.get(_key); }
73
74 void writeTo(Internals::JsonWriter& writer) const {
75 _object.get(_key).writeTo(writer);
76 }
77
78 private:
79 JsonObject& _object;
80 TKey _key;
81};
82
83#if ARDUINOJSON_ENABLE_STD_STREAM
84inline std::ostream& operator<<(
85 std::ostream& os, const JsonObjectSubscript<const String&>& source) {
86 return source.printTo(os);
87}
88
89inline std::ostream& operator<<(
90 std::ostream& os, const JsonObjectSubscript<const char*>& source) {
91 return source.printTo(os);
92}
93#endif
94
95} // namespace ArduinoJson
96
97#ifdef _MSC_VER
98#pragma warning(pop)
99#endif
Note: See TracBrowser for help on using the repository browser.