<commit_before>#ifndef __DARC_COMPONENT_REGISTER_H_INCLUDED_
#define __DARC_COMPONENT_REGISTER_H_INCLUDED_

#include <map>
#include <iostream>
#include <darc/component.h>
#include <darc/node.h>

namespace darc
{

class ComponentRegister
{
private:
  typedef boost::function<Component::Ptr(const std::string&, Node::Ptr)> InstantiateComponentMethod;
  typedef std::map<const std::string, InstantiateComponentMethod> ComponentListType;
  
  ComponentListType component_list_;

  static ComponentRegister * instance_;

private:
  ComponentRegister() {}

  static ComponentRegister * instance()
  {
    if( instance_ == 0 )
    {
      instance_ = new ComponentRegister();
    }
    return instance_;
  }

public:
  static int registerComponent( const std::string& component_name, InstantiateComponentMethod method )
  {
    ComponentRegister * inst = instance();
    inst->component_list_[component_name] = method;
    std::cout << "Registered Component: " << component_name << std::endl;
    return 1;
  }

  static darc::Component::Ptr instantiateComponent( const std::string& instance_name, Node::Ptr node )
  {
    ComponentRegister * inst = instance();
    if( inst->component_list_.count(instance_name) )
    {
      return inst->component_list_[instance_name](instance_name, node);
    }
    else
    {
      assert(0);
      darc::Component::Ptr n;
      return n;
    }
  }

};

}
<commit_msg>added DARC_REGISTER_COMPONENT macro<commit_after>#ifndef __DARC_COMPONENT_REGISTER_H_INCLUDED_
#define __DARC_COMPONENT_REGISTER_H_INCLUDED_

#include <map>
#include <iostream>
#include <darc/component.h>
#include <darc/node.h>

namespace darc
{

class ComponentRegister
{
private:
  typedef boost::function<Component::Ptr(const std::string&, Node::Ptr)> InstantiateComponentMethod;
  typedef std::map<const std::string, InstantiateComponentMethod> ComponentListType;
  
  ComponentListType component_list_;

  static ComponentRegister * instance_;

private:
  ComponentRegister() {}

  static ComponentRegister * instance()
  {
    if( instance_ == 0 )
    {
      instance_ = new ComponentRegister();
    }
    return instance_;
  }

public:
  static int registerComponent( const std::string& component_name, InstantiateComponentMethod method )
  {
    ComponentRegister * inst = instance();
    inst->component_list_[component_name] = method;
    std::cout << "Registered Component: " << component_name << std::endl;
    return 1;
  }

  static darc::Component::Ptr instantiateComponent( const std::string& instance_name, Node::Ptr node )
  {
    ComponentRegister * inst = instance();
    if( inst->component_list_.count(instance_name) )
    {
      return inst->component_list_[instance_name](instance_name, node);
    }
    else
    {
      std::cout << "Component " << instance_name << " not registered" << std::endl;
      assert(0);
      return darc::Component::Ptr();
    }
  }

};

}

#define DARC_REGISTER_COMPONENT(classname) namespace classname##_reg { static int dummy = darc::ComponentRegister::registerComponent( #classname, boost::bind(&darc::Component::instantiate<classname>, _1, _2) ); }

{'fraction_non_alphanumeric': 0.11579285944033452, 'fraction_numerical': 0.002573174654229656, 'mean_word_length': 4.634057971014493, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 22, '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': '4718406', 'n_tokens_mistral': 962, 'n_tokens_neox': 936, 'n_words': 194}