UserID.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //===-- UserID.h ------------------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLDB_UTILITY_USERID_H
  9. #define LLDB_UTILITY_USERID_H
  10. #include "lldb/lldb-defines.h"
  11. #include "lldb/lldb-types.h"
  12. namespace lldb_private {
  13. class Stream;
  14. /// \class UserID UserID.h "lldb/Core/UserID.h"
  15. /// A mix in class that contains a generic user ID.
  16. ///
  17. /// UserID is designed as a mix in class that can contain an integer based
  18. /// unique identifier for a variety of objects in lldb.
  19. ///
  20. /// The value for this identifier is chosen by each parser plug-in. A value
  21. /// should be chosen that makes sense for each kind of object and should allow
  22. /// quick access to further and more in depth parsing.
  23. ///
  24. /// Symbol table entries can use this to store the original symbol table
  25. /// index, functions can use it to store the symbol table index or the
  26. /// DWARF offset.
  27. struct UserID {
  28. /// Construct with optional user ID.
  29. UserID(lldb::user_id_t uid = LLDB_INVALID_UID) : m_uid(uid) {}
  30. /// Destructor.
  31. ~UserID() {}
  32. /// Clears the object state.
  33. ///
  34. /// Clears the object contents back to a default invalid state.
  35. void Clear() { m_uid = LLDB_INVALID_UID; }
  36. /// Get accessor for the user ID.
  37. ///
  38. /// \return
  39. /// The user ID.
  40. lldb::user_id_t GetID() const { return m_uid; }
  41. /// Set accessor for the user ID.
  42. ///
  43. /// \param[in] uid
  44. /// The new user ID.
  45. void SetID(lldb::user_id_t uid) { m_uid = uid; }
  46. /// Unary predicate function object that can search for a matching user ID.
  47. ///
  48. /// Function object that can be used on any class that inherits from UserID:
  49. /// \code
  50. /// iterator pos;
  51. /// pos = std::find_if (coll.begin(), coll.end(), UserID::IDMatches(blockID));
  52. /// \endcode
  53. class IDMatches {
  54. public:
  55. /// Construct with the user ID to look for.
  56. IDMatches(lldb::user_id_t uid) : m_uid(uid) {}
  57. /// Unary predicate function object callback.
  58. bool operator()(const UserID &rhs) const { return m_uid == rhs.GetID(); }
  59. private:
  60. // Member variables.
  61. const lldb::user_id_t m_uid; ///< The user ID we are looking for
  62. };
  63. protected:
  64. // Member variables.
  65. lldb::user_id_t m_uid; ///< The user ID that uniquely identifies an object.
  66. };
  67. inline bool operator==(const UserID &lhs, const UserID &rhs) {
  68. return lhs.GetID() == rhs.GetID();
  69. }
  70. inline bool operator!=(const UserID &lhs, const UserID &rhs) {
  71. return lhs.GetID() != rhs.GetID();
  72. }
  73. /// Stream the UserID object to a Stream.
  74. Stream &operator<<(Stream &strm, const UserID &uid);
  75. } // namespace lldb_private
  76. #endif // LLDB_UTILITY_USERID_H