[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
KLFPosSearchable::Pos Struct Reference

An abstract position in a searchable object. More...

#include <klfsearchbar.h>

Collaboration diagram for KLFPosSearchable::Pos:

Classes

struct  PosData
 A Base class for storing abstract position data. More...
 

Public Member Functions

 Pos ()
 
 Pos (const Pos &other)
 
 ~Pos ()
 
Posoperator= (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< PosDataposdata
 Stores the actual position data, see PosData.
 

Detailed Description

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'
KLFRefPtr< PosData > posdata
Stores the actual position data, see PosData.

Definition at line 97 of file klfsearchbar.h.

Constructor & Destructor Documentation

◆ Pos() [1/2]

KLFPosSearchable::Pos::Pos ( )
inline

Constructs an invalid position. This initializes the data pointer to NULL.

Definition at line 146 of file klfsearchbar.h.

References posdata.

Referenced by equals(), operator=(), and Pos().

◆ Pos() [2/2]

KLFPosSearchable::Pos::Pos ( const Pos & other)
inline

Definition at line 150 of file klfsearchbar.h.

References Pos(), and posdata.

◆ ~Pos()

KLFPosSearchable::Pos::~Pos ( )
inline

Definition at line 154 of file klfsearchbar.h.

References posdata.

Member Function Documentation

◆ data()

template<class TT>
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 KLF_ASSERT_NOT_NULL, and posdata.

Referenced by equals().

◆ equals()

bool KLFPosSearchable::Pos::equals ( const Pos & other) const
inline

Is equal to other if:

  • both this and the other position are valid, and posdata 's equals() test is true;
  • or both are invalid.
Note
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.

References data(), Pos(), posdata, and valid().

◆ operator=()

Pos & KLFPosSearchable::Pos::operator= ( const Pos & other)
inline

Definition at line 160 of file klfsearchbar.h.

References KLF_DEBUG_BLOCK, Pos(), and posdata.

◆ valid()

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, klfDbg, and posdata.

Referenced by KLFSearchBar::emitFoundSignals(), equals(), and KLFSearchable::searchFind().

Member Data Documentation

◆ posdata

KLFRefPtr<PosData> KLFPosSearchable::Pos::posdata

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.

Note
PosData::ref() and PosData::deref() are handled automatically when this field is assigned. See also KLFRefPtr.

Definition at line 196 of file klfsearchbar.h.

Referenced by data(), equals(), operator<<(), operator=(), Pos(), Pos(), KLFSearchable::searchFind(), valid(), and ~Pos().


The documentation for this struct was generated from the following file:

Generated by doxygen 1.13.1