• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef INCLUDE_PERFETTO_TRACING_TRACED_VALUE_FORWARD_H_
18 #define INCLUDE_PERFETTO_TRACING_TRACED_VALUE_FORWARD_H_
19 
20 namespace perfetto {
21 
22 class TracedValue;
23 class TracedArray;
24 class TracedDictionary;
25 template <typename MessageType>
26 class TracedProto;
27 
28 template <typename T>
29 void WriteIntoTracedValue(TracedValue context, T&& value);
30 template <typename MessageType, typename T>
31 void WriteIntoTracedProto(TracedProto<MessageType> context, T&& value);
32 
33 template <typename T, class = void>
34 struct TraceFormatTraits;
35 
36 // Helpers to check whether a given type T can be written into a TracedValue /
37 // TracedProto<MessageType>.
38 //
39 // Intended to be used for types like smart pointers, who should support
40 // WriteIntoTrace only iff their inner type supports being written into
41 // a TracedValue.
42 //
43 // template <typename T>
44 // class SmartPtr {
45 //   ...
46 //
47 //   // Note: |Check| is needed to ensure that using
48 //   SmartPtr<ClassWhichDoesNotSupportTracedValue> does not generate a
49 //   compilation error.
50 //
51 //   template <typename Check=void>
52 //   typename check_traced_value_support<T, Check>::value
53 //   WriteIntoTrace(perfetto::TracedValue context) const {
54 //      WriteIntoTracedValue(std::move(context), *ptr_);
55 //   }
56 //
57 //   template <typename MessageType>
58 //   typename check_traced_value_support<T, MessageType>::value
59 //   WriteIntoTrace(perfetto::TracedProto<MessageType> message) const {
60 //      WriteIntoTracedProto(std::move(message), *ptr_);
61 //   }
62 // };
63 template <typename T, typename ResultType = void, typename = void>
64 struct check_traced_value_support;
65 
66 template <typename MessageType,
67           typename T,
68           typename ResultType = void,
69           typename = void>
70 struct check_traced_proto_support;
71 
72 }  // namespace perfetto
73 
74 #endif  // INCLUDE_PERFETTO_TRACING_TRACED_VALUE_FORWARD_H_
75