forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateCache.h
More file actions
105 lines (80 loc) · 2.2 KB
/
TemplateCache.h
File metadata and controls
105 lines (80 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// TemplateCache.h
//
// Library: JSON
// Package: JSON
// Module: TemplateCache
//
// Definition of the TemplateCache class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef JSON_JSONTemplateCache_INCLUDED
#define JSON_JSONTemplateCache_INCLUDED
#include "Poco/JSON/JSON.h"
#include "Poco/JSON/Template.h"
#include "Poco/Path.h"
#include "Poco/SharedPtr.h"
#include "Poco/Logger.h"
#include <vector>
#include <map>
namespace Poco {
namespace JSON {
class JSON_API TemplateCache
/// Use to cache parsed templates. Templates are
/// stored in a map with the full path as key.
/// When a template file has changed, the cache
/// will remove the old template from the cache
/// and load a new one.
{
public:
TemplateCache();
/// Creates an empty TemplateCache.
///
/// The cache must be created and not destroyed
/// as long as it is used.
virtual ~TemplateCache();
/// Destroys the TemplateCache.
void addPath(const Path& path);
/// Add a path for resolving template paths.
/// The order of check is FIFO.
Template::Ptr getTemplate(const Path& path);
/// Returns a template from the cache.
/// When the template file is not yet loaded
/// or when the file has changed, the template
/// will be (re)loaded and parsed. A shared pointer
/// is returned, so it is safe to use this template
/// even when the template isn't stored anymore in
/// the cache.
static TemplateCache* instance();
/// Returns the only instance of this cache.
void setLogger(Logger& logger);
/// Sets the logger for the cache.
private:
void setup();
Path resolvePath(const Path& path) const;
static TemplateCache* _pInstance;
std::vector<Path> _includePaths;
std::map<std::string, Template::Ptr> _cache;
Logger* _pLogger;
};
//
// inlines
//
inline void TemplateCache::addPath(const Path& path)
{
_includePaths.push_back(path);
}
inline TemplateCache* TemplateCache::instance()
{
return _pInstance;
}
inline void TemplateCache::setLogger(Logger& logger)
{
_pLogger = &logger;
}
} } // namespace Poco::JSON
#endif // JSON_JSONTemplateCache_INCLUDED