An abstract position in a searchable object. More...
#include <klfsearchbar.h>
Classes | |
struct | PosData |
A Base class for storing abstract position data. More... | |
Public Member Functions | |
Pos () | |
Pos (const Pos &other) | |
~Pos () | |
Pos & | operator= (const Pos &other) |
bool | valid () const |
bool | equals (const Pos &other) const |
template<class TT > | |
TT * | data () const |
A shorthand for retrieving the posdata cast into the custom type. | |
Public Attributes | |
KLFRefPtr< PosData > | posdata |
Stores the actual position data, see PosData. |
An abstract position in a searchable object.
Used by KLFPosSearchable to store search result positions.
A position can be invalid, or valid. The actual data representing the position is stored in a custom sub-class of PosData, to which a pointer is held in posdata
.
You can construct an invalid position with the default constructor. Then just assign a data pointer to it and it becomes valid, e.g.
Pos p = Pos(); // p is invalid MyPosData *d = new MyPosData; d->somefield = some_data; d->someotherfield = some_other_data; p.posdata = d; // now p is a valid position object, storing the position represented // by data stored in 'somefield' and 'someotherfield'
Definition at line 97 of file klfsearchbar.h.
KLFPosSearchable::Pos::Pos | ( | ) | [inline] |
Constructs an invalid position. This initializes the data pointer to NULL.
Definition at line 146 of file klfsearchbar.h.
KLFPosSearchable::Pos::Pos | ( | const Pos & | other | ) | [inline] |
Definition at line 150 of file klfsearchbar.h.
KLFPosSearchable::Pos::~Pos | ( | ) | [inline] |
Definition at line 154 of file klfsearchbar.h.
TT* KLFPosSearchable::Pos::data | ( | ) | const [inline] |
A shorthand for retrieving the posdata
cast into the custom type.
Example:
// Instead of: MyPosData * myposdata = dynamic_cast<MyPosData*>(pos.posdata); // we can use MyPosData * myposdata = pos.data<MyPosData>();
Additionally, a warning is issued if posdata
is NULL
or if posdata
cannot by cast (with dynamic_cast<>
) to the required type.
Definition at line 212 of file klfsearchbar.h.
References KLFRefPtr< T >::dyn_cast(), and KLF_ASSERT_NOT_NULL.
Referenced by equals().
bool KLFPosSearchable::Pos::equals | ( | const Pos & | other | ) | const [inline] |
Is equal to other
if:
posdata
's equals() test is true;PosData's
equals() test called if and only if both this and the other position are valid, i.e. have non-NULL posdata
pointer. Definition at line 180 of file klfsearchbar.h.
Definition at line 160 of file klfsearchbar.h.
References KLF_DEBUG_BLOCK, KLF_FUNC_NAME, and posdata.
bool KLFPosSearchable::Pos::valid | ( | ) | const [inline] |
A position is valid if it has a non-NULL posdata pointer. It is invalid otherwise.
Definition at line 168 of file klfsearchbar.h.
References KLF_DEBUG_BLOCK, KLF_FUNC_NAME, and klfDbg.
Referenced by KLFSearchBar::emitFoundSignals(), equals(), and KLFSearchable::searchFind().
Stores the actual position data, see PosData.
This pointer is set up by KLFPosSearchable subclasses to instanciate valid Pos objects. They may use this object transparently, just as a regular PosData*
pointer, see KLFRefPtr.
Definition at line 196 of file klfsearchbar.h.
Referenced by operator<<(), operator=(), and KLFSearchable::searchFind().