<commit_before>// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once

#include <typeinfo>
#include MEMORY_HEADER

#include "fast_pointer_cast.h"
#include "AnySharedPointer.h"
#include "AutoFilterDescriptor.h"

#include "Object.h"
#include "ContextMember.h"
#include "CoreRunnable.h"
#include "BasicThread.h"
#include "ExceptionFilter.h"
#include "BoltBase.h"

#include "EventRegistry.h"

/// <summary>
/// Mapping and extraction structure used to provide a runtime version of an Object-implementing shared pointer
/// </summary>
struct ObjectTraits {
  template<class T>
  ObjectTraits(const std::shared_ptr<typename SelectTypeUnifier<T>::type>& value, T*) :
    type(typeid(T)),
    stump(SlotInformationStump<T>::s_stump),
    value(value),
    cast_offset(this->value->cast_offset()),
    subscriber(MakeAutoFilterDescriptor(value)),
    pObject(autowiring::fast_pointer_cast<Object>(value)),
    pContextMember(autowiring::fast_pointer_cast<ContextMember>(value)),
    pCoreRunnable(autowiring::fast_pointer_cast<CoreRunnable>(value)),
    pBasicThread(autowiring::fast_pointer_cast<BasicThread>(value)),
    pFilter(autowiring::fast_pointer_cast<ExceptionFilter>(value)),
    pBoltBase(autowiring::fast_pointer_cast<BoltBase>(value)),
    receivesEvents(
      [this]{
        for (auto evt = g_pFirstEventEntry; evt; evt = evt->pFlink) {
          auto identifier = evt->NewTypeIdentifier();
          if (identifier->IsSameAs(pObject.get()))
            return true;
        }
        return false;
      }()
    )
  {
    if(!pObject)
      throw autowiring_error("Cannot add a type which does not implement Object");
  }

  // The declared original type:
  const std::type_info& type;

  /// <summary>
  /// Used to obtain a list of slots defined on this type, for reflection purposes
  /// </summary><commit_msg>Manually check if a type implements AutowiringEvents when checking if a type receives events<commit_after>// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once

#include <typeinfo>
#include MEMORY_HEADER

#include "fast_pointer_cast.h"
#include "AnySharedPointer.h"
#include "AutoFilterDescriptor.h"

#include "AutowiringEvents.h"
#include "Object.h"
#include "ContextMember.h"
#include "CoreRunnable.h"
#include "BasicThread.h"
#include "ExceptionFilter.h"
#include "BoltBase.h"

#include "EventRegistry.h"

/// <summary>
/// Mapping and extraction structure used to provide a runtime version of an Object-implementing shared pointer
/// </summary>
struct ObjectTraits {
  template<class T>
  ObjectTraits(const std::shared_ptr<typename SelectTypeUnifier<T>::type>& value, T*) :
    type(typeid(T)),
    stump(SlotInformationStump<T>::s_stump),
    value(value),
    cast_offset(this->value->cast_offset()),
    subscriber(MakeAutoFilterDescriptor(value)),
    pObject(autowiring::fast_pointer_cast<Object>(value)),
    pContextMember(autowiring::fast_pointer_cast<ContextMember>(value)),
    pCoreRunnable(autowiring::fast_pointer_cast<CoreRunnable>(value)),
    pBasicThread(autowiring::fast_pointer_cast<BasicThread>(value)),
    pFilter(autowiring::fast_pointer_cast<ExceptionFilter>(value)),
    pBoltBase(autowiring::fast_pointer_cast<BoltBase>(value)),
    receivesEvents(
      [this]{
        for (auto evt = g_pFirstEventEntry; evt; evt = evt->pFlink) {
          auto identifier = evt->NewTypeIdentifier();
          if (identifier->IsSameAs(pObject.get()))
            return true;
        }
        return !!dynamic_cast<const AutowiringEvents*>(pObject.get());
      }()
    )
  {
    if(!pObject)
      throw autowiring_error("Cannot add a type which does not implement Object");
  }

  // The declared original type:
  const std::type_info& type;

  /// <summary>
  /// Used to obtain a list of slots defined on this type, for reflection purposes
  /// </summary>
{'fraction_non_alphanumeric': 0.1272066458982347, 'fraction_numerical': 0.004153686396677051, 'mean_word_length': 4.496433666191155, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 44, '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': '1173353', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1185, 'n_words': 265}