]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Utility/UserID.h
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Utility / UserID.h
1 //===-- UserID.h ------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_UserID_h_
11 #define liblldb_UserID_h_
12
13 #include "lldb/lldb-defines.h" // for LLDB_INVALID_UID
14 #include "lldb/lldb-types.h"   // for user_id_t
15 namespace lldb_private {
16 class Stream;
17 }
18
19 namespace lldb_private {
20
21 //----------------------------------------------------------------------
22 /// @class UserID UserID.h "lldb/Core/UserID.h"
23 /// @brief A mix in class that contains a generic user ID.
24 ///
25 /// UserID is designed as a mix in class that can contain an integer
26 /// based unique identifier for a variety of objects in lldb.
27 ///
28 /// The value for this identifier is chosen by each parser plug-in. A
29 /// value should be chosen that makes sense for each kind of object
30 /// and should allow quick access to further and more in depth parsing.
31 ///
32 /// Symbol table entries can use this to store the original symbol table
33 /// index, functions can use it to store the symbol table index or the
34 /// DWARF offset.
35 //----------------------------------------------------------------------
36 struct UserID {
37   //------------------------------------------------------------------
38   /// Construct with optional user ID.
39   //------------------------------------------------------------------
40   UserID(lldb::user_id_t uid = LLDB_INVALID_UID) : m_uid(uid) {}
41
42   //------------------------------------------------------------------
43   /// Destructor.
44   //------------------------------------------------------------------
45   ~UserID() {}
46
47   //------------------------------------------------------------------
48   /// Clears the object state.
49   ///
50   /// Clears the object contents back to a default invalid state.
51   //------------------------------------------------------------------
52   void Clear() { m_uid = LLDB_INVALID_UID; }
53
54   //------------------------------------------------------------------
55   /// Get accessor for the user ID.
56   ///
57   /// @return
58   ///     The user ID.
59   //------------------------------------------------------------------
60   lldb::user_id_t GetID() const { return m_uid; }
61
62   //------------------------------------------------------------------
63   /// Set accessor for the user ID.
64   ///
65   /// @param[in] uid
66   ///     The new user ID.
67   //------------------------------------------------------------------
68   void SetID(lldb::user_id_t uid) { m_uid = uid; }
69
70   //------------------------------------------------------------------
71   /// Unary predicate function object that can search for a matching
72   /// user ID.
73   ///
74   /// Function object that can be used on any class that inherits
75   /// from UserID:
76   /// \code
77   /// iterator pos;
78   /// pos = std::find_if (coll.begin(), coll.end(), UserID::IDMatches(blockID));
79   /// \endcode
80   //------------------------------------------------------------------
81   class IDMatches {
82   public:
83     //--------------------------------------------------------------
84     /// Construct with the user ID to look for.
85     //--------------------------------------------------------------
86     IDMatches(lldb::user_id_t uid) : m_uid(uid) {}
87
88     //--------------------------------------------------------------
89     /// Unary predicate function object callback.
90     //--------------------------------------------------------------
91     bool operator()(const UserID &rhs) const { return m_uid == rhs.GetID(); }
92
93   private:
94     //--------------------------------------------------------------
95     // Member variables.
96     //--------------------------------------------------------------
97     const lldb::user_id_t m_uid; ///< The user ID we are looking for
98   };
99
100 protected:
101   //------------------------------------------------------------------
102   // Member variables.
103   //------------------------------------------------------------------
104   lldb::user_id_t m_uid; ///< The user ID that uniquely identifies an object.
105 };
106
107 inline bool operator==(const UserID &lhs, const UserID &rhs) {
108   return lhs.GetID() == rhs.GetID();
109 }
110
111 inline bool operator!=(const UserID &lhs, const UserID &rhs) {
112   return lhs.GetID() != rhs.GetID();
113 }
114
115 //--------------------------------------------------------------
116 /// Stream the UserID object to a Stream.
117 //--------------------------------------------------------------
118 Stream &operator<<(Stream &strm, const UserID &uid);
119
120 } // namespace lldb_private
121
122 #endif // liblldb_UserID_h_