KTextTemplate

cachingloaderdecorator.cpp
1/*
2 This file is part of the KTextTemplate library
3
4 SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7
8*/
9
10#include "cachingloaderdecorator.h"
11
12namespace KTextTemplate
13{
14
15class CachingLoaderDecoratorPrivate
16{
17public:
18 CachingLoaderDecoratorPrivate(QSharedPointer<AbstractTemplateLoader> loader, CachingLoaderDecorator *qq)
19 : q_ptr(qq)
20 , m_wrappedLoader(loader)
21 {
22 }
23
24 Q_DECLARE_PUBLIC(CachingLoaderDecorator)
25 CachingLoaderDecorator *const q_ptr;
26
27 const QSharedPointer<AbstractTemplateLoader> m_wrappedLoader;
28
29 mutable QHash<QString, Template> m_cache;
30};
31}
32
33using namespace KTextTemplate;
34
36 : d_ptr(new CachingLoaderDecoratorPrivate(loader, this))
37{
38}
39
44
46{
48 return d->m_wrappedLoader->canLoadTemplate(name);
49}
50
52{
54 return d->m_cache.clear();
55}
56
58{
60 return d->m_cache.size();
61}
62
64{
66 return d->m_cache.isEmpty();
67}
68
69std::pair<QString, QString> CachingLoaderDecorator::getMediaUri(const QString &fileName) const
70{
72 return d->m_wrappedLoader->getMediaUri(fileName);
73}
74
76{
78 const auto it = d->m_cache.constFind(name);
79 if (it != d->m_cache.constEnd()) {
80 return it.value();
81 }
82
83 const auto t = d->m_wrappedLoader->loadByName(name, engine);
84
85 d->m_cache.insert(name, t);
86
87 return t;
88}
Implements a loader decorator which caches compiled Template objects.
CachingLoaderDecorator(QSharedPointer< AbstractTemplateLoader > loader)
Constructor.
Template loadByName(const QString &name, const KTextTemplate::Engine *engine) const override
Load a Template called name.
std::pair< QString, QString > getMediaUri(const QString &fileName) const override
Return a complete URI for media identified by fileName.
void clear()
Clears the Templates objects cached in the decorator.
bool canLoadTemplate(const QString &name) const override
Return true if a Template identified by name exists and can be loaded.
int size() const
Returns the number of Template objects cached in the decorator.
bool isEmpty() const
Returns whether the cache is empty.
KTextTemplate::Engine is the main entry point for creating KTextTemplate Templates.
Definition engine.h:110
The Template class is a tree of nodes which may be rendered.
Definition template.h:85
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:10:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.