aboutsummaryrefslogtreecommitdiff
path: root/src/support/dom/document_cache.cc
blob: 01332341b88d163ccf1e655647139324af289d7b (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
50
#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(),
		[](xercesc::DOMDocument* ptr) {
			ptr->release();
		}
	);
}

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

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

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

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

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

}