DDLoggedTypeTraits.h (4306B)
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 DDLoggedTypeTraits_h_ 8 #define DDLoggedTypeTraits_h_ 9 10 #include <type_traits> 11 12 namespace mozilla { 13 14 // Templated struct carrying compile-time information about C++ types that may 15 // log messages (including about their lifetime and links to other objects.) 16 // Classes should declare a specialization by using one of the macros below. 17 template <typename T> 18 struct DDLoggedTypeTraits; 19 20 #define DDLoggedTypeName(TYPE) \ 21 template <> \ 22 struct DDLoggedTypeTraits<TYPE> { \ 23 using Type = TYPE; \ 24 static constexpr const char* Name() { return #TYPE; } \ 25 using HasBase = std::false_type; \ 26 using BaseType = TYPE; \ 27 static constexpr const char* BaseTypeName() { return ""; } \ 28 } 29 30 #define DDLoggedTypeNameAndBase(TYPE, BASE) \ 31 template <> \ 32 struct DDLoggedTypeTraits<TYPE> { \ 33 using Type = TYPE; \ 34 static constexpr const char* Name() { return #TYPE; } \ 35 using HasBase = std::true_type; \ 36 using BaseType = BASE; \ 37 static constexpr const char* BaseTypeName() { \ 38 return DDLoggedTypeTraits<BASE>::Name(); \ 39 } \ 40 } 41 42 #define DDLoggedTypeCustomName(TYPE, NAME) \ 43 template <> \ 44 struct DDLoggedTypeTraits<TYPE> { \ 45 using Type = TYPE; \ 46 static constexpr const char* Name() { return #NAME; } \ 47 using HasBase = std::false_type; \ 48 using BaseType = TYPE; \ 49 static constexpr const char* BaseTypeName() { return ""; } \ 50 } 51 52 #define DDLoggedTypeCustomNameAndBase(TYPE, NAME, BASE) \ 53 template <> \ 54 struct DDLoggedTypeTraits<TYPE> { \ 55 using Type = TYPE; \ 56 static constexpr const char* Name() { return #NAME; } \ 57 using HasBase = std::true_type; \ 58 using BaseType = BASE; \ 59 static constexpr const char* BaseTypeName() { \ 60 return DDLoggedTypeTraits<BASE>::Name(); \ 61 } \ 62 } 63 64 // Variants with built-in forward-declaration, will only work 65 // - in mozilla namespace, 66 // - with unqualified mozilla-namespace type names. 67 #define DDLoggedTypeDeclName(TYPE) \ 68 class TYPE; \ 69 DDLoggedTypeName(TYPE); 70 #define DDLoggedTypeDeclNameAndBase(TYPE, BASE) \ 71 class TYPE; \ 72 DDLoggedTypeNameAndBase(TYPE, BASE); 73 #define DDLoggedTypeDeclCustomName(TYPE, NAME) \ 74 class TYPE; \ 75 DDLoggedTypeCustomName(TYPE, NAME); 76 #define DDLoggedTypeDeclCustomNameAndBase(TYPE, NAME, BASE) \ 77 class TYPE; \ 78 DDLoggedTypeCustomNameAndBase(TYPE, NAME, BASE); 79 80 } // namespace mozilla 81 82 // Some essential types that live outside of the media stack. 83 class nsPIDOMWindowInner; 84 class nsPIDOMWindowOuter; 85 86 namespace mozilla { 87 88 namespace dom { 89 class Document; 90 class HTMLAudioElement; 91 class HTMLMediaElement; 92 class HTMLVideoElement; 93 } // namespace dom 94 95 DDLoggedTypeName(nsPIDOMWindowInner); 96 DDLoggedTypeName(nsPIDOMWindowOuter); 97 DDLoggedTypeName(dom::Document); 98 DDLoggedTypeName(dom::HTMLMediaElement); 99 DDLoggedTypeNameAndBase(dom::HTMLAudioElement, dom::HTMLMediaElement); 100 DDLoggedTypeNameAndBase(dom::HTMLVideoElement, dom::HTMLMediaElement); 101 102 } // namespace mozilla 103 104 #endif // DDLoggedTypeTraits_h_