<commit_before>//
// Copyright (c) 2013-2014 <NAME>
// See LICENSE for more information.
//

#ifndef MLK_LOG_ERROR_HANDLER_H
#define MLK_LOG_ERROR_HANDLER_H


#include <mlk/containers/error_container.h>


namespace mlk
{
	namespace logger
	{
		namespace internal
		{
			class error_handler
			{
				cnt::error_container m_cnt;

			public:
				void set_error_container(const cnt::error_container& cnt)
				{m_cnt = cnt;}

				template<typename T>
				void try_call(T error_code) const noexcept
				{
					int index{m_cnt.find(error_code)};
					if(index != -1)
						m_cnt.get(index)->call();
				}

				template<typename T>
				std::string error_str(T error_code) const noexcept
				{
					int index{m_cnt.find(error_code)};
					if(index != -1)
						return m_cnt.get(index)->msg();

					return "";
				}

				template<typename T>
                void link_error(T error_code, const std::string& msg, const mlk::slot<void>& fnc = {})
				{m_cnt.link(error_code, msg, fnc);}

				template<typename T>
				void link_error(const cnt::error_type<T>& error)
				{m_cnt.link(error);}

				template<typename T>
				cnt::error_type<T> get_error(T error_code) const noexcept
				{
					auto index(m_cnt.find(error_code));
					if(index == -1)
						throw std::runtime_error{"mlk::[...]::error_handler: error_code not found"};
					return *m_cnt.get_casted<T>(index);
				}<commit_msg>removing that void<commit_after>//
// Copyright (c) 2013-2014 <NAME>
// See LICENSE for more information.
//

#ifndef MLK_LOG_ERROR_HANDLER_H
#define MLK_LOG_ERROR_HANDLER_H


#include <mlk/containers/error_container.h>


namespace mlk
{
	namespace logger
	{
		namespace internal
		{
			class error_handler
			{
				cnt::error_container m_cnt;

			public:
				void set_error_container(const cnt::error_container& cnt)
				{m_cnt = cnt;}

				template<typename T>
				void try_call(T error_code) const noexcept
				{
					int index{m_cnt.find(error_code)};
					if(index != -1)
						m_cnt.get(index)->call();
				}

				template<typename T>
				std::string error_str(T error_code) const noexcept
				{
					int index{m_cnt.find(error_code)};
					if(index != -1)
						return m_cnt.get(index)->msg();

					return "";
				}

				template<typename T>
				void link_error(T error_code, const std::string& msg, const mlk::slot<>& fnc = {})
				{m_cnt.link(error_code, msg, fnc);}

				template<typename T>
				void link_error(const cnt::error_type<T>& error)
				{m_cnt.link(error);}

				template<typename T>
				cnt::error_type<T> get_error(T error_code) const noexcept
				{
					auto index(m_cnt.find(error_code));
					if(index == -1)
						throw std::runtime_error{"mlk::[...]::error_handler: error_code not found"};
					return *m_cnt.get_casted<T>(index);
				}
{'fraction_non_alphanumeric': 0.13270142180094788, 'fraction_numerical': 0.008020415603353991, 'mean_word_length': 3.2542635658914727, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3722042', 'n_tokens_mistral': 1239, 'n_tokens_neox': 977, 'n_words': 198}