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

#ifndef RJ_SHARED_LEVEL_MANAGER_LEVEL_MANAGER_HPP
#define RJ_SHARED_LEVEL_MANAGER_LEVEL_MANAGER_HPP


#include "level.hpp"
#include "packer_pack.hpp"
#include "packer_unpack.hpp"

#include <mlk/filesystem/filesystem.h>

#include <map>
#include <string>


namespace rj
{
	using level_id = std::string;

	class level_manager
	{
		mlk::fs::dir_handle m_dirh;
		mlk::fs::file_handle m_filemgr;
		const std::string& m_abs_path;

		std::map<level_id, level> m_loaded_levels;

	public:
		level_manager(const std::string& abs_level_path) :
			m_dirh{abs_level_path},
			m_abs_path{m_dirh.get_path()}
		{this->init();}

		const level& load_level(const level_id& id)
		{
			this->load_to_mgr(id, this->make_path(id));
			if(m_loaded_levels.find(id) == std::end(m_loaded_levels))
				throw std::runtime_error{"error while open level"};
			return m_loaded_levels[id];
		}

		bool save_level(const level_packer<packer_mode::pack>& lv, const level_id& id)
		{
			if(!m_filemgr.reopen(this->make_path(id), std::ios::out | std::ios::trunc))
				return false;
			m_filemgr.write(lv.packed_data());
			m_filemgr.close();
			return true;
		}

		const level& get_level(const level_id& id) const noexcept
		{return m_loaded_levels.at(this->make_id(id));}

		auto get_levels() const noexcept
		-> const decltype(m_loaded_levels)&
		{return m_loaded_levels;}<commit_msg>level_manager: removed noexcept<commit_after>//
// Copyright (c) 2013-2014 <NAME>
// See LICENSE for more information.
//

#ifndef RJ_SHARED_LEVEL_MANAGER_LEVEL_MANAGER_HPP
#define RJ_SHARED_LEVEL_MANAGER_LEVEL_MANAGER_HPP


#include "level.hpp"
#include "packer_pack.hpp"
#include "packer_unpack.hpp"

#include <mlk/filesystem/filesystem.h>

#include <map>
#include <string>


namespace rj
{
	using level_id = std::string;

	class level_manager
	{
		mlk::fs::dir_handle m_dirh;
		mlk::fs::file_handle m_filemgr;
		const std::string& m_abs_path;

		std::map<level_id, level> m_loaded_levels;

	public:
		level_manager(const std::string& abs_level_path) :
			m_dirh{abs_level_path},
			m_abs_path{m_dirh.get_path()}
		{this->init();}

		const level& load_level(const level_id& id)
		{
			this->load_to_mgr(id, this->make_path(id));
			if(m_loaded_levels.find(id) == std::end(m_loaded_levels))
				throw std::runtime_error{"error while open level"};
			return m_loaded_levels[id];
		}

		bool save_level(const level_packer<packer_mode::pack>& lv, const level_id& id)
		{
			if(!m_filemgr.reopen(this->make_path(id), std::ios::out | std::ios::trunc))
				return false;
			m_filemgr.write(lv.packed_data());
			m_filemgr.close();
			return true;
		}

		const level& get_level(const level_id& id) const
		{return m_loaded_levels.at(this->make_id(id));}

		auto get_levels() const noexcept
		-> const decltype(m_loaded_levels)&
		{return m_loaded_levels;}
{'fraction_non_alphanumeric': 0.1360332294911734, 'fraction_numerical': 0.005538248528902735, 'mean_word_length': 5.310043668122271, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '2492694', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1124, 'n_words': 198}