MD::PosCache Class

class MD::PosCache

Cache of Markdown items to be accessed via position. More...

Header: #include <md4qt/poscache.h>
CMake: find_package(md4qt REQUIRED COMPONENTS md4qt)
target_link_libraries(mytarget PRIVATE md4qt::md4qt)
Inherits: MD::Visitor

Public Types

class Items

Public Functions

PosCache()
MD::PosCache::Items findFirstInCache(const MD::WithPosition &pos) const
virtual void initialize(QSharedPointer<MD::Document> doc)

Protected Functions

void findFirstInCache(const QVector<QSharedPointer<MD::details::PosRange>> &vec, const MD::details::PosRange &pos, MD::PosCache::Items &res) const
MD::details::PosRange *findInCache(const QVector<QSharedPointer<MD::details::PosRange>> &vec, const MD::details::PosRange &pos, bool ordered = false) const
void insertInCache(const MD::details::PosRange &item, bool sort = false, bool insertInStack = false)
virtual void onReferenceLink(MD::Link *l)

Reimplemented Protected Functions

virtual void onBlockquote(MD::Blockquote *b) override
virtual void onCode(MD::Code *c) override
virtual void onFootnote(MD::Footnote *f) override
virtual void onFootnoteRef(MD::FootnoteRef *ref) override
virtual void onHeading(MD::Heading *h) override
virtual void onHorizontalLine(MD::HorizontalLine *l) override
virtual void onImage(MD::Image *i) override
virtual void onInlineCode(MD::Code *c) override
virtual void onLink(MD::Link *l) override
virtual void onList(MD::List *l) override
virtual void onListItem(MD::ListItem *l, bool first, bool skipOpeningWrap = false) override
virtual void onMath(MD::Math *m) override
virtual void onParagraph(MD::Paragraph *p, bool wrap, bool skipOpeningWrap = false) override
virtual void onRawHtml(MD::RawHtml *h) override
virtual void onTable(MD::Table *t) override
virtual void onText(MD::Text *t) override
virtual void onUserDefined(MD::Item *i) override

Protected Variables

QVector<QSharedPointer<MD::details::PosRange>> m_cache
bool m_skipInCache

Detailed Description

A visitor that during walking through a document gathers information about positions of items and stores it internally. When positions cache is initialized a developer can search for items by its positions with MD::PosCache::findFirstInCache method.

A complexity of walking is O(N), whereas searching is LOG(N).

See also MD::Visitor.

Member Function Documentation

[constexpr noexcept] PosCache::PosCache()

Default constructor.

MD::PosCache::Items PosCache::findFirstInCache(const MD::WithPosition &pos) const

Returns first occurence of Markdown item with all first children by the given position.

pos Position.

[protected] void PosCache::findFirstInCache(const QVector<QSharedPointer<MD::details::PosRange>> &vec, const MD::details::PosRange &pos, MD::PosCache::Items &res) const

Find in cache items with the given position with all parents.

vec Cache.

pos Position of sought-for item.

res Reference to result of search.

[protected] MD::details::PosRange *PosCache::findInCache(const QVector<QSharedPointer<MD::details::PosRange>> &vec, const MD::details::PosRange &pos, bool ordered = false) const

Find in cache an item with the given position.

vec Cache of position.

pos Position of sought-for item.

ordered Indicates that we sure that searching item places after everything.

[virtual] void PosCache::initialize(QSharedPointer<MD::Document> doc)

Initialize m_cache with the given document.

Note: Document should not be recursive.

doc Document.

[protected] void PosCache::insertInCache(const MD::details::PosRange &item, bool sort = false, bool insertInStack = false)

Insert in cache.

item Position for insertion.

sort Should we sord when insert top-level item, or we can be sure that this item is last?

insertInStack Indicates that this item is some kind a block with children that should be added into stack for fast finding parent item for the next children. This techinque allows to have O(N) walking complexity.

[override virtual protected] void PosCache::onBlockquote(MD::Blockquote *b)

Reimplements: Visitor::onBlockquote(MD::Blockquote *b).

Cache blockquote.

b Blockquote.

[override virtual protected] void PosCache::onCode(MD::Code *c)

Reimplements: Visitor::onCode(MD::Code *c).

Cache code.

c Code.

[override virtual protected] void PosCache::onFootnote(MD::Footnote *f)

Reimplements: Visitor::onFootnote(MD::Footnote *f).

Cache footnote.

f Footnote.

[override virtual protected] void PosCache::onFootnoteRef(MD::FootnoteRef *ref)

Reimplements: Visitor::onFootnoteRef(MD::FootnoteRef *ref).

Cache footnote reference.

ref Footnote reference.

[override virtual protected] void PosCache::onHeading(MD::Heading *h)

Reimplements: Visitor::onHeading(MD::Heading *h).

Cache heading.

h Heading.

[override virtual protected] void PosCache::onHorizontalLine(MD::HorizontalLine *l)

Reimplements: Visitor::onHorizontalLine(MD::HorizontalLine *l).

Cache horizontal line.

l Horizontal line.

[override virtual protected] void PosCache::onImage(MD::Image *i)

Reimplements: Visitor::onImage(MD::Image *i).

Cache image.

i Image.

[override virtual protected] void PosCache::onInlineCode(MD::Code *c)

Reimplements: Visitor::onInlineCode(MD::Code *c).

Cache inline code.

c Code.

Reimplements: Visitor::onLink(MD::Link *l).

Cache link.

l Link.

[override virtual protected] void PosCache::onList(MD::List *l)

Reimplements: Visitor::onList(MD::List *l).

Cache list.

l List.

[override virtual protected] void PosCache::onListItem(MD::ListItem *l, bool first, bool skipOpeningWrap = false)

Reimplements: Visitor::onListItem(MD::ListItem *i, bool first, bool skipOpeningWrap).

Cache list item.

l List item.

first Is this item first in the list?

skipOpeningWrap Indicates that opening wrap should be added or no.

[override virtual protected] void PosCache::onMath(MD::Math *m)

Reimplements: Visitor::onMath(MD::Math *m).

Cache LaTeX math expression.

m Math.

[override virtual protected] void PosCache::onParagraph(MD::Paragraph *p, bool wrap, bool skipOpeningWrap = false)

Reimplements: Visitor::onParagraph(MD::Paragraph *p, bool wrap, bool skipOpeningWrap).

Cache paragraph.

p Paragraph.

wrap Wrap this paragraph with something or no? It's useful to not wrap standalone paragraph in list item, for example.

skipOpeningWrap Indicates that opening wrap should be added or no.

[override virtual protected] void PosCache::onRawHtml(MD::RawHtml *h)

Reimplements: Visitor::onRawHtml(MD::RawHtml *h).

Cache raw HTML.

h Raw HTML.

Cache shortcut link.

l Link.

[override virtual protected] void PosCache::onTable(MD::Table *t)

Reimplements: Visitor::onTable(MD::Table *t).

Cache table.

t Table.

[override virtual protected] void PosCache::onText(MD::Text *t)

Reimplements: Visitor::onText(MD::Text *t).

Cache text item.

t Text.

[override virtual protected] void PosCache::onUserDefined(MD::Item *i)

Reimplements: Visitor::onUserDefined(MD::Item *item).

Cache user defined item.

i Item.

Member Variable Documentation

QVector<QSharedPointer<MD::details::PosRange>> PosCache::m_cache

Cache.

bool PosCache::m_skipInCache

Skip adding in cache.