MD::PosCache Class

template <typename Trait> 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

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

Protected Functions

void findFirstInCache(const std::vector<std::shared_ptr<MD::details::PosRange<Trait>>> &vec, const MD::details::PosRange<Trait> &pos, MD::PosCache<Trait>::Items &res) const
MD::details::PosRange<Trait> *findInCache(const std::vector<std::shared_ptr<MD::details::PosRange<Trait>>> &vec, const MD::details::PosRange<Trait> &pos, bool ordered = false) const
void insertInCache(const MD::details::PosRange<Trait> &item, bool sort = false, bool insertInStack = false)
void onBlockquote(MD::Blockquote<Trait> *b) override
void onCode(MD::Code<Trait> *c) override
void onFootnote(MD::Footnote<Trait> *f) override
void onFootnoteRef(MD::FootnoteRef<Trait> *ref) override
void onHeading(MD::Heading<Trait> *h) override
void onHorizontalLine(MD::HorizontalLine<Trait> *l) override
void onImage(MD::Image<Trait> *i) override
void onInlineCode(MD::Code<Trait> *c) override
void onLink(MD::Link<Trait> *l) override
void onList(MD::List<Trait> *l) override
void onListItem(MD::ListItem<Trait> *l, bool first) override
void onMath(MD::Math<Trait> *m) override
void onParagraph(MD::Paragraph<Trait> *p, bool wrap) override
void onRawHtml(MD::RawHtml<Trait> *h) override
virtual void onReferenceLink(MD::Link<Trait> *l)
void onTable(MD::Table<Trait> *t) override
void onText(MD::Text<Trait> *t) override
void onUserDefined(MD::Item<Trait> *i) override

Protected Variables

std::vector<std::shared_ptr<MD::details::PosRange<Trait>>> 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

MD::PosCache<Trait>::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 std::vector<std::shared_ptr<MD::details::PosRange<Trait>>> &vec, const MD::details::PosRange<Trait> &pos, MD::PosCache<Trait>::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<Trait> *PosCache::findInCache(const std::vector<std::shared_ptr<MD::details::PosRange<Trait>>> &vec, const MD::details::PosRange<Trait> &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(std::shared_ptr<MD::Document<Trait>> doc)

Initialize m_cache with the given document.

Note: Document should not be recursive.

doc Document.

[protected] void PosCache::insertInCache(const MD::details::PosRange<Trait> &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.

[protected] void PosCache::onBlockquote(MD::Blockquote<Trait> *b)

Cache blockquote.

b Blockquote.

[protected] void PosCache::onCode(MD::Code<Trait> *c)

Cache code.

c Code.

[protected] void PosCache::onFootnote(MD::Footnote<Trait> *f)

Cache footnote.

f Footnote.

[protected] void PosCache::onFootnoteRef(MD::FootnoteRef<Trait> *ref)

Cache footnote reference.

ref Footnote reference.

[protected] void PosCache::onHeading(MD::Heading<Trait> *h)

Cache heading.

h Heading.

[protected] void PosCache::onHorizontalLine(MD::HorizontalLine<Trait> *l)

Cache horizontal line.

l Horizontal line.

[protected] void PosCache::onImage(MD::Image<Trait> *i)

Cache image.

i Image.

[protected] void PosCache::onInlineCode(MD::Code<Trait> *c)

Cache inline code.

c Code.

Cache link.

l Link.

[protected] void PosCache::onList(MD::List<Trait> *l)

Cache list.

l List.

[protected] void PosCache::onListItem(MD::ListItem<Trait> *l, bool first)

Cache list item.

l List item.

first Is this item first in the list?

[protected] void PosCache::onMath(MD::Math<Trait> *m)

Cache LaTeX math expression.

m Math.

[protected] void PosCache::onParagraph(MD::Paragraph<Trait> *p, bool wrap)

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.

[protected] void PosCache::onRawHtml(MD::RawHtml<Trait> *h)

Cache raw HTML.

h Raw HTML.

Cache shortcut link.

l Link.

[protected] void PosCache::onTable(MD::Table<Trait> *t)

Cache table.

t Table.

[protected] void PosCache::onText(MD::Text<Trait> *t)

Cache text item.

t Text.

[protected] void PosCache::onUserDefined(MD::Item<Trait> *i)

Cache user defined item.

i Item.

Member Variable Documentation

std::vector<std::shared_ptr<MD::details::PosRange<Trait>>> PosCache::m_cache

Cache.

bool PosCache::m_skipInCache

Skip adding in cache.