<commit_before>//
//  mcbNotificationHandler.h
//  SoundSurfer
//
//  Created by <NAME> on 1/23/14.
//
//

#ifndef __mcb__utils__mcbNotificationHandler__
#define __mcb__utils__mcbNotificationHandler__

#include "cocos2d.h"
namespace mcb{ namespace PlatformSupport{
    class NotificationHandler;
    typedef std::shared_ptr<NotificationHandler> pNotificationHandler;
    class NotificationHandler : public cocos2d::CCObject{
        std::map<std::string, std::pair<std::function<void()>, cocos2d::CCString *>> _handlers;
    public:
        static pNotificationHandler create(){return std::make_shared<NotificationHandler>();}
        void _notificationReceived(cocos2d::CCString * name){
            if (!name)
                return;
            auto it(_handlers.find(name->m_sString));
            if (it!=_handlers.end())
                it->second.first();
        }
        void addNotificationHandler(const std::string & name, const std::function<void()>& handler){
            using namespace cocos2d;
            removeNotificationHandler(name);
            CCString * nameS(CCString::create(name));
            nameS->retain();
            
            _handlers[name]={handler, nameS};
            
            CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(NotificationHandler::_notificationReceived), name.c_str(), nameS);
        }
        void removeNotificationHandler(const std::string & name){
            using namespace cocos2d;
            auto it(_handlers.find(name));
            if (it!=_handlers.end()) {
                CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, it->first.c_str());
                it->second.second->release();
                _handlers.erase(it);
            }
        }
        virtual ~NotificationHandler(){
            auto handlersCopy(_handlers);
            for (const auto &p : handlersCopy)
                removeNotificationHandler(p.first);
        }
    };
}}
#endif /* defined(__mcb__utils__mcbNotificationHandler__) */<commit_msg>Notification base class wrapper for convenience<commit_after>//
//  mcbNotificationHandler.h
//  SoundSurfer
//
//  Created by <NAME> on 1/23/14.
//
//

#ifndef __mcb__utils__mcbNotificationHandler__
#define __mcb__utils__mcbNotificationHandler__

#include "cocos2d.h"
namespace mcb{ namespace PlatformSupport{
    class NotificationHandler;
    typedef std::shared_ptr<NotificationHandler> pNotificationHandler;
    class NotificationHandler : public cocos2d::CCObject{
        std::map<std::string, std::pair<std::function<void()>, cocos2d::CCString *>> _handlers;
    public:
        static pNotificationHandler create(){return std::make_shared<NotificationHandler>();}
        void _notificationReceived(cocos2d::CCString * name){
            if (!name)
                return;
            auto it(_handlers.find(name->m_sString));
            if (it!=_handlers.end())
                it->second.first();
        }
        void addNotificationHandler(const std::string & name, const std::function<void()>& handler){
            using namespace cocos2d;
            removeNotificationHandler(name);
            CCString * nameS(CCString::create(name));
            nameS->retain();
            
            _handlers[name]={handler, nameS};
            
            CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(NotificationHandler::_notificationReceived), name.c_str(), nameS);
        }
        void removeNotificationHandler(const std::string & name){
            using namespace cocos2d;
            auto it(_handlers.find(name));
            if (it!=_handlers.end()) {
                CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, it->first.c_str());
                it->second.second->release();
                _handlers.erase(it);
            }
        }
        virtual ~NotificationHandler(){
            auto handlersCopy(_handlers);
            for (const auto &p : handlersCopy)
                removeNotificationHandler(p.first);
        }
    };
    
    //base class for more convenience
    class Notification{
        pNotificationHandler _notificationHandler=nullptr;
    public:
        Notification(){_notificationHandler=NotificationHandler::create();}
        virtual ~Notification()=default;
    protected:
        virtual void addNotificationHandler(const std::string & name, const std::function<void()>& handler){
            _notificationHandler->addNotificationHandler(name, handler);
        }
        virtual void removeNotificationHandler(const std::string & name){
            _notificationHandler->removeNotificationHandler(name);
        }
    };

}}
#endif /* defined(__mcb__utils__mcbNotificationHandler__) */
{'fraction_non_alphanumeric': 0.11334590404357846, 'fraction_numerical': 0.004609260423213911, 'mean_word_length': 2.744313725490196, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 36, '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': '928432', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1217, 'n_words': 223}