<commit_before>#ifndef KEYBOARDMANAGER_HPP
#define KEYBOARDMANAGER_HPP

#include <map>
#include <string>
#include <functional>

#include <SFML/Window/Event.hpp>
#include <SFML/Window/Keyboard.hpp>

namespace swift
{
	class KeyboardManager
	{
		public:
			KeyboardManager() {};
			~KeyboardManager() {};

			void newBinding(const std::string& n, sf::Keyboard::Key k, std::function<void()> f = [](){return true;}, bool onPress = false)
			{
				bindings.emplace(std::make_pair(n, KeyBinding(k, f, onPress)));
			}

			bool operator()(sf::Event& e)
			{
				for(auto &k : bindings)
				{
					if(k.second(e))
						return k.second(e);
				}
				
				return false;
			}

		private:
			class KeyBinding
			{
				public:
					explicit KeyBinding(sf::Keyboard::Key k, std::function<void()> f, bool p)
					{
						key = k;
						onPress = p;
						func = f;
					}

					~KeyBinding()
					{
					}

					sf::Keyboard::Key getKey() const
					{
						return key;
					}

					bool operator()(sf::Event& e)
					{
						if(e.key.code == key)
						{
							if(onPress)
							{
								if(e.type == sf::Event::KeyPressed)
								{
									return this->call();
								}
							}
							else
							{
								if(e.type == sf::Event::KeyReleased)
								{
									return this->call();
								}
							}
						}
						return false;
					}

				private:
					bool call()
					{
						if(!func)
							return false;

						func();

						return true;
					}

					sf::Keyboard::Key key;

					std::function<void()> func;

					bool onPress;	// if true, means if key is pressed, if false, means if key is released
			};

			std::map<std::string, KeyBinding> bindings;
	};
}

#endif // KEYBOARDMANAGER_HPP
<commit_msg>Fixed a dual-call bug<commit_after>#ifndef KEYBOARDMANAGER_HPP
#define KEYBOARDMANAGER_HPP

#include <map>
#include <string>
#include <functional>

#include <SFML/Window/Event.hpp>
#include <SFML/Window/Keyboard.hpp>

namespace swift
{
	class KeyboardManager
	{
		public:
			KeyboardManager() {};
			~KeyboardManager() {};

			void newBinding(const std::string& n, sf::Keyboard::Key k, std::function<void()> f = [](){return true;}, bool onPress = false)
			{
				bindings.emplace(std::make_pair(n, KeyBinding(k, f, onPress)));
			}

			bool operator()(sf::Event& e)
			{
				for(auto &k : bindings)
				{
					if(k.second(e))
						return k.second.call();
				}
				
				return false;
			}

		private:
			class KeyBinding
			{
				public:
					explicit KeyBinding(sf::Keyboard::Key k, std::function<void()> f, bool p)
					{
						key = k;
						onPress = p;
						func = f;
					}

					~KeyBinding()
					{
					}

					sf::Keyboard::Key getKey() const
					{
						return key;
					}

					bool operator()(sf::Event& e)
					{
						if(e.key.code == key)
						{
							if(onPress)
							{
								if(e.type == sf::Event::KeyPressed)
								{
									return true;
								}
							}
							else
							{
								if(e.type == sf::Event::KeyReleased)
								{
									return true;
								}
							}
						}
						return false;
					}
					
					bool call()
					{
						if(!func)
							return false;

						func();

						return true;
					}

				private:
					sf::Keyboard::Key key;

					std::function<void()> func;

					bool onPress;	// if true, means if key is pressed, if false, means if key is released
			};

			std::map<std::string, KeyBinding> bindings;
	};
}

#endif // KEYBOARDMANAGER_HPP

{'fraction_non_alphanumeric': 0.14398595258999122, 'fraction_numerical': 0.0, 'mean_word_length': 2.0167696381288613, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '4252765', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1178, 'n_words': 249}