[M73 Dev][Tizen] Fix compilation errors for TV profile
[platform/framework/web/chromium-efl.git] / base / type_id.h
1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_TYPE_ID_H_
6 #define BASE_TYPE_ID_H_
7
8 #include <stdint.h>
9 #include <string>
10
11 #include "base/base_export.h"
12 #include "base/compiler_specific.h"
13 #include "base/logging.h"
14 #include "base/strings/string_piece.h"
15 #include "build/build_config.h"
16
17 namespace base {
18 // Not ready for public consumption yet.
19 namespace experimental {
20
21 // A substitute for RTTI that uses the linker to uniquely reserve an address in
22 // the binary for each type.
23 class TypeId {
24  public:
25   bool constexpr operator==(const TypeId& other) const {
26     return type_id_ == other.type_id_;
27   }
28
29   bool constexpr operator!=(const TypeId& other) const {
30     return !(*this == other);
31   }
32
33  public:
34   template <typename Type>
35   static constexpr TypeId Create() {
36     return TypeId(&TypeTag<Type>::dummy_var, PRETTY_FUNCTION);
37   }
38
39   std::string ToString() const;
40
41  private:
42   template <typename Type>
43   struct TypeTag {
44     constexpr static char dummy_var = 0;
45   };
46
47   constexpr TypeId(const void* type_id, const char* function_name)
48       :
49 #if DCHECK_IS_ON()
50         function_name_(function_name),
51 #endif
52         type_id_(type_id) {
53   }
54
55 #if DCHECK_IS_ON()
56   const char* const function_name_;
57 #endif
58   const void* const type_id_;
59 };
60
61 template <typename Type>
62 constexpr char TypeId::TypeTag<Type>::dummy_var;
63
64 BASE_EXPORT std::ostream& operator<<(std::ostream& out, const TypeId& type_id);
65
66 }  // namespace experimental
67 }  // namespace base
68
69 #endif  // BASE_TYPE_ID_H_