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"
14 #include "lldb/lldb-types.h"
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 /// 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 based
26 /// unique identifier for a variety of objects in lldb.
27 ///
28 /// The value for this identifier is chosen by each parser plug-in. A value
29 /// should be chosen that makes sense for each kind of object and should allow
30 /// 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   //------------------------------------------------------------------
m_uidUserID40   UserID(lldb::user_id_t uid = LLDB_INVALID_UID) : m_uid(uid) {}
41 
42   //------------------------------------------------------------------
43   /// Destructor.
44   //------------------------------------------------------------------
~UserIDUserID45   ~UserID() {}
46 
47   //------------------------------------------------------------------
48   /// Clears the object state.
49   ///
50   /// Clears the object contents back to a default invalid state.
51   //------------------------------------------------------------------
ClearUserID52   void Clear() { m_uid = LLDB_INVALID_UID; }
53 
54   //------------------------------------------------------------------
55   /// Get accessor for the user ID.
56   ///
57   /// @return
58   ///     The user ID.
59   //------------------------------------------------------------------
GetIDUserID60   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   //------------------------------------------------------------------
SetIDUserID68   void SetID(lldb::user_id_t uid) { m_uid = uid; }
69 
70   //------------------------------------------------------------------
71   /// Unary predicate function object that can search for a matching user ID.
72   ///
73   /// Function object that can be used on any class that inherits from UserID:
74   /// \code
75   /// iterator pos;
76   /// pos = std::find_if (coll.begin(), coll.end(), UserID::IDMatches(blockID));
77   /// \endcode
78   //------------------------------------------------------------------
79   class IDMatches {
80   public:
81     //--------------------------------------------------------------
82     /// Construct with the user ID to look for.
83     //--------------------------------------------------------------
IDMatchesUserID84     IDMatches(lldb::user_id_t uid) : m_uid(uid) {}
85 
86     //--------------------------------------------------------------
87     /// Unary predicate function object callback.
88     //--------------------------------------------------------------
operatorUserID89     bool operator()(const UserID &rhs) const { return m_uid == rhs.GetID(); }
90 
91   private:
92     //--------------------------------------------------------------
93     // Member variables.
94     //--------------------------------------------------------------
95     const lldb::user_id_t m_uid; ///< The user ID we are looking for
96   };
97 
98 protected:
99   //------------------------------------------------------------------
100   // Member variables.
101   //------------------------------------------------------------------
102   lldb::user_id_t m_uid; ///< The user ID that uniquely identifies an object.
103 };
104 
105 inline bool operator==(const UserID &lhs, const UserID &rhs) {
106   return lhs.GetID() == rhs.GetID();
107 }
108 
109 inline bool operator!=(const UserID &lhs, const UserID &rhs) {
110   return lhs.GetID() != rhs.GetID();
111 }
112 
113 //--------------------------------------------------------------
114 /// Stream the UserID object to a Stream.
115 //--------------------------------------------------------------
116 Stream &operator<<(Stream &strm, const UserID &uid);
117 
118 } // namespace lldb_private
119 
120 #endif // liblldb_UserID_h_
121