tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ClientUsageArray.h (1252B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_QUOTA_CLIENTUSAGEARRAY_H_
      8 #define DOM_QUOTA_CLIENTUSAGEARRAY_H_
      9 
     10 #include <cstdint>
     11 
     12 #include "mozilla/Maybe.h"
     13 #include "mozilla/dom/quota/Client.h"
     14 
     15 namespace mozilla::dom::quota {
     16 
     17 class ClientUsageArray final : public Array<Maybe<uint64_t>, Client::TYPE_MAX> {
     18 public:
     19  Maybe<uint64_t>& operator[](size_t aIndex) {
     20    if (MOZ_UNLIKELY(aIndex >= Client::TypeMax())) {
     21      MOZ_CRASH("indexing into invalid element");
     22    }
     23    return Array::operator[](aIndex);
     24  }
     25 
     26  const Maybe<uint64_t>& operator[](size_t aIndex) const {
     27    if (MOZ_UNLIKELY(aIndex >= Client::TypeMax())) {
     28      MOZ_CRASH("indexing into invalid element");
     29    }
     30    return Array::operator[](aIndex);
     31  }
     32 
     33  constexpr size_t Length() const { return size(); }
     34 
     35  void Serialize(nsACString& aText) const;
     36 
     37  nsresult Deserialize(const nsACString& aText);
     38 };
     39 
     40 }  // namespace mozilla::dom::quota
     41 
     42 #endif  // DOM_QUOTA_CLIENTUSAGEARRAY_H_