]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Core/UserID.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Core / 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-private.h"
14
15 namespace lldb_private {
16
17 //----------------------------------------------------------------------
18 /// @class UserID UserID.h "lldb/Core/UserID.h"
19 /// @brief 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
22 /// based unique identifier for a variety of objects in lldb.
23 ///
24 /// The value for this identifier is chosen by each parser plug-in. A
25 /// value should be chosen that makes sense for each kind of object
26 /// and should allow 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 //----------------------------------------------------------------------
32 struct UserID {
33   //------------------------------------------------------------------
34   /// Construct with optional user ID.
35   //------------------------------------------------------------------
36   UserID(lldb::user_id_t uid = LLDB_INVALID_UID) : m_uid(uid) {}
37
38   //------------------------------------------------------------------
39   /// Destructor.
40   //------------------------------------------------------------------
41   ~UserID() {}
42
43   //------------------------------------------------------------------
44   /// Clears the object state.
45   ///
46   /// Clears the object contents back to a default invalid state.
47   //------------------------------------------------------------------
48   void Clear() { m_uid = LLDB_INVALID_UID; }
49
50   //------------------------------------------------------------------
51   /// Get accessor for the user ID.
52   ///
53   /// @return
54   ///     The user ID.
55   //------------------------------------------------------------------
56   lldb::user_id_t GetID() const { return m_uid; }
57
58   //------------------------------------------------------------------
59   /// Set accessor for the user ID.
60   ///
61   /// @param[in] uid
62   ///     The new user ID.
63   //------------------------------------------------------------------
64   void SetID(lldb::user_id_t uid) { m_uid = uid; }
65
66   //------------------------------------------------------------------
67   /// Unary predicate function object that can search for a matching
68   /// user ID.
69   ///
70   /// Function object that can be used on any class that inherits
71   /// from UserID:
72   /// \code
73   /// iterator pos;
74   /// pos = std::find_if (coll.begin(), coll.end(), UserID::IDMatches(blockID));
75   /// \endcode
76   //------------------------------------------------------------------
77   class IDMatches {
78   public:
79     //--------------------------------------------------------------
80     /// Construct with the user ID to look for.
81     //--------------------------------------------------------------
82     IDMatches(lldb::user_id_t uid) : m_uid(uid) {}
83
84     //--------------------------------------------------------------
85     /// Unary predicate function object callback.
86     //--------------------------------------------------------------
87     bool operator()(const UserID &rhs) const { return m_uid == rhs.GetID(); }
88
89   private:
90     //--------------------------------------------------------------
91     // Member variables.
92     //--------------------------------------------------------------
93     const lldb::user_id_t m_uid; ///< The user ID we are looking for
94   };
95
96 protected:
97   //------------------------------------------------------------------
98   // Member variables.
99   //------------------------------------------------------------------
100   lldb::user_id_t m_uid; ///< The user ID that uniquely identifies an object.
101 };
102
103 inline bool operator==(const UserID &lhs, const UserID &rhs) {
104   return lhs.GetID() == rhs.GetID();
105 }
106
107 inline bool operator!=(const UserID &lhs, const UserID &rhs) {
108   return lhs.GetID() != rhs.GetID();
109 }
110
111 //--------------------------------------------------------------
112 /// Stream the UserID object to a Stream.
113 //--------------------------------------------------------------
114 Stream &operator<<(Stream &strm, const UserID &uid);
115
116 } // namespace lldb_private
117
118 #endif // liblldb_UserID_h_