aboutsummaryrefslogtreecommitdiff
path: root/src/support/xerces_string_guard.h
blob: 9c354497d2613a0d9a6f92e87268e29350132a8d (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
#ifndef INPUTXSLT_SRC_SUPPORT_XERCES_STRING_GUARD_H_
#define INPUTXSLT_SRC_SUPPORT_XERCES_STRING_GUARD_H_

#include <xercesc/util/XMLString.hpp>

#include <string>

namespace InputXSLT {

template <typename Type>
class XercesStringGuard {
	public:
		XercesStringGuard(const Type* src):
			string_(src) { }

		XercesStringGuard(
			const std::basic_string<
				typename std::remove_pointer<decltype(
					xercesc::XMLString::transcode(new Type[1])
				)>::type
			>& src
		):
			string_(xercesc::XMLString::transcode(src.data())) { }

		~XercesStringGuard() {
			xercesc::XMLString::release(
				const_cast<Type**>(&this->string_)
			);
		}

		const Type* operator*() const {
			return this->string_;
		}

	private:
		const Type* const string_;

};

}

#endif  // INPUTXSLT_SRC_SUPPORT_XERCES_STRING_GUARD_H_