/work/obj-fuzz/dist/include/SimpleMap.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #ifndef mozilla_SimpleMap_h |
6 | | #define mozilla_SimpleMap_h |
7 | | |
8 | | #include "mozilla/Pair.h" |
9 | | #include "nsTArray.h" |
10 | | |
11 | | namespace mozilla { |
12 | | |
13 | | template<typename T> |
14 | | class SimpleMap |
15 | | { |
16 | | public: |
17 | | typedef Pair<int64_t, T> Element; |
18 | | |
19 | 0 | SimpleMap() : mMutex("SimpleMap") { } Unexecuted instantiation: mozilla::SimpleMap<unsigned long>::SimpleMap() Unexecuted instantiation: mozilla::SimpleMap<long>::SimpleMap() |
20 | | |
21 | | // Insert Key and Value pair at the end of our map. |
22 | | void Insert(int64_t aKey, const T& aValue) |
23 | 0 | { |
24 | 0 | MutexAutoLock lock(mMutex); |
25 | 0 | mMap.AppendElement(MakePair(aKey, aValue)); |
26 | 0 | } Unexecuted instantiation: mozilla::SimpleMap<unsigned long>::Insert(long, unsigned long const&) Unexecuted instantiation: mozilla::SimpleMap<long>::Insert(long, long const&) |
27 | | // Sets aValue matching aKey and remove it from the map if found. |
28 | | // The element returned is the first one found. |
29 | | // Returns true if found, false otherwise. |
30 | | bool Find(int64_t aKey, T& aValue) |
31 | 0 | { |
32 | 0 | MutexAutoLock lock(mMutex); |
33 | 0 | for (uint32_t i = 0; i < mMap.Length(); i++) { |
34 | 0 | Element& element = mMap[i]; |
35 | 0 | if (element.first() == aKey) { |
36 | 0 | aValue = element.second(); |
37 | 0 | mMap.RemoveElementAt(i); |
38 | 0 | return true; |
39 | 0 | } |
40 | 0 | } |
41 | 0 | return false; |
42 | 0 | } Unexecuted instantiation: mozilla::SimpleMap<unsigned long>::Find(long, unsigned long&) Unexecuted instantiation: mozilla::SimpleMap<long>::Find(long, long&) |
43 | | // Remove all elements of the map. |
44 | | void Clear() |
45 | 0 | { |
46 | 0 | MutexAutoLock lock(mMutex); |
47 | 0 | mMap.Clear(); |
48 | 0 | } |
49 | | |
50 | | private: |
51 | | Mutex mMutex; // To protect mMap. |
52 | | AutoTArray<Element, 16> mMap; |
53 | | }; |
54 | | |
55 | | } // namespace mozilla |
56 | | |
57 | | #endif // mozilla_SimpleMap_h |