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