LLDB  mainline
UserID.h
Go to the documentation of this file.
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 liblldb_UserID_h_
10 #define liblldb_UserID_h_
11 
12 #include "lldb/lldb-defines.h"
13 #include "lldb/lldb-types.h"
14 namespace lldb_private {
15 class Stream;
16 }
17 
18 namespace lldb_private {
19 
20 /// \class UserID UserID.h "lldb/Core/UserID.h"
21 /// A mix in class that contains a generic user ID.
22 ///
23 /// UserID is designed as a mix in class that can contain an integer based
24 /// unique identifier for a variety of objects in lldb.
25 ///
26 /// The value for this identifier is chosen by each parser plug-in. A value
27 /// should be chosen that makes sense for each kind of object and should allow
28 /// quick access to further and more in depth parsing.
29 ///
30 /// Symbol table entries can use this to store the original symbol table
31 /// index, functions can use it to store the symbol table index or the
32 /// DWARF offset.
33 struct UserID {
34  /// Construct with optional user ID.
36 
37  /// Destructor.
38  ~UserID() {}
39 
40  /// Clears the object state.
41  ///
42  /// Clears the object contents back to a default invalid state.
44 
45  /// Get accessor for the user ID.
46  ///
47  /// \return
48  /// The user ID.
49  lldb::user_id_t GetID() const { return m_uid; }
50 
51  /// Set accessor for the user ID.
52  ///
53  /// \param[in] uid
54  /// The new user ID.
55  void SetID(lldb::user_id_t uid) { m_uid = uid; }
56 
57  /// Unary predicate function object that can search for a matching user ID.
58  ///
59  /// Function object that can be used on any class that inherits from UserID:
60  /// \code
61  /// iterator pos;
62  /// pos = std::find_if (coll.begin(), coll.end(), UserID::IDMatches(blockID));
63  /// \endcode
64  class IDMatches {
65  public:
66  /// Construct with the user ID to look for.
67  IDMatches(lldb::user_id_t uid) : m_uid(uid) {}
68 
69  /// Unary predicate function object callback.
70  bool operator()(const UserID &rhs) const { return m_uid == rhs.GetID(); }
71 
72  private:
73  // Member variables.
74  const lldb::user_id_t m_uid; ///< The user ID we are looking for
75  };
76 
77 protected:
78  // Member variables.
79  lldb::user_id_t m_uid; ///< The user ID that uniquely identifies an object.
80 };
81 
82 inline bool operator==(const UserID &lhs, const UserID &rhs) {
83  return lhs.GetID() == rhs.GetID();
84 }
85 
86 inline bool operator!=(const UserID &lhs, const UserID &rhs) {
87  return lhs.GetID() != rhs.GetID();
88 }
89 
90 /// Stream the UserID object to a Stream.
91 Stream &operator<<(Stream &strm, const UserID &uid);
92 
93 } // namespace lldb_private
94 
95 #endif // liblldb_UserID_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void Clear()
Clears the object state.
Definition: UserID.h:43
lldb::user_id_t m_uid
The user ID that uniquely identifies an object.
Definition: UserID.h:79
bool operator()(const UserID &rhs) const
Unary predicate function object callback.
Definition: UserID.h:70
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:49
A mix in class that contains a generic user ID.
Definition: UserID.h:33
#define LLDB_INVALID_UID
Definition: lldb-defines.h:91
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition: UserID.h:35
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:973
IDMatches(lldb::user_id_t uid)
Construct with the user ID to look for.
Definition: UserID.h:67
uint64_t user_id_t
Definition: lldb-types.h:84
Unary predicate function object that can search for a matching user ID.
Definition: UserID.h:64
~UserID()
Destructor.
Definition: UserID.h:38
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:979
void SetID(lldb::user_id_t uid)
Set accessor for the user ID.
Definition: UserID.h:55
Stream & operator<<(Stream &s, ConstString str)
Stream the string value str to the stream s.