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 11 #ifndef liblldb_UserID_h_ 12 #define liblldb_UserID_h_ 13 14 #include "lldb/lldb-private.h" 15 16 namespace lldb_private { 17 18 //---------------------------------------------------------------------- 19 /// @class UserID UserID.h "lldb/Core/UserID.h" 20 /// @brief A mix in class that contains a generic user ID. 21 /// 22 /// UserID is desinged as a mix in class that can contain an integer 23 /// based unique identifier for a varietly of objects in lldb. 24 /// 25 /// The value for this identifier is chosen by each parser plug-in. A 26 /// value should be chosen that makes sense for each kind of object 27 /// should and allows quick access to further and more in depth parsing. 28 /// 29 /// Symbol table entries can use this to store the original symbol table 30 /// index, functions can use it to store the symbol table index or the 31 /// DWARF offset. 32 //---------------------------------------------------------------------- 33 struct UserID 34 { 35 //------------------------------------------------------------------ 36 /// Construct with optional user ID. 37 //------------------------------------------------------------------ m_uidUserID38 UserID (lldb::user_id_t uid = LLDB_INVALID_UID) : m_uid(uid) {} 39 40 //------------------------------------------------------------------ 41 /// Destructor. 42 //------------------------------------------------------------------ ~UserIDUserID43 ~UserID () 44 { 45 } 46 47 //------------------------------------------------------------------ 48 /// Clears the object state. 49 /// 50 /// Clears the object contents back to a default invalid state. 51 //------------------------------------------------------------------ 52 void ClearUserID53 Clear () { m_uid = LLDB_INVALID_UID; } 54 55 //------------------------------------------------------------------ 56 /// Get accessor for the user ID. 57 /// 58 /// @return 59 /// The user ID. 60 //------------------------------------------------------------------ 61 lldb::user_id_t GetIDUserID62 GetID () const { return m_uid; } 63 64 //------------------------------------------------------------------ 65 /// Set accessor for the user ID. 66 /// 67 /// @param[in] uid 68 /// The new user ID. 69 //------------------------------------------------------------------ 70 void SetIDUserID71 SetID (lldb::user_id_t uid) { m_uid = uid; } 72 73 //------------------------------------------------------------------ 74 /// Unary predicate function object that can search for a matching 75 /// user ID. 76 /// 77 /// Function object that can be used on any class that inherits 78 /// from UserID: 79 /// \code 80 /// iterator pos; 81 /// pos = std::find_if (coll.begin(), coll.end(), UserID::IDMatches(blockID)); 82 /// \endcode 83 //------------------------------------------------------------------ 84 class IDMatches 85 { 86 public: 87 //-------------------------------------------------------------- 88 /// Construct with the user ID to look for. 89 //-------------------------------------------------------------- IDMatchesUserID90 IDMatches (lldb::user_id_t uid) : m_uid(uid) {} 91 92 //-------------------------------------------------------------- 93 /// Unary predicate function object callback. 94 //-------------------------------------------------------------- 95 bool operatorUserID96 operator () (const UserID& rhs) const { return m_uid == rhs.GetID(); } 97 98 private: 99 //-------------------------------------------------------------- 100 // Member variables. 101 //-------------------------------------------------------------- 102 const lldb::user_id_t m_uid; ///< The user ID we are looking for 103 }; 104 105 106 protected: 107 //------------------------------------------------------------------ 108 // Member variables. 109 //------------------------------------------------------------------ 110 lldb::user_id_t m_uid; ///< The user ID that uniquely identifies an object. 111 }; 112 113 inline bool operator== (const UserID& lhs, const UserID& rhs) 114 { 115 return lhs.GetID() == rhs.GetID(); 116 } 117 118 inline bool operator!= (const UserID& lhs, const UserID& rhs) 119 { 120 return lhs.GetID() != rhs.GetID(); 121 } 122 123 //-------------------------------------------------------------- 124 /// Stream the UserID object to a Stream. 125 //-------------------------------------------------------------- 126 Stream& operator << (Stream& strm, const UserID& uid); 127 128 } // namespace lldb_private 129 130 #endif // liblldb_UserID_h_ 131