UserID.h revision 21f37ad875d4f50d1b4b3d307e120f6d27103730
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 16namespace 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//---------------------------------------------------------------------- 33struct UserID 34{ 35 //------------------------------------------------------------------ 36 /// Construct with optional user ID. 37 //------------------------------------------------------------------ 38 UserID (lldb::user_id_t uid = LLDB_INVALID_UID) : m_uid(uid) {} 39 40 //------------------------------------------------------------------ 41 /// Destructor. 42 /// 43 /// The destructor is virtual in case this class is subclassed. 44 //------------------------------------------------------------------ 45 virtual 46 ~UserID (); 47 48 //------------------------------------------------------------------ 49 /// Clears the object state. 50 /// 51 /// Clears the object contents back to a default invalid state. 52 //------------------------------------------------------------------ 53 void 54 Clear () { m_uid = LLDB_INVALID_UID; } 55 56 //------------------------------------------------------------------ 57 /// Get accessor for the user ID. 58 /// 59 /// @return 60 /// The user ID. 61 //------------------------------------------------------------------ 62 lldb::user_id_t 63 GetID () const { return m_uid; } 64 65 //------------------------------------------------------------------ 66 /// Set accessor for the user ID. 67 /// 68 /// @param[in] uid 69 /// The new user ID. 70 //------------------------------------------------------------------ 71 void 72 SetID (lldb::user_id_t uid) { m_uid = uid; } 73 74 //------------------------------------------------------------------ 75 /// Unary predicate function object that can search for a matching 76 /// user ID. 77 /// 78 /// Function object that can be used on any class that inherits 79 /// from UserID: 80 /// \code 81 /// iterator pos; 82 /// pos = std::find_if (coll.begin(), coll.end(), UserID::IDMatches(blockID)); 83 /// \endcode 84 //------------------------------------------------------------------ 85 class IDMatches 86 { 87 public: 88 //-------------------------------------------------------------- 89 /// Construct with the user ID to look for. 90 //-------------------------------------------------------------- 91 IDMatches (lldb::user_id_t uid) : m_uid(uid) {} 92 93 //-------------------------------------------------------------- 94 /// Unary predicate function object callback. 95 //-------------------------------------------------------------- 96 bool 97 operator () (const UserID& rhs) const { return m_uid == rhs.GetID(); } 98 99 private: 100 //-------------------------------------------------------------- 101 // Member variables. 102 //-------------------------------------------------------------- 103 const lldb::user_id_t m_uid; ///< The user ID we are looking for 104 }; 105 106 107protected: 108 //------------------------------------------------------------------ 109 // Member variables. 110 //------------------------------------------------------------------ 111 lldb::user_id_t m_uid; ///< The user ID that uniquely identifies an object. 112}; 113 114inline bool operator== (const UserID& lhs, const UserID& rhs) 115{ 116 return lhs.GetID() == rhs.GetID(); 117} 118 119inline bool operator!= (const UserID& lhs, const UserID& rhs) 120{ 121 return lhs.GetID() != rhs.GetID(); 122} 123 124//-------------------------------------------------------------- 125/// Stream the UserID object to a Stream. 126//-------------------------------------------------------------- 127Stream& operator << (Stream& strm, const UserID& uid); 128 129} // namespace lldb_private 130 131#endif // liblldb_UserID_h_ 132