blob: c4c57d3c82524cdd79bd7c095e35274dc951ed88 (
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.get());
}
}
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.get());
} else {
return optional_item(false, nullptr);
}
}
}
|