itemid.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/itemid.h
  3. // Purpose: wxItemId class declaration.
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-08-17
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_ITEMID_H_
  10. #define _WX_ITEMID_H_
  11. // ----------------------------------------------------------------------------
  12. // wxItemId: an opaque item identifier used with wx{Tree,TreeList,DataView}Ctrl.
  13. // ----------------------------------------------------------------------------
  14. // The template argument T is typically a pointer to some opaque type. While
  15. // wxTreeItemId and wxDataViewItem use a pointer to void, this is dangerous and
  16. // not recommended for the new item id classes.
  17. template <typename T>
  18. class wxItemId
  19. {
  20. public:
  21. typedef T Type;
  22. // This ctor is implicit which is fine for non-void* types, but if you use
  23. // this class with void* you're strongly advised to make the derived class
  24. // ctor explicit as implicitly converting from any pointer is simply too
  25. // dangerous.
  26. wxItemId(Type item = NULL) : m_pItem(item) { }
  27. // Default copy ctor, assignment operator and dtor are ok.
  28. bool IsOk() const { return m_pItem != NULL; }
  29. Type GetID() const { return m_pItem; }
  30. operator const Type() const { return m_pItem; }
  31. // This is used for implementation purposes only.
  32. Type operator->() const { return m_pItem; }
  33. void Unset() { m_pItem = NULL; }
  34. // This field is public *only* for compatibility with the old wxTreeItemId
  35. // implementation and must not be used in any new code.
  36. //private:
  37. Type m_pItem;
  38. };
  39. template <typename T>
  40. bool operator==(const wxItemId<T>& left, const wxItemId<T>& right)
  41. {
  42. return left.GetID() == right.GetID();
  43. }
  44. template <typename T>
  45. bool operator!=(const wxItemId<T>& left, const wxItemId<T>& right)
  46. {
  47. return !(left == right);
  48. }
  49. #endif // _WX_ITEMID_H_