/src/mozilla-central/dom/media/doctor/DDLogObject.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
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 DDLogObject_h_ |
8 | | #define DDLogObject_h_ |
9 | | |
10 | | #include "nsString.h" |
11 | | |
12 | | namespace mozilla { |
13 | | |
14 | | // DDLogObject identifies a C++ object by its pointer and its class name (as |
15 | | // provided in a DDLoggedTypeTrait.) |
16 | | // Note that a DDLogObject could have the exact same pointer&type as a previous |
17 | | // one, so extra information is needed to distinguish them, see DDLifetime. |
18 | | class DDLogObject |
19 | | { |
20 | | public: |
21 | | // Default-initialization with null pointer. |
22 | | DDLogObject() |
23 | | : mTypeName("<unset>") |
24 | | , mPointer(nullptr) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | // Construction with given non-null type name and pointer. |
29 | | DDLogObject(const char* aTypeName, const void* aPointer) |
30 | | : mTypeName(aTypeName) |
31 | | , mPointer(aPointer) |
32 | | { |
33 | | MOZ_ASSERT(aTypeName); |
34 | | MOZ_ASSERT(aPointer); |
35 | | } |
36 | | |
37 | | // Sets this DDLogObject to an actual object. |
38 | | void Set(const char* aTypeName, const void* aPointer) |
39 | 0 | { |
40 | 0 | MOZ_ASSERT(aTypeName); |
41 | 0 | MOZ_ASSERT(aPointer); |
42 | 0 | mTypeName = aTypeName; |
43 | 0 | mPointer = aPointer; |
44 | 0 | } |
45 | | |
46 | | // Object pointer, used for identification purposes only. |
47 | 0 | const void* Pointer() const { return mPointer; } |
48 | | |
49 | | // Type name. Should only be accessed after non-null pointer initialization. |
50 | | const char* TypeName() const |
51 | 0 | { |
52 | 0 | MOZ_ASSERT(mPointer); |
53 | 0 | return mTypeName; |
54 | 0 | } |
55 | | |
56 | | bool operator==(const DDLogObject& a) const |
57 | 0 | { |
58 | 0 | return mPointer == a.mPointer && (!mPointer || mTypeName == a.mTypeName); |
59 | 0 | } |
60 | | |
61 | | // Print the type name and pointer, e.g.: "MediaDecoder[136078200]". |
62 | | void AppendPrintf(nsCString& mString) const; |
63 | | nsCString Printf() const; |
64 | | |
65 | | private: |
66 | | const char* mTypeName; |
67 | | const void* mPointer; |
68 | | }; |
69 | | |
70 | | } // namespace mozilla |
71 | | |
72 | | #endif // DDLogObject_h_ |