Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NestingLimit.hpp Source File

NestingLimit.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <ArduinoJson/Namespace.hpp>
00008 #include <ArduinoJson/Polyfills/assert.hpp>
00009 
00010 namespace ARDUINOJSON_NAMESPACE {
00011 
00012 class NestingLimit {
00013  public:
00014   NestingLimit() : _value(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {}
00015   explicit NestingLimit(uint8_t n) : _value(n) {}
00016 
00017   NestingLimit decrement() const {
00018     ARDUINOJSON_ASSERT(_value > 0);
00019     return NestingLimit(static_cast<uint8_t>(_value - 1));
00020   }
00021 
00022   bool reached() const {
00023     return _value == 0;
00024   }
00025 
00026  private:
00027   uint8_t _value;
00028 };
00029 }  // namespace ARDUINOJSON_NAMESPACE