Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Utility/UserID.h
Line
Count
Source (jump to first uncovered line)
1
//===-- UserID.h ------------------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLDB_UTILITY_USERID_H
10
#define LLDB_UTILITY_USERID_H
11
12
#include "lldb/lldb-defines.h"
13
#include "lldb/lldb-types.h"
14
15
namespace lldb_private {
16
class Stream;
17
18
/// \class UserID UserID.h "lldb/Core/UserID.h"
19
/// A mix in class that contains a generic user ID.
20
///
21
/// UserID is designed as a mix in class that can contain an integer based
22
/// unique identifier for a variety of objects in lldb.
23
///
24
/// The value for this identifier is chosen by each parser plug-in. A value
25
/// should be chosen that makes sense for each kind of object and should allow
26
/// quick access to further and more in depth parsing.
27
///
28
/// Symbol table entries can use this to store the original symbol table
29
/// index, functions can use it to store the symbol table index or the
30
/// DWARF offset.
31
struct UserID {
32
  /// Construct with optional user ID.
33
3.16M
  UserID(lldb::user_id_t uid = LLDB_INVALID_UID) : m_uid(uid) {}
34
35
  /// Destructor.
36
  ~UserID() = default;
37
38
  /// Clears the object state.
39
  ///
40
  /// Clears the object contents back to a default invalid state.
41
0
  void Clear() { m_uid = LLDB_INVALID_UID; }
42
43
  /// Get accessor for the user ID.
44
  ///
45
  /// \return
46
  ///     The user ID.
47
12.9M
  lldb::user_id_t GetID() const { return m_uid; }
48
49
  /// Set accessor for the user ID.
50
  ///
51
  /// \param[in] uid
52
  ///     The new user ID.
53
25.3k
  void SetID(lldb::user_id_t uid) { m_uid = uid; }
54
55
  /// Unary predicate function object that can search for a matching user ID.
56
  ///
57
  /// Function object that can be used on any class that inherits from UserID:
58
  /// \code
59
  /// iterator pos;
60
  /// pos = std::find_if (coll.begin(), coll.end(), UserID::IDMatches(blockID));
61
  /// \endcode
62
  class IDMatches {
63
  public:
64
    /// Construct with the user ID to look for.
65
0
    IDMatches(lldb::user_id_t uid) : m_uid(uid) {}
66
67
    /// Unary predicate function object callback.
68
0
    bool operator()(const UserID &rhs) const { return m_uid == rhs.GetID(); }
69
70
  private:
71
    // Member variables.
72
    const lldb::user_id_t m_uid; ///< The user ID we are looking for
73
  };
74
75
protected:
76
  // Member variables.
77
  lldb::user_id_t m_uid; ///< The user ID that uniquely identifies an object.
78
};
79
80
0
inline bool operator==(const UserID &lhs, const UserID &rhs) {
81
0
  return lhs.GetID() == rhs.GetID();
82
0
}
83
84
0
inline bool operator!=(const UserID &lhs, const UserID &rhs) {
85
0
  return lhs.GetID() != rhs.GetID();
86
0
}
87
88
/// Stream the UserID object to a Stream.
89
Stream &operator<<(Stream &strm, const UserID &uid);
90
91
} // namespace lldb_private
92
93
#endif // LLDB_UTILITY_USERID_H