<commit_before>//
// Created by zakrent on 7/17/17.
//

#ifndef GAME_4_BASEENTITY_H
#define GAME_4_BASEENTITY_H

#include <unordered_map>
#include <memory>
#include "../misc/types.h"
#include "components/BaseComponent.h"

namespace Entity {
    class Entity {
        //int64 int ID;
        bool shouldBeDestroyed;
        std::unordered_map<std::string, std::unique_ptr<BaseComponent> > components;
    public:
        void addComponent(std::unique_ptr<BaseComponent> componentPtr){
            BaseComponent* component = componentPtr.get();
            components[component->name] = std::move(componentPtr);
        };
        template<typename T>
        T* getComponent(std::string name)
        {
            auto got = components.find(name);
            if (got == components.end())
                return nullptr;
            BaseComponent* component = got->second.get();
            return dynamic_cast<T*>(component);
        }
        void destroy(){shouldBeDestroyed = true;};

        Entity(){};
    };
}


#endif //GAME_4_BASEENTITY_H<commit_msg>Fixed component casting and adding.<commit_after>//
// Created by zakrent on 7/17/17.
//

#ifndef GAME_4_BASEENTITY_H
#define GAME_4_BASEENTITY_H

#include <unordered_map>
#include <memory>
#include "../misc/types.h"
#include "components/BaseComponent.h"

namespace Entity {
    class Entity {
        //int64 int ID;
        bool shouldBeDestroyed;
        std::unordered_map<std::string, std::unique_ptr<BaseComponent> > components;
    public:
        void addComponent(std::unique_ptr<BaseComponent> component)
        {
            components[component.get()->name] = std::move(component);
        }
        template<typename T>
        T* getComponent(std::string name)
        {
            auto got = components.find(name);
            if (got == components.end())
                return nullptr;
            return static_cast<T*>(got->second.get());
        }
        void destroy(){shouldBeDestroyed = true;};

        Entity(){};
    };
}


#endif //GAME_4_BASEENTITY_H
{'fraction_non_alphanumeric': 0.12536728697355534, 'fraction_numerical': 0.009794319294809012, 'mean_word_length': 2.528497409326425, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '3582266', 'n_tokens_mistral': 613, 'n_tokens_neox': 598, 'n_words': 123}