Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/SimpleEnumerator.h
Line
Count
Source
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
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_SimpleEnumerator_h
8
#define mozilla_SimpleEnumerator_h
9
10
#include "nsCOMPtr.h"
11
#include "nsISimpleEnumerator.h"
12
13
namespace mozilla {
14
15
/**
16
 * A wrapper class around nsISimpleEnumerator to support ranged iteration. This
17
 * requires every element in the enumeration to implement the same interface, T.
18
 * If any element does not implement this interface, the enumeration ends at
19
 * that element, and triggers an assertion in debug builds.
20
 *
21
 * Typical usage looks something like:
22
 *
23
 *   for (auto& docShell : SimpleEnumerator<nsIDocShell>(docShellEnum)) {
24
 *     docShell.LoadURI(...);
25
 *   }
26
 */
27
28
template <typename T>
29
class SimpleEnumerator final
30
{
31
public:
32
  explicit SimpleEnumerator(nsISimpleEnumerator* aEnum)
33
    : mEnum(aEnum)
34
10
  {}
mozilla::SimpleEnumerator<nsICategoryEntry>::SimpleEnumerator(nsISimpleEnumerator*)
Line
Count
Source
34
10
  {}
Unexecuted instantiation: mozilla::SimpleEnumerator<nsIDocShell>::SimpleEnumerator(nsISimpleEnumerator*)
35
36
  class Entry
37
  {
38
  public:
39
    explicit Entry(T* aPtr)
40
      : mPtr(aPtr)
41
10
    {}
mozilla::SimpleEnumerator<nsICategoryEntry>::Entry::Entry(nsICategoryEntry*)
Line
Count
Source
41
10
    {}
Unexecuted instantiation: mozilla::SimpleEnumerator<nsIDocShell>::Entry::Entry(nsIDocShell*)
42
43
    explicit Entry(nsISimpleEnumerator& aEnum)
44
      : mEnum(&aEnum)
45
10
    {
46
10
      ++*this;
47
10
    }
mozilla::SimpleEnumerator<nsICategoryEntry>::Entry::Entry(nsISimpleEnumerator&)
Line
Count
Source
45
10
    {
46
10
      ++*this;
47
10
    }
Unexecuted instantiation: mozilla::SimpleEnumerator<nsIDocShell>::Entry::Entry(nsISimpleEnumerator&)
48
49
    const nsCOMPtr<T>& operator*()
50
3
    {
51
3
      MOZ_ASSERT(mPtr);
52
3
      return mPtr;
53
3
    }
mozilla::SimpleEnumerator<nsICategoryEntry>::Entry::operator*()
Line
Count
Source
50
3
    {
51
3
      MOZ_ASSERT(mPtr);
52
3
      return mPtr;
53
3
    }
Unexecuted instantiation: mozilla::SimpleEnumerator<nsIDocShell>::Entry::operator*()
54
55
    Entry& operator++()
56
13
    {
57
13
      MOZ_ASSERT(mEnum);
58
13
      nsCOMPtr<nsISupports> next;
59
13
      if (NS_SUCCEEDED(mEnum->GetNext(getter_AddRefs(next)))) {
60
3
        mPtr = do_QueryInterface(next);
61
3
        MOZ_ASSERT(mPtr);
62
10
      } else {
63
10
        mPtr = nullptr;
64
10
      }
65
13
      return *this;
66
13
    }
mozilla::SimpleEnumerator<nsICategoryEntry>::Entry::operator++()
Line
Count
Source
56
13
    {
57
13
      MOZ_ASSERT(mEnum);
58
13
      nsCOMPtr<nsISupports> next;
59
13
      if (NS_SUCCEEDED(mEnum->GetNext(getter_AddRefs(next)))) {
60
3
        mPtr = do_QueryInterface(next);
61
3
        MOZ_ASSERT(mPtr);
62
10
      } else {
63
10
        mPtr = nullptr;
64
10
      }
65
13
      return *this;
66
13
    }
Unexecuted instantiation: mozilla::SimpleEnumerator<nsIDocShell>::Entry::operator++()
67
68
    bool operator!=(const Entry& aOther) const
69
13
    {
70
13
      return mPtr != aOther.mPtr;
71
13
    }
mozilla::SimpleEnumerator<nsICategoryEntry>::Entry::operator!=(mozilla::SimpleEnumerator<nsICategoryEntry>::Entry const&) const
Line
Count
Source
69
13
    {
70
13
      return mPtr != aOther.mPtr;
71
13
    }
Unexecuted instantiation: mozilla::SimpleEnumerator<nsIDocShell>::Entry::operator!=(mozilla::SimpleEnumerator<nsIDocShell>::Entry const&) const
72
73
  private:
74
    nsCOMPtr<T> mPtr;
75
    nsCOMPtr<nsISimpleEnumerator> mEnum;
76
  };
77
78
10
  Entry begin() {
79
10
    return Entry(*mEnum);
80
10
  }
mozilla::SimpleEnumerator<nsICategoryEntry>::begin()
Line
Count
Source
78
10
  Entry begin() {
79
10
    return Entry(*mEnum);
80
10
  }
Unexecuted instantiation: mozilla::SimpleEnumerator<nsIDocShell>::begin()
81
82
10
  Entry end() {
83
10
    return Entry(nullptr);
84
10
  }
mozilla::SimpleEnumerator<nsICategoryEntry>::end()
Line
Count
Source
82
10
  Entry end() {
83
10
    return Entry(nullptr);
84
10
  }
Unexecuted instantiation: mozilla::SimpleEnumerator<nsIDocShell>::end()
85
86
private:
87
  nsCOMPtr<nsISimpleEnumerator> mEnum;
88
};
89
90
} // namespace mozilla
91
92
#endif // mozilla_SimpleEnumerator_h