diff options
Diffstat (limited to 'src/support/dom')
-rw-r--r-- | src/support/dom/document_cache.cc | 28 | ||||
-rw-r--r-- | src/support/dom/document_cache.h | 15 | ||||
-rw-r--r-- | src/support/dom/document_cache_item.cc | 10 | ||||
-rw-r--r-- | src/support/dom/document_cache_item.h | 6 |
4 files changed, 45 insertions, 14 deletions
diff --git a/src/support/dom/document_cache.cc b/src/support/dom/document_cache.cc index 0ad540c..23805b5 100644 --- a/src/support/dom/document_cache.cc +++ b/src/support/dom/document_cache.cc @@ -1,19 +1,43 @@ #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( + nullptr, + *XercesStringGuard<XMLCh>("content"), + nullptr + ) + ); +} + DomDocumentCache::DomDocumentCache(): write_mutex_(), cache_() { } -xalan::XalanDocument* DomDocumentCache::create(xercesc::DOMDocument* document) { +xalan::XalanDocument* DomDocumentCache::create(document_ptr&& document) { std::lock_guard<std::mutex> guard(this->write_mutex_); - this->cache_.emplace(new item(document)); + this->cache_.emplace( + new item( + std::move(document) + ) + ); return this->cache_.top()->getXalanDocument(); } +void DomDocumentCache::document_deleter::operator()( + xercesc::DOMDocument* document) { + document->release(); +} + } diff --git a/src/support/dom/document_cache.h b/src/support/dom/document_cache.h index 1f9a9e3..3aeb332 100644 --- a/src/support/dom/document_cache.h +++ b/src/support/dom/document_cache.h @@ -14,10 +14,23 @@ namespace InputXSLT { class DomDocumentCache { + class document_deleter { + friend std::unique_ptr<xercesc::DOMDocument, document_deleter>; + + void operator()(xercesc::DOMDocument*); + }; + public: + typedef std::unique_ptr< + xercesc::DOMDocument, + document_deleter + > document_ptr; + + static document_ptr createDocument(); + DomDocumentCache(); - xalan::XalanDocument* create(xercesc::DOMDocument*); + xalan::XalanDocument* create(document_ptr&&); private: class item; diff --git a/src/support/dom/document_cache_item.cc b/src/support/dom/document_cache_item.cc index 9798bfa..a684d97 100644 --- a/src/support/dom/document_cache_item.cc +++ b/src/support/dom/document_cache_item.cc @@ -2,20 +2,16 @@ namespace InputXSLT { -DomDocumentCache::item::item(xercesc::DOMDocument* document): +DomDocumentCache::item::item(document_ptr&& document): + document_(std::move(document)), parser_(), dom_support_(parser_), - document_(document), parsed_source_( - document_, + document_.get(), parser_, dom_support_ ) { } -DomDocumentCache::item::~item() { - this->document_->release(); -} - xalan::XalanDocument* DomDocumentCache::item::getXalanDocument() { return this->parsed_source_.getDocument(); } diff --git a/src/support/dom/document_cache_item.h b/src/support/dom/document_cache_item.h index 13fddfc..ebc9172 100644 --- a/src/support/dom/document_cache_item.h +++ b/src/support/dom/document_cache_item.h @@ -14,19 +14,17 @@ namespace InputXSLT { class DomDocumentCache::item { public: - ~item(); - xalan::XalanDocument* getXalanDocument(); protected: friend DomDocumentCache; - item(xercesc::DOMDocument*); + item(document_ptr&&); private: + document_ptr document_; xalan::XercesParserLiaison parser_; xalan::XercesDOMSupport dom_support_; - xercesc::DOMDocument* const document_; xalan::XercesDOMWrapperParsedSource parsed_source_; }; |