<commit_before>/*
 * Copyright (c) 2014, webvariants GmbH, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * @author: <NAME> (<EMAIL>)
 */

#ifndef __COMPONENTMANAGER__
#define __COMPONENTMANAGER__

#include "util/Any.h"
#include "world/Component.h"

#include <functional>

namespace Susi {
namespace System {

	class ComponentManager {
	protected:
		typedef std::function<std::shared_ptr<Component>(Susi::Util::Any & config)> RegisterFunction;
		struct ComponentData {
			std::shared_ptr<Component> component{nullptr};
			bool running = false;
		};
		Susi::Util::Any::Object config;
		std::map<std::string,RegisterFunction> registerFunctions;
		std::map<std::string,ComponentData> components;
		std::map<std::string,std::vector<std::string>> dependencies;
		std::map<std::string,std::vector<std::string>> inverseDependencies;
	public:

		ComponentManager(Susi::Util::Any::Object config) : config{config} {}

		void registerComponent(std::string name, RegisterFunction func);
		void registerDependency(std::string subject, std::string dependency);
		bool loadComponent(std::string name);
		bool unloadComponent(std::string name);
		bool startComponent(std::string name);
		bool stopComponent(std::string name);
	};
}

}

#endif // __COMPONENTMANAGER__<commit_msg>[component manager] added getComponent template function;<commit_after>/*
 * Copyright (c) 2014, webvariants GmbH, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * @author: <NAME> (<EMAIL>)
 */

#ifndef __COMPONENTMANAGER__
#define __COMPONENTMANAGER__

#include "util/Any.h"
#include "world/Component.h"

#include <functional>

namespace Susi {
namespace System {

	class ComponentManager {
	protected:
		typedef std::function<std::shared_ptr<Component>(Susi::Util::Any & config)> RegisterFunction;
		struct ComponentData {
			std::shared_ptr<Component> component{nullptr};
			bool running = false;
		};
		Susi::Util::Any::Object config;
		std::map<std::string,RegisterFunction> registerFunctions;
		std::map<std::string,ComponentData> components;
		std::map<std::string,std::vector<std::string>> dependencies;
		std::map<std::string,std::vector<std::string>> inverseDependencies;
	public:

		ComponentManager(Susi::Util::Any::Object config) : config{config} {}

		void registerComponent(std::string name, RegisterFunction func);
		void registerDependency(std::string subject, std::string dependency);
		bool loadComponent(std::string name);
		bool unloadComponent(std::string name);
		bool startComponent(std::string name);
		bool stopComponent(std::string name);

		template<class T=Component>
		std::shared_ptr<T> getComponent(std::string name){
			if(components.find(name) == components.end() && !loadComponent(name)){
				return std::shared_ptr<T>{};
			}
			return std::dynamic_pointer_cast<T>(components[name].component);
		}	
	};
}

}

#endif // __COMPONENTMANAGER__
{'fraction_non_alphanumeric': 0.13808184942205562, 'fraction_numerical': 0.002499218994064355, 'mean_word_length': 6.084070796460177, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '393341', 'n_tokens_mistral': 1052, 'n_tokens_neox': 964, 'n_words': 220}