blob: bb41419a991415529558f592043e9d6da33071d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include "lib/ArduinoJson/Polyfills/assert.hpp"
namespace ARDUINOJSON_NAMESPACE {
template <typename TReader>
class Latch {
public:
Latch(TReader reader) : _reader(reader), _loaded(false) {
#if ARDUINOJSON_DEBUG
_ended = false;
#endif
}
void clear() {
_loaded = false;
}
int last() const {
return _current;
}
FORCE_INLINE char current() {
if (!_loaded) {
load();
}
return _current;
}
private:
void load() {
ARDUINOJSON_ASSERT(!_ended);
int c = _reader.read();
#if ARDUINOJSON_DEBUG
if (c <= 0)
_ended = true;
#endif
_current = static_cast<char>(c > 0 ? c : 0);
_loaded = true;
}
TReader _reader;
char _current;
bool _loaded;
#if ARDUINOJSON_DEBUG
bool _ended;
#endif
};
} // namespace ARDUINOJSON_NAMESPACE
|