aboutsummaryrefslogtreecommitdiff
path: root/src/support/error/error_capacitor.cc
blob: 22ec45dce7c0b257a31118879007c7f17ad2b016 (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
#include "error_capacitor.h"

namespace InputXSLT {

ErrorCapacitor::ErrorCapacitor(ErrorMultiplexer* multiplexer):
	ErrorMultiplexer::receiver(multiplexer),
	error_cache_(std::make_unique<error_cache>()) { }

void ErrorCapacitor::discharge() {
	if ( !this->error_cache_->empty() ) {
		throw exception(std::move(this->error_cache_));
	}
}

void ErrorCapacitor::receive(
	const ErrorMultiplexer::error_type type,
	const std::string& message
) {
	if ( type == ErrorMultiplexer::error_type::error ) {
		this->error_cache_->emplace_back(message);
	}
}

ErrorCapacitor::exception::exception(std::unique_ptr<error_cache> ptr):
	error_cache_(std::move(ptr)) { }

auto ErrorCapacitor::exception::operator*() const -> const error_cache& {
	return *(this->error_cache_.get());
}

}