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

#include <stdexcept>

namespace InputXSLT {

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

DomDocumentCache::optional_item DomDocumentCache::get(const std::string& key) {
	auto itemIter = this->map_.find(key);

	if ( itemIter == this->map_.end() ) {
		return optional_item(false, nullptr);
	} else {
		return optional_item(true, (*itemIter).second->getXalanDocument());
	}
}

DomDocumentCache::optional_item DomDocumentCache::create(
	const std::string&    key,
	xercesc::DOMDocument* document
) {
	std::lock_guard<std::mutex> guard(this->write_mutex_);

	auto result = this->map_.emplace(
		std::make_pair(key, std::unique_ptr<item>(new item(document)))
	);

	if ( result.second ) {
		return optional_item(true, (*(result.first)).second->getXalanDocument());
	} else {
		return optional_item(false, nullptr);
	}
}

}