aboutsummaryrefslogtreecommitdiff
path: root/src/support/dom/document_cache.cc
blob: c18bf966adc9aa3ff37457290df0c9bbf751214a (plain)
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
#include "document_cache.h"

#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMImplementation.hpp>

#include <stdexcept>

#include "support/xerces_string_guard.h"

namespace InputXSLT {

auto DomDocumentCache::createDocument() -> document_ptr {
	return document_ptr(
		xercesc::DOMImplementation::getImplementation()->createDocument()
	);
}

auto DomDocumentCache::createDocument(const std::string& name) -> document_ptr {
	return document_ptr(
		xercesc::DOMImplementation::getImplementation()->createDocument(
			nullptr,
			*XercesStringGuard<XMLCh>(name),
			nullptr
		)
	);
}

DomDocumentCache::DomDocumentCache():
	write_mutex_(),
	cache_() { }

xalan::XalanDocument* DomDocumentCache::create(document_ptr&& document) {
	std::lock_guard<std::mutex> guard(this->write_mutex_);

	this->cache_.emplace(
		new item(
			std::move(document)
		)
	);

	return this->cache_.top()->getXalanDocument();
}

void DomDocumentCache::document_deleter::operator()(
	xercesc::DOMDocument* document) {
	document->release();
}

}