Use template instead of macro to generate wxPropertyGridIterator class
This commit is contained in:
@@ -209,95 +209,66 @@ private:
|
|||||||
wxPGProperty::FlagType m_parentExMask;
|
wxPGProperty::FlagType m_parentExMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename PROPERTY, typename STATE>
|
||||||
#define wxPG_IMPLEMENT_ITERATOR(CLASS, PROPERTY, STATE) \
|
class WXDLLIMPEXP_PROPGRID wxPGIterator : public wxPropertyGridIteratorBase
|
||||||
CLASS( STATE* state, int flags = wxPG_ITERATE_DEFAULT, \
|
{
|
||||||
PROPERTY* property = NULL, int dir = 1 ) \
|
public:
|
||||||
: wxPropertyGridIteratorBase() \
|
wxPGIterator(STATE* state, int flags = wxPG_ITERATE_DEFAULT,
|
||||||
{ Init( (wxPropertyGridPageState*)state, flags, \
|
PROPERTY* property = NULL, int dir = 1)
|
||||||
(wxPGProperty*)property, dir ); } \
|
: wxPropertyGridIteratorBase()
|
||||||
CLASS( STATE* state, int flags, int startPos, int dir = 0 ) \
|
{
|
||||||
: wxPropertyGridIteratorBase() \
|
Init((wxPropertyGridPageState*)state, flags, (wxPGProperty*)property, dir);
|
||||||
{ Init( (wxPropertyGridPageState*)state, flags, startPos, dir ); } \
|
}
|
||||||
CLASS() \
|
wxPGIterator(STATE* state, int flags, int startPos, int dir = 0)
|
||||||
: wxPropertyGridIteratorBase() \
|
: wxPropertyGridIteratorBase()
|
||||||
{ \
|
{
|
||||||
m_property = NULL; \
|
Init((wxPropertyGridPageState*)state, flags, startPos, dir);
|
||||||
} \
|
}
|
||||||
CLASS( const CLASS& it ) \
|
wxPGIterator()
|
||||||
: wxPropertyGridIteratorBase( ) \
|
: wxPropertyGridIteratorBase()
|
||||||
{ \
|
{
|
||||||
Assign(it); \
|
m_property = NULL;
|
||||||
} \
|
}
|
||||||
~CLASS() \
|
wxPGIterator(const wxPGIterator& it)
|
||||||
{ \
|
: wxPropertyGridIteratorBase()
|
||||||
} \
|
{
|
||||||
const CLASS& operator=( const CLASS& it ) \
|
Assign(it);
|
||||||
{ \
|
}
|
||||||
if (this != &it) \
|
~wxPGIterator()
|
||||||
Assign(it); \
|
{
|
||||||
return *this; \
|
}
|
||||||
} \
|
wxPGIterator& operator=(const wxPGIterator& it)
|
||||||
CLASS& operator++() { Next(); return *this; } \
|
{
|
||||||
CLASS operator++(int) { CLASS it=*this;Next();return it; } \
|
if ( this != &it )
|
||||||
CLASS& operator--() { Prev(); return *this; } \
|
Assign(it);
|
||||||
CLASS operator--(int) { CLASS it=*this;Prev();return it; } \
|
return *this;
|
||||||
PROPERTY* operator *() const { return (PROPERTY*)m_property; } \
|
|
||||||
static PROPERTY* OneStep( STATE* state, \
|
|
||||||
int flags = wxPG_ITERATE_DEFAULT, \
|
|
||||||
PROPERTY* property = NULL, \
|
|
||||||
int dir = 1 ) \
|
|
||||||
{ \
|
|
||||||
CLASS it( state, flags, property, dir ); \
|
|
||||||
if ( property ) \
|
|
||||||
{ \
|
|
||||||
if ( dir == 1 ) it.Next(); \
|
|
||||||
else it.Prev(); \
|
|
||||||
} \
|
|
||||||
return *it; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxPGIterator& operator++() { Next(); return *this; }
|
||||||
|
wxPGIterator operator++(int) { wxPGIterator it = *this; Next(); return it; }
|
||||||
|
wxPGIterator& operator--() { Prev(); return *this; }
|
||||||
|
wxPGIterator operator--(int) { wxPGIterator it = *this; Prev(); return it; }
|
||||||
|
PROPERTY* operator *() const { return (PROPERTY*)m_property; }
|
||||||
|
static PROPERTY* OneStep(STATE* state, int flags = wxPG_ITERATE_DEFAULT,
|
||||||
|
PROPERTY* property = NULL, int dir = 1)
|
||||||
|
{
|
||||||
|
wxPGIterator it(state, flags, property, dir);
|
||||||
|
if ( property )
|
||||||
|
{
|
||||||
|
if ( dir == 1 )
|
||||||
|
it.Next();
|
||||||
|
else
|
||||||
|
it.Prev();
|
||||||
|
}
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Preferable way to iterate through contents of wxPropertyGrid,
|
// Preferable way to iterate through contents of wxPropertyGrid,
|
||||||
// wxPropertyGridManager, and wxPropertyGridPage.
|
// wxPropertyGridManager, and wxPropertyGridPage.
|
||||||
// See wxPropertyGridInterface::GetIterator() for more information about usage.
|
// See wxPropertyGridInterface::GetIterator() for more information about usage.
|
||||||
class WXDLLIMPEXP_PROPGRID
|
typedef wxPGIterator<wxPGProperty, wxPropertyGridPageState> wxPropertyGridIterator;
|
||||||
wxPropertyGridIterator : public wxPropertyGridIteratorBase
|
typedef wxPGIterator<const wxPGProperty, const wxPropertyGridPageState> wxPropertyGridConstIterator;
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
wxPG_IMPLEMENT_ITERATOR(wxPropertyGridIterator,
|
|
||||||
wxPGProperty,
|
|
||||||
wxPropertyGridPageState)
|
|
||||||
|
|
||||||
protected:
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Const version of wxPropertyGridIterator.
|
|
||||||
class WXDLLIMPEXP_PROPGRID
|
|
||||||
wxPropertyGridConstIterator : public wxPropertyGridIteratorBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
wxPG_IMPLEMENT_ITERATOR(wxPropertyGridConstIterator,
|
|
||||||
const wxPGProperty,
|
|
||||||
const wxPropertyGridPageState)
|
|
||||||
|
|
||||||
// Additional copy constructor.
|
|
||||||
wxPropertyGridConstIterator( const wxPropertyGridIterator& other )
|
|
||||||
{
|
|
||||||
Assign(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Additional assignment operator.
|
|
||||||
const wxPropertyGridConstIterator& operator=( const wxPropertyGridIterator& it )
|
|
||||||
{
|
|
||||||
Assign(it);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
};
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user