Sha256: c7816cf7f9de1bf85a5729e880442ae287b084233afef71d2252a5af1f014cb1

Contents?: true

Size: 948 Bytes

Versions: 7

Compression:

Stored size: 948 Bytes

Contents

// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/json/

#ifndef TAO_JSON_EVENTS_LIMIT_VALUE_COUNT_HPP
#define TAO_JSON_EVENTS_LIMIT_VALUE_COUNT_HPP

#include <cstddef>
#include <cstdint>

#include <stdexcept>

namespace tao::json::events
{
   template< typename Consumer, std::size_t Limit >
   class limit_value_count
      : public Consumer
   {
   private:
      std::size_t m_count = 1;  // Top-level value is implied.

      void count_and_limit()
      {
         if( ++m_count > Limit ) {
            throw std::runtime_error( "value count limit exceeded" );
         }
      }

   public:
      using Consumer::Consumer;

      void element()
      {
         count_and_limit();
         Consumer::element();
      }

      void member()
      {
         count_and_limit();
         Consumer::member();
      }
   };

}  // namespace tao::json::events

#endif

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
couchbase-3.4.5 ext/couchbase/third_party/json/include/tao/json/events/limit_value_count.hpp
couchbase-3.4.4 ext/couchbase/third_party/json/include/tao/json/events/limit_value_count.hpp
couchbase-3.4.3 ext/couchbase/third_party/json/include/tao/json/events/limit_value_count.hpp
couchbase-3.4.2 ext/couchbase/third_party/json/include/tao/json/events/limit_value_count.hpp
couchbase-3.4.1 ext/couchbase/third_party/json/include/tao/json/events/limit_value_count.hpp
couchbase-3.4.0 ext/couchbase/third_party/json/include/tao/json/events/limit_value_count.hpp
couchbase-3.3.0 ext/couchbase/third_party/json/include/tao/json/events/limit_value_count.hpp