<commit_before>#include <swri_profiler_tools/profile_database.h>
#include <QDebug>

namespace swri_profiler_tools
{
ProfileDatabase::ProfileDatabase()
{
}

ProfileDatabase::~ProfileDatabase()
{
  for (auto &item : profiles_) {
    delete item.second;
  }
}

int ProfileDatabase::createHandle(const QString &name)
{
  if (name.isEmpty()) {
    qWarning("Refusing to create a nameless profile.");
    return -1;
  }

  // Find an available handle
  int handle = profiles_.size();
  while (profiles_.count(handle) != 0) { handle++; }

  // We are creating a new handle
  profiles_[handle] = new Profile();
  Profile &profile = *(profiles_.at(handle));
  profile.initialize(handle, name);

  // todo(elliotjo): connect profile signals here.
    
  Q_EMIT profileAdded(handle);
  return handle;
}

Profile& ProfileDatabase::getProfile(int handle)
{
  if (profiles_.count(handle) == 0) {
    qWarning("Invalid profile handle: %d", handle);
    return invalid_profile_;
  }

  return *(profiles_.at(handle));
}

const Profile& ProfileDatabase::getProfile(int handle) const
{
  if (profiles_.count(handle) == 0) {
    qWarning("Invalid profile handle: %d", handle);
    return invalid_profile_;
  }<commit_msg>Connect profile signals to profile database.<commit_after>#include <swri_profiler_tools/profile_database.h>
#include <QDebug>

namespace swri_profiler_tools
{
ProfileDatabase::ProfileDatabase()
{
}

ProfileDatabase::~ProfileDatabase()
{
  for (auto &item : profiles_) {
    delete item.second;
  }
}

int ProfileDatabase::createHandle(const QString &name)
{
  if (name.isEmpty()) {
    qWarning("Refusing to create a nameless profile.");
    return -1;
  }

  // Find an available handle
  int handle = profiles_.size();
  while (profiles_.count(handle) != 0) { handle++; }

  // We are creating a new handle
  profiles_[handle] = new Profile();
  Profile &profile = *(profiles_.at(handle));
  profile.initialize(handle, name);

  // We rebroadcast the individual profile signals in bulk so that
  // other objects can just connect to us and not deal with
  // adding/removing connections as profiles are added or deleted.
  QObject::connect(&profile, SIGNAL(blocksAdded(int)),
                   this, SIGNAL(blocksAdded(int)));
  QObject::connect(&profile, SIGNAL(dataAdded(int)),
                   this, SIGNAL(dataAdded(int)));
    
  Q_EMIT profileAdded(handle);
  return handle;
}

Profile& ProfileDatabase::getProfile(int handle)
{
  if (profiles_.count(handle) == 0) {
    qWarning("Invalid profile handle: %d", handle);
    return invalid_profile_;
  }

  return *(profiles_.at(handle));
}

const Profile& ProfileDatabase::getProfile(int handle) const
{
  if (profiles_.count(handle) == 0) {
    qWarning("Invalid profile handle: %d", handle);
    return invalid_profile_;
  }
{'fraction_non_alphanumeric': 0.12948350071736012, 'fraction_numerical': 0.0028694404591104736, 'mean_word_length': 4.222846441947565, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3511109', 'n_tokens_mistral': 854, 'n_tokens_neox': 840, 'n_words': 221}