xref: /aosp_15_r20/external/perfetto/src/trace_processor/db/base_id.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2022 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 #include <stdint.h>
18 #include <type_traits>
19 
20 #ifndef SRC_TRACE_PROCESSOR_DB_BASE_ID_H_
21 #define SRC_TRACE_PROCESSOR_DB_BASE_ID_H_
22 
23 namespace perfetto {
24 namespace trace_processor {
25 
26 // Id type which can be used as a base for strongly typed ids.
27 // TypedColumn has support for storing descendents of BaseId seamlessly
28 // in a Column.
29 struct BaseId {
30   BaseId() = default;
BaseIdBaseId31   explicit constexpr BaseId(uint32_t v) : value(v) {}
32 
33   bool operator==(const BaseId& o) const { return o.value == value; }
34   bool operator!=(const BaseId& o) const { return !(*this == o); }
35   bool operator<(const BaseId& o) const { return value < o.value; }
36 
37   uint32_t value;
38 };
39 static_assert(std::is_trivially_destructible<BaseId>::value,
40               "Inheritance used without trivial destruction");
41 
42 }  // namespace trace_processor
43 }  // namespace perfetto
44 
45 #endif  // SRC_TRACE_PROCESSOR_DB_BASE_ID_H_
46